Tutorialspoint

COBOL Two-Dimensional Table

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-TABLE.
      05 WS-A OCCURS 2 TIMES.
         10 WS-B PIC A(10) VALUE ' TUTORIALS'.
         10 WS-C OCCURS 2 TIMES.
            15 WS-D PIC X(6) VALUE ' POINT'.

PROCEDURE DIVISION.
   DISPLAY "TWO-D TABLE : "WS-TABLE.

STOP RUN.

COBOL Replacing String Handling

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-STRING PIC X(15) VALUE 'ABCDACDADEAAAFF'.

PROCEDURE DIVISION.
   DISPLAY "OLD STRING : "WS-STRING.
   INSPECT WS-STRING REPLACING ALL 'A' BY 'X'.
   DISPLAY "NEW STRING : "WS-STRING.
   
STOP RUN.

COBOL GO TO Statement

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-A PIC 9 VALUE 2.
   
PROCEDURE DIVISION.
   A-PARA.
   DISPLAY 'IN A-PARA'
   GO TO B-PARA.
   
   B-PARA.
   DISPLAY 'IN B-PARA '.
   GO TO C-PARA D-PARA DEPENDING ON WS-A.
   
   C-PARA.
   DISPLAY 'IN C-PARA '.
   
   D-PARA.
   DISPLAY 'IN D-PARA '.
   STOP RUN.

COBOL Perform Varying

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-A PIC 9 VALUE 0.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM B-PARA VARYING WS-A FROM 1 BY 1 UNTIL WS-A=5
   STOP RUN.
   
   B-PARA.
   DISPLAY 'IN B-PARA ' WS-A.

COBOL Perform Times Loop

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM B-PARA 3 TIMES.
   STOP RUN.
   
   B-PARA.
   DISPLAY 'IN B-PARA'.

COBOL Perform Until Loop

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-CNT PIC 9(1) VALUE 0. 

PROCEDURE DIVISION.
   A-PARA.
   PERFORM B-PARA WITH TEST AFTER UNTIL WS-CNT>3.
   STOP RUN.
   
   B-PARA.
   DISPLAY 'WS-CNT : 'WS-CNT.
   ADD 1 TO WS-CNT.

COBOL Loop Perform Thru

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

PROCEDURE DIVISION.
   A-PARA.
   PERFORM DISPLAY 'IN A-PARA'
   END-PERFORM.
   PERFORM C-PARA THRU E-PARA.
   
   B-PARA.
   DISPLAY 'IN B-PARA'.
   STOP RUN.
   
   C-PARA.
   DISPLAY 'IN C-PARA'.
   
   D-PARA.
   DISPLAY 'IN D-PARA'.
   
   E-PARA.
   DISPLAY 'IN E-PARA'.

COBOL Evaluate Verb

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-A PIC 9 VALUE 0.
   
PROCEDURE DIVISION.
   MOVE 3 TO WS-A.
   
   EVALUATE TRUE
      WHEN WS-A > 2
         DISPLAY 'WS-A GREATER THAN 2'

      WHEN WS-A < 0
         DISPLAY 'WS-A LESS THAN 0'

      WHEN OTHER
         DISPLAY 'INVALID VALUE OF WS-A'
   END-EVALUATE.
   
STOP RUN.

COBOL Combined Condition

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(2) VALUE 20.
   01 WS-NUM2 PIC 9(2) VALUE 25.
   01 WS-NUM3 PIC 9(2) VALUE 20.

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   
   IF WS-NUM1 IS LESS THAN WS-NUM2 AND WS-NUM1=WS-NUM3 THEN
      DISPLAY 'Both condition OK'
   ELSE
      DISPLAY 'Error'
   END-IF.
   
STOP RUN.

COBOL Negated Condition

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.

DATA DIVISION.
   WORKING-STORAGE SECTION.
   01 WS-NUM1 PIC 9(2) VALUE 20.
   01 WS-NUM2 PIC 9(9) VALUE 25.

PROCEDURE DIVISION.
   A000-FIRST-PARA.
   
   IF NOT WS-NUM1 IS LESS THAN WS-NUM2 THEN
      DISPLAY 'IF-BLOCK'
   ELSE
      DISPLAY 'ELSE-BLOCK'
   END-IF.
   
STOP RUN.

Advertisements
Loading...