|
View previous topic :: View next topic
|
| Author |
Message |
sudhakar_mainframe Warnings : 1 New User
Joined: 29 Jun 2006 Posts: 25
|
|
|
|
Hi all,
My requirement is to count the no of values in each field (column) and display in Count in bottom for each column.
Sample:
| Code: |
XXX XXX XXX XXX
YYY YYY YYY
ZZZ ZZZ ZZZ ZZZ
111 222
---------------
4 3 2 4
--------------- |
This count shows the no of values in each field or column (wont count the Spaces)
Thanks,
Venkata.
Code'd and de-mangled |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
On INREC, IFTHEN in WHEN=INIT to set a four-byte extension to zero. Four IFTHENs to test the field for non-blank and extend the record by one byte for each column with a value of one if non-blank.
Use OUTFIL reporting functions with REMOVECC, use TRAILER2 for some TOTs and BUILD to drop of the four excess bytes. |
|
| Back to top |
|
 |
sudhakar_mainframe Warnings : 1 New User
Joined: 29 Jun 2006 Posts: 25
|
|
|
|
Can you give sample code plz. urgent
Thanks,
Venkata. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| If you can type out a request like that, you can type out the code yourself. Really, which part was difficult? Probably the TRAILER2, so find examples of that (the manual, here, internet search). |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Hi Bill,
Don't you think HIT=NEXT will also be needed on IFTHEN statements (in case of more than one overlay is required for same record)? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, mistah kurtz, very good point.
I spent more time coding and de-mangling than thinking about it, because I half-suspect that the columns will turn out not to be fixed-position and that, along with the lines of dashes magically appearing, led me to expect a request for code, rather than hints :-) |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
Hi Sudhakar.
Please try something similar to the below code. First understand it and then modify it to get the required output.
| Code: |
OPTION COPY
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:C'1111')),
IFTHEN=(WHEN=(01,03,CH,EQ,C' '),
OVERLAY=(81:C'0'),HIT=NEXT),
IFTHEN=(WHEN=(05,03,CH,EQ,C' '),
OVERLAY=(82:C'0'),HIT=NEXT),
IFTHEN=(WHEN=(09,03,CH,EQ,C' '),
OVERLAY=(83:C'0'),HIT=NEXT),
IFTHEN=(WHEN=(13,03,CH,EQ,C' '),
OVERLAY=(84:C'0'))
OUTFIL REMOVECC,BUILD=(1,80),
TRAILER2=(1:TOT=(81,1,ZD,EDIT=(IIT)),
5:TOT=(82,1,ZD,EDIT=(IIT)),
9:TOT=(83,1,ZD,EDIT=(IIT)),
13:TOT=(84,1,ZD,EDIT=(IIT))) |
And please don't pester for code. Nobody is going to help you that way even if someone wants to. |
|
| Back to top |
|
 |
sudhakar_mainframe Warnings : 1 New User
Joined: 29 Jun 2006 Posts: 25
|
|
|
|
thanks for the responses. Any how i already got the solution before this post. I derived the result in same way. (Used Build instead of OVERLAY)
Thanks,
Venkata. |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
| Good for you! |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
I've been passed this one, which is a very useful way to do it:
| Code: |
OPTION COPY
INREC OVERLAY=(51:C'0000',
51:01,3,CHANGE=(1,C' ',C'0'),NOMATCH=(C'1'),
52:05,3,CHANGE=(1,C' ',C'0'),NOMATCH=(C'1'),
53:09,3,CHANGE=(1,C' ',C'0'),NOMATCH=(C'1'),
54:13,3,CHANGE=(1,C' ',C'0'),NOMATCH=(C'1')) |
The OUTFIL would be the same.
It is well worth understanding, and CHANGE doesn't seem to get the use it deserves. Anyone want to have a go at explaining exactly what that single OVERLAY statement does? |
|
| Back to top |
|
 |
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
This is really great! The single OVERLAY is by default populating the string '0000' in the 51st column and the subsequent CHANGE statements are looking up for spaces and setting the value to 1 if it does not find the match.
CHANGE syntax:
| Code: |
| input field start position,input field length,CHANGE=(output field length,find value,set value if find a match),NOMATCH=(set value if does not match) |
Thanks Bill for sharing this. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Correct mistah kurtz.
All in one shot it:
Sets four bytes from position 51 to zero
In position 51, for one byte, it will change that value to zero where there are spaces at position 1,3 otherwise it will be "1" at that position
This is repeated for the remaining three byte groups and one-byte positions from 52 to 54.
Note that the OVERLAY allows re-use of a position whose value has already changed in the OVERLAY. You can't do that with BUILD (you can use CHANGE in BUILD, of course). |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|