IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To Unstring spaces in a field


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Chidane

New User


Joined: 25 Nov 2021
Posts: 26
Location: India

PostPosted: Fri Jul 18, 2025 5:20 pm
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2263
Location: USA

PostPosted: Fri Jul 18, 2025 6:26 pm
Reply with quote

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
View user's profile Send private message
Chidane

New User


Joined: 25 Nov 2021
Posts: 26
Location: India

PostPosted: Sat Jul 19, 2025 10:19 am
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2263
Location: USA

PostPosted: Mon Jul 21, 2025 5:37 pm
Reply with quote

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
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts how to complete the end of a record w... DFSORT/ICETOOL 2
No new posts BPXBATCH SFTP to remote path having s... All Other Mainframe Topics 6
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:


Back to Top