JCL
JCL
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=
//SORTOUT DD DSN=
//SORTWK01 DD SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA
//SORTWK02 DD SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA
//SORTWK03 DD SPACE=(TRK,(1,1),RLSE),UNIT=SYSDA
//SYSIN DD *
SORT BASIC
SORT FIELDS=(1,10,CH,ASC)
REMOVE DUPLICATE
SORT FIELDS=COPY
SORT FIELDS=(1,80,CH,A),EQUALS
SUM FIELDS=NONE
MULTIPLE SORTS
SORT FIELDS=(1,6,CH,A,9,3,ZD,A)
**********************************************************************************
SORT FIELDS=COPY
OUTREC FIELDS=(1,20,25,6)
TO ADD SEQUENCE NUMBER TO THE ROW
SORT FIELDS=(1,3,ZD,A)
INREC FIELDS=(1,20,X,25,6,X,SEQNUM,4,ZD)
//SORTIN DD DSN=FILE,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(47:1,6)
TRAN OPTION
OPTION COPY
FIND REPLACE
OPTION COPY
INREC FINDREP=(IN=C’Mr.’,OUT=C’Mister’)
OPTION COPY
OUTREC FINDREP=(IN=C’TML’,OUT=C’TPL’)
OR
OUTREC FINDREP=(INOUT=(C’TML’,C’TPL’))
Adding sequence number to the output file & INCREMENT THE NUMBER WITH 2
OPTION COPY
BUILD=(1:1,5,10:SEQNUM,4,ZD,START=1000,INCR=2)
SORT FIELDS=COPY
OUTFIL REMOVECC,
HEADER1=(1:C’HDR’,10:X’020110131C’),
TRAILER1=(1:C’TRLR’,TOT=(10,9,PD,TO=PD,LENGTH=9))
SORT FIELDS=COPY
OUTFIL FILES=01,INCLUDE=(1,6,CH,EQ,C’JCL ‘)
OUTFIL FILES=02,INCLUDE=(1,6,CH,EQ,C’VSAM ‘)
OUTFIL FILES=04,INCLUDE=(1,6,CH,EQ,C’COBOL ‘)
OPTION COPY
IFTHEN=(WHEN=(6,1,CH,EQ,C’ ‘),BUILD=(1:1,5,7:C’EMPTY ‘)
//MAIN DD DSN=
//LOOKUP DD DSN=
//MATCH DD DSN=OUTPUT1
//NOMATCH1 DD DSN=OUTPUT2
//NOMATCH2 DD DSN=OUTPUT3
//SYSIN DD *
JOINKEYS F1=MAIN,FIELDS=(1,4,A)
JOINKEYS F2=LOOKUP,FIELDS=(1,4,A)
REFORMAT FIELDS=(?,F1:1,4,F2:1,4)
OPTION COPY
OUTFIL FNAMES=MATCH,INCLUDE=(1,1,CH,EQ,C’B’),BUILD=(1:2,4)
OUTFIL FNAMES=NOMATCH1,INCLUDE=(1,1,CH,EQ,C’1’),BUILD=(1:2,4)
OUTFIL FNAMES=NOMATCH2,INCLUDE=(1,1,CH,EQ,C’2’),BUILD=(1:2,4)
B – MATCHED RECORDS
UNPAIRED F1 AND F2 (FULL OUTER JOIN) – MATCHED RECORDS & UNMATCHED RECORDS
Inner join
SORT FIELDS=COPY
JOINKEYS FILES=F2,FIELDS=(1,10,A)
REFORMAT FIELDS=(F1,1:70,F2,1:10)
JOINKEYS FILES=F1,FIELDS=(1,10,A)
JOINKEYS FILES=F1,FIELDS=(1,10,A)
JOIN UNPAIRED,F1,ONLY
REFORMAT FIELDS=(F1:1,71)
INCLUDE / OMIT
SORT FIELDS=COPY
INCLUDE COND=(1,6,CH,EQ,C’COBOL’)
SORT FIELDS=COPY
OMIT COND=(1,6,CH,EQ,C’COBOL’)
CONVERT
OPTION COPY
OUTREC FIELDS=(1,4,BI,TO=ZD,LENGTH=6)
OPTION COPY
OUTREC FIELDS=(1,4,PD,TO=ZD,LENGTH=6)
COND
COND=(RC-USER,OPERATOR,STEP-RC)
COBOL
PROGRAM
DIVISIONS
7-12 ED
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FS.
INPUT-OUTPUT CONTROL
13-15 DD
FILE SECTION.
FD filename
01 record name
Nn … fieldlength type.
Nn … fieldlength type.
WORKING-STORAGE SECTION.
16+ PD
SECTIONS
PARAGRAPHS
SENTENCES
STATEMENTS
CHARACTERS
FIELDS
7 INDICATOR FIELD
8-11 AREA A
12-72 AREA B
LEVELS
REDEFINES used to define a storage with different data description. Redefined & redefining level
number should be same. 66 & 88 cannot be redefined.
RENAMES used to give different names to the existing data items. Used to regroup the data
items & give a new name to them.66 level
01 WS-OLD.
10 WS-A PIC 9(12).
10 WS-B PIC X(20).
10 WS-C PIC A(25).
10 WS-D PIC X(12).
66 WS-NEW RENAMES WS-A THRU WS-C.
USAGE - Specifies OS in which format the data is stored. cannot be used in 66 88 levels
Display - stored in ASCII format as (1 byte for each letter) default usage.
PERFORM
PERFORM UNTIL
INSPECT
Convert LC to UC
01 wp-char-case.
05 wp-upper-case pic x(26) value "ABCD ... Z"
05 WP-LOWER-CASE PIC X(26) VALUE ' abcd... z'
INSPECT WR-IN-STRNG5
converting WW-LOWER-CASE to ww-upper-case
STRING & UNSTRING to format or split the string as per the need.
MOVE
SIMPLE MOVE
CORRESSPONDING MOVE
ARRAY
SUBSCRIPT An integer data item which describes the number of occurrences. Not an
actual memory location rather refers to a position of data item. Subscript should be
declared in working storage section
INDEX SUBSCRIPT
Offset or displacement from the beginning Number of occurrences of the array element
INDEXED BY clause is used INDEXED BY clause not used
INDEX is faster as it refers to the memory SUBSCRIPT is slower compared to INDEX as it
location so has comparatively better doesnot refer memory location
performance
INDEX is not defined in working storage SUBSCRIPT has to be defined in working storage
Initialized by SET operations Initialized by VALUE or MOVE statement
SEARCH SEARCH ALL
Used to find an element/record in linear Used to find an element/record in binary
manner – sequential search manner – binary search
Can use for the table which has records either Can be used for the table which has records
in sorted or unsorted manner only in sorted manner
INDEX must be initialized INDEX need not be initialized
Condition can’t be compound condition (i.e. Only ‘EQUAL TO’ comparison is possible.
you cannot concatenate multiple conditions Compound condition is allowed
using AND/OR)
No concept of ASCENDING or DESCENDING key ASCENDING or DESCENDING Key must be
defined in Array
Applied for 1/2/any dimensional array Applied only for 1 dimensional array
Access is slower Access is faster
We can use multiple WHEN conditions We can use only one WHEN condition
SET verb is used to increase or decrease the NO SET Verb is required
offset value
LOGIC LOGIC
Index should be initialized. SEARCH statement
Binary search works like this:-
auto-increments index S1 by 1 after each single
element’s look up. First of all array on which search is to be made
should be in ascending order
Element to be searched is compared with
middle element of array
If matches, search process ends.
If search element is less than middle element,
array is divided into two halves considering
middle element, and search will be done only in
first half
If search element is greater than middle
element, only second half will be searched
further
The search operation continues same way in
selected half until either element is found or
there are no more element to search.
Example Example
Data division
01 NAME PIC A(15). 77 ID PIC 9(4).
01 STUDENT-DATA. 01 STUDENT-DATA.
05 STUDENT-ARRAY OCCURS 500 TIMES INDEXED 05 STUDENT-ARRAY OCCURS 500 TIMES
BY S1. ASCENDING KEY IS
10 STUDENT-ID PIC 9(04). STUDENT-ID
10 STUDENT-NAME PIC A(15). INDEXED BY S1.
10 STUDENT-MARKS PIC 9(03). 10 STUDENT-ID PIC 9(04).
10 STUDENT-NAME PIC A(15).
Procedure Divison 10 STUDENT-MARKS PIC 9(03).
SET S1 TO 1.
SEARCH STUDENT-ARRAY
SEARCH STUDENT-ARRAY
AT END
AT END
DISPLAY ‘STUDENT NOT FOUND’.
DISPLAY ‘STUDENT NOT FOUND’.
WHEN ID = STUDENT-ID(S1)
WHEN NAME = STUDENT-NAME(S1)
DISPLAY ‘STUDENT-NAME:’ STUDENT-
DISPLAY ‘STUDENT-ID:’ STUDENT-ID(S1)
NAME(S1)
DISPLAY ‘STUDENT-MARKS:’ STUDENT-
DISPLAY ‘STUDENT-MARKS:’ STUDENT-
MARKS(S1)
MARKS(S1)
Preferred when: Preferred when:-
Array size is small Array size is large
Array loaded in such way that most Array contains unique key
frequently accessing element can be There is no track of frequently accessed
loaded in the first few occurrences elements
ON SIZE ERROR
Occurs during arithmetic operation when result value exceeds the size of the PIC clause specified in
the receiving field.
DATA-A = 60 (PIC 99) and DATA-B = 60 (PIC 99). Now, arithmetic operation “ADD DATA-A TO DATA-
B” will result DATA-B =20 even though the expected value is 120, but due to PIC specification of
DATA-B, truncation occurred.
ADD A B C GIVING TOTAL
ON SIZER ERROR
MOVE ZERO TO TOTAL.
SOURCE CODE
(COBOL + DB2)
Precompilation (DSNHPC)
Timestamp t1 Timestamp t2