Page 1 of 1

Logic to reverse a file in JCL.

Posted: Thu Feb 22, 2018 12:04 pm
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?

Re: Logic to reverse a file in JCL.

Posted: Thu Feb 22, 2018 4:02 pm
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.

Re: Logic to reverse a file in JCL.

Posted: Mon Feb 26, 2018 6:11 pm
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?

Re: Logic to reverse a file in JCL.

Posted: Mon Feb 26, 2018 7:04 pm
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

Re: Logic to reverse a file in JCL.

Posted: Mon Feb 26, 2018 8:05 pm
by nicc
Sandy wrote: Mon Feb 26, 2018 6:11 pmSo what should we call a JCL which executes SORT?
A [batch] job.

Re: Logic to reverse a file in JCL.

Posted: Tue Mar 06, 2018 7:27 pm
by Sandy
Thanks Enrico.

Ok, Thanks @Nicc. Saying SORT JCL should also be ok? Or it should be called SORT Job?

Re: Logic to reverse a file in JCL.

Posted: Tue Mar 06, 2018 7:53 pm
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-)

Re: Logic to reverse a file in JCL.

Posted: Thu Mar 08, 2018 10:08 am
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)                         
/*
//*