23. Func='dcl'. DB2 table information

A DCL library is a partitioned dataset containing DCL structures, created by the DB2 dclgen command. The DCL structure describes the fields of a DB2 table. It is intended for use in the access of DB2 from compiled languages like COBOL.

Using func='dcl' implies that input to the action block must be a member of a dataset containing DCL. The action block is triggered once for each field described in the DCL structure. Information about format and field name is then available inside the action block.

The same information may be read from the DB2 system catalogue by using func='sql', but accessing the DCL area might require less coding in the RXS program.

The following variables are assigned values for use inside the action block:

dataname

DB2 field name for current field

datatype

Type of field. Contains DATE TIMESTAMP CHAR DECIMAL VARCHAR, BLOB, CLOB or SMALLINT

length

Number of bytes (Example: 26 for a timestamp) - or maximum number of digits including decimals - if the field type is numeric

decimals

Only if field type is numeric: Number of digits after the decimal point

nulls

A value of '1' if the field holds a null indicator. '0' if the field does not hold a null indicator

Example 23.1:

)action in='ourquali.dcl.cobol(ourtab)'

)&      func='dcl'

if nulls = '1' then do

"      IF OURTAB-"dataname"-I = -1 "

if datatype = 'DECIMAL' ! datatype = 'SMALLINT' then do

"        MOVE ZERO TO OURTAB-"dataname

end

else do

"        MOVE SPACE TO OURTAB-"dataname

end

"      END-IF"

end

)endaction

The resulting COBOL code will initialize all fields in a DB2 structure if they hold a null indicator and if the indicator actually indicates the field to be null. Such coding may come in handy after a successful DB2 select call in COBOL.