Friday, September 18, 2015

DB2 TIPS : VARCHAR

For each VARCHAR in a copybook you need a datastructure with a length-field and a string:

  EXEC SQL DECLARE GB5F.FINIDOC TABLE
  ( PKEY                           TIMESTAMP NOT NULL,
    APDU                           VARCHAR(11000) NOT NULL
  ) END-EXEC.
                
******************************************************************
* COBOL DECLARATION FOR TABLE GB5F.FINIDOC      *
******************************************************************
          01  DCLFINIDOC.
            10 PKEY                 PIC X(26).
            10 APDU.
               49 APDU-LEN          PIC S9(4) USAGE COMP.
               49 APDU-TEXT         PIC X(11000).
       
Long Varchars
The length-field will be defined as PIC S9(4) COMP. If the length of the VARCHAR is greater than 9999, it seems that this length-field will be too short. But DB2 uses the full binary length (2 bytes), so the length of the VARCHAR can be up to 32.767. Normally COBOL recognises only values until 9999. Bigger values will be truncated (data truncation). Data truncation can be switched off by using the compiler option TRUNC(BIN). The default for this option is (STD). When using STD, the result of a MOVE will be truncated after the number of digits according to the picture-clause. The option TRUNC(BIN) must be specified with a PROCESS-statement in the program source before the IDENTIFICATION DIVISION and before the first line of comment.
Example:
        PROCESS TRUNC(BIN)
        *****************************************************************
        *      PROGRAMMA-NAAM : MU01000
                  

No comments:

Post a Comment