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

Mistake I am committing in the unstring statement


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Tue May 25, 2010 9:09 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Tue May 25, 2010 9:31 pm
Reply with quote

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
View user's profile Send private message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Tue May 25, 2010 9:40 pm
Reply with quote

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
View user's profile Send private message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Tue May 25, 2010 9:46 pm
Reply with quote

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
View user's profile Send private message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Wed May 26, 2010 8:36 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed May 26, 2010 8:53 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Wed May 26, 2010 8:54 pm
Reply with quote

tomehta wrote:
I was not able to resolve the above probelm,
however I used the below workaround to get the desired output.

If the POINTER phrase is specified, the field is examined, beginning at the relative character position specified by the value in the pointer field.
A better way would to leave the POINTER in and drop the reference modification out.
Back to top
View user's profile Send private message
tomehta

New User


Joined: 18 Aug 2008
Posts: 98
Location: India

PostPosted: Thu May 27, 2010 7:30 pm
Reply with quote

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
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
No new posts JOIN STATEMENT PERFORMANCE. DFSORT/ICETOOL 12
No new posts Relate COBOL statements to EGL statement All Other Mainframe Topics 0
No new posts Handling the numeric data in unstring... COBOL Programming 18
No new posts process statement for SUPREC, CMPCOLM... TSO/ISPF 4
No new posts SYNCSORT/ICETOOL JOINKEYS SORT Statem... DFSORT/ICETOOL 13
Search our Forums:

Back to Top