You are on page 1of 28

LAB EXERCISE-MODULE:COBOL

COBCOMP

//MTPLB21S JOB ,,LINES=(1,CANCEL),


// CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1),
// NOTIFY=MTPLB21
//* EXAMPLE JCL TO COMPILE & LINK COBOL BATCH PROGRAM
//*JOBPROC JCLLIB ORDER=NREDDY.SAMPLE.PROC
//COBCL EXEC IGYWCL,
// PGMLIB=MTPLB21.COBOL.LOADLIB, =>LOADMOUDEL DATASET NAME
// GOPGM=INITIAL
//COBOL.SYSIN DD DSN=MTPLB21.COBOL.JAIKUM(SORTFILE),DISP=SHR
//COBOL.SYSLIB DD DSN=MTPLB21.COBOL.JAIKUM,DISP=SHR ==>COPY LIBRARY
//

COBRUN

//MTPLB21J JOB ,,
// CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1),LINES=(1,CANCEL),
// NOTIFY=MTPLB21
//RUN EXEC PGM=INITIAL
//*DD1 DD DSN=MTPLB21.COBOL.PRI4,DISP=SHR
//*DD3 DD DSN=MTPLB21.COBOL.PRI5,DISP=OLD
//* UNIT=SYSDA,VOL=SER=MTBLR1,
//* SPACE=(TRK,(1,2),RLSE),
//* DCB=(LRECL=80,RECFM=FB,BLKSIZE=800)
//STEPLIB DD DSN=MTPLB21.COBOL.LOADLIB,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD DUMMY
//

[WHEN WE DO COBOL PGMS. IN ORDER TO EXECUTE THE PROGRAMS COPY COBCOMP & COBRUN
TO THE PDS CONTAINING OUR COBOL PGMS
COBCOMP
-------
IF PDS IS MTPLB21.COBOL.JAIKUM & MEMBER = SORTFILE THEN IN COBCOMP GIVE
//COBOL.SYSIN DD DSN=MTPLB21.COBOL.JAIKUM(SORTFILE),DISP=SHR
//COBOL.SYSLIB DD DSN=MTPLB21.COBOL.JAIKUM,DISP=SHR ==>COPY LIBRARY
COBRUN
------
IF THERE IS INPUT TO GIVE CHANGE
//SYSIN DD DUMMY
AS
//SYSIN DD *
---
---
--- (INPUT)
//

1
IT IS A MUST IN SORT & MERGE PGMS TO GIVE
//SYSOUT DD SYSOUT=*
IF THERE IS DD NAMES GIVE THAT AS
//DD1 DD DSN=MTPLB21.COBOL.PRI4,DISP=SHR
//DD3 DD DSN=MTPLB21.COBOL.PRI5,DISP=OLD
]

PGM1 : SAMPLE PROGRAM


IDENTIFICATION DIVISION.
PROGRAM-ID SAMPLE.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(2) VALUE 20.
01 B PIC 9(3) VALUE 30.
01 C PIC 9(3) VALUE ZEROS.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'THE SUM IS'.
ADD A,B GIVING C.
DISPLAY C.
STOP RUN.

PGM2 : ADDITION

IDENTIFICATION DIVISION.
PROGRAM-ID SAMPLE.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(2).
01 B PIC 9(2).
01 C PIC Z99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'ENTER THE VALUE FOR A'
ACCEPT A
DISPLAY 'ENTER THE VALUE FOR B'
ACCEPT B
ADD A, B GIVING C.
DISPLAY C.
STOP RUN.

PGM3 : SUBTRACT
IDENTIFICATION DIVISION.
PROGRAM-ID SUBST.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(2).
01 B PIC 9(2).

2
01 C PIC +99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'ENTER THE VALUE FOR A'
ACCEPT A
DISPLAY 'ENTER THE VALUE FOR B'
ACCEPT B
SUBTRACT A FROM B GIVING C.
DISPLAY C.
STOP RUN.

PGM4 : MULTIPLY
IDENTIFICATION DIVISION.
PROGRAM-ID MULTI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 9(2).
01 B PIC 9(2).
01 C PIC ZZ99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'ENTER THE VALUE FOR A'
ACCEPT A
DISPLAY 'ENTER THE VALUE FOR B'
ACCEPT B
MULTIPLY A BY B GIVING C.
DISPLAY C.
STOP RUN.

PGM5 : DIVISION
IDENTIFICATION DIVISION.
PROGRAM-ID DIVIS.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 99.
01 B PIC 99.
01 C PIC 99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY 'ENTER THE VALUE FOR A'.
ACCEPT A.
DISPLAY 'ENTER THE VALUE FOR B'.
ACCEPT B.
DIVIDE B INTO A GIVING C.
DISPLAY 'THE RESULT IS'
DISPLAY C.
STOP RUN.

PGM6 : MOVE

3
IDENTIFICATION DIVISION.
PROGRAM-ID REDEFI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MSG-FLD PIC X(10) VALUE IS 'HAI'.
01 DATA-FLD PIC X(10).
01 OLD-ADDR.
05 NOM PIC X(5) VALUE IS '123'.
05 NAME PIC X(15) VALUE IS 'ABCDEF'.
01 NEW-ADDR.
05 N-NO PIC X(5).
05 N-NAME PIC X(15).
PROCEDURE DIVISION.
MAIN-PARA.
MOVE MSG-FLD TO DATA-FLD.
MOVE OLD-ADDR TO NEW-ADDR.
DISPLAY DATA-FLD.
DISPLAY NEW-ADDR.
STOP RUN.

PGM7: LAB PGM11 : DISPLAY


IDENTIFICATION DIVISION.
PROGRAM-ID.PGM11.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY 'HELLO WELCOME TO MAINFRAMES'
STOP RUN.

PGM8 : LAB PGM12 : ADD,SUBTRACT,DIVIDE,MULTIPLY


IDENTIFICATION DIVISION.
PROGRAM-ID.PGM12.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FLD1 PIC 9(2).
01 FLD2 PIC 9(3).
01 FLD3 PIC 9(4)V99.
77 FLD4 PIC 9(5).
77 FLD5 PIC 9(5)V99.
77 SUM1 PIC 9(4)V99.
77 SUM11 PIC Z(3)9.99.
77 SUBS PIC 9(3).
77 SUBS1 PIC ZZ9.
77 DIVI PIC 9(6).
77 DIVI1 PIC ZZZZZ9.
77 PROD PIC 9(7)V99.
77 PROD1 PIC Z(6)9.99.
PROCEDURE DIVISION.

4
MAIN-PARA.
DISPLAY 'ENTER THE FIRST NO.'.
ACCEPT FLD1.
DISPLAY 'ENTER THE SECOND NO.'.
ACCEPT FLD2.
DISPLAY 'ENTER THE THIRD NO.'.
ACCEPT FLD3.
DISPLAY 'ENTER THE FOURTH NO.'.
ACCEPT FLD4.
DISPLAY 'ENTER THE FIFTH NO.'.
ACCEPT FLD5.
ADD FLD1, FLD2 GIVING SUM1.
DISPLAY SUM1.
SUBTRACT FLD2 FROM FLD3 GIVING SUBS.
DISPLAY SUBS.
DIVIDE FLD4 BY FLD2 GIVING DIVI.
DISPLAY DIVI.
MULTIPLY FLD5 BY FLD1 GIVING PROD.
DISPLAY PROD.
COMPUTE SUM1 = FLD1 + FLD2.
MOVE SUM1 TO SUM11.
DISPLAY SUM11.
COMPUTE SUBS = FLD3 - FLD2.
MOVE SUBS TO SUBS1.
DISPLAY SUBS1.
COMPUTE DIVI = FLD4 / FLD2.
MOVE DIVI TO DIVI1.
DISPLAY DIVI1.
COMPUTE PROD = FLD5 * FLD1.
MOVE PROD TO PROD1.
DISPLAY PROD1.
STOP RUN.
[ INPUT
-----
//SYSIN DD *
60
100
100000
60000
0070000
OUTPUT
------
SUM = 160.00
SUBS = 900
DIVI = 600
PROD = 42000.00 ]

PGM9 : LAB PGM13 : MOVE CORRESPONDING


IDENTIFICATION DIVISION.
PROGRAM-ID PGM13.
ENVIRONMENT DIVISION.

5
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP1.
05 AAA PIC X(12).
05 BBB PIC A(10).
05 CCC PIC X(10).
01 GRP2.
05 BBB PIC A(10).
05 FILL1 PIC X(2).
05 AAA PIC X(12).
05 FILL2 PIC X(2).
05 CCC PIC X(10).
05 FILL3 PIC X(2).
PROCEDURE DIVISION.
MAIN-PARA.
ACCEPT AAA OF GRP1.
ACCEPT BBB OF GRP1.
ACCEPT CCC OF GRP1.
MOVE CORRESPONDING GRP1 TO GRP2.
DISPLAY GRP2.
STOP RUN.
[ INPUT
-----
//SYSIN DD *
COBOLPROGRAM1
COMPUTEVER
MULTIPLY12
//
SAME OUTPUT]

PGM10 : LAB PGM211 : REDEFINES


IDENTIFICATION DIVISION.
PROGRAM-ID REDEFI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X1.
02 Y PIC 99.
02 Y1 REDEFINES Y PIC XX.
01 X3.
02 Z PIC X VALUE "M".
02 ZZ PIC X(25) VALUE ALL "*".
02 ZZZ PIC X(45) VALUE ALL "-".
01 X4 REDEFINES X3.
02 FILL1 PIC X.
02 FILL2 PIC X(70).
01 X5 REDEFINES X4.
02 BUFFER PIC X(71).
PROCEDURE DIVISION.
MAIN-PARA.
MOVE 20 TO Y.

6
DISPLAY X1.
MOVE "A1" TO Y1.
DISPLAY X1.
DISPLAY X3.
DISPLAY X4.
DISPLAY X5.
STOP RUN.

PGM11 : LAB PGM212 : RENAMES


IDENTIFICATION DIVISION.
PROGRAM-ID REDEFI.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PAY.
02 FIXED-PAY.
10 E-BASIC PIC 9(6).99.
10 E-DA PIC 9(6).99.
05 ADDL-PAY.
10 HRA PIC 9(4).99.
10 INCENTIVE PIC 9(3).99.
05 DEDUCTIONS.
10 E-PF PIC 9(3).99.
10 E-IT PIC 9(4).99.
10 OTHERS PIC 9(3).99.
66 PAY-LESS-BASIC RENAMES E-DA THRU INCENTIVE.
66 IT-AND-PF RENAMES E-PF THRU E-IT.
PROCEDURE DIVISION.
MAIN-PARA.
MOVE 123456.78 TO E-BASIC.
MOVE 234567.89 TO E-DA.
MOVE 1234.56 TO HRA.
MOVE 123.45 TO INCENTIVE.
MOVE 123.45 TO E-PF.
MOVE 1234.56 TO E-IT.
MOVE 123.45 TO OTHERS.
DISPLAY PAY.
DISPLAY FIXED-PAY.
DISPLAY ADDL-PAY.
DISPLAY DEDUCTIONS.
DISPLAY PAY-LESS-BASIC.
DISPLAY IT-AND-PF.
STOP RUN.

PGM12 : LAB PGM22 : REFERENCE MODIFICATION & INLINE PERFORM


IDENTIFICATION DIVISION.
PROGRAM-ID. PGM22.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 STR1 PIC X(10) VALUE 'MATHEMATI'.

7
01 STR2 PIC X(10).
77 I PIC 99.
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM VARYING I FROM 1 BY 1 UNTIL STR1 = STR2
MOVE STR1(1:I) TO STR2
DISPLAY STR2
* DISPLAY I
IF STR1 = STR2
DISPLAY "LENGTH OF " STR1 "IS " I
END-IF
END-PERFORM.
STOP RUN.
[OUTPUT
------
M
MA
MAT
MATH
MATHE
MATHEM
MATHEMA
MATHEMAT
MATHEMATI
LENGHT OF MATHEMATI IS O9]

