Page 1 of 1

Write output on a condition in SORT.

Posted: Mon Sep 12, 2016 3:31 pm
by Akash Vairan
I have a file which has got fields in it. Two fields are like department and somme other description. All the records has same department name but description part is populated only once for a given department. So the input will look like the following example:

Code: Select all

-----5----------------15
Dept1 
Dept1  
Dept1 description1
Dept1  
Dept1  
Dept2 
Dept2  
Dept2 description2
Dept2  
Dept2 



Now my SORT should write only that record in the output which has got some description. In most of the case one of the records will have a description. In case if all the records don't have any description than any one of the record can be put in the output.

My input is FB and LRECL is 80. Output should be of same attributes. The Department can be repeated 5 times and 5 bytes long. Description is 10 bytes long. Can soomeone please help me on this.

Coded for your

Re: Write output on a condition in SORT.

Posted: Mon Sep 12, 2016 5:35 pm
by nicc
Please use the code tags to present your data.
You do not have a file but a data set
Will the description always be on the third record - if it there at all?

Re: Write output on a condition in SORT.

Posted: Mon Sep 12, 2016 10:08 pm
by Magesh_j
Is there is a possibility where you have more than one record having description ?

Code: Select all

Dept1 
Dept1  
Dept1 descripti1
Dept1 descripti2 
Dept1 
If yes what should be the output ?

Here is the code for you. Assuming 1,5 is dept and 7,10 is description and you have only one or no description for a dept

Code: Select all

INREC IFTHEN=(WHEN=GROUP,                    
              KEYBEGIN=(1,5),                
              BEGIN=(7,10,CH,NE,C' '),       
              PUSH=(7:7,10))                 
                                             
OPTION COPY                                  
                                             
OUTFIL SECTIONS=(1,5,TRAILER3=(1,80)),       
       REMOVECC,                             
       NODETAIL                              
Thanks
Magesh