| Author |
Message |
aaleya
New User
Joined: 10 Apr 2008 Posts: 3 Location: chennai
|
|
|
|
Hi,
I have a requirement of extracting words from a given text using cobol. I tried using UNSTRING option but not getting the desired output. Can someone help me out with this?
Thanks! |
|
| Back to top |
|
 |
References
|
Posted: Wed May 07, 2008 1:13 pm Post subject: Re: Extracting word by word from a text using cobol program |
 |
|
|
 |
Moved: Wed May 07, 2008 1:14 pm by superk From DFSORT/ICETOOL to Mainframe COBOL |
dbzTHEdinosauer
Senior Member
Joined: 20 Oct 2006 Posts: 883 Location: germany
|
|
|
|
| not getting the desired output? what does your input look like and what are your expectations? |
|
| Back to top |
|
 |
aaleya
New User
Joined: 10 Apr 2008 Posts: 3 Location: chennai
|
|
|
|
Actually say i have a text 'abc bcd cde def '. Now my requirement is to extract word by word from the text. We can say first moving abc to one field and rest to another field. We can use space as a delimiter. When i tried parsing this using UNSTRING, its moving abc to one field and bcd to another field. But my requirement is move abc to one field A(can be a array) and rest to another field B. This field B can be my input to UNSTRING again so next time it moves bcd to field A and rest to field B. This process will continue untill it encounters spaces. Could you please help me with this?
Thanks! |
|
| Back to top |
|
 |
ashimer Warnings : 1 Active User
Joined: 13 Feb 2004 Posts: 108
|
|
|
|
Use INSPECT here
| Code: |
77 COUNTR PIC 9 VALUE ZERO.
01 WS-TEXT PI X(20).
01 WS-A PIC X(3).
01 WS-B PIC X(17).
MOVE 'abc bcd cde def ' TO WS-TEXT
PERFORM UNTIL WS-TEXT = SPACES
INSPECT WS-TEXT TALLYING COUNTR FOR LEADING SPACE
MOVE WS-TEXT(1:COUNTR) TO WS-A
MOVE WS-TEXT(COUNTR+2 : LENGTH OF WS-TEXT - COUNTR+1) TO WS-B
MOVE 0 TO COUNTR
MOVE WS-B TO WS-TEXT
END-PERFORM
|
|
|
| Back to top |
|
 |
dbzTHEdinosauer
Senior Member
Joined: 20 Oct 2006 Posts: 883 Location: germany
|
|
|
|
or
| Code: |
01 WORK-AREA.
05 ALPHA-FIELD PIC X(20) VALUE '999 901 ALB'.
05 WORK1 PIC X(5) VALUE SPACES.
05 WORK2 PIC X(20) VALUE SPACES.
DISPLAY 'ALPHA-FIELD ' ALPHA-FIELD
DISPLAY 'WORK1 ' WORK1
PERFORM UNTIL ALPHA-FIELD = SPACES
INSPECT ALPHA-FIELD
REPLACING FIRST SPACE BY '#'
UNSTRING ALPHA-FIELD
DELIMITED BY '#'
INTO WORK1
ALPHA-FIELD
END-UNSTRING
DISPLAY 'ALPHA-FIELD ' ALPHA-FIELD
DISPLAY 'WORK1 ' WORK1
MOVE SPACES TO WORK1
END-PERFORM
GOBACK.
|
| Code: |
ALPHA-FIELD 999 901 ALB
WORK1
ALPHA-FIELD 901 ALB
WORK1 999
ALPHA-FIELD ALB
WORK1 901
ALPHA-FIELD
WORK1 ALB
|
|
|
| Back to top |
|
 |
aaleya
New User
Joined: 10 Apr 2008 Posts: 3 Location: chennai
|
|
|
|
| Thank you so much!!!! |
|
| Back to top |
|
 |
|
|