IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Arrange columns of a file based on record type


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ruma Dutta

New User


Joined: 26 Aug 2011
Posts: 5
Location: INDIA

PostPosted: Fri Sep 02, 2011 1:33 pm
Reply with quote

Hi,

I want to write a DFSORT to arrange the following records of a file based on record types:

Code:
1097201108120001
210000001AAAAT20
300000000UUU0005
500000000   AAB3
7000000000000000
7000000000000000
7000000000000000
8000000000000000
210000003BBBBB20
300000000UUU0005
500000000   ABCD

I want the output file like this:

Code:
1097201108120001
210000001AAAAT20
500000000   AAB3
300000000UUU0005
7000000000000000
7000000000000000
7000000000000000
8000000000000000
210000003BBBBB20
500000000   ABCD
300000000UUU0005


1st column of the records are record type. Record type=1 is header record. Please help me with the solution. Thanx in advance
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Sep 02, 2011 1:42 pm
Reply with quote

to improve readability Your post was edited to add the code tags

see here
ibmmainframes.com/faq.php#17

and here
ibmmainframes.com/faq.php?mode=bbcode

properly formatting Your questions and the sample data will help people willing to help icon_cool.gif


Quote:
Please help me with the solution.

Not until You will be able to describe the process in clear words
just <dumping> a sample of the input and of the output will not help You to get an answer

ok for the "1" identifying the header, but what criteria must be used for the other records
the sample posted just rearranges them in some <illogical> way
Back to top
View user's profile Send private message
kratos86

Active User


Joined: 17 Mar 2008
Posts: 148
Location: Anna NGR

PostPosted: Fri Sep 02, 2011 1:59 pm
Reply with quote

Requirements are not clear. Please provide us all the rules followed in order to attain your output. Until unless you give us a clear picture we cannot help you much.
Back to top
View user's profile Send private message
Ruma Dutta

New User


Joined: 26 Aug 2011
Posts: 5
Location: INDIA

PostPosted: Fri Sep 02, 2011 3:16 pm
Reply with quote

As per requirement, the input file have 6 kind of records. 1 st clumn of every record is the record type. rectype=1 is header record. record type 2,3,5,7,8 are a set of record in which 2 and 5 have single occurance in a set and 3,7,8 have either single/multipleoccurarances for a set or may not be present at all.
Input file eg.:
Code:
1097201108120001
210000001AAAAT20
300000000UUU0005
300000000UUU0007
500000000   AAB3
7000000000000123
7000000000000321
7000000000000100
8000000000000000


I want to write a DFSORT where i can get record 2 and 5 in an alternative order of record types: first record types 2 and 5, followed by the other types.

Output file should be look like:
Code:
1097201108120001
210000001AAAAT20
500000000   AAB3
300000000UUU0005
300000000UUU0007
7000000000000123
7000000000000321
7000000000000100
8000000000000000


Please let me know if you want any other details.

edited again to enclose data within the frigging code tags
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Sep 02, 2011 3:28 pm
Reply with quote

Having had your first post Coded, why didn't you do the second one yourself?

Are these "groups" of records delimited by the header=1, or is this an entire file?

You want 1, 2, 5, which must exist, in that order, followed by 3, 7, 8, which may be multiple, or may not even exist in numeric order within this second grouping?

You got any recfm/lrecl for your input and output.

See if you can work out from "stickies" in DFSORT forum how to tell your level of DFSORT.

Process is resonably simple. If 1 2 5, set generated field to a value, else set it to a different value. Sort on that value, then on record type. This is in English, the wizards will have ways to implement.

If this is not an entire file, would need another "key" for the sorting, and would need to know if header is for file or for key.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Sep 02, 2011 3:35 pm
Reply with quote

There is a discrepancy in example you shown initially and now.
In Initial example, You have two records with record type 2 and 3..

Where as in recent one you say there will be single record. this Is confusion...
Initial input example
Code:

1097201108120001
210000001AAAAT20
300000000UUU0005
500000000   AAB3
7000000000000000
7000000000000000
7000000000000000
8000000000000000
210000003BBBBB20
300000000UUU0005
500000000   ABCD

Recent input example
Code:

1097201108120001
210000001AAAAT20
300000000UUU0005
300000000UUU0007
500000000 AAB3
7000000000000123
7000000000000321
7000000000000100
8000000000000000

Are you trying to say that:
1: File will have one record with record type 1
2:Followed by chunk of record types 2 then 3(optional) then 5 then 7 (optional) then 8(optional)
And your are trying to sort records like record type 1(file level) then record type 2 then 5 then optional record types if present like 3,7,8

Confirm if my assumption is correct...


Also please provide:
What is LRECL\RECFM of input file
Back to top
View user's profile Send private message
kratos86

Active User


Joined: 17 Mar 2008
Posts: 148
Location: Anna NGR

PostPosted: Fri Sep 02, 2011 4:14 pm
Reply with quote

Please clarify -
1. Always record type 1 will be the first record
2. Second record will be type 2 and the set continues till the next occurance of type 2 record.
3. You want to sort the records between the type2 records? In which you want to follow the order 2,5 and other records in ascending order.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Sep 02, 2011 4:21 pm
Reply with quote

Ruma Dutta,

ask your school instructor for the answer.

we actually have things to do,
and needlessly wasting time pulling info from you to define your requirements
is not something,
even on a Friday,
that we want to do.
Back to top
View user's profile Send private message
Ruma Dutta

New User


Joined: 26 Aug 2011
Posts: 5
Location: INDIA

PostPosted: Fri Sep 02, 2011 4:31 pm
Reply with quote

Your assumption is correct.
1. Always record type 1 will be the first record
2. Second record will be type 2 and the set continues till the next occurance of type 2 record.
3.I want to sort the records between the type2 records? In which you want to follow the order 2,5 and other records in ascending order.
I think these will clarify other people doubts too. Thank you
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Sep 02, 2011 4:33 pm
Reply with quote

Ruma Dutta wrote:
Your assumption is correct.
1. Always record type 1 will be the first record
2. Second record will be type 2 and the set continues till the next occurance of type 2 record.
3.I want to sort the records between the type2 records? In which you want to follow the order 2,5 and other records in ascending order.
I think these will clarify other people doubts too. Thank you

You still havn't told LRECL and RECFM of input file and output file yet
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Sep 02, 2011 4:36 pm
Reply with quote

Assuming your record lenght is 80 and RECFM is FB

Below will give you desired output..
Code:

//S1    EXEC  PGM=SORT                                         
//SORTIN DD *                                                 
1097201108120001                                               
210000001AAAAT20                                               
300000000UUU0005                                               
500000000   AAB3                                               
7000000000000000                                               
7000000000000000                                               
7000000000000000                                               
8000000000000000                                               
210000003BBBBB20                                               
300000000UUU0005                                               
500000000   ABCD                                               
//SORTOUT DD SYSOUT=*                                         
//SYSOUT    DD  SYSOUT=*                                       
//SYSIN    DD *                                               
  ALTSEQ CODE=(F3F5,F5F3)                                     
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,ZD,EQ,2,OR,1,1,ZD,EQ,1),
  PUSH=(81:ID=8))     
  SORT FIELDS=(81,8,ZD,A,1,1,AQ,A)                                                       
  OUTREC FIELDS=(1,80)                                                                                 

Output will be
Code:

1097201108120001
210000001AAAAT20
500000000   AAB3
300000000UUU0005
7000000000000000
7000000000000000
7000000000000000
8000000000000000
210000003BBBBB20
500000000   ABCD
300000000UUU0005
Back to top
View user's profile Send private message
THINKSRINIII
Warnings : 1

New User


Joined: 09 Jan 2009
Posts: 88
Location: India

PostPosted: Fri Sep 02, 2011 4:50 pm
Reply with quote

Input

Code:
 
1097201108120001
210000001AAAAT20
300000000UUU0005
500000000   AAB3
7000000000000000
7000000000000000
7000000000000000
8000000000000000
210000003BBBBB20
300000000UUU0005
500000000   ABCD


Code:

Code:

//SYSIN    DD *                                                       
    INREC IFTHEN=(WHEN=GROUP,                                         
     BEGIN=(1,1,CH,EQ,C'2'),PUSH=(20:SEQ=1,ID=3)),                   
     IFTHEN=(WHEN=(1,1,CH,EQ,C'2'),OVERLAY(24:C'1')),                 
     IFTHEN=(WHEN=(1,1,CH,EQ,C'5'),OVERLAY(24:C'1')),                 
     IFTHEN=(WHEN=(1,1,CH,NE,C'5',OR,1,1,CH,NE,C'2'),OVERLAY(24:C'2'))
  SORT FIELDS=(21,3,CH,A,24,1,CH,A,1,1,CH,A)                         
    OUTREC BUILD=(1,16)                                               


Output:

Code:

1097201108120001
210000001AAAAT20
500000000   AAB3
300000000UUU0005
7000000000000000
7000000000000000
7000000000000000
8000000000000000
210000003BBBBB20
500000000   ABCD
300000000UUU0005


Is this fine ?
Back to top
View user's profile Send private message
Ruma Dutta

New User


Joined: 26 Aug 2011
Posts: 5
Location: INDIA

PostPosted: Fri Sep 02, 2011 4:52 pm
Reply with quote

Thank you Escapa for the solution, its working icon_smile.gif
Back to top
View user's profile Send private message
Ruma Dutta

New User


Joined: 26 Aug 2011
Posts: 5
Location: INDIA

PostPosted: Fri Sep 02, 2011 5:03 pm
Reply with quote

To THINKSRINIII,

This is also working fine. thank you
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Sep 02, 2011 5:05 pm
Reply with quote

Ruma Dutta
You are welcome...

THINKSRINIII
Didnt check if your solution actually works but few quick point I could observe..
1:WHEN=(1,1,CH,NE,C'5',OR,1,1,CH,NE,C'2'),
This is weird
2: Also Why you have added sequence number? Doesn't look you have used anywhere...
Back to top
View user's profile Send private message
THINKSRINIII
Warnings : 1

New User


Joined: 09 Jan 2009
Posts: 88
Location: India

PostPosted: Fri Sep 02, 2011 5:19 pm
Reply with quote

Escapa,

You are right.
Seq num was not used.

1:WHEN=(1,1,CH,NE,C'5',OR,1,1,CH,NE,C'2'),

This was used to pick all other records that are not having position 1 as 2 or 5.

Is there any other better method to pick the same?
Back to top
View user's profile Send private message
THINKSRINIII
Warnings : 1

New User


Joined: 09 Jan 2009
Posts: 88
Location: India

PostPosted: Fri Sep 02, 2011 5:24 pm
Reply with quote

Escapa,


1:WHEN=(1,1,CH,NE,C'5',OR,1,1,CH,NE,C'2'),
This was used to pick all other records other than those having character 2 or 5 in position 1.

Is there any other better method to do this?

2: Also Why you have added sequence number? Doesn't look you have used anywhere...

I had initial thoughts of using it but was not required. icon_confused.gif
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Sep 02, 2011 5:25 pm
Reply with quote

Quote:

1:WHEN=(1,1,CH,NE,C'5',OR,1,1,CH,NE,C'2'),

Dont you think you wanted to give

1:WHEN=(1,1,CH,NE,C'5',AND,1,1,CH,NE,C'2'),

And at this place

1:WHEN=(NONE), could have been used
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Sep 02, 2011 10:59 pm
Reply with quote

Escapa has the right approach. The control statements can be simplified to:

Code:

  ALTSEQ CODE=(F3F5,F5F3)                                           
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'2'),PUSH=(81:ID=8))   
  SORT FIELDS=(81,8,ZD,A,1,1,AQ,A)                                 
  OUTREC BUILD=(1,80)                                               
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top