View previous topic :: View next topic
Author
Message
cuauhtli New User Joined: 15 Sep 2017Posts: 2 Location: Mexico
I want to split a record in name and percent, only records that contain the symbol %
input file LRECL=40
Code:
JOZD HABWRT ROPWZ 50.00%
RAZ ARRZNZ ROPWZ 50.00%
FDDGG EGGDG XSFDGG
RAYZRDO JAMWNWZ ZRBWRZWZ 50%
ZRWJZNDRO JAMWNWZ ZRBWRZWZ 50%
GGGHGGHGH JHJJHJ
RAYZRDO JAMWNWZ ZRBWRZWZ 50%
GRWNNYS DAZZ YW-8-98271 25%
ZNZ Y MOJAYZ V Y8-746-218 25%
ZNTONAO MOJAYZ Y8-166-7V 25%
MNMBBB DSFSFFSFFFSFSF
JOSW OTWRO YZSZR 34%%
DAWGO OTWRO YZSZR 33%
ROSZ MZRAZ OTWRO YZSZR 33%
GGHGGHGGHGHGHG
JWSSW YZMARZ GAZMZN 100%
GJGJGJHGJHGHJG
JOZD HABWRT ROPWZ 50.00%
RAZ ARRZNZ ROPWZ 50.00%
HGHGHGHG
RAA XAZ ZHA DW RAZO 100.00%
GHFFGFGFGFG
RWTAYAZ YWYARAZ DAZRTW NNANWS 100%
the output should be like below, LRECL=48
Code:
JOZD HABWRT ROPWZ |50.00%
RAZ ARRZNZ ROPWZ |50.00%
RAYZRDO JAMWNWZ ZRBWRZWZ |50%
ZRWJZNDRO JAMWNWZ ZRBWRZWZ |50%
RAYZRDO JAMWNWZ ZRBWRZWZ |50%
GRWNNYS DAZZ YW-8-98271 |25%
ZNZ Y MOJAYZ V Y8-746-218 |25%
ZNTONAO MOJAYZ Y8-166-7V |25%
JOSW OTWRO YZSZR |34%
DAWGO OTWRO YZSZR |33%
ROSZ MZRAZ OTWRO YZSZR |33%
JWSSW YZMARZ GAZMZN |100%
JOZD HABWRT ROPWZ |50.00%
RAZ ARRZNZ ROPWZ |50.00%
RAA XAZ ZHA DW RAZO |100.00%
RWTAYAZ YWYARAZ DAZRTW NNANWS |100%
Please anybody help me to achieve this.
Back to top
Phrzby Phil Senior Member Joined: 31 Oct 2006Posts: 1050 Location: Richmond, Virginia
Per your profile, you're an analyst with COBOL experience who joined the forum 5 years ago.
What have you tried so far?
Back to top
Rohit Umarjikar Global Moderator Joined: 21 Sep 2010Posts: 3076 Location: NYC,USA
Inrec parse into four elements
Then outfile build according how you want ( specially last one) and use omit cond to eliminate fourth parse element eq spaces.
I hope this will work.
Back to top
Joerg.Findeisen Senior Member Joined: 15 Aug 2015Posts: 1335 Location: Bamberg, Germany
Input:
Code:
JOZD HABWRT ROPWZ 50.00%
RAZ ARRZNZ ROPWZ 50.00%
FDDGG EGGDG XSFDGG
RAYZRDO JAMWNWZ ZRBWRZWZ 50%
ZRWJZNDRO JAMWNWZ ZRBWRZWZ 50%
GGGHGGHGH JHJJHJ
RAYZRDO JAMWNWZ ZRBWRZWZ 50%
GRWNNYS DAZZ YW-8-98271 25%
ZNZ Y MOJAYZ V Y8-746-218 25%
ZNTONAO MOJAYZ Y8-166-7V 25%
MNMBBB DSFSFFSFFFSFSF
JOSW OTWRO YZSZR 34%%
DAWGO OTWRO YZSZR 33%
ROSZ MZRAZ OTWRO YZSZR 33%
GGHGGHGGHGHGHG
JWSSW YZMARZ GAZMZN 100%
GJGJGJHGJHGHJG
JOZD HABWRT ROPWZ 50.00%
RAZ ARRZNZ ROPWZ 50.00%
HGHGHGHG
RAA XAZ ZHA DW RAZO 100.00%
GHFFGFGFGFG
RWTAYAZ YWYARAZ DAZRTW NNANWS 100%
Z 0%
Y Y Y 0%
Code:
Code:
OPTION COPY
INCLUDE COND=(1,40,SS,EQ,C'%')
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(FIXLEN=40,
ENDBEFR=C' 0',
ENDBEFR=C' 1',
ENDBEFR=C' 2',
ENDBEFR=C' 3',
ENDBEFR=C' 4',
ENDBEFR=C' 5',
ENDBEFR=C' 6',
ENDBEFR=C' 7',
ENDBEFR=C' 8',
ENDBEFR=C' 9'),
%=(STARTAT=C'%',FIXLEN=1),
%02=(SUBPOS=8,FIXLEN=7,ENDBEFR=C'%',
STARTAT=C' 0',
STARTAT=C' 1',
STARTAT=C' 2',
STARTAT=C' 3',
STARTAT=C' 4',
STARTAT=C' 5',
STARTAT=C' 6',
STARTAT=C' 7',
STARTAT=C' 8',
STARTAT=C' 9')),
BUILD=(%01,%02,SQZ=(SHIFT=LEFT,LEAD=C'|',TRAIL=C'%',LENGTH=8)))
END
Output:
Code:
JOZD HABWRT ROPWZ |50.00%
RAZ ARRZNZ ROPWZ |50.00%
RAYZRDO JAMWNWZ ZRBWRZWZ |50%
ZRWJZNDRO JAMWNWZ ZRBWRZWZ |50%
RAYZRDO JAMWNWZ ZRBWRZWZ |50%
GRWNNYS DAZZ YW-8-98271 |25%
ZNZ Y MOJAYZ V Y8-746-218 |25%
ZNTONAO MOJAYZ Y8-166-7V |25%
JOSW OTWRO YZSZR |34%
DAWGO OTWRO YZSZR |33%
ROSZ MZRAZ OTWRO YZSZR |33%
JWSSW YZMARZ GAZMZN |100%
JOZD HABWRT ROPWZ |50.00%
RAZ ARRZNZ ROPWZ |50.00%
RAA XAZ ZHA DW RAZO |100.00%
RWTAYAZ YWYARAZ DAZRTW NNANWS |100%
Z |0%
Y Y Y |0%
Back to top
cuauhtli New User Joined: 15 Sep 2017Posts: 2 Location: Mexico
Thank you so much Joerg.Findeisen is an excellent contribution. I was trying a cobol program with unstring and reverse but your code is better.
Thanks again.!!
Back to top
sergeyken Senior Member Joined: 29 Apr 2008Posts: 2141 Location: USA
The parameters STARTAT=… and SUBPOS= are in fact not required in this specific case. By default PARSE continues from previous stop point.
Back to top
Joerg.Findeisen Senior Member Joined: 15 Aug 2015Posts: 1335 Location: Bamberg, Germany
One SUBPOS is required as the first digit of the percentage is part of the previous PARSE . However the code can be reduced to this:
Code:
INREC IFTHEN=(WHEN=INIT,
PARSE=(%01=(FIXLEN=40,
ENDBEFR=C' 0',
ENDBEFR=C' 1',
ENDBEFR=C' 2',
ENDBEFR=C' 3',
ENDBEFR=C' 4',
ENDBEFR=C' 5',
ENDBEFR=C' 6',
ENDBEFR=C' 7',
ENDBEFR=C' 8',
ENDBEFR=C' 9'),
%02=(SUBPOS=1,FIXLEN=7,ENDBEFR=C'%')),
BUILD=(%01,%02,SQZ=(SHIFT=LEFT,LEAD=C'|',TRAIL=C'%',LENGTH=8)))
Thanks for your suggestion.
Back to top
Rohit Umarjikar Global Moderator Joined: 21 Sep 2010Posts: 3076 Location: NYC,USA
I suggest don’t wait here .. understand the logic and read manuals so that you can do it yourself next time or at least you can give a try.
Back to top
Phrzby Phil Senior Member Joined: 31 Oct 2006Posts: 1050 Location: Richmond, Virginia
Just my 2cents worth here.
Although the SORT way is easier in many ways as opposed to a COBOL program, are there programmers down the line in your organization who will inherit this code and be as conversant in the SORT commands and techniques as opposed to a general purpose language?
If you still need COBOL for other processing here, consider if it might be best for one program to have all of the processing.
Not saying yes or no - just things to consider.
Back to top
Please enable JavaScript!