Suppressing variables



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Suppressing variables

Postby luckyboyroh » Thu Apr 18, 2013 4:49 pm

hi guys,

Need your help.

i have the below code.

05 WS-SYMBOL.
10 FILLER PIC X(08)
VALUE '<symbol>'.
10 symbol pic X(12).
10 FILLER PIC X(09)
VALUE '</symbol>'.
.........
........
MOVE ''ÁBCDE' TO symbol...

The output will be
output file :<symbol>ABCDE </symbol>

Here the value ABCDE followed by 7 spaces is moved between the tags. Is there any way to supress the spaces.. ideally the output i require needs to be as below.
<symbol>ABCDE</symbol>.

Please share your ideas. thanks
luckyboyroh
 
Posts: 35
Joined: Wed Jan 16, 2013 4:05 pm
Has thanked: 3 times
Been thanked: 0 time

Re: Suppressing variables

Postby Pandora-Box » Thu Apr 18, 2013 5:54 pm

Can you try STRING DELIMITED BY SPACE?
User avatar
Pandora-Box
 
Posts: 65
Joined: Fri Feb 10, 2012 8:30 pm
Location: Mars
Has thanked: 3 times
Been thanked: 6 times

Re: Suppressing variables

Postby Stefan » Thu Apr 18, 2013 6:06 pm

I assume you don't know the length of the non-blank content of your symbol.
In my example this content is stored in variable ws-symbol.
The output will be stored in ws-symbol-dynamic.
The field ws-count is for counting the non-blank characters in ws-symbol.
                                                                 
05  ws-symbol          pic x(12).
05  ws-count           pic 9(02) binary.
05  ws-symbol-dynamic  pic x(39).
move 'ABCDE'                to  ws-symbol
move zero                   to  ws-count
move space                  to  ws-symbol-dynamic
inspect ws-symbol     tallying  ws-count
                           for  characters
                before initial  space
string '<symbol>'               delimited by size
       ws-symbol(1:ws-len)      delimited by size
       '</symbol>'              delimited by size
                          into  ws-symbol-dynamic

After executing this code the field ws-count contains 5 and the field ws-symbol-dynamic contains '<symbol>ABCDE</symbol>' padded at the right with 17 blanks.
This technique only works if your character string has no blanks imbedded.
If you want to handle this too, you might loop through your string from the end to the beginning tallying all blanks until you find a non-blank character. Then subtract the counter from the total field length. This will be then the value for ws-count and you can run the STRING statement from the above example again.
Hope that helps.
There are 10 types of people in the world: Those who understand binary, and those who don't.
User avatar
Stefan
 
Posts: 27
Joined: Tue Aug 21, 2012 3:02 pm
Has thanked: 0 time
Been thanked: 2 times

Re: Suppressing variables

Postby Pandora-Box » Thu Apr 18, 2013 6:20 pm

Stefan,

You dont need to know the lenth of non space data but delimited by space should suffice
User avatar
Pandora-Box
 
Posts: 65
Joined: Fri Feb 10, 2012 8:30 pm
Location: Mars
Has thanked: 3 times
Been thanked: 6 times

Re: Suppressing variables

Postby Stefan » Thu Apr 18, 2013 6:27 pm

Yep, you're right. I think it's time for me to RTFM again. ;)
There are 10 types of people in the world: Those who understand binary, and those who don't.
User avatar
Stefan
 
Posts: 27
Joined: Tue Aug 21, 2012 3:02 pm
Has thanked: 0 time
Been thanked: 2 times

Re: Suppressing variables

Postby BillyBoyo » Thu Apr 18, 2013 9:18 pm

If you give your FILLERs names and go with what Pandora-Box has suggested, you should get what you want.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post