Get Handler
This example shows how to get the long varchar chapter_text from the database and write it to a text file.
IDENTIFICATION DIVISION.
PROGRAM-ID. GET-HANDLER.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
EXEC SQL INCLUDE SQLCA END-EXEC.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 SEG-BUF PIC X(2000).
01 SEG-LEN PIC Z9(6) USAGE COMP.
01 DATA-END PIC Z9(9) USAGE COMP.
01 MAX-LEN PIC S9(9) USAGE COMP.
EXEC SQL end DECLARE SECTION END-EXEC.
LINKAGE SECTION.
01 HDLR-ARG.
02 ARG-CHAR PIC X(100).
02 ARG-INT PIC S9(9) USAGE COMP.
PROCEDURE DIVISION USING HDLR-ARG.
BEGIN.
...
process information passed in via the HDLR-ARG...
open file...
* Get a maximum segment length of 2000 bytes.
MOVE 0 TO DATA-END.
MOVE 2000 TO MAX-LEN.
* seg-len: will contain the length of the segment retrieved.
* seg-buf: will contain a segment of the column chapter_text.
* data-end: will be set to '1' when the entire value in chapter_text has * been retrieved.
PERFORM UNTIL DATA-END = 1
EXEC SQL GET DATA (:SEG-BUF = SEGMENT,
:SEG-LEN = SEGMENTLENGTH,
:DATA-END = DATAEND)
WITH MAXLENGTH = :MAX-LEN
END-EXEC.
write segment to file...
END-PERFORM.
...
set HDLR-ARG to return appropriate values...
END PROGRAM GET-HANDLER.