I've data in the below batch card format. Data for different country starts with 'SAC'. Each batch within SAC starts with 120 record and ends with '128'. 123-1 is invoice header and 123-2 is invoice amount detail line. I need to sort the file such that if 123-2 has amount zeroes, both 123-1 and 123-2 should be dropped. Please help on this.
SAC XXXX
120 batch header
123-1 Invoice1
123-2 AMT - 99999
123-1 Invoice 2
123-2 AMT - 00000
123-1 Invoice 3
123-2 AMT - 68293
128
Note: One SAC may have multiple batches(120 thru 128) and one file may have multiple SAC cards(SAC thru 128)
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Do you really want to SORT the file (as in re-sequence it) or just use the SORT-MAGIC?
Quote:
such that if 123-2 has amount zeroes, both 123-1 and 123-2 should be dropped
Here you mean only the specific 123-1 that is related to the zero 123-2? I ask, because then the requirement becomes:
Code:
123-1 Invoice 2
123-2 AMT - 00000
"When I see 123-2 with 'AMT - 00000' I want to delete it and the 123-1 immediately in front of it. All other data is to remain, and remain in the same sequence" or something like that?
You talk of "invoice line" but there is only one 123-2 in any or your examples. Can there be multiple 123-2's? If so, what if one of those is zero? You have "country", you say, are all the amounts in one currency? Why no decimal places on the amount?
123-1 and 123-2 lines belongs to one invoice but Invoice amount is available in 123-2. If Invoice amount is zero, then I want to skip 123-2 and its corresponding 123-1(that is the previous record in the file).
I gave the sample amount. The actual format is s9(14)v9(02) ebcdic.
See my answers below..
1. Do you really want to SORT the file (as in re-sequence it) or just use the SORT-MAGIC?
I dont want the file to be sorted. I want to use SORT for eliminating unwanted records. So the sequence in the file should be retained.
2. Here you mean only the specific 123-1 that is related to the zero 123-2?
Yes. When 123-2 has zero amount, both 123-1 and 123-2 should be omitted
3. "When I see 123-2 with 'AMT - 00000' I want to delete it and the 123-1 immediately in front of it. All other data is to remain, and remain in the same sequence" or something like that?
Yes
4. You talk of "invoice line" but there is only one 123-2 in any or your examples. Can there be multiple 123-2's
No. one 123-1 will have only one 123-2 record.
5. You have "country", you say, are all the amounts in one currency?
Yes, all amounts under one SAC will have same currency
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Code:
123-1 Invoice 2
123-2 AMT - 0000000000000000
"When I see 123-2 with 'AMT - 0000000000000000' I want to delete it and the 123-1 immediately in front of it. All other data is to remain, and remain in the same sequence".
Is the amount "display" or "packed" or even "binary"? Ie, when you look at the file does it show zeros like above? Is the position of the zeros correct? What are the RECFM and LRECL of your file? Or are you going to deal with all those after a basic example?
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
vasanthz,
Please don't complicate a simple request with 2 passes of sorting when you just need 1 pass of data with a copy operation. Keep it Simple.
srinut123,
The following DFSORT JCL will give you the desired results. I assumed that your input is FB recfm and LRECL=80. The amount field on 123-2 record starts at pos 13 for 5 btyes and you want to eliminate if it is -0 or +0.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Never thought I'd get the chance to query either Frank or Kolusu. Yet, not only on the same day, but the same topic :-)
Problem is, the zero is not a case of + and -, but + and unsigned. the "{" is positive zero (matching TS's s9(14)v9(02)), checked on dbz's STICKY in the Cobol forum, and just now on my trusty "yellow card".
From an eminent tome:
Quote:
NOSZERO
specifies that DFSORT should treat numeric zero values as unsigned. −0
and +0 are treated as the same value, that is, −0 and +0 are both treated as
positive values. NOSZERO affects DFSORT processing of numeric values
as follows:
For collation of SORT and MERGE fields, −0 collates equally with +0.
For comparisons of INCLUDE, OMIT and OUTFIL compare fields and
constants, −0 compares as equal to +0.
For editing and conversions of INREC, OUTREC, and OUTFIL
reformatting fields, decimal constants, and the results of arithmetic
expressions, −0 and +0 are treated as positive.
For minimums and maximums of OUTFIL TRAILERx fields, −0 and +0
are treated as positive.
Which doesn't, excplicitly, cover the TS's unusual situation. An unsigned zero (F0) and a positive zero (C0). I have searched the Application Programming Guide, but apart from something in a sideways table at the back (which is only a possible-maybe), there is nothing to indicate if +0 also covers the unsigned zero, but if so it would be nice if it were mentioned in the above text for clarity.
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
Quote:
Please don't complicate a simple request with 2 passes of sorting
True I overkilled it. Thanks for educating with the optimum/best solution. Someone told that "there can't be interesting thoughts, if there were no stupid thoughts", my solution belonged to the latter category (:
Quote:
2 new avatars today?
Ya D, He is Rajnikanth a great actor, he is on bad health
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Skolusu wrote:
Bill Woodger,
Read the notes under DFSORT Data Formats for ZD Format
Got it. Will work a treat.
What took me away was the specific focus on +0, -0 without reference to the deeper meaning of these in the ZD description. I searched every reference to "unsigned" thinking that might get me somewhere.
Thanks for every one. I tried the one pass Sort JCL and it gave me the results as expected. It worked for both numbers ending with an EBCDIC and non EBCDIC value.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
srinut123,
Don't forget about the "problem" with the file. A mix of signed and unsigned data in a field defined in a Cobol program may not work and is not good practice.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
As a side note, Kolusu and I discussed the +0, -0 situation offline. I felt there was no indication that -0 could be present. He suggested covering it anyway, so we threw in NOSZERO just in case. If only +0 has to be covered, then ',NOSZERO' can be removed.