|
View previous topic :: View next topic
|
| Author |
Message |
sudhanaveenkumar
New User

Joined: 29 Apr 2010 Posts: 28 Location: chennai
|
|
|
|
Hi,
I have a requirement like this:
1)Each record has one field of variable length in a flat file of length 10.
aaa
bbbbb
ccccccc
I want each record to be suffixed with ,(comma) at the end of non blank chars in the record.
i.e.
o/p should be:::
aaa,
bbbbb,
ccccccc,
I had tried with PARSE but no use as it uses FIXLENGTH. Whenever PARSE finds blank, i moved it to FIXLENGTH of 7 and used BUILD to append comma.i could see few spacess before comma.
o/p was :
aaa ,
bbbbb ,
ccccccc,
Will it be possible to do with icetool/sort.
Thanks a lot. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Can you have embedded spaces in your data?
If not, FINDREP (which finds and replaces) can do it for you. Change a space to a comma, and DO it only once.
Edit: This looks related to your previous question. If so, it is probably best to list the whole requirement, otherwise we might spend time on things we later find aren't necessary. |
|
| Back to top |
|
 |
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
what if there is no space in last byte ?
If there are no embedded spaces then this might help
| Code: |
//STEP0001 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC IFTHEN=(WHEN=(10,1,CH,EQ,C' '),
OVERLAY=(10:C','))
OUTREC BUILD=(1,10,SQZ=(SHIFT=LEFT))
/*
|
Gerry |
|
| Back to top |
|
 |
sudhanaveenkumar
New User

Joined: 29 Apr 2010 Posts: 28 Location: chennai
|
|
|
|
Good call, worked a treat!
Thanks a lot gcicchet and Bill.
There will be a space in last byte and no embedded spaces. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
OK, no problem.
Remember, if connected to your previous question and one of the every-third input records contains eight characters, the trailing comma will be chopped off when it becomes one of three parts of a 28-byte record.
I'd done on for the "embedded spaces", so it may as well appear...
| Code: |
//TRLCOMMA EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(01,10,CH,EQ,C' '),OVERLAY=(01:C' ')),
IFTHEN=(WHEN=(02,09,CH,EQ,C' '),OVERLAY=(02:C',')),
IFTHEN=(WHEN=(03,08,CH,EQ,C' '),OVERLAY=(03:C',')),
IFTHEN=(WHEN=(04,07,CH,EQ,C' '),OVERLAY=(04:C',')),
IFTHEN=(WHEN=(05,06,CH,EQ,C' '),OVERLAY=(05:C',')),
IFTHEN=(WHEN=(06,05,CH,EQ,C' '),OVERLAY=(06:C',')),
IFTHEN=(WHEN=(07,04,CH,EQ,C' '),OVERLAY=(07:C',')),
IFTHEN=(WHEN=(08,03,CH,EQ,C' '),OVERLAY=(08:C',')),
IFTHEN=(WHEN=(09,02,CH,EQ,C' '),OVERLAY=(09:C',')),
IFTHEN=(WHEN=(10,01,CH,EQ,C' '),OVERLAY=(10:C','))
//SORTIN DD *
0
1234567 9
12345 78
123 567
1 3456
1 3 5
12 4
1 3
12
1 |
Output is:
| Code: |
0
1234567 9,
12345 78,
123 567,
1 3456,
1 3 5,
12 4,
1 3,
12,
1,
|
|
|
| Back to top |
|
 |
sudhanaveenkumar
New User

Joined: 29 Apr 2010 Posts: 28 Location: chennai
|
|
|
|
Many thanks Bill for your inputs.
Regards |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| sudhanaveenkumar wrote: |
Good call, worked a treat!
Thanks a lot gcicchet and Bill.
There will be a space in last byte and no embedded spaces. |
If there are no embedded spaces then you can use the following DFSORT JCL
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
INREC BUILD=(1,10,SQZ=(SHIFT=LEFT,TRAIL=C','))
//* |
|
|
| Back to top |
|
 |
sudhanaveenkumar
New User

Joined: 29 Apr 2010 Posts: 28 Location: chennai
|
|
|
|
Thanks Kolusu.
I have one more question.
I want to do a specific processing for the last record in an input file and i dont know how many records are in the input file and i cant uniquely identify the last record.
For the same sample jcl you have given above ,
For example if i want to append semicolon (;) to the last record alone in an input file.How can it be done?
Thanks a lot |
|
| Back to top |
|
 |
sudhanaveenkumar
New User

Joined: 29 Apr 2010 Posts: 28 Location: chennai
|
|
|
|
Of course, i can include all possibilities as mentioned in Bill Woodger sample jcl.
But It will be too lengthy if the field size increases to 20(10 shown above).
Would you please advise much simpler way to perform specific processing on last record alone where i cant uniquely identify it? |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| sudhanaveenkumar wrote: |
Thanks Kolusu.
I have one more question.
I want to do a specific processing for the last record in an input file and i dont know how many records are in the input file and i cant uniquely identify the last record.
For the same sample jcl you have given above ,
For example if i want to append semicolon (;) to the last record alone in an input file.How can it be done?
Thanks a lot |
Use the following DFSORT/ICETOOL JCL which will give you the desired results
| Code: |
//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
1234567890
123456789
12345678
1234567
123456
12345
1234
123
12
1
//T1 DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//LR DD DSN=&&LR,DISP=(,PASS),SPACE=(TRK,(1,0),RLSE)
//TOOLIN DD *
SUBSET FROM(IN) TO(LR) DISCARD(T1) INPUT KEEP TRAILER USING(CTL1)
//CTL1CNTL DD *
INREC BUILD=(1,10)
OUTFIL FNAMES=LR,OVERLAY=(1,10,SQZ=(SHIFT=LEFT,TRAIL=C','))
//*
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=&&T1,DISP=SHR
// DD DSN=&&LR,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
//* |
|
|
| Back to top |
|
 |
sudhanaveenkumar
New User

Joined: 29 Apr 2010 Posts: 28 Location: chennai
|
|
|
|
| Thanks Kolusu. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|