Example: SQL declare section template for COBOL embedded SQL applications
When you are creating
an embedded SQL application in COBOL, there is a template that you
can use to declare your host variables and data structures.
The following code is a sample SQL declare section with a host
variable declared for each supported SQL data type.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
*
01 age PIC S9(4) COMP-5. /* SQL type 500 */
01 divis PIC S9(9) COMP-5. /* SQL type 496 */
01 salary PIC S9(6)V9(3) COMP-3. /* SQL type 484 */
01 bonus USAGE IS COMP-1. /* SQL type 480 */
01 wage USAGE IS COMP-2. /* SQL type 480 */
01 nm PIC X(5). /* SQL type 452 */
01 varchar.
49 leng PIC S9(4) COMP-5. /* SQL type 448 */
49 strg PIC X(14). /* SQL type 448 */
01 longvchar.
49 len PIC S9(4) COMP-5. /* SQL type 456 */
49 str PIC X(6027). /* SQL type 456 */
01 MY-CLOB USAGE IS SQL TYPE IS CLOB(1M). /* SQL type 408 */
01 MY-CLOB-LOCATOR USAGE IS SQL TYPE IS CLOB-LOCATOR. /* SQL type 964 */
01 MY-CLOB-FILE USAGE IS SQL TYPE IS CLOB-FILE. /* SQL type 920 */
01 MY-BLOB USAGE IS SQL TYPE IS BLOB(1M). /* SQL type 404 */
01 MY-BLOB-LOCATOR USAGE IS SQL TYPE IS BLOB-LOCATOR. /* SQL type 960 */
01 MY-BLOB-FILE USAGE IS SQL TYPE IS BLOB-FILE. /* SQL type 916 */
01 MY-DBCLOB USAGE IS SQL TYPE IS DBCLOB(1M). /* SQL type 412 */
01 MY-DBCLOB-LOCATOR USAGE IS SQL TYPE IS DBCLOB-LOCATOR. /* SQL type 968 */
01 MY-DBCLOB-FILE USAGE IS SQL TYPE IS DBCLOB-FILE. /* SQL type 924 */
01 MY-PICTURE PIC G(16000) USAGE IS DISPLAY-1. /* SQL type 464 */
01 dt PIC X(10). /* SQL type 384 */
01 tm PIC X(8). /* SQL type 388 */
01 tmstmp PIC X(26). /* SQL type 392 */
01 wage-ind PIC S9(4) COMP-5. /* SQL type 464 */
*
EXEC SQL END DECLARE SECTION END-EXEC.