How to delete leading spaces/blank in COBOL ?
Example:- 01 data-name-1 pic x(220) " English is a
language".
I would like to delete leading spaces.

Answers were Sorted based on User's Feedback



How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / varun v

Yes, we can use "Inspect Tallying" for the same.

Wroking storage Variable:
01 WS-VAR PIC X(15) VALUE ' COBOL'.
01 WS-VAR-FINAL PIC X(15).
01 WS-TALLY1 PIC 9(02) VALUE ZERO.

Procedure Dvision:
Inspect WS-VAR Tallying WS-TALLY1 for leading spaces
Move WS-VAR(WS-TALLY1+1 : 15-WS-TALLY1) to
WS-VAR-FINAL.

Now WS-INSPECT-FINAL should have
Value 'COBOL'.

Is This Answer Correct ?    50 Yes 12 No

How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / xyz

USe the Inspect Clause , get the number of the leading
spaces in the Count variable. Use the reference move then.

Is This Answer Correct ?    32 Yes 5 No

How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / naveen

You have many options.

1. Use Reference modification if you want a COBOL program.
2. INSPECT will also do.
3. Use SORT, OUTREC option, it will also work.

Is This Answer Correct ?    8 Yes 1 No

How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / varun v

I agree with Ans # 1 also.

But I think "Inspect Tallying" is the effective one as
there is no manual calculation is required for finding the
exact length of the second variable field(CHR6 in Ans #1)
is required.

Is This Answer Correct ?    7 Yes 3 No

How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / arne royce tiangson

I CAN FIND THE WRITE OUTPUT.. PLEASE EXPLAIN THIS CODE
'MOVE WS-USERID-TEMP(WS-TALLY + 1 : ) TO WS-LS-USERID'

THNX

Is This Answer Correct ?    1 Yes 2 No

How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / prasanth

Wroking storage Variable:
01 WS-VAR PIC X(15) VALUE ' COBOL'.
01 WS-VAR-FINAL PIC X(15).
01 WS-TALLY1 PIC 9(02) VALUE ZERO.

Procedure division


INITIALIZE WS-TALLY

MOVE ID-TBL-IMMS OF TBL TO WS-USERID-TEMP

INSPECT WS-USERID-TEMP TALLYING WS-TALLY
FOR LEADING SPACE

MOVE WS-TALLY TO WS-TEMP
IF WS-TALLY IS NOT ZERO

MOVE WS-USERID-TEMP(WS-TALLY + 1 : ) TO WS-LS-USERID

Is This Answer Correct ?    6 Yes 10 No

How to delete leading spaces/blank in COBOL ? Example:- 01 data-name-1 pic x(220) " English ..

Answer / minarul

you can do this by defining another varible with JUSTIFIED
RIGHT clause. then move the value from data-name-1 to that
varible. You have to define the picture clause of that
varible with proper length : below code will exactly do
that:

01 data-name-1 pic x(220) " English is a language".
01 CHR6 PIC X(217) JUSTIFIED RIGHT.
now do a move from data-name-1 to CHR6 and then disolay
the content of CHR6

Is This Answer Correct ?    20 Yes 33 No

Post New Answer

More COBOL Interview Questions

File status must be checked both while opening and reading the file or only while reading the file?

2 Answers  


I have a File that has duplicate records. I need only those records that occur more than thrice.?

3 Answers   IBM, Wipro,


how will u find out 3rd week's 2nd day using occurs ?

3 Answers   L&T,


Which is the best IBM mainframe Training Institute in Ameerpet, Hyderabad

35 Answers  


Can we access the a[0] in the array ?

6 Answers   DCL, IBM,






what is the size of W-REC in the following 01 W-REC 05 A PIC 9(4)V99 05 B READLINES A 10 C PIC XX 10 D PIC S9(4) 05 E OCCURS 7 PIC ZZ.ZZ 05 F OCCURS 5 10 G PIC ZZ.ZZZ99 10 H OCCURS 3 15 J PIC 9(3) 15 K PIC V99

2 Answers   TCS,


How to pass return codes from cobol to jcl?

5 Answers  


Why we should use cursor ?

3 Answers  


What is the maximum length of a field you can define using COMP-3 in COBOL?

1 Answers   UGC Corporation,


diffrence between renames and redifnes with examples

3 Answers   IBM,


I have a sequential file. How do I access a record in this sequential file randomly in my program ?

8 Answers   CGI, Xansa,


can we use COPY statement in w-s section? how?

3 Answers  


Categories