WHEN=GROUP facilitates various types of group operations such as sorting by groups, including or omitting records by groups, and so on. You may also propagating fields, identifiers and sequence numbers within groups. WHEN=GROUP clauses can be used in INREC, OUTREC and OUTFIL statements by themselves or in conjunction with the other existing types of IFTHEN clauses.
An example to brief you on this new function, you could use the following statement to define groups of 3 records and add an identifier and sequence number to each record of each group.
INREC IFTHEN=(WHEN=GROUP,RECORDS=3,PUSH=(15:ID=3,19:SEQ=5))
Input records are:
Vicky
Sri
Hari
Frank
David
Dave
Regina
Sam
Viet
The output records would be:
Vicky 001 00001
Sri Hari 001 00002
Frank 001 00003
David 002 00001
Dave 002 00002
Regina 002 00003
Sam 003 00001
Viet 003 00002
Syntax :
The syntax for the IFTHEN WHEN=GROUP clause is as follows:
IFTHEN=(WHEN=GROUP,BEGIN=(logexp),END=(logexp),RECORDS=n,PUSH=(c:item,...))
Description :
- WHEN=GROUP must be specified to indicate this is a WHEN=GROUP clause.
You can specify the BEGIN, END and RECORDS operands in any combination to define the groups, but You must specify at least one of these operands. - BEGIN=(logexp) - Specifies the criteria to be tested to determine if a record starts a group.
- END=(logexp) - Specifies the criteria to be tested to determine if a record ends a group.
- RECORDS=n - Specifies the maximum number of records in a group. n can be 1 to 2000000000.
- PUSH=(c:item,...) - Specifies the position where each field, identifier or sequence number is to be overlaid in the records of each group.
- ID=n - Specifies a ZD identifier of length n is to be added to every record of each group. The identifier starts at 1 for the first group and is incremented by 1 for each subsequent group. n can be 1 to 15.
- SEQ=n - Specifies a ZD sequence number of length n is to be added to every record of each group. The sequence number starts at 1 for the first record of each group and is incremented by 1 for each subsequent record of the group. n can be 1 to 15.
Please do provide your comments or reactions. For further reference click here.
very useful and nicely explained. thanks!
ReplyDeleteI WANT TO GROUP A SET OF RECORDS IF A PARTICULAR RECORD IS FOUND IN THE GROUP ..FOR EG :
ReplyDeleteINPUT
=======
HDR
1XXY
2YYYX
3ZZX
TRL
HDR
122X
2XX2
3XXX3
TRL
CRITERIA: GROUP ONLY THOSE RECORDS THAT CONTAINS A DETAIL RECORD "22" IN BYTE 2 AND 3
OUTPUT
==========
HDR
122X
2XX2
3XXX3
TRL
Excellent
ReplyDelete