Logic to reverse a file in JCL.
Logic to reverse a file in JCL.
Hi,
The interviewer has asked me if there is a way to reverse the data in a file using JCL? Let's say, there is a file in the order from a number from 100 to 199 and we need it reversed in the order of 199 to 100.
I said, that I think it is possible using FILE-AID batch process but interviewer wanted to know using SORT. Can someone please tell how can we do this in SORT?
The interviewer has asked me if there is a way to reverse the data in a file using JCL? Let's say, there is a file in the order from a number from 100 to 199 and we need it reversed in the order of 199 to 100.
I said, that I think it is possible using FILE-AID batch process but interviewer wanted to know using SORT. Can someone please tell how can we do this in SORT?
Re: Logic to reverse a file in JCL.
Sort and FILE-AID are not JCL. Many people seem to mis-understand what JCL is.
Although the 'L' in JCL stands for 'Language' JCL is not executable.
JCL does not manipulate data, it does not even look at data.
JCL is like a memo from you to the Operating System (OS) requesting it (the OS) to run one or more programs.
The JCL specifies some, or all, the resources required to accomplish the requested tasks.
When the JCL is read the OS reads it and sets up whatever it requires to do the tasks defined in the JCL.
It then DISCARDS the JCL, i.e. writes it to the output spool, never to look at it again.
The OS then runs the program(s) in accordance with the information it has extracted.
The data is kept in a data set not a file.
To reverse the order of the records using sort simply reverse the order that they are sorted on - if ascending then descending and vice versa.
Although the 'L' in JCL stands for 'Language' JCL is not executable.
JCL does not manipulate data, it does not even look at data.
JCL is like a memo from you to the Operating System (OS) requesting it (the OS) to run one or more programs.
The JCL specifies some, or all, the resources required to accomplish the requested tasks.
When the JCL is read the OS reads it and sets up whatever it requires to do the tasks defined in the JCL.
It then DISCARDS the JCL, i.e. writes it to the output spool, never to look at it again.
The OS then runs the program(s) in accordance with the information it has extracted.
The data is kept in a data set not a file.
To reverse the order of the records using sort simply reverse the order that they are sorted on - if ascending then descending and vice versa.
Regards
Nic
Nic
Re: Logic to reverse a file in JCL.
Hi Nicc,
Thanks. So what should we call a JCL which executes SORT?
For SORT option the interviewer said me that there is no key in the dataset. Then how do we sort it?
Thanks. So what should we call a JCL which executes SORT?
For SORT option the interviewer said me that there is no key in the dataset. Then how do we sort it?
- enrico-sorichetti
- Global Moderator
- Posts: 843
- Joined: Wed Sep 11, 2013 3:57 pm
Re: Logic to reverse a file in JCL.
add a sequence number ( with enough digits )For SORT option the interviewer said me that there is no key in the dataset. Then how do we sort it?
sort on the sequence number in DESCENDING order
drop the sequence number ON the output
and search the forum, there are a few topics with almost ready to run snippets
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

Re: Logic to reverse a file in JCL.
Thanks Enrico.
Ok, Thanks @Nicc. Saying SORT JCL should also be ok? Or it should be called SORT Job?
Ok, Thanks @Nicc. Saying SORT JCL should also be ok? Or it should be called SORT Job?
- enrico-sorichetti
- Global Moderator
- Posts: 843
- Joined: Wed Sep 11, 2013 3:57 pm
Re: Logic to reverse a file in JCL.
the JCL control statements are JCL ...
( the statements starting with a // )
the sort control statements are - the name tells - sort control statements
they are part of job stream but are NOT jcl
JES and the jcl processor - in general - will just pass them along without even looking at the content
anyway when You want to do something
just tell the name of the program You will be using
can I do that using SORT/DFSORT/SYNCSORT/IDCAMS/IEBGENER/<some other utility - general purpose - program> ) ?
probably will be generally understood
for the question
how to write a sort job step ?
an answer
look at the sort manuals for the required ddnames
and for the sort control statements
look at the JCL guide / JCL reference
for the format and keywords of the JCL cards/statements
might be acceptable
( the statements starting with a // )
the sort control statements are - the name tells - sort control statements
they are part of job stream but are NOT jcl
JES and the jcl processor - in general - will just pass them along without even looking at the content
anyway when You want to do something
just tell the name of the program You will be using
can I do that using SORT/DFSORT/SYNCSORT/IDCAMS/IEBGENER/<some other utility - general purpose - program> ) ?
a SORT JOB/job stepSo what should we call a JCL which executes SORT?
probably will be generally understood
for the question
how to write a sort job step ?
an answer
look at the sort manuals for the required ddnames
and for the sort control statements
look at the JCL guide / JCL reference
for the format and keywords of the JCL cards/statements
might be acceptable

cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

Re: Logic to reverse a file in JCL.
Hi,
If your file is of LRECL 80, you can use the below SORT as sample:
If your file is of LRECL 80, you can use the below SORT as sample:
Code: Select all
//STEP01 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file (FB/80)
//SORTOUT DD DSN=... output file (FB/80)
//SYSIN DD *
INREC OVERLAY=(81:SEQNUM,8,ZD)
SORT FIELDS=(81,8,ZD,D)
OUTREC BUILD=(1,80)
/*
//*
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute