View previous topic :: View next topic
|
Author |
Message |
SreekanthMada
New User
Joined: 06 Jan 2020 Posts: 2 Location: India
|
|
|
|
I want to convert a variable length file that does not have ‘fixed’ columns lengths and also has a non-fixed decimal.
Ex:
123|ABC|12.5043|
12345|ABC|112.5043|
1|ABC|2.50000043|
I want to have a fixed file with the decimal in 9(6)v99. Can some one please guide me. Thanks in advance
Thanks
Sreekanth |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2019 Location: USA
|
|
|
|
There are two separate issues:
1) To split CSV character-type fields by separators you need to use PARSE=…,BUILD=… parameters in either INREC/OUTREC/OUTFIL statements. The separator used instead of "comma" must be specified in ENDBEFR=C'|' and/or other separators.
2) More complicated case is, parsing numeric values with variable decimal point position. A special PARSE/BUILD combination is needed with ENDBEFR=C'.' parameter, in order to split actual whole/fractional parts of the numeric value. The provided SORT formats ZD/UFF/SFF cannot detect decimal point position.
Unfortunately, none of SORT manuals give any clue on how to parse flexible numeric values with variable decimal point position, but there are examples of similar operations in this forum. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2019 Location: USA
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2019 Location: USA
|
|
|
|
Code: |
//VARPOINT EXEC PGM=SORT
//*
//SYSOUT DD SYSOUT=*
//*
//SORTIN DD *
123|ABC|12.5043|
12345|ABC|112.5043|
1|ABC|2.50000043|
//*
//SORTOUT DD SYSOUT=*
//*
//SYSIN DD *
INREC PARSE=(%1=(STARTAT=NONBLANK,
ENDBEFR=C'|',
ENDBEFR=C' ',
FIXLEN=5),
%2=(ENDBEFR=C'|',
ENDBEFR=C' ',
FIXLEN=3),
%3=(ENDBEFR=C'.',
ENDBEFR=C'|',
ENDBEFR=C' ',
FIXLEN=6),
%4=(ENDBEFR=C'|',
ENDBEFR=C' ',
FIXLEN=2)),
BUILD=(%1,JFY=(SHIFT=RIGHT,LEAD=C'00000'),
X,%2,
X,%3,JFY=(SHIFT=RIGHT,LEAD=C'000000'),
%4,JFY=(SHIFT=LEFT,TRAIL=C'00'))
*
SORT FIELDS=COPY
*
END
//* |
Code: |
********************************* TOP OF DATA ******
00123 ABC 00001250
12345 ABC 00011250
00001 ABC 00000250
******************************** BOTTOM OF DATA **** |
|
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1246 Location: Bamberg, Germany
|
|
|
|
Why not chose a simpler form for %1 and %3 variables?
Code: |
BUILD=(%1,UFF,M11,X,%2,X,%3,UFF,M11,
%4,JFY=(SHIFT=LEFT,TRAIL=C'00')) |
|
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2019 Location: USA
|
|
|
|
Joerg.Findeisen wrote: |
Why not chose a simpler form for %1 and %3 variables?
Code: |
BUILD=(%1,UFF,M11,X,%2,X,%3,UFF,M11,
%4,JFY=(SHIFT=LEFT,TRAIL=C'00')) |
|
The reason is: I do not keep in mind all those formats M1-M100500, and I'm lazy to re-check the manual every time. |
|
Back to top |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1246 Location: Bamberg, Germany
|
|
|
|
Accepted. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3051 Location: NYC,USA
|
|
|
|
Quote: |
I want to convert a variable length file that does not have ‘fixed’ columns lengths and also has a non-fixed decimal. |
If you could have done Google and did some Research then you would have got many links and solutions to convert CSV (VB ) Data to FB including Decimals.
e.g.
ibmmainframes.com/about54790.html |
|
Back to top |
|
|
SreekanthMada
New User
Joined: 06 Jan 2020 Posts: 2 Location: India
|
|
|
|
Thanks sergeyken, Joerg.Findeisen, Rohit Umarjikar
Its working |
|
Back to top |
|
|
|