View previous topic :: View next topic
|
Author |
Message |
d katkuri
New User
Joined: 27 Feb 2013 Posts: 16 Location: india
|
|
|
|
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 |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
"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 |
|
|
d katkuri
New User
Joined: 27 Feb 2013 Posts: 16 Location: india
|
|
|
|
These messages are stored in working storage variable: |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 158 Location: Kuala Lumpur
|
|
|
|
here is the quickest code:
UNSTRING WS-RECORD DELIMITED BY '$' INTO
WS-MSG1 WS-MSG2 WS-MSG3..................
END-UNSTRING. |
|
Back to top |
|
|
d katkuri
New User
Joined: 27 Feb 2013 Posts: 16 Location: india
|
|
|
|
suresh it will not work |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
d katkuri
New User
Joined: 27 Feb 2013 Posts: 16 Location: india
|
|
|
|
$ 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 |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 158 Location: Kuala Lumpur
|
|
|
|
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 |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No quotes on the second message? No space in front of the brackets? No other possible messages? |
|
Back to top |
|
|
d katkuri
New User
Joined: 27 Feb 2013 Posts: 16 Location: india
|
|
|
|
There will bo no quotes in the second message |
|
Back to top |
|
|
sureshpathi10
Active User
Joined: 03 May 2010 Posts: 158 Location: Kuala Lumpur
|
|
|
|
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 |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
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 |
|
|
|