Page 1 of 1

Parsing strings in COBOL

PostPosted: Fri Jun 17, 2022 10:05 pm
by kanipriya2785
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

Re: Parsing strings in COBOL

PostPosted: Sat Jun 18, 2022 5:41 am
by Robert Sample
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).

Re: Parsing strings in COBOL

PostPosted: Sun Jun 19, 2022 9:42 pm
by sergeyken
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

Re: Parsing strings in COBOL

PostPosted: Tue Jun 21, 2022 1:53 am
by kanipriya2785
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.

Re: Parsing strings in COBOL

PostPosted: Tue Jun 21, 2022 7:47 pm
by Robert Sample
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.

Re: Parsing strings in COBOL

PostPosted: Tue Jun 21, 2022 9:32 pm
by kanipriya2785
Thank you. I will try this. Thanks for your timely help.