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?
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
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----------------------
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?
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).
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.
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?
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.
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.
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
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..."
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?
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..
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.
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.
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.
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.
Joined: 10 May 2007 Posts: 2455 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.)