PGM13 : NEXT SENTENCE & CONTINUE


IDENTIFICATION DIVISION.
PROGRAM-ID. PGM22.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC 999 VALUE 555.
01 B PIC 999 VALUE 555.
01 C PIC XX VALUE 'AP'.
01 D PIC XX VALUE 'AP'.
77 K PIC XXX VALUE 'HAI'.
77 M PIC XXXXX VALUE 'HELLO'.
PROCEDURE DIVISION.
NEXT-PARA.
IF A = B
IF C = D
NEXT SENTENCE
ELSE
DISPLAY "CONTROL PASSED TO C<>D PART"
END-IF
DISPLAY "HI"
DISPLAY "THIS COMES AS C<>D "
END-IF.
DISPLAY "CONTROL COMES OUT OF WHOLE LOOP".
DISPLAY "NEXT SENTENCE GOT EXECUTED".

8
CONT-PARA.
IF K = "HAI"
IF M = "HELLO"
CONTINUE
ELSE
DISPLAY "CONTROL PASSED TO M<>HELLO"
END-IF
DISPLAY "HI"
DISPLAY "M=HELLO--SO CONTROL COMES OUT OF CURRENT IF".
END-IF.
LAST-PARA.
STOP RUN.

[OUTPUT
------
CONTROL COMES OUT OF WHOLE LOOP
NEXT SENTENCE GOT EXECUTED
HI
M=HELLO--SO CONTROL COMES OUT OF CURRENT IF]

PGM14 : EVALUATE
IDENTIFICATION DIVISION.
PROGRAM-ID. EVAL.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MONTH PIC 99.
01 MONTHNAME PIC A(10).
01 DAYS PIC 99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY "ENTER THE MONTH NUMBER" .
ACCEPT MONTH.
DISPLAY MONTH.
* DISPLAY MONTHNAME.
MONTH-PARA.
EVALUATE MONTH
WHEN 1 MOVE 'JANUARY' TO MONTHNAME
WHEN 2 MOVE 'FEBRUARY' TO MONTHNAME
WHEN 3 MOVE 'MARCH' TO MONTHNAME
WHEN 4 MOVE 'APRIL' TO MONTHNAME
WHEN 5 MOVE 'MAY' TO MONTHNAME
WHEN 6 MOVE 'JUNE' TO MONTHNAME
WHEN 7 MOVE 'JULY' TO MONTHNAME
WHEN 8 MOVE 'AUGUST' TO MONTHNAME
WHEN 9 MOVE 'SEPTEMBER' TO MONTHNAME
WHEN 10 MOVE 'OCTOBER' TO MONTHNAME
WHEN 11 MOVE 'NOVEMBER' TO MONTHNAME
WHEN 12 MOVE 'DECEMBER' TO MONTHNAME
END-EVALUATE.
DAY-PARA.

9
* MOVE 'DDDDDDD' TO MONTHNAME.
* DISPLAY MONTHNAME.
EVALUATE TRUE
WHEN MONTH = 4 OR 6 OR 9 OR 11
MOVE 30 TO DAYS
WHEN MONTH = 2
MOVE 28 TO DAYS
WHEN OTHER MOVE 31 TO DAYS
END-EVALUATE.
DISP-PARA.
DISPLAY "THE MONTH IS " MONTHNAME.
DISPLAY "DAYS IS " DAYS.
STOP-PARA.
STOP RUN.
[INPUT
-----
//SYSIN DD *
05
//
OUTPUT
------
05
THE MONTH IS MAY
DAYS IS 31]

PGM15 : CONDITION NAMES


IDENTIFICATION DIVISION.
PROGRAM-ID. CONDNAME.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 MARITAL-STATUS PIC 9.
88 SINGLE VALUE 0.
88 MARRIED VALUE 1.
88 WIDOWED VALUE 2.
88 DIVORCED VALUE 3.
88 ONCE-MARRIED VALUES ARE 1,2,3.
88 VALID-STATUS VALUES ARE 0 THRU 3.
77 AMOUNT PIC 9(4) VALUE 1000.
PROCEDURE DIVISION.
MAIN-P.
DISPLAY "MARITAL STATUS".
DISPLAY "0-SINGLE/1-MARRIED/2-WIDOWED/3.DIVORCED".
ACCEPT MARITAL-STATUS.
IF NOT VALID-STATUS DISPLAY "ERROR IN ENTRY".
IF SINGLE SUBTRACT 100 FROM AMOUNT.
IF MARRIED ADD 100 TO AMOUNT.
IF DIVORCED SUBTRACT 200 FROM AMOUNT.
IF ONCE-MARRIED ADD 250 TO AMOUNT.
DISPLAY AMOUNT.
STOP RUN.

10
[INPUT
-----
//SYSIN DD *
1
//
OUTPUT
------
MARITAL STATUS
0-SINGLE/1-MARRIED/2-WIDOWED/3.DIVORCED (VALUE ACCEPTED FROM SYSIN)
1350 ]

