The Answer is: when you trying to display the fields, you will get the following as a results
WS-VAR1 = 'abcde'
WS-VAR2 = Junk value or Low values.
raul
May 30th, 2007
Actually both will have the 'abcde' value because both vars are pointing to the same memory area. the problem is that if you want to reference var-2 you will get a SC07 due to the fact that it is not a recognized numerical value.
kumar
Jun 3rd, 2007
it will not display any type error it will display
When I tried executing the program, I got the results as below: ws-var1 - 12345 ws-var2 - 12345 If I don't move var1 to var2, then both are showing abcde.
saheer
Jul 17th, 2007
When a redefines is used, as in the given case, it just gives two names to
the memory allocated.
In the current scenario,
Move "ABCDE" to ws-var1 is a valid statement as the PIC clause is alphanumeric.
But then, redefines gives two names to this memory location
When we try to retrieve the data using the variable name ws-var2 it will
definitely give "ABCDE" and noting else as it is just an alias.
Note that it's the duty of a compiler to check if the data being moved is in
accordance with the PIC clause. The compilation check is done only during
variable definition and that too its just for the user convenience, there is
absolutely no difference in the memory allocated to a Alpha-numeric and a
Numeric data item. There is no compilation check while we retrieve and hence no
problems.
Of course, the following statement would have given an error
Move "ABCDE" to ws-var2.
SOC7 ERROR
bcaz whenever ws-var1 is redefined by ws-var2 (num),the numeric pic 9(5) stands in-front of Alphanumeric pic x(5) and so it takes the values anything that comes to ws-var1.if once any variable is redefined ,it is almost killed/replaced.
if u have initialized before ws-var1 as INITIALIZE ABCDE .than it gives ABCDE as output.
Vahida Syed
Apr 7th, 2013
I tried implementing this in mainframes.. Neither it has given compilation error nor abended when executing the program.
Result is : both the fields holds "abcde".
ashwini
Sep 10th, 2013
Hi all,
I run the program and it ran successfully.
After moving :
WS-B displays ABCD5
It means Movement has not been properly done .The previous values of A have not properly erased out plus the junk values have been displayed appended to it.I think it depends upon the compiler how it will treat the memory with the same variables
Harsha
Jul 24th, 2014
Both will have the same values. But when you display WS-VAR2 or do any sort of arithmetic operation, you will get S0C7.
NAGA SUDHINDRA
Oct 13th, 2014
When we define the variables in the w-s section we can initialize the variables with spaces and zeros to avoid junk values.The program does not throws any error wen we try to display the var2 .Wen we try to do any arithmetic operations also it does not throws any error rather return garbage/junk values as output.
Code
IDENTIFICATIONDIVISION.
PROGRAM-ID. REDFPRGM.
DATADIVISION.
WORKING-STORAGESECTION.
01 WS-VAR1 PIC X(5)VALUESPACES.
01 WS-VAR2 REDEFINES WS-VAR1 PIC9(5)VALUE ZEROS.
PROCEDUREDIVISION.
0000-MAIN.
MOVE ABCD TO WS-VAR1.
DISPLAY WS-VAR1.
DISPLAY WS-VAR2.
ADD99TO WS-VAR2.
DISPLAY WS-VAR2.
STOPRUN.
Srinivas Enumula
Nov 3rd, 2014
Both WS-VAR1 and WS-VAR2 having same value i.e ABCDE but if you try to move ABCDE to WS-VAR2 then you will get RETURN CODE 12 saying that "IGYPA3005-S ""ABCDE"" and "WS-VAR2 (NUMERIC INTEGER)" did not follow the "MOVE" statement compatibility rules.
Suganya
May 19th, 2015
Both ws-var-1 and ws-var-2 contain ABCDE . It wont throw any error. I executed the code and found out the result
supriya
Sep 5th, 2017
Here given 05 WS-VAR2 redefines WA-VAR1 pic 9(5). means WA-VAR1 should be defined in working storage so while compiling it will throw the error. but excluding this next statement in procedure division is move abcde to ws-var1. means value of ws-var1 is =abcde
In the example below