Logic to reverse a file in JCL.

All sort of Mainframes Interview Questions.
Post Reply
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Logic to reverse a file in JCL.

Post by Sandy »

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?
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Logic to reverse a file in JCL.

Post by nicc »

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.
Regards
Nic
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Logic to reverse a file in JCL.

Post by Sandy »

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?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 825
Joined: Wed Sep 11, 2013 3:57 pm

Re: Logic to reverse a file in JCL.

Post by enrico-sorichetti »

For SORT option the interviewer said me that there is no key in the dataset. Then how do we sort it?
add a sequence number ( with enough digits )
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 8-)
nicc
Global Moderator
Global Moderator
Posts: 691
Joined: Wed Apr 23, 2014 8:45 pm

Re: Logic to reverse a file in JCL.

Post by nicc »

Sandy wrote: Mon Feb 26, 2018 6:11 pmSo what should we call a JCL which executes SORT?
A [batch] job.
Regards
Nic
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: Logic to reverse a file in JCL.

Post by Sandy »

Thanks Enrico.

Ok, Thanks @Nicc. Saying SORT JCL should also be ok? Or it should be called SORT Job?
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 825
Joined: Wed Sep 11, 2013 3:57 pm

Re: Logic to reverse a file in JCL.

Post by enrico-sorichetti »

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> ) ?
So what should we call a JCL which executes SORT?
a SORT JOB/job step
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 8-)
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 8-)
RyanFox
Registered Member
Posts: 52
Joined: Sat Jun 15, 2013 12:54 pm

Re: Logic to reverse a file in JCL.

Post by RyanFox »

Hi,

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)                         
/*
//*
Post Reply

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

Register

Sign in

Return to “Interview Questions.”