Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Unstring the message

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
d katkuri

New User


Joined: 27 Feb 2013
Posts: 16
Location: india

PostPosted: Wed Aug 14, 2013 12:28 pm    Post subject: Unstring the message
Reply with quote

I have the following message:
Added $XXX1 occuring on $XXX2 to $XXX3 record" or "Removed $XXX4 occuring on to $XXX5 record

I need to parse the total message character by character. IF $ founds i need to extract the character unitl space and store it ia varaible.

In this message I have 5 $ so the output should have the below way:
OUTPUT VARIABLES:
MSG1 : XXX1
MSG2: XXX2
MSG3 : XXX3
MSG4 : XXX4
MSG5 : XXX5

Could you please let me know how to achieve this task
Back to top
View user's profile Send private message

mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 268
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Wed Aug 14, 2013 12:44 pm    Post subject:
Reply with quote

"Added $XXX1 occuring on $XXX2 to $XXX3 record" and "Removed $XXX4 occuring on to $XXX5 record" are two different messages or a single message?

How these messages are stored in your COBOL Program?

What is the maximum number of such values XXX1, XXX2 you are expecting in each message. What is the data type and maximum possible length of these values.

you can use INSPECT, UNSTRING and PERFORM to achieve this.

Check this link
Back to top
View user's profile Send private message
d katkuri

New User


Joined: 27 Feb 2013
Posts: 16
Location: india

PostPosted: Wed Aug 14, 2013 12:46 pm    Post subject:
Reply with quote

These messages are stored in working storage variable:
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Wed Aug 14, 2013 12:46 pm    Post subject: Re: Unstring the message
Reply with quote

here is the quickest code:

UNSTRING WS-RECORD DELIMITED BY '$' INTO
WS-MSG1 WS-MSG2 WS-MSG3..................
END-UNSTRING.
Back to top
View user's profile Send private message
d katkuri

New User


Joined: 27 Feb 2013
Posts: 16
Location: india

PostPosted: Wed Aug 14, 2013 12:47 pm    Post subject:
Reply with quote

suresh it will not work
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7231

PostPosted: Wed Aug 14, 2013 12:52 pm    Post subject: Reply to: Unstring the message
Reply with quote

If your $ messages are fixed in length (individually) then just define the data.

If not, there are several ways to do it.

Is there only one message to process? Is it from a file? How many reciords, if so?

If more than one message, are there messages of other styles to ignore?

Can you show a good sample of intput data, showing the possibilities. At least two "records" (unless there can be only one).
Back to top
View user's profile Send private message
d katkuri

New User


Joined: 27 Feb 2013
Posts: 16
Location: india

PostPosted: Wed Aug 14, 2013 12:59 pm    Post subject:
Reply with quote

$ message of fixed lenth 150 bytes. Messages are coming from a file . i need to read the record by record and moved the values unstring values into a ws variables and do some process

Input Message:
"Added $XXX1 occuring on $XXX2 to $XXX3 driving record" or "Removed $XXX4occuring on to $XXX5 driving record"

output :
MSG1: $XXX1
MSG2: $XXX2
MSG3: $XXX3
MSG4: $XXX4
MSG5: $XXX5

mESSAGE 2:

Existing incident occuring on $XXX1 was changed from $XXX2(old data) to $XXX3(new data)

OUPTU :
MSG1: $XXX1
MSG2: $XXX2
MSG3: $XXX3
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Wed Aug 14, 2013 1:03 pm    Post subject:
Reply with quote

MOVE LENGTH OF WS-RECORD TO WS-REC-CNT.
MOVE ZEROES TO WS-CNT.
MOVE ZEROES TO CTR.

PERFORM UNTIL WS-CNT >= WS-REC-CNT
INSPECT WS-RECORD TALLYING WS-CNT FOR CHARECTERS BEFORE INITIAL '$'
ADD 2 TO WS-CNT
ADD 1 TO CTR
PERFORM UNTIL WS-RECORD(WS-CNT) = SPACE OR WS-CNT > WS-REC-CNT
MOVE WS-RECORD(WS-CNT:1) TO WS-MSG(CTR)
END-PERFORM
MOVE SPACES TO WS-RECORD(1:WS-CNT)
END-PERFORM.

PERFORM VARYING CNT FROM 1 BY 1 UNTIL CNT > CTR
DISPLAY 'MESSAGE' CNT ': ' WS-MSG(CNT)
END-PERFORM.

There may be some small correction needed.. but i guess it'll work icon_smile.gif
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7231

PostPosted: Wed Aug 14, 2013 1:03 pm    Post subject: Reply to: Unstring the message
Reply with quote

No quotes on the second message? No space in front of the brackets? No other possible messages?
Back to top
View user's profile Send private message
d katkuri

New User


Joined: 27 Feb 2013
Posts: 16
Location: india

PostPosted: Wed Aug 14, 2013 1:06 pm    Post subject:
Reply with quote

There will bo no quotes in the second message
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Wed Aug 14, 2013 1:25 pm    Post subject:
Reply with quote

There is a small change....
CTR1 need to initialize with value 1.

PERFORM UNTIL WS-RECORD(WS-CNT) = SPACE OR WS-CNT > WS-REC-CNT
MOVE WS-RECORD(WS-CNT:1) TO WS-MSG(CTR)(CTR1:1)
ADD 1 TO WS-CNT CTR1
END-PERFORM
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Wed Aug 14, 2013 2:17 pm    Post subject: Re: Unstring the message
Reply with quote

Hi,

sureshpathi10 wrote:
here is the quickest code:

UNSTRING WS-RECORD DELIMITED BY '$' INTO
WS-MSG1 WS-MSG2 WS-MSG3..................
END-UNSTRING.

Have you tried above code and what problem you are facing with this?

I tried it like below
Working storage:
Code:
      10 WS-STR               PIC X(100) VALUE
             'ADDED $XXX1 OCCURING ON $XXX2 TO $XXX3 RECORD" OR "RE
 -           'EMOVED $XXX4 OCCURING ON TO $XXX5 RECORD'.
          10 WS-IGNORE            PIC X(04).
          10 WS-MSG1              PIC X(04).
          10 WS-MSG2              PIC X(04).
          10 WS-MSG3              PIC X(04).
          10 WS-MSG4              PIC X(04).
          10 WS-MSG5              PIC X(04).


Procedure Division
Code:
UNSTRING WS-STR DELIMITED BY '$' INTO WS-IGNORE
   WS-MSG1 WS-MSG2 WS-MSG3 WS-MSG4 WS-MSG5
END-UNSTRING.
DISPLAY 'WS-MSG1 : 'WS-MSG1.
DISPLAY 'WS-MSG2 : 'WS-MSG2.
DISPLAY 'WS-MSG3 : 'WS-MSG3.
DISPLAY 'WS-MSG4 : 'WS-MSG4.
DISPLAY 'WS-MSG5 : 'WS-MSG5.


Spool Dipslay's
Code:
WS-MSG1 : XXX1
WS-MSG2 : XXX2
WS-MSG3 : XXX3
WS-MSG4 : XXX4
WS-MSG5 : XXX5


This is what is expected or is there anything I am misisng?

Regards,
Chandan
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7231

PostPosted: Wed Aug 14, 2013 3:28 pm    Post subject: Reply to: Unstring the message
Reply with quote

No answer about the fixed or otherwise nature of the strings.

If fixed in length, define the data that way.

If variable, follow Chandan's testing of your own solution, and add a second UNSTRING, delimited by SPACE, for each field to get rid of the data after the string.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 269
Location: Mumbai

PostPosted: Wed Aug 14, 2013 3:42 pm    Post subject: Reply to: Unstring the message
Reply with quote

Hi,

If you will be following solution provided by me you will need to have another variable deifined explicitly for '$' may be like below

Code:
05  WS-MSG1-TOTAL.
    10 FILLER               PIC X(01) VALUE '$'.
    10 WS-MSG1              PIC X(04).
05  WS-MSG2-TOTAL.
    10 FILLER               PIC X(01) VALUE '$'.
    10 WS-MSG2              PIC X(04).
05  WS-MSG3-TOTAL.
    10 FILLER               PIC X(01) VALUE '$'.
    10 WS-MSG3              PIC X(04).
05  WS-MSG4-TOTAL.
    10 FILLER               PIC X(01) VALUE '$'.
    10 WS-MSG4              PIC X(04).
05  WS-MSG5-TOTAL.
    10 FILLER               PIC X(01) VALUE '$'.
    10 WS-MSG5              PIC X(04).


Regards,
Chandan
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to show message using batch jobs madprasy TSO/ISPF 7 Fri Sep 09, 2016 6:55 pm
No new posts Truncated error message after VERIFY ... David Sde TSO/ISPF 4 Mon Sep 05, 2016 11:26 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts IEC999I MESSAGE ERROR Manshadi ABENDS & Debugging 3 Sun Apr 17, 2016 3:43 pm
No new posts Problem with UNSTRING of CSV data Bill Woodger COBOL Programming 14 Tue Dec 15, 2015 5:32 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us