View previous topic :: View next topic |
Author |
Message |
Oldie Beginner
Joined: 19 Dec 2002 Posts: 10 Topics: 3 Location: Munich, Germany
|
Posted: Tue Jan 13, 2004 7:02 am Post subject: Unstring |
|
|
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 |
|
|
cobcurious Beginner
Joined: 04 Oct 2003 Posts: 68 Topics: 25
|
Posted: Tue Jan 13, 2004 9:14 am Post subject: |
|
|
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 |
|
|
Oldie Beginner
Joined: 19 Dec 2002 Posts: 10 Topics: 3 Location: Munich, Germany
|
Posted: Tue Jan 13, 2004 9:24 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Jan 13, 2004 10:50 am Post subject: |
|
|
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 |
|
|
Oldie Beginner
Joined: 19 Dec 2002 Posts: 10 Topics: 3 Location: Munich, Germany
|
Posted: Wed Jan 14, 2004 2:12 am Post subject: |
|
|
That's exactly what I need - Thanks Kolosu, and a Happy New Year !
Oldie |
|
Back to top |
|
|
RobertL Beginner
Joined: 18 Nov 2003 Posts: 22 Topics: 0 Location: Lisbon, Portugal
|
Posted: Tue Jan 20, 2004 1:35 pm Post subject: |
|
|
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 |
|
|
|
|