IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Unstring the message


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Wed Aug 14, 2013 12:44 pm
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
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
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
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Aug 14, 2013 12:52 pm
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
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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Aug 14, 2013 1:03 pm
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
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
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: 275
Location: Mumbai

PostPosted: Wed Aug 14, 2013 2:17 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Aug 14, 2013 3:28 pm
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: 275
Location: Mumbai

PostPosted: Wed Aug 14, 2013 3:42 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
This topic is locked: you cannot edit posts or make replies. how can I proof that message was post... Java & MQSeries 1
No new posts IMS Message : DFS3577A IMS DB/DC 4
No new posts dsnrexx fails without error message CLIST & REXX 9
No new posts Print out all lines with 'IBM' compil... CLIST & REXX 8
No new posts Handling the numeric data in unstring... COBOL Programming 18
Search our Forums:

Back to Top