JCL

CHANGE Input Data using SORT Lookup

CHANGE in OUTREC statement can be used to look up and change the content in the file while sorting. Build parameter is used to reformat records. Build give complete control over output file format. BUILD parameter can be used on INREC and OUTREC statements in SORT card. BUILD parameter is an alias of the FIELDS parameter. Build parameter can be used in OUTFIL statement also. 

Syntax

OUTREC FIELDS=(Starting position of field1,Length of field1, CHANGE=(v,find,set,.),.)

OUTREC BUILD=(Starting position of field1, Length of field1,
CHANGE=(v,find,set,…),…) 

NOMATCH can be used to change if no match is found with any of the constants in the table. NOMATCH=(set) to set the output value when an input field value does not match any of the find constants.

NOMATCH=(C'string') sets a character string constant.
NOMATCH=(X'string') sets a hexadecimal string constant. 
NOMATCH=(q,n) sets an input field value.
NameDescription
Starting position of field1Specifies field1 starting position in the input file after sorting.
Length of feild1Field1 physical length in input file.
VSpecifies the length of the output field
FindTable consisting pairs of find constants
SetSet constants or set fields

Example 01

Input data on the Employee & Month of Joining.

EMP NO (1:10)NAME (11:20)MONTH (31:3)
1CherylJAN
2NormanMAR
3LeonaidDEC
4IanOCT
5LindaFEB

This example illustrates how Name can be converted to Upper Case & how values in a text field can be changed to another text using a lookup table using BUILD.

//STEP001  EXEC PGM=SORT
//SYSOUT   DD SYSOUT=* 
//SORTIN   DD DSN=XXXXX.YYYYY.INPUT,DISP=SHR        
//SORTOUT  DD DSN= XXXXX.YYYYY.OUTPUT, 
//         DISP=(NEW,CATLG,DELETE),UNIT=3390,   
//         SPACE=(CYL,(5,1)),DCB=(LRECL=22)   
//SYSIN    DD *                        
//SYSIN DD *
  SORT FIELDS=COPY
  OUTREC BUILD=(1,30,TRAN=LTOU,31,3, - 
                CHANGE=(10, - 
                C'JAN',C'JANUARY', - 
                C’FEB',C'FEBRUARY', - 
                C'MAR',C'MARCH', - 
                C'APR',C'APRIL', - 
                C'MAY',C'MAY', -                  
                C'JUN',C'JUNE', - 
                C'JUL',C'JULY', - 
                C'AUG',C'AUGUST', - 
                C'SEP',C'SEPTEMBER', - 
                C'OCT',C'OCTOBER', - 
                C'NOV',C'NOVEMBER', - 
                C'DEC',C'DECEMBER'), - 
                NOMATCH=(31,3)) 
/*

Explanation – 

This sort card will copy first 30 bytes from input file & convert all letter to upper case letters. p, m,CHANGE=(v,find,set,…) to give the position and length of the input field, the length of the output field, and the “table” consisting of pairs of find constants, and set constants or set fields. For example, for the first field in the previous OUTREC statement:

  • The input field starts in position 31.
  • The length of the input field and find constants is 3.
  • The length of the output field and set constants is 10.
  • The first find constant is ‘JAN’ (padding with a blank is not needed as all the fields are having 3 characters).
  • The first set constant is ‘JANUARY’ (padded with blanks at the end to 10 characters).
  • If there is not match found (NOMATCH) data at 31st position from input file will be moved to output file (31,3).

Data at 31st position of the input file (3 bytes) will be compared with the data provided in CHANGE list. if any match found in the list corresponding data will be moved to output file  e.g.whenever the month contains ‘JAN’, the output field is set to ‘JANUARY’. Whenever the month contains ‘FEB’, the output field is set to ‘FEBRUARY’, and so on.

The results produced for this OUTREC statement are:

EMP NO (1:10)NAME (11:20)MONTH (31:10)
1CHERYLJANUARY
2NORMANMARCH
3LEONAIDDECEMBER
4IANOCTOBER
5LINDAFEBRURARY

Example 02

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:5)
1CherylJANENGL
2NormanMARBUSIN
3LeonaidDECCOMP
4IanOCTHIST
5LindaFEBPSYCH

This example illustrates how Name can be converted to Upper Case & how values in two text fields can be changed to other text using a lookup table.

//STEP001  EXEC PGM=SORT
//SYSOUT   DD SYSOUT=* 
//SORTIN   DD DSN=XXXXX.YYYYY.INPUT,DISP=SHR        
//SORTOUT  DD DSN= XXXXX.YYYYY.OUTPUT, 
//         DISP=(NEW,CATLG,DELETE),UNIT=3390,   
//         SPACE=(CYL,(5,1)),DCB=(LRECL=22)   
//SYSIN    DD *                        
//SYSIN DD *
  SORT FIELDS=COPY
  OUTREC FIELDS=(1,30,TRAN=LTOU,
                 31,3,CHANGE=(10, 
                 C'JAN',C'JANUARY', 
                 C’FEB',C'FEBRUARY',
                 C’MAR',C'MARCH',                           
                 C'APR',C'APRIL', 
                 C'MAY',C'MAY', 
                 C'JUN',C'JUNE',                         
                 C'JUL',C'JULY',
                 C'AUG',C'AUGUST',
                 C’SEP',C'SEPTEMBER                           
                 C'OCT',C'OCTOBER', 
                 C'NOV',C'NOVEMBER',
                 C'DEC',C'DECEMBER'                         
                 NOMATCH=(C’UNDIFINED’), 
                 35,5,CHANGE=(20,
                 C'HIST',C'HISTORY',
                 C'BUSIN',C'BUSINESS'                        
                 C'COMP',C'COMPUTER SCIENCE',
                 C'ENGL',C'ENGLISH',
                 C’BIOL’,C'BIOLOGY',                        
                 C'PSYCH',C'PSYCHOLOGY'),
                 NOMATCH=(C’UNAFFILIATED’))
/*

Explanation – 

This sort card will copy first 30 bytes from input file & convert all letter to upper case letters. p, m,CHANGE=(v,find,set,…) to give the position and length of the input field, the length of the output field, and the “table” consisting of pairs of find constants, and set constants or set fields. For example, for the first field in the previous OUTREC statement:

  • The input field starts in position 31 & 35.
  • The length of the input field and find constants is 3 & 5.
  • The length of the output field and set constants is 10 & 20.
  • The first find constant is ‘JAN’ (padding with a blank is not needed as all the fields are having 3 characters). Also the first set constant is ‘HIST’ (padded with a blank at the end to 5 characters)
  • The first set constant is ‘JANUARY’ (padded with blanks at the end to 10 characters).Also the first set constant is ‘HISTORY’ (padded with blanks at the end to 20 characters).
  • If there is no match found (NOMATCH) UNDEFINED & UNAFFILIATED will be written to output.

Data at 31st position of the input file (3 bytes) will be compared with the data provided in CHANGE list. if any match found in the list corresponding data will be moved to output file  e.g.whenever the month contains ‘JAN’, the output field is set to ‘JANUARY’. Whenever the month contains ‘FEB’, the output field is set to ‘FEBRUARY’, and so on.

The results produced for this OUTREC statement are:

EMP NO (1:10)NAME (11:20)MONTH (31:3)SUBJECT (35:5)
1CHERYLJANUARYENGLISH
2NORMANMARCHBUSINESS
3LEONAIDDECEMBERCOMPUTER
4IANOCTOBERHISTORY
5LINDAFEBRURARYPHYSICS

Example 03

This example illustrates how a sequence number can be generated, how values in one numeric or date format can be converted to another format, and how a lookup table can be used.

  OPTION COPY,Y2PAST=1985
  INREC FIELDS=(SEQNUM,4,BI,
                8,5,ZD,TO=PD,
                31,2,PD,TO=FI,LENGTH=2,
                15,6,Y2TP,25,3,
  CHANGE=(1,C'L92',X'01',C'M72',X'02',C'J42',X'03'),
                 NOMATCH=(X’FF’))

Explanation – 

The reformatted input records will look as follows:

  • 1-4 position contains a binary sequence number that starts at 1 and increments by 1.
  • 5–7 position contains a PD field containing the converted ZD field from input positions 8 through 12.
  • 8–9 position contains  an FI field containing the converted PD field from input positions 31 through 32.
  • 10–14 position contains a P’yyyymmdd’ date field containing the C’yymmdd’ date field from input positions 15-20 transformed according to the specified century window of 1985-2084.
  • 15 position contains a BI field containing X’01’, X’02’, X’03’ or X’FF’ as determined by using a lookup table for the input field in positions 25-27.

The SORT statement can now refer to the “sort” field in the reformatted input records. The OUTREC statement is used to restore the records to their original format.

JCL blogs – Click Here SYNCSORT Manual: Click Here

Admin

Share
Published by
Admin

Recent Posts

Increase Transparency and Collaboration Product Backlog

A well-maintained product backlog is crucial for successful product development. It serves as a single…

5 days ago

Product Backlog – Incremental value to the customer

Incremental value to the customer refers to the gradual delivery of small, functional parts of…

7 days ago

Product Market, Customer’s Desire, Need, and Challenges

A Product Market refers to the group of potential customers who might be interested in…

1 week ago

PAL-EBM Professional Agile Leadership – EBM Certification

The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…

3 months ago

PAL I Professional Agile Leadership Certification

The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…

4 months ago

Scrum Master Certification: CSM, PSM, SSM

Choosing the right Scrum Master Certification depends on your current experience and career goals. If…

5 months ago