[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
  DB2/SQL Singleton Select embedded in a COBOL program
  DB2/SQL Add Change Delete program
  DB2/SQL program to read table with cursor
  DB2/SQL load table program
  DB2/SQL program to read a table randomly
  DB2/SQL bare bones skeleton program
  DB2/SQL program to insert a row into a table
  DB2/SQL program to update a row
  DB2/SQL program for handling variable length column
  DB2/SQL program for handling column with null indicator
  Embedded SQL. Short tutorial.
  Examples of DCLGEN. Short tutorial.
  Examples of SQL Joins. Short tutorial.
  Examples of DB2 View. Short tutorial.
  Just Enough SQL/QMF/SPUFI To Be Dangerous
  Sample tables STAFF, ORG, EMP and DEPT
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  Using QMF to Execute Your SQL
  QMF Cheat Sheet. Edit codes. QMF Commands, Text Variables, Usage Codes
  Executing SQL in a batch job
  Using Spufi to Execute Your SQL
  Books on DB2 and SQL
  DB2 and SQL, Structured Query Language manuals
  SQLCODES and Their Causes
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > DB2 and SQL   > Insert a row, in Embedded SQL

Description of the example tables STAFF, ORG, EMP and DEPT

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. 'WORK3'.
000300* WORKSHOP SOLUTION 3
000400* INSERT A ROW OF DATA ON STAFF FOR ID 15 - YOUR NAME
000500 ENVIRONMENT DIVISION.
000600 INPUT-OUTPUT SECTION.
000700 FILE-CONTROL.
000800 DATA DIVISION.
000900 FILE SECTION.
001000 WORKING-STORAGE SECTION.

001300     EXEC SQL
001400            INCLUDE SQLCA
001500     END-EXEC.
001600*    IN PRODUCTION ENVIRONMENT IT IS NOT IN THIS LIBRARY
001700*    SEE PRECOMPILER SYSLIB JCL STATEMENT
001800     EXEC SQL
001900            INCLUDE STAFF
002000     END-EXEC.
002100
002200 01  DISPLAY-SQLCODE PIC Z(8)9-.
002300
002400 01  NULL-NAME       PIC S9(4) COMP VALUE ZERO.
002500 01  NULL-DEPT       PIC S9(4) COMP VALUE ZERO.
002600 01  NULL-JOB        PIC S9(4) COMP VALUE ZERO.
002700 01  NULL-YEARS      PIC S9(4) COMP VALUE ZERO.
002800 01  NULL-SALARY     PIC S9(4) COMP VALUE ZERO.
002900 01  NULL-COMM       PIC S9(4) COMP VALUE ZERO.
003000
003100 PROCEDURE DIVISION.
003200     DISPLAY 'STARTING  PROGRAM work3'.
003300
003400     MOVE 0 TO NULL-NAME, NULL-DEPT, NULL-JOB,
003500               NULL-YEARS, NULL-SALARY, NULL-COMM
003700     MOVE SPACES TO NAME-TEXT
003800     MOVE 15 TO ID-X
003900     MOVE 'JOE DOE ' TO NAME-TEXT
004000     MOVE 9 TO NAME-LEN
004100     MOVE 38 TO DEPT
004200     MOVE 'PRES' TO JOB
004300     MOVE 21 TO YEARS
004400     MOVE 92030 TO SALARY
004500     MOVE 4873.14 TO COMM
004600
004700     EXEC SQL
004800         INSERT INTO STAFF
004900            (ID,     NAME,              DEPT,
005000             JOB,                       YEARS,
005100             SALARY,                    COMM)
005200         VALUES
005300            (:ID-X, :NAME-X:NULL-NAME, :DEPT:NULL-DEPT,
005400             :JOB:NULL-JOB,            :YEARS:NULL-YEARS,
005500             :SALARY:NULL-SALARY,      :COMM:NULL-COMM)
005600
005700     END-EXEC
005800
005900     EVALUATE SQLCODE
006000       WHEN 0
006100         DISPLAY 'SUCCESSFUL '
006200       WHEN +100
006300         DISPLAY 'CANNOT FIND ROW '
006400       WHEN OTHER
006500         GO TO ERROR-EXIT
006600      END-EVALUATE
006700
006800     DISPLAY 'FINISHED NOW'.
006900     GOBACK.
007000
007100 ERROR-EXIT.
007200     MOVE SQLCODE TO DISPLAY-SQLCODE.
007300     DISPLAY 'SQLCODE FOLLOWS' DISPLAY-SQLCODE
007400     GOBACK.
005400**HTTP://theamericanprogrammer.com/db2-sql/index.html



Top of Page




















































































List of books on DB2 and other mainframe topics

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |