TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Write Statement Example


Let's see an example which shows how to insert a record in a new file when the organization is sequential:

COBOL Coding:

IDENTIFICATION DIVISION.
PROGRAM-ID. COBWRITE.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT EMPLOYEE ASSIGN TO EMP-FILE
    ORGANIZATION IS SEQUENTIAL
    ACCESS IS SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD EMPLOYEE.
01 EMPLOYEE-FILE.
   05 EMPLOYEE-ID PIC X(5).
   05 NAME PIC A(10).

PROCEDURE DIVISION.

    OPEN EXTEND EMPLOYEE.
    MOVE '100' TO EMPLOYEE-ID.
    MOVE 'REVATHY' TO NAME.
       WRITE EMPLOYEE-FILE
       END-WRITE.
    CLOSE EMPLOYEE.
    STOP RUN.

Output:

100 REVATHY


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal