HPE Community read-only access December 15, 2018
This is a maintenance upgrade. You will be able to read articles and posts, but not post or reply.
Hours:
Dec 15, 4:00 am to 10:00 am UTC
Dec 14, 10:00 pm CST to Dec 15, 4:00 am CST
Dec 14, 8:00 pm PST to Dec 15, 2:00 am PST
Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

sting manipulation

 
sunny123
Occasional Advisor

sting manipulation

Hi,

I have a alphanumeric variable say x(200) which contains a string with spaces in between. Can someone help me how to remove the spaces in the string in cobol.

Thanks,
Sunil
9 REPLIES
Wim Van den Wyngaert
Honored Contributor

Re: sting manipulation

MOVE 1 TO I
PERFORM UNTIL I = 200
IF X(I) = SPACE
THEN
MOVE X(I+1:200 - I)
TO X(I:200 - I + 1)
END-IF
ADD 1 TO I
END-PERFORM

Or use system calls.

Hope it's correct because not used COBOL in 10 years.

Wim


Wim
Barry Alford
Frequent Advisor

Re: sting manipulation

I seem to remember a VARYING clause:

PERFORM ... VARYING I BY 1 UNTIL 200

...but I haven't used COBOL in 30 years!

Barry Alford
Frequent Advisor

Re: sting manipulation

...or was it

PERFORM ... VARYING I FROM 1 TO 200 BY 1

anyhow, there are also a few full stops (aka periods) missing from the example!
Phil.Howell
Honored Contributor

Re: sting manipulation

Wim Van den Wyngaert
Honored Contributor

Re: sting manipulation

Phil,

STRING ? INSPECT could do it but it replaces characters by characters of equal length. So, no go.

Wim
Wim
Phil.Howell
Honored Contributor

Re: sting manipulation

ok, to be more specific...
I would use STRING
with a DELIMITED BY value and a POINTER
Phil
Hein van den Heuvel
Honored Contributor

Re: sting manipulation

I would call the BASIC RTL EDIT$ function with code 2 or 258

Example:
IDENTIFICATION DIVISION.
PROGRAM-ID. BENCH_MOVTC.
DATA DIVISION.
WORKING-STORAGE SECTION.

77 WS-SOURCE-NAME PIC X(55).
77 WS-DEST-NAME PIC X(55).


01 EDIT_VAL_COMP PIC 9(9) USAGE COMP.
01 EDIT_VAL_TEXT PIC 9(3) USAGE DISPLAY.

PROCEDURE DIVISION.
PGM-BEGIN.
DISPLAY "Edit: " NO ADVANCING.
ACCEPT EDIT_VAL_TEXT.
MOVE EDIT_VAL_TEXT TO EDIT_VAL_COMP.
DISPLAY "Name: " NO ADVANCING
ACCEPT WS-SOURCE-NAME

CALL 'DBASIC$EDIT' USING BY DESCRIPTOR WS-DEST-NAME, WS-SOURCE-NAME,
BY VALUE EDIT_VAL_COMP.

Display ws-dest-name.

stop run.

Edit functions available:


$ HELP/LIBRARY=BASICHELP edit% synt

EDIT$

Syntax


str-var = EDIT$(str-exp, int-exp)

Values Effect

1% Trim parity bits
2% Discard all spaces and tabs
4% Discard characters: CR, LF, FF, ESC, RUBOUT, and NULL
8% Discard leading spaces and tabs
16% Reduce spaces and tabs to one space
32% Convert lowercase to uppercase
64% Convert [ to ( and ] to )
128% Discard trailing spaces and tabs
256% Do not alter characters inside quotes


Enjoy!
Hein.

sunny123
Occasional Advisor

Re: sting manipulation

Hi All,

Thank you very much for all your help and valuable suggestions which made my job easy.
Thanks again
Jan van den Ende
Honored Contributor

Re: sting manipulation

Sunil,

perhaps you could read

http://forums1.itrc.hp.com/service/forums/helptips.do?#33

to find out hpw to express your thanks.

(and zero points for this please)

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.