In the example below

05 WS-VAR1 PIC X(5),05 WS-VAR2 REDEFINES WA-VAR1 PIC 9(5),PROCEDURE DIVISION MOVE 'ABCDE' TO WS-VAR1.Now what is the value of WS-VAR1 and WS-VAR2 ?

Showing Answers 1 - 30 of 30 Answers

Chandru

  • Aug 3rd, 2005
 

WS-VAR1 = ABCDE 
WS-VAR2 = ABCDE

gowda

  • Aug 5th, 2005
 

this will gives syntax error and as will as soc error

Omi

  • Aug 12th, 2005
 

This code give error gives compilation error..it is not possible to move alphanumeric field into numeric field.

sanjeevkumar koneri

  • Sep 21st, 2005
 

hi,

as per my knowledge both variable will displays "abcde" only. bcoz in the redefination ,pic clause does not matter and pgm will run wihout any error.

sanju.

Dilip P

  • Sep 30th, 2005
 

Redefines Clauses allocates space. The picture clause can be any.

Both the variables will have ABCDE

John

  • Jan 24th, 2006
 

Var1 will have 'abcde', but Var2 will have the equivalent ebcdic value.

  Was this answer useful?  Yes

pradipta

  • Feb 4th, 2006
 

WS-VAR1-----ABCDE

WS-VAR2-----NULL

  Was this answer useful?  Yes

sandhya

  • Mar 20th, 2006
 

ws-va2 is redefined with wa-var1,where wa-var1 is not decalred,then it will b a error.

if it is typo error and ws-va2 is redefined to ws-va1,then both the values will b abcde :-)

  Was this answer useful?  Yes

praleo

  • Jul 12th, 2006
 

The answer is : ABCDE ABCDE. But if you try to move the value 'ABCDE' to the WS-VAR2 then it will show compile error.

vrajendran

  • May 18th, 2007
 

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.
 

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

kumar

  • Jun 3rd, 2007
 

it will not display any type error it will display



ws-var1 abcde

ws-var2 abcde

  Was this answer useful?  Yes

shriniv

  • Jul 6th, 2007
 

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.

  Was this answer useful?  Yes

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.


-Saheer.

  Was this answer useful?  Yes

Madhavi07

  • Oct 10th, 2007
 

var1 : ABCDE                          
var2 : ??????           INVALID DECIMAL

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

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".

  Was this answer useful?  Yes

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

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

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
  1.  IDENTIFICATION DIVISION.                              

  2.  PROGRAM-ID. REDFPRGM.                                  

  3.  DATA DIVISION.                                        

  4.  WORKING-STORAGE SECTION.                              

  5.  01 WS-VAR1                      PIC X(5) VALUE SPACES.

  6.  01 WS-VAR2 REDEFINES WS-VAR1    PIC 9(5) VALUE ZEROS.  

  7.  PROCEDURE DIVISION.                                    

  8.  0000-MAIN.                                            

  9.       MOVE ABCD TO WS-VAR1.                          

  10.       DISPLAY WS-VAR1.                                  

  11.       DISPLAY WS-VAR2.                                  

  12.       ADD 99 TO WS-VAR2.                                

  13.       DISPLAY WS-VAR2.                                  

  14.       STOP RUN.                                        

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

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

  Was this answer useful?  Yes

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

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.