|
View previous topic :: View next topic
|
| Author |
Message |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
Hi,
I have a following requirement in sorting records in a file.
I have a file with DATE, member id along with page headers in between.
Sample Layout as shown below
| Code: |
PAGE HEADER1 PAGE NO: 1 TIME:XXXX DATE XXX
MEMID4 20020101
MEMID2 20020501
MEMID3 20020501
MEMID1 20020102
PAGE HEADER2 PAGE NO: 2 TIME:XXXX DATE XXX
MEMID7 20020104
MEMID9 20040501
MEMID3 20020501
MEMID2 20060102 |
I want to sort the file based on date keeping the headers intact.
Can this be achieved using DFSORT? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Certainly. Would you like to decide what you want it sorted on? Does the sort take place within the page? Otherwise keeping the headers is a bit of a nonsense. Why don't you sort the data going in to the report? |
|
| Back to top |
|
 |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
I want to sort the file based on date keeping the headers intact.
The input data(The records along with the headers) is coming from a separate system so we do not have the liberty to sort the data going in to the report. We only have the report as input to us unfortunately  |
|
| Back to top |
|
 |
dbzTHEdinosauer
Global Moderator

Joined: 20 Oct 2006 Posts: 6965 Location: porcelain throne
|
|
|
|
Frank, Kolusu
(or any of the members here that write DFSORT control statements for free)
will need some details.
Record Type,
Record Length
Identifying characteristics of a 'Header'.
field assignment (position, datatype) |
|
| Back to top |
|
 |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
Thanks..
The record type is FB and with LRECL = 300
The date that is to be sorted is of length 8 bytes starting at position 25.
After sorting the record based on DATEIN field the headers/trailers should be intact.
The sample file content is as below
| Code: |
06/04/11 WELCOME TO ABC CORP page 1
03:55
-----------------------------------------
MEMBER ID DATE IN
-----------------------------------------
abcf123 20050501
def1122 20030401
gihi545 20070401
06/04/11 WELCOME TO ABC CORP page 2
03:55
-----------------------------------------
MEMBER ID DATE IN
-----------------------------------------
abcf456 20000501
def1666 20040401
gihi111 20020401
--------end of report---------------------- |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| seahawk789 wrote: |
I want to sort the file based on date keeping the headers intact.
The input data(The records along with the headers) is coming from a separate system so we do not have the liberty to sort the data going in to the report. We only have the report as input to us unfortunately  |
To confirm, by "keeping the headers intact" you want the data sorted within the existing report page.
You will have to be able to reliably identify the headings where they start and end. What about blank lines?
What does it look like when it goes-over-a-page with the same grouping? Do you want them sorted across the group as a whole, or on the actual existing pages when there is an inconvenient page-break? What is the existing report grouped on? |
|
| Back to top |
|
 |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
Yes , by "keeping the headers intact" I want the data sorted within the existing report page.
I want them sorted across the group as a whole. i.e it should seem like the file was initially sorted based on the whole based on date(pos 80,leng10) and then headers were inserted.
The headers start at pos 1 and end at 80
Header description is as follows
The Line one of headers will always have 'welcome' at position 40.
LINE2 will have 'REPORT' at POSITION 35. (I have not shown that above)
LINE3 will contain '-------' in first 50 positions
Line4 will contain 'MEMBERID' starting at position 1.
LINE5 will contain '-------' in first 50 positions
Also lines having spaces in first 5 positions also should be considered as part of the header (that should not be considered for sorting either). |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I still don't see in your example what has cause the "break" to make a new page between your first two sample pages.
This might be needed if you have, say, 80 items which are within a "break", so would print on two pages, but need to be sorted so that different data can appear on 1st/2nd page than appeared before. That'll be the tricky part of the problem.
Apart from that, if you turn-it-upside-down. The identification of the non-data-lines is complex. So, can the data-lines be reliably idenfitied (like date starting with "20")? Then there is non-data, retain original sequence, data, for instance set all in group to seq number of first data line, then sort on date. Then sort whole kit-and-kaboodle on sequence and date (can be set to zero, or whatever, for all non-data).
But, you have that tricky bit. Without knowing the control information which has caused the break and which hasn't caused the 2nd-type-of-break, which was just the page filling up. |
|
| Back to top |
|
 |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
ohh its getting complicated..
Do u have any examples where u don't include certain records for sorting but include them in the sort output?
I mean if u use omit condition, it will be excluded completely, but I want it to be excluded only from sorting logic but has to be present in the output? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It is not too complicated. Except for the lack of control information for when it crosses a page. That can be the killer.
Otherwise, I'm sure the wizards can do if you don't manage it yourself. Look through the forum, you'll see aparently complex things which can be dealt with.
But, lacking control information (not used to seeing a report with nothing to indicate why it paginates like that, personally) then you'd have to go back to the report producer to get reliable output, I think. |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
from the overall wording the detail sort should take place only within the current layout of pages,
and leave the overall report aspect the same |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, enrico, but...
If you have a group of data with 80 items, it gets the page-break for being a new group of data and a page-break for filling up the page. Items on the second page of the group might, if you were able to sort, appear on the first page logically, and vice versa. What if there are 300 lines in a logical group?
OK, not what the TS asked for, but I bet the user won't be happy with "Oh, and if the page is full, just have a quick check on the next page(s) as well".
Other than this problem, I think it is fairly straightforward.
Even with the control information it would increase the complexity. With the control information, and if too complex, I'd go for extracting the data from this report and doing a new report from that data. |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
Yep...
but, as You have noticed already, people around here are concerned only about the lowly technicalities ,
not about logical application/organization/common_practce wise solutions !
and as long as they get a ready to run solution they do not care about anything else |
|
| Back to top |
|
 |
dbzTHEdinosauer
Global Moderator

Joined: 20 Oct 2006 Posts: 6965 Location: porcelain throne
|
|
|
|
seahawk789,
you are not consistant with your header information.
I would suggest that you - provide an accurate description (cut&paste) of the headers - you have several.
- accurate description of the detail lines
by looking at your Report it appears to be a listing of people and a date.
the afore talked-about control breaks appear to be number of lines.
if the above is true, one solution would be- toolstep1
- save the first n number of lines - as they are headers to temp1 file
- omit all headers, writing all detail to temp2
- sort the detail (temp2) giving temp3
- merge modified versions of temp1 with temp3
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
's why I asked about necessity to keep data within page originally appeared on. Confirmed by TS. Only sense I can see to that is that it is some part of a "group". If not, then I'd go back to this:
| Quote: |
| The identification of the non-data-lines is complex. So, can the data-lines be reliably idenfitied (like date starting with "20")? Then there is non-data, retain original sequence, data, for instance set all in group to seq number of first data line, then sort on date. Then sort whole kit-and-kaboodle on sequence and date (can be set to zero, or whatever, for all non-data). |
Although, if not in groups, not necessary to be on original page, so the above would be fine as well. Unless the user of the original contacts the user of the new and talks about "I have this item on page 17..." |
|
| Back to top |
|
 |
PeterHolland
Global Moderator

Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
This requirement is a lot of crap. The TS shows input that is clearly output
of a utility. That utility can not be used to reproduce the output sorted on date? Or to sort the input of that utility on date? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Been there Peter. It is from an external source. Certainly worth a go at getting it changed, even if "external" has to do it.
Then they post here... |
|
| Back to top |
|
 |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