PGM16 : LAB PGM 3.1 : CREATE ONE SEQ. FILE & WRITE TO IT.
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM32FI.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SEQ-FILE ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD SEQ-FILE.
01 SEQ-REC.
02 EMP-NO PIC X(6).
02 EMP-NAME PIC X(15).
02 DESG PIC X(10).
02 AGE PIC 9(2).
02 DEPT PIC X(8).
02 FILLER PIC X(39).
02 DEPT PIC X(8).
02 FILLER PIC X(39).
WORKING-STORAGE SECTION.
01 EOF PIC X.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN OUTPUT SEQ-FILE.
PERFORM ACCEPT-P 3 TIMES.
PERFORM CLOSE-P.
ACCEPT-P.
ACCEPT EMP-NO.
ACCEPT EMP-NAME.
ACCEPT DESG.
ACCEPT AGE.
ACCEPT DEPT.
WRITE SEQ-REC.
CLOSE-P.
CLOSE SEQ-FILE.
STOP RUN.
[IN RUNCOB AFTER THE STMT. //RUN EXEC PGM=INITIAL GIVE FOLLOWING CODE
//DD1 DD DSN=MTPLB21.COBOL.PRI2,DISP=(NEW,CATLG,DELETE),
// DCB=(BLKSIZE=800,LRECL=80,RECFM=FB),UNIT=SYSDA,SPACE=(TRK,(1,1)RLSE)

11
-------
-------
INPUT FROM SYSIN
----------------
//SYSIN DD *
123
JAIKUM
PS
25
ET
.
.
. (15 ENTRIES FOR 3 RECORDS)
/*
AFTER EXECUTING RUNCOB OPEN FILE MTPLB21.COBOL.PRI2 -3 RECORDS WILL BE SHOWN AS
OUTPUT
------
123 JAIKUM PS 25 ET
456 PRIYA ET 24 GH
234 ANU WE 21 RT
]

PGM17 : EXTEND MODE TO APPEND RECORDS IN A FILE.


IDENTIFICATION DIVISION.
PROGRAM-ID. EXTFILE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SEQ-FILE ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD SEQ-FILE.
01 SEQ-REC.
02 EMP-NO PIC X(6).
02 EMP-NAME PIC X(15).
02 DESG PIC X(10).
02 AGE PIC 9(2).
02 DEPT PIC X(8).
02 FILLER PIC X(39).
WORKING-STORAGE SECTION.
01 EOF PIC X.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN EXTEND SEQ-FILE.
ACCEPT EMP-NO.
ACCEPT EMP-NAME.
ACCEPT DESG.
ACCEPT AGE.
ACCEPT DEPT.

12
WRITE SEQ-REC.
CLOSE SEQ-FILE.
STOP RUN.
[IN RUNCOB GIVE
//DD1=MTPLB21.COBOL.PRI2,DISP=OLD
-------
--------
//SYSIN DD *
133
ASDFDF
AS
DF
56
/*

THEN THIS RECORD WILL BE APPENDED AT END OF FILE]

PGM18 : LAB PGM 3.2 : READ RECORDS FROM AN OLD FILE & WRITE THEM TO A NEW FILE
ALSO DISPLAY RECORDS.
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM32.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SEQ-FILE ASSIGN TO DD1SEQ
ORGANIZATION IS SEQUENTIAL.
SELECT SOUT-FILE ASSIGN TO DD2SEQ
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD SEQ-FILE
LABEL RECORDS ARE STANDARD.
01 SEQ-REC.
02 EMP-NO PIC X(6).
02 EMP-NAME PIC X(15).
02 DESG PIC X(10).
02 AGE PIC 9(2).
02 DEPT PIC X(8).
02 FILLER PIC X(39).
FD SOUT-FILE
LABEL RECORDS ARE STANDARD.
01 SOUT-REC.
02 SEMP-NO PIC X(6).
02 SEMP-NAME PIC X(15).
02 SDESG PIC X(10).
02 SAGE PIC 9(2).
02 SDEPT PIC X(8).
02 FILLER PIC X(39).
WORKING-STORAGE SECTION.
01 EOF PIC X.
PROCEDURE DIVISION.

13
MAIN-PARA.
OPEN INPUT SEQ-FILE.
OPEN OUTPUT SOUT-FILE.
DISPH-P.
PERFORM READ-WRITE UNTIL EOF = 'Y'.
PERFORM CLOSE-P.
READ-WRITE.
READ SEQ-FILE AT END MOVE 'Y' TO EOF.
MOVE SEQ-REC TO SOUT-REC.
IF EOF NOT EQUAL TO 'Y' WRITE SOUT-REC.
IF EOF NOT EQUAL TO 'Y' DISPLAY SEQ-REC.
CLOSE-P.
CLOSE SEQ-FILE.
CLOSE SOUT-FILE.
STOP RUN.
[IN RUNCOB GIVE
//DD1SEQ DD DSN=MTPLB21.COBOL.PRI4,DISP=OLD
//DD2SEQ DD DSN=MTPLB21.COBOL.PRI6,DISP=(NEW,CATLG,DELETE),
// DCB=(BLKSIZE=800,LRECL=80,RECFM=FB),UNIT=SYSDA,SPACE=(TRK,(1,1)RLSE)D2
-------
--------
//SYSIN DUMMY
/*

THE RECORDS FROM MTPLB21.COBOL.PRI4 WILL BE WRITTEN TO MTPLB21.COBOL.PRI6 & THE


OUTPUT IS ALSO DIPLAYED IN TSO SDSF ST]

PGM19 : TABLE SORTING


IDENTIFICATION DIVISION.
PROGRAM-ID. PGM32.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NUMB.
02 A PIC 9(3) OCCURS 10 TIMES.
77 I PIC 9(2) VALUE 0.
77 J PIC 9(2) VALUE 0.
77 TEMP PIC 9(3).
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM ACCEPT-P VARYING I FROM 1 BY 1 UNTIL I>10.
PERFORM SORT-P.
PERFORM DISP-P VARYING I FROM 1 BY 1 UNTIL I>10.
STOP RUN.
ACCEPT-P.
ACCEPT A(I).
SORT-P.
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
PERFORM VARYING J FROM 1 BY 1 UNTIL J > 10
IF A(I) < A(J)

14
MOVE A(I) TO TEMP
MOVE A(J) TO A(I)
MOVE TEMP TO A(J)
END-IF
END-PERFORM
END-PERFORM.
DISP-P.
DISPLAY A(I).

[INPUT OUTPUT
045 012
023 023
078 033
089 034
012 045
034 056
097 078
056 088
088 089
033 097]

PGM20 : ONE DIMENSIONAL ARRAY


IDENTIFICATION DIVISION.
PROGRAM-ID. ONEDARRY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 CT PIC 99 VALUE 0.
01 TAX-RATE.
05 RATE PIC 999 OCCURS 5 TIMES.
01 MONTH-TABLE.
02 FILLER PIC X(9) VALUE "JANUARY".
02 FILLER PIC X(9) VALUE "FEBRUARY".
02 FILLER PIC X(9) VALUE "MARCH".
02 FILLER PIC X(9) VALUE "APRIL".
02 FILLER PIC X(9) VALUE "MAY".
02 FILLER PIC X(9) VALUE "JUNE".
02 FILLER PIC X(9) VALUE "JULY".
02 FILLER PIC X(9) VALUE "AUGUST".
02 FILLER PIC X(9) VALUE "SEPTEMBER".
02 FILLER PIC X(9) VALUE "OCTOBER".
02 FILLER PIC X(9) VALUE "NOVEMBER".
02 FILLER PIC X(9) VALUE "DECEMBER".
01 MONTH-NAME REDEFINES MONTH-TABLE.
02 MONTH PIC X(9) OCCURS 12 TIMES.
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM FILL-P VARYING CT FROM 1 BY 1 UNTIL CT>5.
PERFORM DISP-P VARYING CT FROM 1 BY 1 UNTIL CT>5.
PERFORM MNTH-P.

15
STOP RUN.
FILL-P.
COMPUTE RATE(CT) = CT * 100.
DISP-P.
DISPLAY RATE(CT).
MNTH-P.
DISPLAY " ENTER MONTH NUMBER".
ACCEPT CT.
IF CT < 1 OR >12 DISPLAY "ERROR IN NUMBER"
ELSE DISPLAY MONTH(CT).

[INPUT
//SYSIN DD *
05
/*
OUTPUT
100
200
300
400
500
ENTER MONTH NUMBER (ALREADY ENTERED IN SYSIN)
MAY ]

PGM21 : LAB PGM 3.3 COBOL PGM TO SUBMIT A JCL

IDENTIFICATION DIVISION.
PROGRAM-ID. SORTPROC.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT JCL-FILE ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD JCL-FILE.
01 JCL-REC PIC X(80).
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN OUTPUT JCL-FILE.
MOVE '//MTPLB21J JOB ,,CLASS=A,MSGCLASS=H,NOTIFY=&SYSUID'
TO JCL-REC.
WRITE JCL-REC.
MOVE '//STEP1 EXEC PGM=IEFBR14' TO JCL-REC.
WRITE JCL-REC.
MOVE '//DD1 DD DSN=MTPLB21.JCL.ANJ123,' TO JCL-REC.
WRITE JCL-REC.
MOVE '// DISP=(NEW,CATLG,DELETE),' TO JCL-REC.
WRITE JCL-REC.
MOVE '// UNIT=SYSDA,SPACE=(TRK,(4,2),RLSE),'

16
TO JCL-REC.
WRITE JCL-REC.
MOVE '// DCB=(LRECL=80,RECFM=FB,BLKSIZE=800),'
TO JCL-REC.
WRITE JCL-REC.
MOVE '// VOL=SER=MTBLR1' TO JCL-REC.
WRITE JCL-REC.
MOVE '//SYSPRINT DD SYSOUT=*' TO JCL-REC.
WRITE JCL-REC.
MOVE '//SYSIN DD DUMMY' TO JCL-REC.
WRITE JCL-REC.
CLOSE JCL-FILE.
STOP RUN.

[OUTPUT

COBRUN
------
IN COBRUN GIVE //DDNAME DD SYSOUT=(*,INTRDR)
SO COBRUN WILL BE LIKE

//MTPLB21J JOB ,,
// CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),LINES=(1,CANCEL),
// NOTIFY=MTPLB21
//RUN EXEC PGM=INITIAL
//DD1 DD SYSOUT=(*,INTRDR)
//*DD2 DD DSN=MTPLB21.COBOL.PRI5,DISP=OLD
//*DD3 DD DSN=MTPLB21.COBOL.PRI6,DISP=OLD
//* UNIT=SYSDA,VOL=SER=MTBLR1,
//* SPACE=(TRK,(1,2),RLSE),
//* DCB=(LRECL=80,RECFM=FB,BLKSIZE=800)
//STEPLIB DD DSN=MTPLB21.COBOL.LOADLIB,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD DUMMY
//

AFTER EXECUTING THIS WE CAN SEE THAT THE FILE MTPLB21.JCL.ANJ123 IS CREATED.]

PGM22 : LAB PGM 4.1 ADD FIRST 10 ODD & EVEN NUMBERS IN 2 ARRAYS TAB1,TAB2 TO A
ARRAY TAB3
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM41.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 I PIC 9(2) VALUE 1.
77 J PIC 9(2) VALUE 2.
77 K PIC 9(2).
01 TABS.

17
02 TAB1 PIC 9(2) OCCURS 10 TIMES.
02 TAB2 PIC 9(2) OCCURS 10 TIMES.
02 TAB3 PIC 9(2) OCCURS 10 TIMES.
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM ACCEPT-P VARYING K FROM 1 BY 1 UNTIL K > 10.
PERFORM DISP-P.
STOP RUN.
ACCEPT-P.
MOVE I TO TAB1(K).
MOVE J TO TAB2(K).
COMPUTE TAB3(K) = TAB1(K) + TAB2(K).
COMPUTE I = I + 2.
COMPUTE J = J + 2.
DISP-P.
PERFORM VARYING K FROM 1 BY 1 UNTIL K > 10
* DISPLAY TAB1(K)
* DISPLAY TAB2(K)
DISPLAY TAB1(K) , ' + ' , TAB2(K) , ' = ' , TAB3(K)
END-PERFORM.

[OUTPUT
01 + 02 = 03
03 + 04 = 07
05 + 06 = 11
07 + 08 = 15
09 + 10 = 19
11 + 12 = 23
13 + 14 = 27
15 + 16 = 31
17 + 18 = 35
19 + 20 = 39 ]

PGM23 : LAB PGM 4.2 ACCEPT 12 ELEMENTS IN AN ARRAY & USE SEARCH
VERB TO SERCH A VALUE
IDENTIFICATION DIVISION.
PROGRAM-ID. ONEDARRY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MONTH-TABLE.
02 FILLER PIC X(9) VALUE "JANUARY".
02 FILLER PIC X(9) VALUE "FEBRUARY".
02 FILLER PIC X(9) VALUE "MARCH".
02 FILLER PIC X(9) VALUE "APRIL".
02 FILLER PIC X(9) VALUE "MAY".
02 FILLER PIC X(9) VALUE "JUNE".
02 FILLER PIC X(9) VALUE "JULY".
02 FILLER PIC X(9) VALUE "AUGUST".
02 FILLER PIC X(9) VALUE "SEPTEMBER".

18
02 FILLER PIC X(9) VALUE "OCTOBER".
02 FILLER PIC X(9) VALUE "NOVEMBER".
02 FILLER PIC X(9) VALUE "DECEMBER".
01 MONTH-NAME REDEFINES MONTH-TABLE.
02 MONTH OCCURS 12 TIMES INDEXED BY CT.
05 FIRST-THREE PIC X(3).
05 BALANCE-REST PIC X(6).
77 M-NAME PIC X(9) VALUE SPACES.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY "MONTH NAME".
ACCEPT M-NAME.
SET CT TO 1.
SEARCH MONTH AT END DISPLAY "NOT FOUND"
WHEN M-NAME = MONTH(CT)
DISPLAY FIRST-THREE (CT).
STOP RUN.
[INPUT
//SYSIN DD*
MARCH
/*
OUTPUT
MONTH NAME (ALREADY ACCEPTED FROM SYSIN)
MAR

PGM24 : TWO DIMENSIONAL ARRAY


IDENTIFICATION DIVISION.
PROGRAM-ID. ONEDARRY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ABC.
05 D OCCURS 2 TIMES.
10 H OCCURS 2 TIMES.
15 XYZ PIC 9(3).
77 I PIC 99.
77 J PIC 99.
77 TEMP PIC 999.
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM ACCP-P VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
PERFORM DISP-P VARYING I FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
STOP RUN.
ACCP-P.
COMPUTE TEMP = I + J.
MOVE TEMP TO XYZ(I, J).
DISP-P.
DISPLAY XYZ(I J).

19
[OUTPUT
002 003
003 004]

PGM25 : THREE DIMENSIONAL ARRAY


IDENTIFICATION DIVISION.
PROGRAM-ID. THRDARRY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 EN.
02 F OCCURS 3 TIMES.
03 D OCCURS 3 TIMES.
04 Y OCCURS 3 TIMES.
05 XYZ PIC 999.
77 I PIC 99 VALUE 0.
77 J PIC 99 VALUE 0.
77 TEMP PIC 999.
77 L PIC 99 VALUE 0.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY " 3 D ARRAY VALUES ARE :" .
PERFORM ACC-P VARYING I FROM 1 BY 1 UNTIL I > 3
AFTER J FROM 1 BY 1 UNTIL J > 3
AFTER L FROM 1 BY 1 UNTIL L > 3.
PERFORM DISP-P VARYING I FROM 1 BY 1 UNTIL I > 3
AFTER J FROM 1 BY 1 UNTIL J > 3
AFTER L FROM 1 BY 1 UNTIL L > 3.
STOP RUN.
ACC-P.
COMPUTE TEMP = I + J + L.
MOVE TEMP TO XYZ(I J L).
DISP-P.
DISPLAY XYZ(I, J, L).

[OUTPUT

003 004 005 004 005 006 005 006 007


004 005 006 005 006 007 006 007 008
005 006 007 006 007 008 007 008 009

INITIALLY,
I=1, J=1, K=1 THEN XYZ =3
I=1, J=1, K=2 THEN XYZ =4
I=1, J=1, K=3 THEN XYZ =5
I=1, J=2, K=1 THEN XYZ =4
I=1, J=2, K=2 THEN XYZ =5
I=1, J=2, K=3 THEN XYZ =6
I=1, J=3, K=1 THEN XYZ =5 and so on...........]

20
PGM26 : LAB PGM 4.3 STRING,UNSTRING,INSPECT
IDENTIFICATION DIVISION.
PROGRAM-ID. ONEDARRY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 A PIC X(7) VALUE 'CON,CON'.
77 B PIC X(7) VALUE 'CAT,CAT'.
77 C PIC X(10) VALUE 'ENATED,ABC'.
77 D PIC X(12) VALUE SPACES.
77 F PIC X(7) VALUE 'HIGHTEC'.
*77 G PIC X(7) VALUE SPACES.
77 SN PIC X(30) VALUE 'RAJA ROMOHAN ROY'.
77 FN PIC X(10) VALUE SPACES.
77 MN PIC X(10) VALUE SPACES.
77 LN PIC X(10) VALUE SPACES.
77 PS PIC X(15) VALUE 'SSUPERINDENDENT'.
77 HE PIC X(14) VALUE 'JAIKUM PRADEEP'.
77 COUN PIC 9(3) VALUE 1.
77 TALLY-COUNT PIC 9(2) VALUE 0.
PROCEDURE DIVISION.
MAIN-P.
PERFORM STRING-P.
PERFORM UNSTRING-P.
* PERFORM EXAMINE-P.
PERFORM INSPECT-P.
STOP RUN.
STRING-P.
DISPLAY "STRING VERB TO CONCATENATE STRINGS".
STRING A, B, C DELIMITED BY "," INTO D WITH POINTER COUN.
DISPLAY "STRING IS ", D.
COMPUTE COUN = COUN - 1.
DISPLAY "NO OF CHARACTERS IN ", D, "IS ", COUN.
STRING "MAIN" DELIMITED SIZE INTO F.
DISPLAY "HIGHTEC CHANGED TO ", F.
UNSTRING-P.
UNSTRING SN DELIMITED BY SPACE INTO FN, LN, MN.
DISPLAY "UNSTRINGED WORDS ARE ", FN, LN, MN.
*EXAMINE-P.
* EXAMINE PS TALLYING ALL "E".
* DISPLAY "E IN", PS, "IS", TALLY.
* EXAMINE PS TALLYING ALL "S".
* DISPLAY "LEADING S IN", PS, "IS", TALLY.
* EXAMINE PS TALLYING UNTIL FIRST "I".
* DISPLAY "NO. OF CHARS. TILL I IS", TALLY.
* EXAMINE PS REPLACING ALL "D" BY "Q".
* DISPLAY PS.
* EXAMINE PS REPLACING UNTIL FIRST "I" BY "W".
* DISPLAY PS.

21
INSPECT-P.
INSPECT HE TALLYING TALLY-COUNT FOR ALL "A".
DISPLAY "A IN ", HE, " IS ", TALLY-COUNT.
MOVE 0 TO TALLY-COUNT.
INSPECT HE TALLYING TALLY-COUNT FOR CHARACTERS.
DISPLAY "NO OF CHARS. IN ", HE, "IS " , TALLY-COUNT.
INSPECT HE REPLACING ALL 'E' BY 'S'.
DISPLAY HE.

[OUTPUT
STRING VERB TO CONCATENATE STRINGS
STRING IS CONCATENATED
NO OF CHARACTERS IN CONCATENATEDIS 012
HIGHTEC CHANGED TO MAINTEC
UNSTRINGED WORDS ARE RAJA ROMOHAN ROY
A IN JAIKUM PRADEEP IS 03
NO OF CHARS. IN JAIKUM PRADEEPIS 14
JAIKUM PRADSSP ]

PGM27 : SORTING FILE


IDENTIFICATION DIVISION.
PROGRAM-ID. SORTFILE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL.
SELECT WORK-FILE ASSIGN TO DD2.
SELECT OUT-FILE ASSIGN TO DD3
ORGANIZATION IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD IN-FILE.
01 IN-REC.
02 NUM PIC XX.
02 NAME PIC X(10).
02 ADDR PIC X(10).
02 FILLER PIC X(58).
SD WORK-FILE.
01 WORK-REC.
02 WNUM PIC X(2).
02 WNAME PIC X(10).
02 WADDR PIC X(10).
02 FILLER PIC X(58).
FD OUT-FILE.
01 OUT-REC PIC X(80).
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
SORT WORK-FILE ON ASCENDING KEY WNUM USING
IN-FILE GIVING OUT-FILE.
STOP RUN.

22
[OUTPUT

IN-FILE. DD1 - MTPLB21.COBOL.PRI4


---------------------------------
35 JAIKUMA AAZHAKATHU
12 PRIYAAA AABANGLORE
24 ANURAGG GGBOMBAYYYY
77 PRADEEPP PPBAHARAIN
50 ABHILASH HMUMBAIIII
COBCOMP
-------
//MTPLB21S JOB ,,LINES=(1,CANCEL),
// CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1),
// NOTIFY=MTPLB21
//* EXAMPLE JCL TO COMPILE & LINK COBOL BATCH PROGRAM
//*JOBPROC JCLLIB ORDER=NREDDY.SAMPLE.PROC
//COBCL EXEC IGYWCL,
// PGMLIB=MTPLB21.COBOL.LOADLIB, =>LOADMOUDEL DATASET NAME
// GOPGM=INITIAL
//COBOL.SYSIN DD DSN=MTPLB21.COBOL.JAIKUM(SORTFILE),DISP=SHR
//COBOL.SYSLIB DD DSN=MTPLB21.COBOL.JAIKUM,DISP=SHR ==>COPY LIBRARY
//
COBRUN
------
GIVE
//DD1 DD DSN=MTPLB21.COBOL.PRI4,DISP=SHR
//DD3 DD DSN=MTPLB21.COBOL.PRI5,DISP=OLD
IT IS A MUST IN SORT & MERGE PGMS TO GIVE
//SYSOUT DD SYSOUT=*

SO COBRUN PGM WILL BE LIKE


---------------------------
//MTPLB21J JOB ,,
// CLASS=A,MSGCLASS=H,MSGLEVEL=(1,1),LINES=(1,CANCEL),
// NOTIFY=MTPLB21
//RUN EXEC PGM=INITIAL
//DD1 DD DSN=MTPLB21.COBOL.PRI4,DISP=SHR
//DD3 DD DSN=MTPLB21.COBOL.PRI5,DISP=OLD
//* UNIT=SYSDA,VOL=SER=MTBLR1,
//* SPACE=(TRK,(1,2),RLSE),
//* DCB=(LRECL=80,RECFM=FB,BLKSIZE=800)
//STEPLIB DD DSN=MTPLB21.COBOL.LOADLIB,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD DUMMY
//
OUT-FILE.DD3 - MTPLB21.COBOL.PRI5
---------------------------------
12 PRIYAAA AABANGLORE
24 ANURAGG GGBOMBAYYYY
35 JAIKUMA AAZHAKATHU

23
50 ABHILASH HMUMBAIIII
77 PRADEEPP PPBAHARAIN ]

PGM28 : MERGING FILE


IDENTIFICATION DIVISION.
PROGRAM-ID. MERGFILE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE1 ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL.
SELECT IN-FILE2 ASSIGN TO DD2
ORGANIZATION IS SEQUENTIAL.
SELECT OUT-FILE ASSIGN TO DD3
ORGANIZATION IS SEQUENTIAL.
SELECT WORK-FILE ASSIGN TO DD4.
DATA DIVISION.
FILE SECTION.
FD IN-FILE1.
01 IN-REC1.
02 NUM PIC XX.
02 NAME PIC X(10).
02 ADDR PIC X(10).
02 FILLER PIC X(58).
FD IN-FILE2.
01 IN-REC2.
02 NUM PIC XX.
02 NAME PIC X(10).
02 ADDR PIC X(10).
02 FILLER PIC X(58).
SD WORK-FILE.
01 WORK-REC.
02 WNUM PIC X(2).
02 WNAME PIC X(10).
02 WADDR PIC X(10).
02 FILLER PIC X(58).
FD OUT-FILE.
01 OUT-REC PIC X(80).
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
MERGE WORK-FILE ON ASCENDING KEY WNUM USING
IN-FILE1, IN-FILE2 GIVING OUT-FILE.
STOP RUN.

[INPUT
-----
IN-FILE1 == MTPLB21.COBOL.PRI4
------------------------------
10 JAIKUMA AAZHAKATHU
15 PRIYAAA AABANGLORE
20 ANURAGG GGBOMBAYYYY

24
25 PRADEEPP PPBAHARAIN
30 ABHILASH HMUMBAIIII

IN-FILE2 == MTPLB21.COBOL.PRI5
------------------------------
12 AMITAAA AABANGLORE
17 TEJUAGG GGBOMBAYYYY
22 PREETHY AAZHAKATHU
54 APARNASH HMUMBAIIII
90 LEENAEPP PPBAHARAIN

COBRUN
------
//DD1 DD DSN=MTPLB21.COBOL.PRI4,DISP=SHR
//DD2 DD DSN=MTPLB21.COBOL.PRI5,DISP=SHR
//DD3 DD DSN=MTPLB21.COBOL.PRI6,DISP=OLD
OUTPUT
------
10 JAIKUMA AAZHAKATHU
12 AMITAAA AABANGLORE
15 PRIYAAA AABANGLORE
17 TEJUAGG GGBOMBAYYYY
20 ANURAGG GGBOMBAYYYY
22 PREETHY AAZHAKATHU
25 PRADEEPP PPBAHARAIN
30 ABHILASH HMUMBAIIII
54 APARNASH HMUMBAIIII
90 LEENAEPP PPBAHARAIN

PGM29 : LAB PGM 4.4 CALL STATEMENT


IDENTIFICATION DIVISION.
PROGRAM-ID. MPGM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MNTEC PIC X(32) GLOBAL.
PROCEDURE DIVISION.
MOVE "BEGINNING CONTENTS" TO MNTEC
CALL "SUBPGM"
DISPLAY MNTEC.
STOP RUN.
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPGM.
DATA DIVISION.
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
DISPLAY "ENTERING SUBPROGRAM".
DISPLAY MNTEC.
MOVE "ENDING CONTENTS" TO MNTEC.
DISPLAY "LEAVING SUBPGM".
EXIT PROGRAM.

25
END PROGRAM MPGM.

[OUTPUT
ENTERING SUBPROGRAM
BEGINNING CONTENTS
LEAVING SUBPGM
ENDING CONTENTS ]

PGM30 : SORTING USING INPUT & OUTPUT PROCEDURE (NOT WORKING)

IDENTIFICATION DIVISION.
PROGRAM-ID. SORTPROC.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE ASSIGN TO DD1
ORGANIZATION IS SEQUENTIAL.
SELECT OUT-FILE ASSIGN TO DD2
ORGANIZATION IS SEQUENTIAL.
SELECT WORK-FILE ASSIGN TO DD3.
DATA DIVISION.
FILE SECTION.
FD IN-FILE.
01 IN-REC.
02 IN-SNO PIC 9(3).
02 IN-NAME PIC X(20).
02 IN-AMT PIC 9(6).
02 FILLER PIC X(51).
FD OUT-FILE.
01 OUT-REC.
02 OUT-SNO PIC 9(3).
02 OUT-NAME PIC X(20).
02 OUT-AMT PIC 9(6).
02 FILLER PIC X(51).
SD WORK-FILE.
01 WORK-REC.
02 W-NO PIC 9(3).
02 W-NAME PIC X(20).
02 W-AMT PIC 9(6).
02 FILLER PIC X(51).
WORKING-STORAGE SECTION.
01 EOF PIC X VALUE 'N'.
01 EOF1 PIC X VALUE 'N'.
PROCEDURE DIVISION.
SORTING SECTION.
MAIN-PARA.
SORT WORK-FILE ON ASCENDING KEY W-NO
INPUT PROCEDURE IS INPROC
OUTPUT PROCEDURE IS OUTPROC.
STOP RUN.
INPROC SECTION.

26
OPEN INPUT IN-FILE.
PERFORM READ-P UNTIL EOF = 'Y'.
CLOSE IN-FILE.
READ-P.
READ IN-FILE AT END MOVE 'Y' TO EOF.
IF IN-SNO = ZERO
NEXT SENTENCE
ELSE
RELEASE WORK-REC FROM IN-REC
END-IF.
OUTPROC SECTION.
OPEN OUTPUT OUT-FILE.
PERFORM READ1-PARA UNTIL EOF = 'Y'
CLOSE OUT-FILE.
READ1-PARA.
RETURN WORK-FILE INTO OUT-REC
AT END MOVE 'Y' TO EOF1.
IF OUT-AMT = ZERO
MOVE 999999 TO OUT-AMT
END-IF.
WRITE OUT-REC.

PGM31 : LAB PGM 4.5 USING PARM PARAMETER TO RETRIEVE VALUE

IDENTIFICATION DIVISION.
PROGRAM-ID. PARM.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 PAR.
49 PAR-LEN PIC S9(4) COMP.
49 PAR-TXT PIC X(50).
PROCEDURE DIVISION USING PAR.
DISPLAY PAR.
DISPLAY PAR-LEN.
STOP RUN.

[ COBRUN
------
//MTPLB21J JOB ,,
// CLASS=A,MSGCLASS=A,MSGLEVEL=(1,1),LINES=(1,CANCEL),
// NOTIFY=MTPLB21
//RUN EXEC PGM=INITIAL,PARM='JAIKUM'
//*D1 DD SYSOUT=(*,INTRDR)
//*DD2 DD DSN=MTPLB21.COBOL.PRI5,DISP=OLD
//*DD3 DD DSN=MTPLB21.COBOL.PRI6,DISP=OLD
//* UNIT=SYSDA,VOL=SER=MTBLR1,
//* SPACE=(TRK,(1,2),RLSE),
//* DCB=(LRECL=80,RECFM=FB,BLKSIZE=800)
//STEPLIB DD DSN=MTPLB21.COBOL.LOADLIB,DISP=SHR
//SYSOUT DD SYSOUT=*

27
//SYSPRINT DD SYSOUT=*
//SYSIN DD DUMMY
//

OUTPUT
------
JAIKUM
0006
]

[NOTE : NUM ON STD COB , F10 ====> TO DISPLAY LINE NUMBERS IN A COBOL PGM]

28