Page 2 of 2

Re: Need to add new character in O/P when input key gets cha

PostPosted: Thu Oct 02, 2014 8:49 pm
by BillyBoyo
Now I can see the code, a couple of things.

You are specifying DCB for an output file from SORT. There is no need to do this, SORT will do it. Since SORT will do it, using a DCB yourself just increases complexity and maintenance.

I think your expected output is incorrect, as you show three records with a key of 1, but only two on your input.

This may have lead you to code the OVERLAY like that.

On the REFORMAT record the "left" side represents the current record, and the right the next record. You should have no need to take the data from the right and put it on the left.

  INREC IFTHEN=(WHEN=((1,6,CH,NE,7,6,CH),AND,7,6,CH,NE,C' '),         
                 BUILD=(1,6,3X,C'Y')),           
         IFTHEN=(WHEN=NONE,                               
                 BUILD=(1,6,4X))

The first IFTHEN gets your "end of key" condition, the BUILD makes a new record, how you want it, with the flag on.

The second IFTHEN deals with all other records, where you can BUILD with a blank in your flag.

I you not realise it, but once a record is true for IFTHEN=(WHEN=(logical expression) no more IFTHEN processing ceases for that record, unless you specify HIT=NEXT in the IFTHEN. So you don't need to "avoid" the record you've just changed by negating the condition.

I've changed OUTREC to INREC. In this case makes no difference to processing, and in such cases I personally standardise on INREC (partly because people seem to think OUTREC has "special powers").

I've taken off all your column positions. The default start position for a fixed-length record is 1:, so you don't need that. If you don't specify a column, the next available position is used anyway. So taking them out and letting SORT roll with it is much easier for maintenance and readability.

You specified 3C' ', which is fine, but 3X does exactly the same thing without needing to ensure there is only one space between those quotes. It is worth locating this in the manual, as you should then find a couple of other things which can be helpful in a similar way.

Re: Need to add new character in O/P when input key gets cha

PostPosted: Thu Oct 02, 2014 9:38 pm
by Hariprasad K
Hi Billy,

Small correction in sort statement:

Modified statement line :-
JOIN UNPAIRED,F2
instead of
JOIN UNPAIRED,F1,F2


(Your Note: I think your expected output is incorrect, as you show three records with a key of 1, but only two on your input. - Yes, my output is not correct, after multiple iterations I found and modified above statement)

I will consider all your suggestions and make a note for future use. If I not consider the data from right side then flag (Y) is setting first record of each key instead of last record key. That's reason I took it from right side.

Re: Need to add new character in O/P when input key gets cha

PostPosted: Thu Oct 02, 2014 10:18 pm
by BillyBoyo
Well, serves me right for not checking your JNFnCNTLs. If you change the code in the JNF1CNTL to start at 1, and in the JNF2CNTL to start at 0, you shouldn't need to use the "right" side.

Because you are using the right side, you need the UNPAIRED,F2. So now change that to UNPAIRED,F1.

The F2 is the "next" record. The first record is not needed, as it cannot be the "next" record for anything.

The F1 is the "current" record. You need all the F1 records, including the final one, which has no F2 to match (as there is no "next" record for the last record).

It doesn't really matter which way around you code it. If you want to keep the F2 as "current" and the F1 as "next", the easiest thing to do is swap the fields on the REFORMAT statement, so the F2 appears first. Same difference, I just think it a little clearer the other way.

Re: Need to add new character in O/P when input key gets cha

PostPosted: Thu Oct 02, 2014 10:59 pm
by Hariprasad K
Thanks again Billy, it is also important, what we coded should be understand to others. I modified as per you suggestions !