0

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.

Walee
  • 1
  • 2
  • define "delete the extra spaces" because all of the picture clauses in cobol have a set length, you can't really delete them. Do you just want to display the field without the spaces, or are you trying to write it out to a file? – SaggingRufus Aug 02 '17 at 18:55
  • i'm trying to display them without space basically if thats possible. – Walee Aug 02 '17 at 19:13
  • @Walee Don't you have `FUNCTION TRIM` on your compiler (you did not specified the compiler)? Note. both mainframe + gnu-cobol tag is in most cases wrong (I've heard about someone using gnucobol on a mainframe for 64bit COBOL but I guess this is not your use case). Additional to cleaning the tags and specifying the compiler: please accept the answer that works best for you. – Simon Sobisch Aug 05 '17 at 21:06
  • The gnucobol is sus, with JCL, unless you are executing on USS with BPXBATCH. – mckenzm Dec 04 '18 at 20:58

2 Answers2

2

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.

SaggingRufus
  • 1,814
  • 16
  • 32
  • `ACCEPT ALPHA-ITEM. MOVE MOVE-ITEM TO NUM-ITEM. DISPLAY NUM-ITEM. PERFORM VARYING WS-INDEX FROM 50 BY -1 UNTIL NUM-ITEM(WS-INDEX:1) NOT EQUAL SPACE OR WS-INDEX < 1 END-PERFORM DISPLAY NUM-ITEM(1:WS-INDEX). `it still displays spaces and for some reason its not JUSTIFIED RIGHT VALUE SPACES. – Walee Aug 02 '17 at 19:41
  • 1
    yes and it will because you just right justified it with spaces after removing the spaces. The problem is that you are removing the spaces, then when you move it to the right justified field it is using spaces to right justify it – SaggingRufus Aug 02 '17 at 19:47
  • basically you cant right justify it with spaces and then expect to not be leading spaces. do it without the justification like I have in my example – SaggingRufus Aug 02 '17 at 19:56
  • 1
    @Walee: Please accept this answer as that seems to work best for you. And please edit your question cleaning the tags and specifying the compiler you've used (I still find it confusing as-is as `FUNCTION TRIM` is the solution to the tags you've used). – Simon Sobisch Aug 28 '17 at 10:52
0

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

mckenzm
  • 1,545
  • 1
  • 12
  • 19