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
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 |
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 |
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 |
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 |
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 |
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.
. How do we cast a variable in COBOL
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)
I have to write to a outfile where the number of records in that file should be the header of that file using IMS.. can anyone help me in this issue
What kind of error is trapped by on size error option?
how many bytes does s9(7)COMP-3 field occupies?
which is Best IBM Mainframe Training and Placement Institute in Ameerpet Hyderabad
I have a source program compiled with Cobol-2. The output file has a record length of 100 defined in the program but a record of 60 bytes getting written into it. i.e. The rest of 40 bytes I am not Writing anything. But it by default puts some values into the last 40 bytes. However it does not impact anything. But when Compiled the module with Enterprise Cobol the last 40 bytes were spaces as fillers. Can anyone explain?
write a program to eliminate duplicate records in a input file and send them to output file.THIS IS IGATE RECENT QUESTIONN.....JUST 1 WEEK BACKKKK...
wht is load module and object module ?
Explain the difference between an internal and an external sort, the pros and cons, internal sort syntax etc.
How to know whether the module is dynamical or statistical?