Micro Focus COBOL new style and old style

I compared side by side of 2 COBOL code styles and hopefully someone can tell me how to do it:

Old style: ---Connect.sqb

==============================================
       Working-Storage Section.

           copy "sqlenv.cbl".
           copy "sql.cbl".
           copy "sqlca.cbl".

           EXEC SQL BEGIN DECLARE SECTION END-EXEC.
       01 dbalias.
          49 dbalias-len    pic s9(4) comp-5 value 0.
          49 dbalias-buf    pic x(9) value " ".
       01 userid.
          49 userid-len     pic s9(4) comp-5 value 0.
          49 userid-buf     pic x(128) value " ".
       01 pswd.
          49 pswd-len       pic s9(4) comp-5 value 0.
          49 pswd-buf       pic x(19).
           EXEC SQL END DECLARE SECTION END-EXEC.

      PROCEDURE DIVISION.
           display "Enter database alias( 'sample' by default): "
              with no advancing.
           accept dbalias-buf.
           if dbalias-buf = spaces
              move "sample" to dbalias-buf.
           inspect dbalias-buf
              tallying dbalias-len for characters before initial " ".

           display "Enter user id( current by default)        : "
              with no advancing.
           accept userid-buf.
           inspect userid-buf
              tallying userid-len for characters before initial " ".
           if userid-buf not equal spaces
              display "Enter password                            : "
                 with no advancing
              accept pswd-buf.
              inspect pswd-buf
                 tallying pswd-len for characters before initial " ".

           if userid-buf = spaces
              EXEC SQL CONNECT TO :dbalias END-EXEC
           else
              EXEC SQL
                CONNECT TO :dbalias USER :userid USING :pswd
              END-EXEC.

===================================================

I can use db2 command to create both  bind file and cbl file:

db2 prep Connect.sqb  bindfile target mfcob CALL_RESOLUTION DEFERRED

New style: ---Connect.sqb

==============================================

working-storage section.

           EXEC SQL INCLUDE SQLCA END-EXEC.

       01 ws-db        pic x(08).
       01 ws-usr       pic x(08).
       01 ws-pass      pic x(18).

procedure division.

           EXEC SQL
               CONNECT TO :ws-db USER :ws-usr  USING :ws-pass
           END-EXEC

       procedure division.

           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

           EXEC SQL
               CONNECT TO :ws-db USER :ws-usr  USING :ws-pass
           END-EXEC

==========================================

With the new style I can create  both Connect.bnd file and executable from  Visual COBOL eclipse

But with db2 command,

db2 prep Connect.sqb  bindfile target mfcob CALL_RESOLUTION DEFERRED

I create Connect.cbl but no Connect.bnd file with  error:

==================================================

   57   SQL4911N  The host variable data type is not valid.
   81   SQL4002N  "WS-PASS" and "WS-USR" are undeclared host
                  variables that cannot both be used as descriptor names in a
                  single SQL statement.
  110   SQL4002N  "WS-VAR-PASS" and "WS-USR" are undeclared host
                  variables that cannot both be used as descriptor names in a
                  single SQL statement.
        SQL0095N  No bind file was created because of previous
                  errors.

===============================================

Is there anyway -- without changing the code style,  I can make all Visual COBOL embedded samples  working under db2 command line?

Thank you in advance,

-Jack

Parents
  • Thank you, Chris.

      Your code works,  My purpose for that question is -- I am looking for the COBOL syntax working for both Micro Focus DB2 ECM (External Compiler Module)   and  DB2 PREP Precompiler.

     So far as  I can see -- Micro Focus DB2 ECM  makes embedded SQL and COBOL code more seamlessly.

    while DB2 PREP Precompiler requires more embedded directives,  but Micro Focus DB2 ECM  is still compatible with it.  (Can I call it backward compatibility?)

    If I stay with DB2 Prep Style, it should be OK to exchange code between PC and Mainframe.

Reply
  • Thank you, Chris.

      Your code works,  My purpose for that question is -- I am looking for the COBOL syntax working for both Micro Focus DB2 ECM (External Compiler Module)   and  DB2 PREP Precompiler.

     So far as  I can see -- Micro Focus DB2 ECM  makes embedded SQL and COBOL code more seamlessly.

    while DB2 PREP Precompiler requires more embedded directives,  but Micro Focus DB2 ECM  is still compatible with it.  (Can I call it backward compatibility?)

    If I stay with DB2 Prep Style, it should be OK to exchange code between PC and Mainframe.

Children
No Data