I am not a DB2 expert so I am hoping others will chime in here also but the original set of samples that you are using are delivered by IBM and are written to support the syntax supported by the DB2 PREP precompiler. The Samples that are part of Visual COBOL are written to support the Micro Focus DB2 ECM (External Compiler Module) which is the Micro Focus precompiler for DB2. The ECM and PREP precompilers are not the same as there are many extensions made to the ECM to support additional syntax. In order to get the Connect.cbl sample delivered with Visual COBOL to compile using DB2 PREP I had to add the BEGIN DECLARE SECTION and END DECLARE SECTION headers around the host variables and also move the comments within the section to begin in column 7. There may be some additional PREP directives to change this requirement but that would be more of a question for IBM. Why is it that you wish to use the DB2 PREP for everything? If you wish to compile these programs from a .bnat file or from the command line then you can do so from a Visual COBOL Command prompt using the cobol and cbllink commands directly. The connect.sqb after modification looks like: *set db2(db=sample) **************************************************************** * Copyright (C) Micro Focus 2010-2013. All rights reserved. * * This sample code is supplied for demonstration purposes only * on an "as is" basis and is for use at your own risk. * **************************************************************** working-storage section. * Include the SQL Communications Area. This includes the * definitions of SQLCODE, etc EXEC SQL INCLUDE SQLCA END-EXEC. EXEC SQL BEGIN DECLARE SECTION END-EXEC. * DB2 UDB limits database alias names to 8 characters * other DB2 servers such DB2/MVS can have database names up to * 18 characters which you can still access via DB2 CONNECT * by creating an ALIAS name for the database with a max of 8 * characters 01 ws-db pic x(08). * DB2 UDB has a limit of 8 characters for a logon id. * Passwords may be up 18 characters but if you may run into case * and length problems going to other DB2 servers if you use more * than 8 characters or if you use lower case characters in a * password 01 ws-usr pic x(08). 01 ws-pass pic x(18). 01 ws-var-pass. 49 ws-var-pass-len pic s9(04) comp-5. 49 ws-var-pass-dat pic x(18). EXEC SQL END DECLARE SECTION END-EXEC. procedure division. * Connect to an IBM DB2 Sample database display "Connect statement tests" display " " display "Enter database alias to connect to (Eg Sample) " with no advancing accept ws-db display "Enter username " with no advancing accept ws-usr display "Enter password " with no advancing accept ws-pass * test 1 - basic type 1 CONNECT without id or password display "Test 1:" EXEC SQL CONNECT TO :ws-db END-EXEC if sqlcode not = 0 display "Error: cannot connect " display sqlcode display sqlerrmc stop run else display "Test 1: OK" EXEC SQL DISCONNECT CURRENT END-EXEC if sqlcode not = 0 display "Error: cannot disconnect " display sqlcode display sqlerrmc stop run end-if end-if * test2 * type 1 connect with id / password passed as char fields display "Test 2:" EXEC SQL CONNECT TO :ws-db USER :ws-usr USING :ws-pass END-EXEC if sqlcode not = 0 display "Error: cannot connect Test 2 " display sqlcode display sqlerrmc stop run end-if display "Test 2: OK" EXEC SQL DISCONNECT CURRENT END-EXEC if sqlcode not = 0 display "Error: cannot disconnect " display sqlcode display sqlerrmc stop run end-if * test3 * type 1 connect with id / password passed as varchar field display "Test 3:" move 0 to ws-var-pass-len move ws-pass to ws-var-pass-dat inspect ws-pass tallying ws-var-pass-len for characters before initial " " EXEC SQL CONNECT TO :ws-db USER :ws-usr USING :ws-var-pass END-EXEC if sqlcode not = 0 display "Error: cannot connect Test 3 " display sqlcode display sqlerrmc stop run end-if display "Test 3: OK" EXEC SQL CONNECT RESET END-EXEC if sqlcode not = 0 display "Error: cannot disconnect " display sqlcode display sqlerrmc stop run end-if stop run.
↧