Can we move SPACES to numeric field and ZEROES to
alphabetic field? If yes what are the way doing this?

Answers were Sorted based on User's Feedback



Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing ..

Answer / siva

yes, we can move accordingly thru REDEFINES clause.
Example :
01 WS-A PIC 9(5).
01 WS-AR REDEFINES WS-A PIC X(5).
01 WS-B PIC A(5).
01 WS-BR REDEFINES WS-B PIC X(5).


MOVE 12345 TO WS-A.
MOVE SPACES TO WS-AR.
MOVE 'ABCDE' TO WS-B.
MOVE ZEROES TO WS-BR.

WS-A, WS-AR contains spaces and WS-B, WS-BR contains
zeroes.

Is This Answer Correct ?    19 Yes 1 No

Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing ..

Answer / sriram

NO.
Only Alphanumiric field allow numric or alphabetic or both.

Is This Answer Correct ?    10 Yes 1 No

Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing ..

Answer / chakri

Sriram we can move numeric data items to alphanumeric data
items and vice versa. But when we do arithmetic operations
then only it will throw error if we move alphanumeric data
items to numeric items.

Is This Answer Correct ?    9 Yes 5 No

Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing ..

Answer / maneendra

Hi all,

I am adding one more point to all.
we can move spaces to numeric field without using redefines
also. it can be possible by Reference modification(The
compiler will then treat your WS-NUM field as alphanumeric.
The field length is not necessary).

sample prog and results are:
IDENTIFICATION DIVISION.
PROGRAM-ID. SPATONUM.
AUTHOR. MANEENDRA.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUM PIC 99.
01 WS-STR REDEFINES WS-NUM PIC XX.
PROCEDURE DIVISION.
MOVE ZEROS TO WS-NUM.
DISPLAY 'BEFORE:', WS-NUM.
MOVE SPACES TO WS-NUM(1:).
DISPLAY 'AFTER:', WS-NUM.
STOP RUN.

OUTPUT:
BEFORE:00
AFTER:

For moving numeric field to Alphanumeric field, we can pass
it directly.

Is This Answer Correct ?    3 Yes 0 No

Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing ..

Answer / guest

Chakri, you are wrong. Only Numeric data can be moved to
alphanumeric variable. The reverse is not possible.
One way of doing it is using Redefines clause.

Is This Answer Correct ?    6 Yes 5 No

Can we move SPACES to numeric field and ZEROES to alphabetic field? If yes what are the way doing ..

Answer / jayaprabhu

we can move the numeric to alphanumeric or alphabetic and
vive versa only using the redefines.

this concept is useful when you want to have only one copy
book field need to change to num/aplha for particular
program.

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More COBOL Interview Questions

What are the various section in data division and briefly explain them.

0 Answers  


can u give result for the fallowing example... 05 a pic 9(2) 05 b redifines a pic x(2). move 'xy' to b. display a,b.

10 Answers   IBM,


what is the use of comp2 ? where can we use it with example ?

3 Answers   Covansys,


There is a variable with value 19446. Requirement is to convert it to 194.46. I tried it by doing divide by 100 and my receiving field data type is 9(03)v99. But the output is 194. I am not getting the decimal value. Could anyone pls let me know how to get this done?

2 Answers  


What is the problem of ordered sequential files access?

0 Answers  


What is the size of s9(19)comp3? explain

8 Answers  


what will be the output when a)pic 9(6)value 000178 is moved to pic ***,***. b)pic 9(5) value 57397 is moved to pic $$,$$9.

5 Answers  


how do you reference the fixed unblock file formats from cobol programs

0 Answers  


What is the difference between CONTINUE & NEXT SENTENCE ?

2 Answers  


What are differences between Static Call and Dynamic Call?

10 Answers   IBM, KBC, Keane India Ltd, Verizon,


I know my query will return more than one row but I don't want cursor what should I do?

1 Answers  


What are the different open modes available in cobol?

0 Answers  


Categories