SPICE - Write Record to Output File

来源:互联网 发布:网络配线图 编辑:程序博客网 时间:2024/05/15 07:08

Application programs write to SPICE SQL sequential output files with SQL INSERT statements against table SPICE_SAM. They can, optionally, open and/or close the files with variants of SQL UPDATE statements against the table.

01 SPICE-SAM PIC X(18) VALUE '!SPICE!_SAM'.
01 ACTION-OPEN PIC X(18) VALUE '!ACTION!=OPEN_OUT'.
01 OUTDDB-DD PIC X(18) VALUE '!DDNAME!=OUTDDB'.
01 OUTDDB-RECLEN PIC X(18) VALUE '!RECLEN!=151'.

     EXEC SQL
          INCLUDE SPIRINCC
     END-EXEC.

     EXEC SQL UPDATE SPICE_SAM
          SET ACTION=:ACTION-OPEN
          WHERE CATEGORY=:SPICE-SAM AND FILE=:OUTDDB-DD
          AND RECLEN=:OUTDDB-RECLEN
     END-EXEC.

Note:
If an open request is the first reference to the file since a restart, SPICE will restart the file. It will re-position it to its position at the time of the last successful commit point. If SPICE is unable to open the file, an I/O error for instance, anSQLCODE of -681 is returned.
The SQL INSERT statement against the SPICE_SAM table is used to write records to SPICE SAM files.

01 SPICE-SAM PIC X(18) VALUE '!SPICE!_SAM'.
01 OUTDDB-DD PIC X(18) VALUE '!DDNAME!=OUTDDB'.
01 STRUCT-R.
     02 FILL-1 PIC X(5) VALUE 'NAME:'.
     02 NAME PIC X(32).
     02 FILL-2 PIC X(5) VALUE ' AGE '.
     02 AGE PIC X(3) .
     02 FILL-3 PIC X(9) VALUE ' ADDRESS '.
     02 ADDRESS.
          49 ADDRESSL PIC S9(4) COMP.
          49 ADDRESSC PIC X(64).
     02 FILL-4 PIC X(7) VALUE ' PHONE '.
     02 PHONE-NO PIC X(24).

     EXEC SQL
          INCLUDE SPIRINCC
     END-EXEC.

     EXEC SQL 
          INSERT INTO SPICE_SAM
          (CATEGORY,FILE,CHAR_1,CHAR_2,CHAR_3,CHAR_4,INT_1,CHAR_5,
          VARCHAR_1,CHAR_6,CHAR_7)
          VALUES (:SPICE-SAM,:OUTDDB-DD,:STRUCT-R)
     END-EXEC.

The host structure or set of host variables must collate into a single continuous area of storage. Host structures in COBOL programs should not contain any variables named FILLER, as the DB2 precompiler will omit them from the list of data items passed to SPICE SQL.

Note:
If the designated file DD name does not exist, an SQLCODE of -681 is returned.
If this statement is the first reference to the file since a restart, SPICE will restart the file. It will re-position it to its position at the time of the last successful commit point.
If SPICE is unable to write the record, I/O error for instance, an SQLCODE of -681 is returned.

SPICE SAM output files do not need to be explicitly opened or closed. SPICE will automatically open a file upon the first SELECT or UPDATE request to it, and close it during termination.

--------------------------------------------------------------------------------------

01 SPICE-SAM PIC X(18) VALUE '!SPICE!_SAM'.
01 OUTDDC-DD PIC X(18) VALUE '!DDNAME!=OUTDDC'.
     02 STRUCT-C.
          49 L PIC S9(4) COMP.
          49 D PIC X(64).

     EXEC SQL
          INCLUDE SPIRINCC
     END-EXEC.

     MOVE +16 TO STRUCT-C-L.
     MOVE 'A SIMPLE MESSAGE' TO STRUCT-C-C.
     EXEC SQL
          INSERT INTO SPICE_SAM
          (CATEGORY,FILE,VARCHAR_1)
          VALUES (:SPICE-SAM,:OUTDDC-DD,:STRUCT-C)
     END-EXEC.


--------------------------------------------------------------------------------------

01 SPICE-SAM PIC X(18) VALUE '!SPICE!_SAM'.
01 OUTDDA-DD PIC X(18) VALUE '!DDNAME!=OUTDDA'.
01 VAR-A PIC X(128).

     EXEC SQL
          INCLUDE SPIRINCC
     END-EXEC.

     EXEC SQL
          INSERT INTO SPICE_SAM
          (CATEGORY,FILE,CHAR_1)
          VALUES (:SPICE-SAM,:OUTDDA-DD,:VAR-A)
     END-EXEC.


 

原创粉丝点击