|
View previous topic :: View next topic
|
| Author |
Message |
Chidane
New User
Joined: 25 Nov 2021 Posts: 26 Location: India
|
|
|
|
01 WS-A PIC X(7) VALUE ' S'.
01 WS-B PIC X(8) VALUE ' AB'
01 WS-C PIC X(5) VALUE 'CD '
01 WS-ABC PIC X(20)
I would like to remove all the leading spaces of WS-A and WS-B and Trailing spaces of WS-C and store the concatenated result in WS-ABC separated by hyphen char
| Code: |
| Result of WS-ABC => S-AB-CD |
I have trried UNSTRING DELIMITED BY SPACES but while saving it is not correctly coming.
Could you please help me to acheive this result
Thanks |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
You must present here:
1) the exact code you've tried to use (enclosed within Code tags), and
2) the exact result you've got after execution of your code (with any error/diagnostic messages, too). |
|
| Back to top |
|
 |
Chidane
New User
Joined: 25 Nov 2021 Posts: 26 Location: India
|
|
|
|
Thanks for the reply
| Code: |
01 WS-A PIC X(7) VALUE ' S'.
01 WS-B PIC X(8) VALUE ' AB'
01 WS-C PIC X(5) VALUE 'CD '
01 WS-ABC PIC X(20)
01 WS-SPACE PIC X(5)
01 WS-X PIC X(7)
01 WS-Y PIC X(8)
01 WS-Z PIC X(5)
UNSTRING WS-A DELIMITED BY ALL SPACES INTO WS-SPACE, WS-X
UNSTRING WS-B DELIMITED BY ALL SPACES INTO WS-SPACE, WS-Y
UNSTRING WS-C DELIMITED BY ALL SPACES INTO WS-SPACE, WS-Z
STRING WS-X "-" WS-Y "-" WS-Z "-" DELIMITED BY SIZE INTO WS-ABC |
| Code: |
| Incorrect Output that I got is S -AB -CD |
Expected output is S-AB-CD
The input values can also be like
| Code: |
01 WS-A PIC X(7) VALUE ' '.
01 WS-B PIC X(8) VALUE ' W3ER4GH'
01 WS-C PIC X(5) VALUE 'CDSD '
The expected output is -W3ER4GH-CDSD |
Thanks |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2263 Location: USA
|
|
|
|
Any string value, when moved (e.g. assigned, or set) to a variable of type PIC X(nn) is extended at the right side to the full length of nn characters with blanks.
This is exactly what you get. It cannot be recognized as "not correctly coming"; this is exactly what you requested from COBOL.
As a hint, take a look at this:
www.ibm.com/docs/en/cobol-zos/6.3.0?topic=statements-string-statement
Also it makes sense to RTFM. |
|
| Back to top |
|
 |
|
|