Takes you through the process of calling your published stored procedure from a COBOL program. 
                  	  
               
            
 
            	 
            
               Save and close the SQLServerSP solution
 
               		 
               		
                
                  		  
                  - From the Visual Studio main menu, click 
                     			 File > Close Solution. 
                     		  
                  
- If prompted to save, click 
                     			 OK. 
                     		  
                  
  
            	 
            
               Create the SQLServerSPCall solution and project
 
               		 
               		
               
                  			
                  		   
                  		   
                  		   
                  		   
                  		  
                  - On the 
                     			 What would you like to do? dialog box, click 
                     			 Create a new project. 
                     		  
                  
- On the 
                     			 Create a new project dialog box, scroll down the list, and select 
                     			 SQL Server Database Project, and then click 
                     			 Next. 
                     			 
                     Attention: Be sure that you select the SQL Server Database Project template for COBOL and Windows as other templates with this name might
                        exist. 
                        			 
                      
- Complete the fields as follows: 
                     			 
                     
                         
                           				   
                           				   
                           				  
                            
                              					 
                               
                                 						
                                 | Project name | SQLServerSPCall |   
                                 						
                                 | Location | c:\tutorials\SQL |  
 
 
- Check 
                     			 Place solution and project in the same directory. 
                     		  
                  
- Click 
                     			 Create. 
                     		  
                  
  
            	  
            	 
            
               Set project properties
 
               		 
               		
                
                  		  
                  - From the 
                     			 Solution Explorer, double-click 
                     			 Properties under your 
                     			 SQLServerSPCall project. 
                     		  
                  
- On the 
                     			 Application tab, change the 
                     			 Output type to 
                     			 Console Application. 
                     		  
                  
- On the 
                     			 SQL tab, select 
                     			 OpenESQL from the 
                     			 ESQL Preprocessor drop-down list. 
                     		  
                  
- Click 
                     			 Add. 
                     		  
                  
- On the 
                     			 Available Directives list, click 
                     			 DBMAN; then click 
                     			 OK. 
                     		  
                  
- Repeat steps 
                     			 3 and 
                     			 4, but this time add the 
                     			 BEHAVIOR directive. 
                     			 
                     Note: The default value for both DBMAN (ADO) and BEHAVIOR (OPTIMIZE) are correct, so you don't need to make any value changes. 
                        			 
                      
- Click 
                     			 Save 
                     			  ; then close the 
                     			 Properties window. ; then close the 
                     			 Properties window.
  
            	 
            
               Code a COBOL program
 
               		 
               		
               You now code a COBOL program to call your stored procedure. 
                  		
               
 
               		
                
                  		  
                  - If 
                     			 StoredProcedure1.cbl is not open in the COBOL editor, double-click it from the 
                     			 Solution Explorer. If it is open, click its tab to bring it into focus. 
                     		  
                  
- Replace all of the code in the program with the following code: 
                     			        program-id. StoredProcedure1 as "SQLServerSPCall.StoredProcedure1".
       data division.
        working-storage section.
        exec sql include sqlca end-exec.
        01 empid       PIC X(6).  *>string.
        01 lastname    PIC X(50). *>string.
        01 firstname   PIC X(50). *>string.
       
        01 connectString  string.
        01 spReturnCode binary-long.
       
        procedure division.
            exec sql connect to "SQLServerDB" end-exec
    
            if sqlcode <> 0
               display "CONNECT FAILED"
            end-if
        
            set empid to "000020"
            exec sql
                 :spReturnCode = call "LookupEMP" (:empid INOUT, :lastname OUT, :firstname OUT)
            end-exec
           
            if sqlcode <> 0
                 display "Call FAILED"
            else
                 display "User = " firstname " " lastname
            end-if
       
            exec sql disconnect all end-exec.
            goback.
           
        end program StoredProcedure1.Note: You could also use the 
                        				OpenESQL Assistant to generate the CALL statement from the 
                        				Auxiliary Code tab and insert it into the program rather than coding it manually as done here. 
                        			 
                      
- Click 
                     			 Save 
                     			  to save 
                     			 StoredProcedure1.cbl. to save 
                     			 StoredProcedure1.cbl.
  
            	 
            
               Run the COBOL Program
 
               		 
               		
                
                  		  
                  - In the COBOL editor, insert a breakpoint at the 
                     			 goback statement. 
                     		  
                  
- Press 
                     			 F5 to run the program in the debugger. 
                     			 
                      When the debugger hits the breakpoint, you should see the following in a generated console window as a result of calling
                        the stored procedure: 
                        				 User = THOMPSON                 MICHAEL 
- Press 
                     			 F5 to stop debugging.