Parsing strings in COBOL

Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS
kanipriya2785
Posts: 7
Joined: Fri Jun 17, 2022 9:59 pm
Skillset: Mainframe - COBOL,JCL,DB2,VSAM
Referer: internet

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

Robert Sample
Global moderator
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
Referer: other forum
Location: Dubuque, Iowa, USA

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).

User avatar
sergeyken
Posts: 458
Joined: Wed Jul 24, 2019 10:12 pm
Skillset: Assembler, JCL, Utilities, PL/I, C/C++, DB2, SQL, REXX, COBOL, etc. etc. etc.
Referer: Internet search

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.

Code: Select all

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.

kanipriya2785
Posts: 7
Joined: Fri Jun 17, 2022 9:59 pm
Skillset: Mainframe - COBOL,JCL,DB2,VSAM
Referer: internet

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.

Robert Sample
Global moderator
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
Referer: other forum
Location: Dubuque, Iowa, USA

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.

kanipriya2785
Posts: 7
Joined: Fri Jun 17, 2022 9:59 pm
Skillset: Mainframe - COBOL,JCL,DB2,VSAM
Referer: internet

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.


  • Similar Topics
    Replies
    Views
    Last post