| Bill, for me its not in groups, and its not necessary to be on original page. only thing I want to insert the respective page headers after 80 lines. That is page 1 header should be placed after first set of 80 lines and page2 header after 180 lines and so on.. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| seahawk789 wrote: |
Yes , by "keeping the headers intact" I want the data sorted within the existing report page.
I want them sorted across the group as a whole. i.e it should seem like the file was initially sorted based on the whole based on date(pos 80,leng10) and then headers were inserted.
[...]
|
Mmmm... I missed the second paragraph. To me, contradicts the first, but I probably wasn't clear enough.
dbz got it. Either approach sh/would work.
Without the example dbz has asked for, you'll just have to change positions from any provided solutions.
So, data-lines copied out, sorted on date, acquires sequence number. Original data-lines aquire sequence number. Re-insert sorted into original (with report headings, blank lines, end of report, and everything already on it), based on generated sequence numbers. Drop generated sequence numbers.
Cake anyone? |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
seahawk789,
See if below works... I have tried to create header records matching all 6 of your header conditions but if you have more you need to add them in the 3rd IFTHEN condition.
For future reference, please try to provide sample test data matching all of your condition.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
HEADER COND1 WELCOME
HEADER COND2 REPORT
--------------------------------------------------HEADER COND3
MEMBERID HEADER COND4
--------------------------------------------------HEADER COND5
HEADER COND6
MEMID4 20020101
MEMID4 20020101
MEMID2 20020501
MEMID3 20020501
MEMID1 20020102
HEADER COND1 WELCOME
HEADER COND2 REPORT
--------------------------------------------------HEADER COND3
MEMBERID HEADER COND4
--------------------------------------------------HEADER COND5
HEADER COND6
MEMID7 20020104
MEMID9 20040501
MEMID9 20040501
MEMID3 20020501
MEMID2 20060102
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(40,07,CH,EQ,C'WELCOME'),
PUSH=(301:ID=8)),
IFTHEN=(WHEN=INIT,OVERLAY=(309:25,8)),
IFTHEN=(WHEN=((40,07,CH,EQ,C'WELCOME'),OR,
(35,06,CH,EQ,C'REPORT'),OR,
(01,50,CH,EQ,C'-'),OR,
(01,08,CH,EQ,C'MEMBERID'),OR,
(01,05,CH,EQ,C' ')),OVERLAY=(309:8C'0'))
SORT FIELDS=(301,8,ZD,A,309,8,ZD,A),EQUALS
OUTFIL BUILD=(1,300)
//* |
OUTPUT
| Code: |
HEADER COND1 WELCOME
HEADER COND2 REPORT
--------------------------------------------------HEADER COND3
MEMBERID HEADER COND4
--------------------------------------------------HEADER COND5
HEADER COND6
MEMID4 20020101
MEMID4 20020101
MEMID1 20020102
MEMID2 20020501
MEMID3 20020501
HEADER COND1 WELCOME
HEADER COND2 REPORT
--------------------------------------------------HEADER COND3
MEMBERID HEADER COND4
--------------------------------------------------HEADER COND5
HEADER COND6
MEMID7 20020104
MEMID3 20020501
MEMID9 20040501
MEMID9 20040501
MEMID2 20060102 |
Thanks, |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
sqlcode,
I've been trying to make this easy to do :-)
Why don't you like "identify the data lines/leave everything else alone"? Positions, content, artistic style of everything except the data lines becomes irrelevant. Copy 'em out. Sort 'em. Stick 'em back where a data-line was originally.
I've even been thinking I could code it, using enrico's duplicate-matching code.
Don't worry, only thinking. |
|
| Back to top |
|
 |
sqlcode1
Active Member
Joined: 08 Apr 2010 Posts: 577 Location: USA
|
|
|
|
Bill Woodger,
The logic here in the code I gave, identifies HEADER records and populate sort key values in such a way so that HEADER records are kept together and at the top for every group starting with given HEADER conditions.
Sure, we may approach "identify the data lines/leave everything else alone", but unless, I am missing some of OP's remarks here, I don't see a way to identify "detail" records.
One way to achieve the same would be to use below conditions,which checks for "NUM"erics on 25th position,but I am not sure if that will suffice OP's requirement. This would fail if one of the header conditions has numbers at 25th position.
| Code: |
//SYSIN DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(40,07,CH,EQ,C'WELCOME'),
PUSH=(301:ID=8)),
IFTHEN=(WHEN=INIT,OVERLAY=(309:25,8)),
IFTHEN=(WHEN=(25,8,FS,NE,NUM),OVERLAY=(309:8C'0'))
SORT FIELDS=(301,8,ZD,A,309,8,ZD,A),EQUALS
OUTFIL BUILD=(1,300)
//* |
Thanks, |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| sqlcode, you are right. Didn't get an answer to "reliably identify" and still no actual example of the data. |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
I think the issue may have been resolved earlier if there had been sample output to go with the sample input - then we could have seen if data lines changed pages or not - there could be a lot of language problem here.
One of the replies from OP suggests that the data lines should be extracted, sorted and headers re-inserted every 80 lines (page of A4?) except the every 80 lines was line 80, 180 etc (but that could have been a typo and should have been 80, 160,240 etc.) |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| seahawk789, anything for sqlcode1 on this one, before you move on to the next? |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|