View previous topic :: View next topic
|
Author |
Message |
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
hi
I am running following piece of code
Code: |
move 1 to WS-STR-POS
move 'aaabbbcccbbbdddbbbfffbbbgggbbb' to H-INPUT-MSG
PERFORM VARYING LOOP-VAR FROM 1 BY 1 UNTIL LOOP-VAR > 15
UNSTRING H-INPUT-MSG
(WS-STR-POS: )
DELIMITED BY 'bbb'
INTO WS-VAR1
with pointer WS-STR-POS
END-UNSTRING |
getting the output
Code: |
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
CTR-1
WS-VAR1 aaa
WS-STR-POS 00000007
WS-VAR1 ddd
WS-STR-POS 00000013
WS-VAR1 ggg
WS-STR-POS 00000019
|
As per manual 'with pointer'
Quote: |
identifier-7
Specifies a field to hold a relative character position during UNSTRING
processing. |
Can someone guide me , what mistake I am committing in the unstring statement ?
Thanks |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
tomehta wrote: |
Can someone guide me , what mistake I am committing in the unstring statement ? |
Good question...
What code is between the "END-UNSTRING" and the "END-PERFORM"?
Why is there a blank line between the display of "WS-STR-POS 00000013" and "WS-VAR1 ggg"? |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
hi
Quote: |
What code is between the "END-UNSTRING" and the "END-PERFORM"? |
nothing, just displays
Quote: |
Why is there a blank line between the display of "WS-STR-POS 00000013" and "WS-VAR1 ggg"? |
just a typo..
i expected that output will have
aaa
ccc
ddd
... |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
Compalete code
Code: |
move 1 to WS-STR-POS
move 'aaabbbcccbbbdddbbbfffbbbgggbbb' to H-INPUT-MSG
PERFORM VARYING LOOP-VAR FROM 1 BY 1 UNTIL LOOP-VAR > 15
UNSTRING H-INPUT-MSG
(WS-STR-POS: )
DELIMITED By all 'bbb'
INTO WS-VAR1
COUNT IN CTR-1
with pointer WS-STR-POS
END-UNSTRING
display ' rohit test '
display ' H-INPUT-MSG ' H-INPUT-MSG
display ' CTR-1' CTR-1
display ' WS-VAR1 ' WS-VAR1
display ' WS-STR-POS ' WS-STR-POS
end-perform
goback. |
output
Code: |
******************************** TOP OF DATA ***********
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
CTR-100000003
WS-VAR1 aaa
WS-STR-POS 00000007
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
CTR-100000003
WS-VAR1 ddd
WS-STR-POS 00000013
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
CTR-100000003
WS-VAR1 ggg
WS-STR-POS 00000019
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
CTR-100000064
WS-VAR1
WS-STR-POS 00000083 |
thanks
[/code] |
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
Hi
I was not able to resolve the above probelm,
however I used the below workaround to get the desired output.
Code: |
move 1 to WS-STR-POS
move 'aaabbbcccbbbdddbbbfffbbbgggbbb' to H-INPUT-MSG
PERFORM VARYING LOOP-VAR FROM 1 BY 1 UNTIL LOOP-VAR > 15
UNSTRING H-INPUT-MSG
(WS-STR-POS: )
DELIMITED BY 'bbb'
INTO WS-VAR
COUNT IN WS-CTR
END-UNSTRING
COMPUTE WS-STR-POS = WS-STR-POS + WS-CTR + 3
display ' rohit test '
display ' H-INPUT-MSG ' H-INPUT-MSG
display ' ws-ct' ws-ctr
display ' WS-VAR ' WS-VAR
display ' WS-STR-POS ' WS-STR-POS
end-perform
goback. |
got the output which I was expecting
Code: |
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR aaa
WS-STR-POS 00000007
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR ccc
WS-STR-POS 00000013
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR ddd
WS-STR-POS 00000019
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR fff
WS-STR-POS 00000025
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR ggg
WS-STR-POS 00000031 |
I will appreciate if someone can point let me know what was wrong in the first piece of code I posted.
Thanks |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
From the COBOL Language Reference manual (link at the top of the page)):
Quote: |
6.2.39.7.1 Values at the end of execution of the UNSTRING statement
The following operations are performed only once, at the beginning of the execution of the UNSTRING statement:
* Calculations of subscripts, reference modifications, variable-lengths, variable locations
* Evaluations of functions
Therefore, if identifier-4, identifier-5, identifier-6, identifier-7, or identifier-8 is used as a subscript, reference-modifier, or function argument in the UNSTRING statement, or affects the length or location of any of the identifiers in the UNSTRING statement, these values are determined at the beginning of the UNSTRING statement, and are not affected by any results of the UNSTRING statement. |
Identifier-7 is the WITH POINTER variable -- it cannot be used in the way you attempted to use it. |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
tomehta
New User
Joined: 18 Aug 2008 Posts: 98 Location: India
|
|
|
|
Hi CICS Guy,
As you suggested following worked,
Code: |
move 1 to WS-STR-POS
move 'aaabbbcccbbbdddbbbfffbbbgggbbb' to H-INPUT-MSG
PERFORM VARYING LOOP-VAR FROM 1 BY 1 UNTIL LOOP-VAR > 15
UNSTRING H-INPUT-MSG
DELIMITED BY 'bbb'
INTO WS-VAR
COUNT IN WS-CTR
with pointer WS-STR-POS
END-UNSTRING |
got the result
Code: |
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR aaa
WS-STR-POS 00000007
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR ccc
WS-STR-POS 00000013
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR ddd
WS-STR-POS 00000019
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR fff
WS-STR-POS 00000025
rohit test
H-INPUT-MSG aaabbbcccbbbdddbbbfffbbbgggbbb
ws-ct00000003
WS-VAR ggg
WS-STR-POS 00000031
rohit test
|
sometime solution does not seem so simple !!!
thanks |
|
Back to top |
|
|
|