This tutorial takes you through the process of migrating a DB2 application to a SQL Server application, using HCOSS to convert
                  labeled duration calculations and managing date formats. 
                  	  
               
            
 
            	 
            SQL Server does not support labeled duration calculations directly. HCOSS handles the conversion to T-SQL to implement the
               DB2 syntax of an EXEC SQL statement using labeled durations. 
               	 
            
 
            	 
            This tutorial also demonstrates binding the application using a post-build event in 
               		Visual Studio. 
               	 
            
 
            	 
            
               Requirements
 
               		 
               		
               Before attempting this tutorial, you must first complete the following tutorials to ensure you have an established SQL Server
                  database named HCO_Test containing the required PROD and TEST schemas and a connection to the HCO_Test database: 
                  		
                  
 
                     		  
                     - Tutorial: Create a SQL Server Database 
                           			  
                        		  
                     
- Tutorial: Create a Database Connection 
                        		  
                     
- Tutorial: DB2 Database Migration or 
                        			 Tutorial: Setup for Application Migration Tutorials 
                        		  
                     
  
            	 
            
               Visual Studio Solution 
               
 
               		 
               		
                The 
                  		  Visual Studio solution we provide for this tutorial contains 
                  		  two HCOSS projects. The 
                  		  LBLDURATION project is a native COBOL project. 
                  		  The 
                     			 MLBLDURATION project is a managed COBOL project. However, the COBOL code is the same in both projects. 
                  		
               
 
               	 
              
            	 
            
               Phase 1: Start 
                  		  Enterprise Developer and HCO for SQL Server Tools
               
 
               		 
               		
               If 
                  		  Enterprise Developer and HCOSS for SQL Server tools are already running, skip this phase. 
                  		
               
 
               		
                
                  		  
                  - Start 
                     			 Enterprise Developer as an administrator. This procedure varies depending on your Windows version. If you need instructions, see 
                     			 To start 
                        				Enterprise Developer as an administrator. 
                     		  
                  
- In 
                     			 Visual Studio, click 
                     			 View > Micro Focus SQL Tools > HCO for SQL Server Tools. 
                     		  
                  
  
            	 
            
               Phase 2: Analyze, Build, and Bind the Native Application
 
               		 
               		
                
                  		   
                  			 
                  - Analyze the Native Application 
                     			 
                  
-  
                     				
                      
                        				  
                        - In 
                           					 Visual Studio, 
                           					 open the solution named 
                           					 LBLDURATION, which is located in the 
                           					 %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\hcoss\LBLDURATION directory. 
                           				  
                        
- From the 
                           					 Solution Explorer, 
                           					  open the 
                           					 LBLDURATION.cbl file to view its contents. Pay particular attention to the following EXEC SQL statement: 
                           					            EXEC SQL 
               DECLARE CSR69 CURSOR FOR SELECT 
                A.PROJNO
               ,A.PROJNAME
               ,A.PRSTDATE
               ,A.PRENDATE
               ,(((DAYS(A.PRENDATE) - DAYS(A.PRSTDATE) ) / 7) + 1) * 40 
               AS MANHOURS
               FROM PROJ A
               ORDER BY A.PROJNAME
           END-EXECThis contains your labeled duration calculation: 
                              						 ,(((DAYS(A.PRENDATE) - DAYS(A.PRSTDATE) ) / 7) + 1) * 40 
In this case, you are using the DAYS labeled duration in a calculation where you: 
                              					 
                                
                                 						
                                 - Start with the number of days between the start and end date for projects 
                                    						
                                 
- Divide that number by 7 to get the number of weeks 
                                    						
                                 
- Add 1 to account for truncation of a partial week 
                                    						
                                 
- Multiply that result by 40 to get the number of hours needed to complete the project 
                                    						
                                 
 
- Close the code editor. 
                           				  
                        
- Open the project properties for the 
                           					 LBLDURATION project. 
                           				  
                        
- Notice that the 
                           					 Output type on the 
                           					 Application tab is 
                           					 Console Application. 
                           				  
                        
- Switch to the 
                           					 COBOL tab, and set the following: 
                           					 
                           
                               
                                 						  
                                  
                                    							 
                                     
                                       								
                                       | Configuration | Debug |   
                                       								
                                       | Platform target | x86 (default) |  
 
 
- Switch to the 
                              						SQL tab. Several OpenESQL compiler directives have been set for you. The following table offers a brief description of each: 
                           					 
                           
                               
                                 						  
                                  
                                    							 
                                     
                                       								
                                       | SQL(DBMAN=ODBC) | Uses an ODBC connection |   
                                       								
                                       | SQL(TARGETDB=MSSQLSERVER) | Target database is SQL Server |   
                                       								
                                       | SQL(DB=HCODemo) | SQL Server connection name is HCODemo |   
                                       								
                                       | SQL(DIALECT=MAINFRAME) | HCOSS database syntax conversion is enabled |   
                                       								
                                       | SQL(DBRMLIB) | EXEC-SQL commands are extracted and placed in database request module (DBRM) |   
                                       								
                                       | SQL(DATE=USA) | Date output is in USA format |   
                                       								
                                       | SQL(INIT) | Initiates the database connection |   
                                       								
                                       | SQL(QUALIFIER=TEST) | Schema qualifier is TEST |   
                                       								
                                       | SQL(NOCHECK) | No SQL compile-time checking performed |   
                                       								
                                       | SQL(BEHAVIOR=OPTIMIZED) | Optimizes migration process |  
 
 
 
- Define a Post-Build Event 
                     			 
                  
-  
                     				
                      
                        				  
                        - In the Properties window, 
                           					 click the 
                              						COBOL tab; then click 
                                 						  Build Events. 
                           				  
                        
- In the Post build event command line field, type the following command: 
                           					 DSN SYSTEM(HCODemo) @"$(ProjectDir)LBLDURATION.hcodsn" This command calls the DSN Bind utility, specifies the SQL database connection to use, and states the location and name of
                              a bind script file. 
                              						Visual Studio executes this event immediately after building the application, automatically binding the application at that time. 
                              					 
                            
- Click 
                           					 OK to close the 
                              						Build Events dialog box. 
                           				  
                        
 
- View the Contents of the Bind Script File 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the 
                           					 Solution Explorer, open and review the content of 
                           					 LBLDURATION.hcodsn. This bind script file contains one BIND PLAN command that binds the LBLDURATION member into a plan named LBLDURATION. 
                           				  
                        
 
- Build and Bind the Applcation 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the 
                           					 Solution Explorer, rebuild the 
                           					 LBLDURATION project, thereby generating a DBRM for the application and automatically binding it to the DBRM using the post-build event.
                           
                           				  
                        
- Verify that the project built successfully. 
                           				  
                        
 
- Verify the Results 
                     			 
                  
-  
                     				
                      
                        				  
                        - Using Microsoft SQL Server Management Studio, connect to your SQL Server instance. 
                           				  
                        
- On the Object Explorer, expand 
                           					 Databases > HCO_Test > Programmability > Stored Procedures to see the stored procedures HCOSS created when you executed your packages and plan. 
                           				  
                        
- Open the stored procedure named 
                           					 PLN:LBLDURATION.LBLDURATIONconsistency-token$0, where 
                           					 consistency-token is the value of the generated consistency token. 
                           					 
                           In this, you see the SQL from your application code. You also see that HCOSS has converted the original DB2 DAYS expression
                              into T-SQL syntax that recreates the same functionality in SQL Server. This is due to having set the SQL(DIALECT=MAINFRAME)
                              directive when you compiled. 
                              					 
                            
 
  
            	 
            
               Phase 3: Run the Native Application
 
               		 
               		
                
                  		  
                  - From the 
                     			 Solution Explorer, open the 
                     			 LBLDURATION.cbl source file. 
                     		  
                  
- Set a break point on the GO BACK line. 
                     		  
                  
- Press 
                     			 F5 to start debugging. 
                     		  
                  
- Use the tools available from the 
                     			 Debug toolbar or menu to continue to your breakpoint. 
                     		  
                  
You see from the output that your results show the hours required to complete each project. All output dates are in USA format.
                  
                  		
               
 
               		 
               	 
              
            	 
            
               Phase 4: Analyze, Build, Bind, and Run the Managed Application
 
               		 
               		
                
                  		   
                  			 
                  - Analyze the Managed Application 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the Solution Explorer, switch the starting project: Right-click the 
                           					 MLBLDURATION project and select 
                           					 Set as StartUp Project. 
                           				  
                        
- Open the project properties for the 
                           					 MLBLDURATION project. 
                           				  
                        
- Click the 
                           					 SQL tab. 
                           					 
                           Notice the directive settings for the OpenESQL ESQL Preprocessor include SQL(DBMAN=ADO). This means that we're using the ADO.NET
                              database connection rather than the ODBC database connection. 
                              					 
                            Also notice the SQL(DATE=EUR) directive, which specifies the European output format. 
                              					 
                            
 
- Define a Post-Build Event 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the Properties window add a post-build event to execute the following command (same command you used for the native project):
                           
                           					 DSN SYSTEM(HCODemo) @"$(ProjectDir)LBLDURATION.hcodsn" 
- Close the Properties window. 
                           				  
                        
 
- Build and Bind the Managed Application 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the Solution Explorer, right-click the 
                           					 MLBLDURATION project and select 
                           					 Rebuild. 
                           				  
                        
 
- Run the Managed Application 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the Solution Explorer in Visual Studio, open the 
                           					 LBLDURATION.cbl source file. 
                           				  
                        
- Set a break point on the GO BACK line. 
                           				  
                        
- Run the application. 
                           				  
                        
 
  
            	 
            This completes the tutorial.