Counting and appending a constant
Select messages from
# through # FAQ
[/[Print]\]

MVSFORUMS.com -> Utilities

#1: Counting and appending a constant Author: rajvasan PostPosted: Fri Dec 20, 2002 1:06 am
    —
Dear All,
I have a doubt. Say, I have a 1000 records. Now, can I append a constant, say at the end of every 50 records. Hence, there would be a constant at the 50th, 100th, 150th records and so on... Is it possible ???

With Best Regards,
Rajvasan

#2:  Author: PremkumarLocation: Chennai, India PostPosted: Fri Dec 20, 2002 1:20 am
    —
You can do that using Sort.

  1. Append 2 digit SEQNUM to all the records using INREC.
  2. Append the constant for the records that have 00 or 50 in the SEQNUM column, using OUTREC.
  3. Remove the SEQNUM column using OUTFIL OUTREC.

#3:  Author: rajvasan PostPosted: Fri Dec 20, 2002 2:47 am
    —
Prem,
Thanks for the quick reply. But as per what you said, I need to code about 20 outrec statements (for 1000 records) . Is there any method to do it ??

With Best Regards,
Rajvasan

#4:  Author: PremkumarLocation: Chennai, India PostPosted: Fri Dec 20, 2002 4:39 am
    —
Raj,

You need not code 20 outrec statements. Your sort control cards for FB80 file will be,
Code:

OPTION COPY                                       
INREC  FIELDS=(SEQNUM,2,ZD,1,80)                   
OUTREC FIELDS=(3,80,1,2,CHANGE=(5,C'00',C'12345',
                                  C'50',C'12345'),
                       NOMATCH=(C'     '))       


I coupled removing the SEQNUM with OUTREC itself.
Your output file will be FB85 with every 50th record having '12345' appended and other records having 5 blanks appended.

Hope this helps.

#5:  Author: PremkumarLocation: Chennai, India PostPosted: Fri Dec 20, 2002 4:50 am
    —
In case, you don't want Syncsort throwing the message,
WER238I POTENTIALLY INEFFICIENT USE OF INREC
modify the sort control statements as follows.
Code:

OPTION COPY                                       
OUTREC FIELDS=(SEQNUM,2,ZD,1,80)                 
OUTFIL OUTREC=(3,80,1,2,CHANGE=(5,C'00',C'12345',
                                  C'50',C'12345'),
                        NOMATCH=(C'     '))       

#6:  Author: rajvasan PostPosted: Fri Dec 20, 2002 9:20 am
    —
Prem,
Thanks once again for a prompt reply. Suppose the no of records go up to say 1000,000 how do we go about solving this problem

Thanks,
Rajvasan

#7:  Author: kolusuLocation: San Jose PostPosted: Fri Dec 20, 2002 9:37 am
    —
Rajvasan,

Premkumar's solution will work for any number of records.The solution has to be changed only when you need it for some other sequence.Right now you are changing every 50th record to have a constant value.If tommorrow you decide to change it to every 25th record , then you need to change the control cards as follows:

Code:

 OPTION COPY                                       
 OUTREC FIELDS=(SEQNUM,2,ZD,1,10)                       
 OUTFIL OUTREC=(3,10,1,2,CHANGE=(5,C'00',C'12345',       
                                  C'25',C'12345',       
                                  C'50',C'12345',       
                                  C'75',C'12345'),     
                         NOMATCH=(C'     '))             


Hope this helps...

cheers

kolusu

#8:  Author: rajvasan PostPosted: Fri Dec 20, 2002 9:55 am
    —
Kolusu/Prem,
I understand the reply that you both have given me. But, for a lot of records, I have to go ahead coding the outrec as below

Code:

OPTION COPY                                       
OUTREC FIELDS=(SEQNUM,2,ZD,1,10)                       
OUTFIL OUTREC=(3,10,1,2,CHANGE=(5,C'00',C'12345',       
                                  C'25',C'12345',       
                                  C'50',C'12345',       
                                  C'75',C'12345',       
                                  C'100',C'12345',       
                                  ................
                                  C'10000',C'12345'),
                                 NOMATCH=(C'     '))             


I would like to another if there is any other way than this ???

Best Regards,
Rajvasan

[/code]

#9:  Author: kolusuLocation: San Jose PostPosted: Fri Dec 20, 2002 10:07 am
    —
Rajvasan,

You don't have to code all the control cards as you showed.Since the seqnum is only 2 bytes,it will start over once again from 01 after every 100 records.To explain this clearly , let us say your file has 250 records.
so the seqnum will be

Code:

01
02
...
50
...
00   - 100th record
01   - 101 record
...

50   - 150th record
....
00   - 200th record
01   - 201 record   
..
50   - 250th record



So the seqnum keeps starting from 1 for every 100 records.This is applicable for 'n' no: of records in your input file.Since we want to change only multiples of 50, all we need is to change control cards for records which has seqnum 00 & 50

50 - 50th record
00 - 100th record

Hope this helps....

cheers

kolusu

#10:  Author: rajvasan PostPosted: Sat Dec 21, 2002 5:38 am
    —
Kolusu/Prem
Thanks a lot guys for your help

With Best Regards,
Rajvasan



MVSFORUMS.com -> Utilities


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Page 1 of 1

Powered by phpBB © 2001, 2005 phpBB Group