I've one string with spaces ( I N D I A ). My question is I
want remove the spaces & combine in to single string without
space (INDIA).How we can write the cobol program & wich
options we need to use. Please let me know.

Answers were Sorted based on User's Feedback



I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / jagan

Inspect string1 replacing all spaces by ''

Is This Answer Correct ?    13 Yes 2 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / mayank rastogi

Use following code: It'll work

MOVE 'I N D I A' TO WS-NAME.

UNSTRING WS-NAME DELIMITED BY ' '
INTO WS-CHAR1, WS-CHAR2, WS-CHAR3, WS-CHAR4, WS-CHAR5.
STRING WS-CHAR1, WS-CHAR2, WS-CHAR3, WS-CHAR4, WS-CHAR5
DELIMITED BY SIZE INTO WS-NAME1.

ws-name1 is the new variable that will contain INDIA
without any spaces

Is This Answer Correct ?    11 Yes 1 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / uday

Through reference modification we can acheive and it is the
best way.

In Working storage section

01 ws-india pic x(10) value ' I N D I A '
01 ws-india-f pic x(05).


In procedure division

Perform varying ws-i from 1 by 1 until wi-i > 20

If ws-india(ws-i:1) = spaces
continue
Else
move ws-india(ws-i:1)to ws-india-f
End-if

End-perform

Is This Answer Correct ?    3 Yes 0 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / wairagade

Can we do with referrence modication operator .. your
thoughts :)

Is This Answer Correct ?    2 Yes 0 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / jagan

Yes we can do it with reference modification too . But feel
the code will become a bit complex.

Is This Answer Correct ?    1 Yes 0 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / arpan

Probably you can write SPACES instead of ' ' in the
UNSTRING statement.

UNSTRING WS-NAME DELIMITED BY SPACES
INTO WS-CHAR1, WS-CHAR2, WS-CHAR3, WS-CHAR4, WS-CHAR5.
STRING WS-CHAR1, WS-CHAR2, WS-CHAR3, WS-CHAR4, WS-CHAR5
DELIMITED BY SIZE INTO WS-NAME1.

Is This Answer Correct ?    2 Yes 1 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / jagan

Thanks Mayank .... My answer was not correct. The code what
you mentioned is working properly .. But what in case we
don't know how many spaces (or) delimiters are there in the
string.....

Is This Answer Correct ?    0 Yes 0 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / sup

small modification to ans 9th,

If ws-india(ws-i:1) = spaces
continue
Else
move ws-india(ws-i:1)to ws-india-f(i:1)
i=i+1
End-if

Is This Answer Correct ?    3 Yes 3 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / karthik

STRING WS-NAME DELIMETED BY SPACES
INTO
OUT-VAB

Is This Answer Correct ?    0 Yes 6 No

I've one string with spaces ( I N D I A ). My question is I want remove the spaces & comb..

Answer / ashwani

With the help of Unstring delimited by ' ' , you can do so

Please correct me if i am wrong............

Is This Answer Correct ?    0 Yes 8 No

Post New Answer

More COBOL Interview Questions

can we use variable picture clause as xx.99 in cobol.

3 Answers  


created cluster using IDCAMS ..that is empty ..when i write a program for read using Input ..wil it open the cluster or gives any error?

2 Answers   HCL,


How can we find out wether to declare the data items like Integer, Char,Comp? If comp types how can we decide wether it is Comp and Comp3.How it is? Please Explain... Cheers.

1 Answers   Syntel,


what modification we need to do in jcl if we use sort in cobol? I mean whether we need to include tempary file used for sorting in assign statement?

3 Answers   TCS,


What is the difference between SEARCH and SEARCH ALL?

6 Answers   Cognizant,






if you code move high-values to variable,can you move it into numeric variable or alphanumeric variable?

1 Answers   Patni,


in how many mode we can open a file ?

4 Answers  


Difference between file status codes 02 and 22.... since both are for duplicate key detection.

1 Answers  


what do you mean by copybook? and what is the difference between the copybook which we are using in working storage and procedure division.

3 Answers   HCL, TCS,


01 var1 pic x(10) 01 var2 redefines var1 pic 9(10). then in procedure division move 'abcde' to var1 then waht is the value of var1 and var2

9 Answers   HSBC,


I need to compare two VSAM files, both having 'number' as key. If there is a matching record, write the data into another VSAM file. How will it be possible.

1 Answers   DSRC,


01 MOVE 10 TO N 05 PERFOM PARA1 TIMES STOP RUN WAT WILL HAPPEN?? WILL IT RUN INFINITELY OR AN ERROR WIL BE THER BECAUSE NO OF TIMES IS NOT GIVEN??

1 Answers  


Categories