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
 

 

Mistake I am committing in the unstring statement

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Mistake I am committing in the unstring statement
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: 2150
Location: At my coffee table

PostPosted: Tue May 25, 2010 9:31 pm    Post subject: Re: Unstring help
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    Post subject: Reply to: Unstring help
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    Post subject:
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    Post subject:
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: 7931
Location: Bellevue, IA

PostPosted: Wed May 26, 2010 8:53 pm    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Wed May 26, 2010 8:54 pm    Post subject:
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    Post subject:
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    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 -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts COBOL DB2 - CALL statement - high CPU... TS70363 DB2 15 Sun Sep 11, 2016 6:07 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm
This topic is locked: you cannot edit posts or make replies. Updating value of key using rewrite s... ParminderKumar COBOL Programming 4 Thu Aug 04, 2016 12:46 am
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm


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