MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unstring

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Oldie
Beginner


Joined: 19 Dec 2002
Posts: 10
Topics: 3
Location: Munich, Germany

PostPosted: Tue Jan 13, 2004 7:02 am    Post subject: Unstring Reply with quote

Hi,

is it possible to trim a string with UNSTRING into some fixed parts and all the rest into another field ?
An example:

MOVE 'AA BB XXX YYYY' INTO F
UNSTRING F INTO
F1
F2
REST
DELIMITED BY ...
END-UNSTRING

What I`m awaiting is F1='AA' F2='BB' and REST='XXX YYYY'.
Can I with a single UNSTRING (I suspect no) or only with programm logic ?

Cheers / Oldie
Back to top
View user's profile Send private message
cobcurious
Beginner


Joined: 04 Oct 2003
Posts: 68
Topics: 25

PostPosted: Tue Jan 13, 2004 9:14 am    Post subject: Reply with quote

Hi Oldie,
Tell me is the string to be divided is a fixed length string.If it is so,the purpose can solved by making a group item like
Code:

MOVE your-input TO Group-item
where,

01 Group-item
   05 element-1-2 pic X(02).
   05 element-2-2 pic X(02).
   05 rest           pic X(07).   


Tell me if serves the purpose.Ths solution can be made better if you can us tell what kind of operation you want to do on the strings.
Regards
Cobcurious
Back to top
View user's profile Send private message
Oldie
Beginner


Joined: 19 Dec 2002
Posts: 10
Topics: 3
Location: Munich, Germany

PostPosted: Tue Jan 13, 2004 9:24 am    Post subject: Reply with quote

cobcurious,

what I need is a general solution - I mean, the strings have a variable length - therefore the unstring and not a simple move into a structure. But for the sake of your example, let's take the data from your structure.

Cheers
Oldie
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Jan 13, 2004 10:50 am    Post subject: Reply with quote

Oldie,

Sorry for the delayed response. Here is something close to what you wanted.

Code:

WORKING-STORAGE SECTION.                                     
                                                             
01 WS-STR                PIC X(80) VALUE 'AA BB XXX YYYY'.   
01 WS-PTR                PIC S9(04) COMP.                     
01 WS-FLD1               PIC X(20).                           
01 WS-FLD2               PIC X(20).                           
01 WS-REST               PIC X(40).                           
                                                             
PROCEDURE DIVISION. 
                                         
     MOVE +1 TO WS-PTR                                       

     UNSTRING WS-STR DELIMITED BY SPACE INTO WS-FLD1, WS-FLD2
     WITH POINTER WS-PTR                                     

     MOVE WS-STR (WS-PTR : 80 - WS-PTR) TO WS-REST           

     DISPLAY 'THE POINTER VALUE IS      : ' WS-PTR                         
     DISPLAY 'THE CONTENTS OF WS-FLD1 IS: ' WS-FLD1                       
     DISPLAY 'THE CONTENTS OF WS-FLD2 IS: ' WS-FLD2                       
     DISPLAY 'THE CONTENTS OF WS-REST IS: ' WS-REST                       

     GOBACK.                                                 


We use the pointer to find the start position for the rest of the record and then use the reference modification to achieve the results.

The output from the above code is :

Code:

THE POINTER VALUE IS      : 0007       
THE CONTENTS OF WS-FLD1 IS: AA         
THE CONTENTS OF WS-FLD2 IS: BB         
THE CONTENTS OF WS-REST IS: XXX YYYY   


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Oldie
Beginner


Joined: 19 Dec 2002
Posts: 10
Topics: 3
Location: Munich, Germany

PostPosted: Wed Jan 14, 2004 2:12 am    Post subject: Reply with quote

That's exactly what I need - Thanks Kolosu, and a Happy New Year !

Oldie
Back to top
View user's profile Send private message
RobertL
Beginner


Joined: 18 Nov 2003
Posts: 22
Topics: 0
Location: Lisbon, Portugal

PostPosted: Tue Jan 20, 2004 1:35 pm    Post subject: Reply with quote

Just one comment. When moving the remaining data, there is no need to specify the second value in the reference modification field (shown below).

MOVE WS-STR (WS-PTR : ) TO WS-REST

If you specify the first one, COBOL will assume a length that moves the rest of the field.

Regards,
Robert
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group