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 is rediffine clause?in what situation it can use?give me real time example?

1 Answers   IBM,


how to display date in reverse order if the pic clause of the is numeric suppose date is 09032010 ==> need to print in 20100309 (pic clause is numeric)

6 Answers  


The hierarchy of the execution of logical operators is (a) NOT AND OR (b) AND OR NOT (c) OR AND NOT (d) OR NOT AND

10 Answers   Huawei, IBM, TCS,


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

35 Answers  


how can count the number of character in feild ?? suppose for instance i have a feild with value ' rajesh sarkar' then how can v count the number of characters whitout spaces...........

4 Answers   Wipro,






What are all the divisions of a COBOL program?

0 Answers  


We are using the searching a table which is indexed, once the key is found, how can we get the occurance at which the key was found.

1 Answers  


What are the different data types in cobol?

0 Answers  


What is length is cobol?

0 Answers  


Consider the following COBOL entries 05 X PIC 99 VALUE 10. ADD 40 X TO X. COMPUTE X = 3 * X - 40. The result in X is

12 Answers   TCS,


when iam reading a flat file which has 100 records through cobol program when iam reading 50th records it gets abends .. so when i run the program again it should read from 50th record .where it got abened ? how it is possible

1 Answers   Patni,


In an EVALUTE statement is the order of the WHEN clauses significant?

4 Answers  


Categories