This tutorial takes you through the process of migrating a DB2 application to a SQL Server application, using HCOSS to add
                  function emulation. 
                  	  
               
            
 
            	 
            This tutorial demonstrates adding function emulation by taking you through the process of: 
               	 
               
 
                  		
                  - Adding math functions to SQL Server that represent standard math functions in DB2. 
                     		
                  
- Mapping the DB2 functions to the new SQL Server functions using the Customize SQL Name Mapping tool. 
                     		
                  
This tutorial also demonstrates binding the application using a post-build event in 
               		Eclipse. 
               	 
            
 
            	 
            
               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 
                        		  
                     
  
            	 
            
               Eclipse Project 
               
 
               		 
               		
                The 
                  		  Eclipse project we provide for this tutorial contains 
                  		  the 
                  		  FunctionEmulation project, which is a native COBOL project. 
                  		   
                  		
               
 
               	 
              
            	 
            
               Phase 1: Create User-defined Functions
 
               		 
               		
                
                  		  
                  - Launch SQL Server Management Studio, and select the 
                     			 HCO_Test database. 
                     		  
                  
- Navigate to and open the 
                     			 FunctionEmulation.sql file, located in the 
                     			 %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\hcoss\FunctionEmulation directory. 
                     			 
                      This file contains a script that creates some user defined math functions needed by the example code. 
                        			 
                      
- Click 
                     			 Execute. 
                     		  
                  
- From the Object Explorer expand and select 
                     			 HCO_Test > Programmability > Functions > Scalar-Valued Functions and 
                     			 Refresh this folder. You should now see the newly created functions. 
                     		  
                  
  
            	 
            
               Phase 2: 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 
                     			 Eclipse, click 
                     			 Run > Tools > Data Tools > HCO for SQL Server. 
                     		  
                  
  
            	 
            
               Phase 3: Map the Functions for HCOSS
 
               		 
               		
                
                  		  
                  - From the HCO for SQL Server interface, click 
                     			 Customize SQL Name Mappings. 
                     		  
                  
- Scroll to the bottom of the grid and double-click in the first empty cell to activate it for editing. Type the following information
                     in the appropriate rows and columns, and check the corresponding 
                     			 Is Function box for each: 
                     			 
                     
                         
                           				   
                           				   
                           				  
                            
                              					 
                               
                                 						
                                 | DB2 Function/Special Register | SQL Server Equivalent |   
                                 						
                                 | atanh | dbo.atanh |   
                                 						
                                 | cosh | dbo.cosh |   
                                 						
                                 | sinh | dbo.sinh |   
                                 						
                                 | tanh | dbo.tanh |  
 
 
- Click 
                     			 Save to save the mappings. 
                     		  
                  
  
            	 
            
               Phase 4: Analyze, Build, and Bind the Native Application 
 
               		 
               		
                
                  		   
                  			 
                  - Analyze the Native Application 
                     			 
                  
-  
                     				
                      
                        				   
                        				  
                        - From the Eclipse IDE, click 
                           					 File > 
                           					 Import. 
                           				  
                        
- Expand 
                           					 General, and select 
                           					 Existing Projects into Workspace; then click 
                           					 Next. 
                           				  
                        
- Select 
                           					 Set root directory; then browse to the 
                           					 %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Mainframe\SQL\hcoss\FunctionEmulation directory, and click 
                           					 Apply and Close. 
                           				  
                        
- On the 
                           					 Projects list, check 
                           					 FunctionEmulation. 
                           				  
                        
- Check 
                           					 Copy projects into workspace. 
                           				  
                        
- Click 
                           					 Finish. Eclipse loads the project and builds it automatically. 
                           				  
                        
- From the 
                           					 COBOL Explorer, 
                           					  expand 
                              						FunctionEmulation > COBOL Programs; then double-click the 
                           					 FunctionEmulation.cbl file to view its contents.Pay particular attention to the EXEC SQL statement that references the user-defined functions.
                           
                           				  
                        
- Close the code editor. 
                           				  
                        
- Open the project properties for the 
                           					 FunctionEmulation project. 
                           				  
                        
- Expand 
                              						Micro Focus > Project Settings > COBOL; then select 
                              						SQL Settings. Several OpenESQL compiler directives have been set for you. The following table offers a brief description of each: 
                           					 
                           
                               
                                 						  
                                  
                                    							 
                                     
                                       								
                                       | 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(INIT) | Initiates the database connection |   
                                       								
                                       | SQL(NOCHECK) | No SQL compile-time checking performed |   
                                       								
                                       | SQL(BEHAVIOR=OPTIMIZED) | Optimizes migration process |  
 
 
 
- Define a Post-Build Event 
                     			 
                  
-  
                     				
                      
                        				  
                        - In the Properties window, 
                           					 expand 
                              						Micro Focus > Build Configurations > Events. 
                           				  
                        
- In the Post build event command line field, type the following command: 
                           					 DSN SYSTEM(HCODemo) @"FunctionEmulation.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. 
                              						Eclipse executes this event immediately after building the application, automatically binding the application at that time. 
                              					 
                            
- Click 
                           					 Apply and Close. Eclipse builds the native application automatically. 
                           				  
                        
 
- View the Contents of the Bind Script File 
                     			 
                  
-  
                     				
                      
                        				  
                        - From the 
                           					 COBOL Explorer, open and review the content of 
                           					 FunctionEmulation.hcodsn. This bind script file contains one BIND PLAN command that binds the FunctionEmulation member into a plan named FunctionEmulation.
                           
                           				  
                        
 
- 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 one of the stored procedures that contains 
                           					 PLN as part of its name. 
                           					 
                           In this, you see your application code making the calls to the user-defined functions. 
                              					 
                            
 
  
            	 
            
               Phase 5: Run the Native Application
 
               		 
               		
                
                  		  
                  - From the 
                     			 COBOL Explorer, open the 
                     			 FunctionEmulation.cbl source file. 
                     		  
                  
- Set a break point on the line containing 
                     			 if sqlcode = 0. 
                     		  
                  
- Click 
                     			 Run > Debug to start debugging. 
                     		  
                  
- If prompted with the Debug As dialog box, select 
                     			 COBOL Application; then click 
                     			 OK. 
                     		  
                  
- When prompted to open the Debug perspective, click 
                     			 Yes. 
                     		  
                  
- Click 
                     			 Resume to continue to your breakpoint. 
                     		  
                  
You should see from the output that the results are calculations performed by your user-defined functions. 
                  		
               
 
               		
               Note: If the output window is not visible, minimize Eclipse to reveal it. 
                  		
               
 
               	 
              
            	  
            	 
            This completes the tutorial.