Parsing strings in COBOL



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Parsing strings in COBOL

Postby kanipriya2785 » Fri Jun 17, 2022 10:05 pm

Hi,

I need to parse only strings in below record using COBOL. Record has strings and sequence numbers. i need to take strings alone.
Please help me how to do.

MAINFRAME001
DOCUMENTATION002
FILES003
DATABSE004
kanipriya2785
 
Posts: 7
Joined: Fri Jun 17, 2022 9:59 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Parsing strings in COBOL

Postby Robert Sample » Sat Jun 18, 2022 5:41 am

As with your other post, your problem description lacks a LOT of the necessary details.

- Are the sequence numbers always at the end of the string?
- Are all the sequence numbers three digits?
- How long can the strings be?
- When you say "take the strings' what are you going to do with them?

For the sample data you provided, it is a minor process to peel off the last 3 digits from each value (using intrinsic functions and reference modification).
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Parsing strings in COBOL

Postby sergeyken » Sun Jun 19, 2022 9:42 pm

kanipriya2785 wrote:Hi,

I need to parse only strings in below record using COBOL. Record has strings and sequence numbers. i need to take strings alone.
Please help me how to do.

MAINFRAME001
DOCUMENTATION002
FILES003
DATABSE004


1) Please, learn how to use the Code button to format parts of the code in your postings.

2) Please, try to read something about UNSTRING statement in COBOL
Javas and Pythons come and go, but JCL and SORT stay forever.
User avatar
sergeyken
 
Posts: 436
Joined: Wed Jul 24, 2019 10:12 pm
Has thanked: 7 times
Been thanked: 40 times

Re: Parsing strings in COBOL

Postby kanipriya2785 » Tue Jun 21, 2022 1:53 am

Hi,

Here is my answers for your questions. Here there is no delimiter in the string. What function should i use to extract the String value alone?

- Are the sequence numbers always at the end of the string? -> yes.
- Are all the sequence numbers three digits? - yes
- How long can the strings be? - it is variable length.
- When you say "take the strings' what are you going to do with them? -> I need them to pass into another program as input.
kanipriya2785
 
Posts: 7
Joined: Fri Jun 17, 2022 9:59 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Parsing strings in COBOL

Postby Robert Sample » Tue Jun 21, 2022 7:47 pm

Use FUNCTION REVERSE() to reverse the string.
Use FUNCTION TRIM( , LEADING) on the reversed string to remove leading spaces.
Use reference modification to move characters from the reversed, trimmed string starting with the 4th to another variable (which strips the sequence number).
Use FUNCTION REVERSE to get the string back in original sequence. Depending upon your lengths and desired output, you may need to use FUNCTION TRIM as well.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Parsing strings in COBOL

Postby kanipriya2785 » Tue Jun 21, 2022 9:32 pm

Thank you. I will try this. Thanks for your timely help.
kanipriya2785
 
Posts: 7
Joined: Fri Jun 17, 2022 9:59 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post