View previous topic :: View next topic
|
Author |
Message |
srini24
New User
Joined: 14 Feb 2017 Posts: 12 Location: India
|
|
|
|
My input string is 'WRITE IN COBOL LANGUAGE'.
Output should be in 'RITE N OBOL ANGUAGE'.
which is first character of every string from input to be removed and then to be captured into output string.
I tried to unstring the message into 4 delimited by spaces and then splitted into 4 strings with countin(length).Using reference modification,i moved each string from its second position to its length specified in COUNTIN.
Is there any other way to do it?
Code: |
05 WS-STRING1 PIC X(20) VALUE 'WRITE IN COBOL LANGUAGE'.
UNSTRING WS-STRING1 DELIMITED BY SPACES INTO
WS-OUTPUT1 COUNT IN WS-COUNT1
WS-OUTPUT2 COUNT IN WS-COUNT2
WS-OUTPUT3 COUNT IN WS-COUNT3.
END-UNSTRING.
MOVE WS-OUTPUT1(2:WS-COUNT1) TO WS-FIN1
MOVE WS-OUTPUT2(2:WS-COUNT2) TO WS-FIN2
MOVE WS-OUTPUT3(2:WS-COUNT3) TO WS-FIN3
|
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
Is there any other way to do it? |
It would be rare indeed for there only one way to do something in COBOL. You could also use reference modification to accomplish what you want. |
|
Back to top |
|
|
srini24
New User
Joined: 14 Feb 2017 Posts: 12 Location: India
|
|
|
|
What logic can be applied using reference modification alone? |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Is that an exercise ?
Are there always 4 words in the sentence ? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
1.See if you can twist INSPECT the way you want.
2.If you are allowed to use SQLs then use scalar functions.
3. As suggested by Robert , Use Ref modifications. loop thru the whole string to skip first letter and when you encountered SPACE then set a flag and skip the first letter of the next word and unset that same flag and move remaining letters until you hot next SPACE and repeat this till end of the string.
4. If these are record from the data set then use DFSORT to create a new Data Set the way you want and then run Cobol Program. I would not prefer this when COBOL is simpler. |
|
Back to top |
|
|
|