Walee
Walee

Reputation: 1

cobol & JCL removing extra spaces

I am trying to accept input from jcl for example 'John Snow' and run it from my cobol program Im using JUSTIFIED RIGHT VALUE SPACES to move the string to the right side however I need to delete the extra spaces using my cobol pgm.

example my working storage is:

01 ALPHA-ITEM PIC X(50).                           
01 MOVE-ITEM REDEFINES ALPHA-ITEM PIC X(50).       
01 NUM-ITEM PIC X(50) JUSTIFIED RIGHT VALUE SPACES.

and in my PROCEDURE DIVISION

ACCEPT ALPHA-ITEM.         
MOVE MOVE-ITEM TO NUM-ITEM.
DISPLAY NUM-ITEM.  

it displays 'John Snow' on the right of the screen however i don't know how to remove the extra spaces.

Upvotes: 0

Views: 2014

Answers (2)

mckenzm
mckenzm

Reputation: 1820

There is also.. Unpopular for some reason. UNSTRING MOVE-ITEM DELIMITED BY SPACES INTO NUM-ITEM.

Upvotes: 0

SaggingRufus
SaggingRufus

Reputation: 1834

you need something like this:

01 ALPHA-ITEM PIC X(50).                                 
01 WS-INDEX PIC 99.

ACCEPT ALPHA-ITEM  

PERFORM VARYING WS-INDEX 
    FROM 50 BY -1
   UNTIL ALPHA-ITEM(WS-INDEX:1) NOT EQUAL SPACE
         OR WS-INDEX < 1
END-PERFORM

DISPLAY ALPHA-ITEM(1:WS-INDEX).  

This code will accept the alpha item, then run a loop to find out how long the data actually is. Then it will display that field starting from position 1 until the counter that was set in the loop.

Upvotes: 2

Related Questions