DB2 Equivalent COBOL Data Types

As DB2/SQL and COBOL field declarations are different, It is important to have Equivalanet COBOL data types to the corresponding DB2 table columns in COBOL programs to process the data correctly. More importantly, the precompiler uses the equivalent SQL data types for the declared Host variables. So if the host variable declaration is not correct, we might face issues while executing the programs.


Below are the compatible COBOL and SQL data types.

DB2/SQL Data TppeCOBOL Equivalent PIC Clause
INTEGERPIC S9(08) COMP
SMALLINTPIC S9(04) COMP
DATEPIC X(10)
TIMEPIC X(08)
TIMESTAMPPIC X(26)
CHAR(n)PIC X(n)
DECIMAL(x,y)PIC S9(x-y)V9(y)
VARCHAR(n)01 WS-GRP-VAR.
49 WS-LENGTH PIC S9(04) COMP.
49 WS-VAR PIC X(n)

Special care needs to be taken while processing the VARCHAR data in host programs. A group variable consisting of Length and Actual variable as the sub fields needs to be declared. Without the length variable, data gets truncated and inappropriate results encounter.

Refer the below IBM link for more details.

https://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/apsg/src/tpc/db2z_equivalentcoboldatatypes.html

One Comment

Leave a Reply to David Churn Cancel reply

Your email address will not be published. Required fields are marked *

Close Bitnami banner