3. Embedded SQL for COBOL : Advanced Processing : Sample Programs : Put Handler
 
Share this page                  
Put Handler
This example shows how to read the long varchar chapter_text from a text file and insert it into the database a segment at a time.
IDENTIFICATION DIVISION.
PROGRAM-ID. PUT-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(1000).
01 SEG-LEN PIC s9(9) USAGE COMP.
01 DATA-END 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 ARG-ADDR.
BEGIN.
...
process information passed in via the HDLR-ARG...
open file...
...
MOVE 0 TO DATA-END.
PERFORM UNTIL DATA-END = 1
read segment of less than 1000 chars from file into segbuf...
IF end-of-file
MOVE 1 TO DATA-END
END-IF.
EXEC SQL PUT DATA (SEGMENT = :SEG-BUF,
SEGMENTLENGTH = :SEG-LEN, DATAEND = :DATA-END)
END-EXEC
END-PERFORM.
...
close file ...
set HDLR-ARG to return appropriate values...
...
END PROGRAM PUT-HANDLER.