Monday, November 28, 2011

Application Progamming(COBOL+DB2)

DCLGEN :

   Declaration Generator .  a tool to generates the equivalent COBOL variables.
   Which can be used to generate host variables with equivalent data types of DB2 columns.

Host variables:

Ø  Can be used to pass the data from cobol program to DB2 table or DB2 table to COBOL program.
Ø  When host variables are coded with sql statements it must be prefixed with : like :hv-cname.
Ø  Table name must be supplied as input to DCLGEN & partition dataset should be as output.
Ø  After creating DCLGEN variables which must be copied to application program in WORKING-STORAGE SECTION  by using include command i.e.
Exec sql
   Inlcude custDCL
End-exec.
Ø  Include & copy have the same functionality

SQLCODE :

Ø  Predefined numeric number which can be used to check SQL statements for successful , unsuccessful execution.
Ø  SQLCODE can be stored in SQLCA(SQL Communication Area)
Ø  Copy SQLCA in WORKING-STORAGE SECTION
Ø  System defined variable
Ø  Evaluate or if statement must be coded to check the SQLCODE immediately after SQL statement.
Ø  SQLCODE =00 ---- successful
                          = +100 --- end of table or record not found.

Sample program:

WORKING-STORAGE SECTION.

            EXEC SQL
                        INCLUDE SQLCA
            END-EXEC

            EXEC SQL
                         INCLUDE CUSTDCL
            END-EXEC.
01 WS-SQL-CODE PIC S9(4)
            88 88-SUCCESS VALUE 00
            88 88-NOTFOUND VALUE 100
            88 88-FORIENG KEY VOILATION VALUE –532
            88 88- MULITPLE ROW VALUE –811



PROCEDURE DIVISION.

            UPDATE CUST
                        SET CNAME = :HV-CNAME
            WHERE CNO=:HV-CNO
            MOVE SQLCODE TO WS-SQLCODE.
            EVALUE WS-SQL-CODE
                        WHEN 88-SUCCESS
                                    DISPLAY “SUCCESSFULLY UPDATED”
                        WHEN 88-NOTFOUND
                                    DISPLAY “ RECORD NOT FOUND”
                        WHEN 88-FOREIGNKEYVOILATION
                                    DISPLAY “ FOREIGN KEY VOILATION”
                        WHEN OTHER
                                    DISPLAY “ ERROR OCCURRED IN UPDATE”
                                    STOP RUN
            END-EVALUATE.
            STOP RUN.

1 comment: