IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Cobol redefines for Signed pictured clause


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gvvjags

New User


Joined: 27 Feb 2020
Posts: 1
Location: INDIA

PostPosted: Thu Feb 27, 2020 4:33 pm
Reply with quote

Hi , I have defined COBOL Variable as below.

03 VARIABLE-A PIC S9(04)

03 FILLER REDEFINES VARIABLE A.

05 VARIABLE-B S9(02).
05 VARIABLE-C S9(02).

Is this redefinition correct. I mean for example 24 is moved to VARIABLE-B
and 40 is moved to Variable-C .

Where does Sign stored in Variable-a, Variable-b and Variable-c.
Does variable-a exactly store values in b and c together.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Feb 27, 2020 5:29 pm
Reply with quote

It took me a few minutes to write the following program:
Code:
       IDENTIFICATION DIVISION.                             
       PROGRAM-ID.                     MYTEST.             
       DATA DIVISION.                                       
       WORKING-STORAGE SECTION.                             
                                                           
        01  VARIABLE-A     PIC S9(4).                       
        01  FILLER                     REDEFINES VARIABLE-A.
           03 VARIABLE-B   PIC S9(2).                       
           03 VARIABLE-C   PIC S9(2).                       
                                                           
       PROCEDURE DIVISION.                                 
                                                           
           MOVE 1357 TO VARIABLE-A               *> NO SIGN
           DISPLAY 'VARIABLE-A= ' VARIABLE-A               
               ' VARIABLE-B=' VARIABLE-B                   
               ' VARIABLE-C=' VARIABLE-C                   
                                                           
           MOVE -9876 TO VARIABLE-A              *> NEGATIVE
           DISPLAY 'VARIABLE-A= ' VARIABLE-A               
               ' VARIABLE-B=' VARIABLE-B                   
               ' VARIABLE-C=' VARIABLE-C                   
                                                           
           MOVE +2468 TO VARIABLE-A              *> POSITIVE
           DISPLAY 'VARIABLE-A= ' VARIABLE-A               
               ' VARIABLE-B=' VARIABLE-B                   
               ' VARIABLE-C=' VARIABLE-C                   
                                                           
           GOBACK.                                         
And another few seconds to write some JCL:
Code:
//MYTEST  JOB  NOTIFY=&SYSUID
//STEP001   EXEC PGM=MYTEST
//STEPLIB   DD   DISP=SHR,DSN=hlq.WHERE.LOAD   
//SYSOUT    DD   SYSOUT=*                     
And after a few more seconds, got the result:
Code:
VARIABLE-A= 135G VARIABLE-B=13 VARIABLE-C=5G
VARIABLE-A= 987O VARIABLE-B=98 VARIABLE-C=7O
VARIABLE-A= 246H VARIABLE-B=24 VARIABLE-C=6H
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Feb 27, 2020 5:50 pm
Reply with quote

I also added:
Code:
          MOVE 24 TO VARIABLE-B             
          MOVE 40 TO VARIABLE-C             
          DISPLAY 'VARIABLE-A= ' VARIABLE-A 
              ' VARIABLE-B=' VARIABLE-B     
              ' VARIABLE-C=' VARIABLE-C     
and the DISPLAY showed:
Code:
VARIABLE-A= 2D4{ VARIABLE-B=2D VARIABLE-C=4{

I guess this answers your question.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8700
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 27, 2020 8:10 pm
Reply with quote

Quote:
Is this redefinition correct.
Absolutely, categorically no. Will it "work" for COBOL? MAYBE. The Language Reference manual tells us that a zoned decimal variable that is declared as signed stores the sign in the rightmost character's zone bits. Hence variable A will have its sign stored in the zone field of the 4th byte. If you move something to B, it will have a sign stored in the zone of the second byte. What does this mean for A? At a minimum, you've got a sign that will be ignored if A is used as a variable. COBOL allows you to do many things that are not within the purview of the rules. Such things are, typically, creating unpredictable results.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2141
Location: USA

PostPosted: Thu Feb 27, 2020 11:45 pm
Reply with quote

gvvjags wrote:
Hi , I have defined COBOL Variable as below.

03 VARIABLE-A PIC S9(04)

03 FILLER REDEFINES VARIABLE A.

05 VARIABLE-B S9(02).
05 VARIABLE-C S9(02).

Is this redefinition correct.


Definitely NOT is you are using SIGNED numeric variables (e.g. "decimal unpacked" in IBM environment). It may (or may not) work with UNSIGNED numeric variables...

Unless you are using simple CHARACTER values (e.g. PIC X...), the result of REDEFINES can be unpredictable; one needs to understand well the internal data representation in particular environments.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL sorting, with input GDG base COBOL Programming 7
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 0
No new posts Replacing FILLER with FILLER<SeqNu... DFSORT/ICETOOL 2
No new posts Compile Sp Cobol base COBOL Programming 1
No new posts SQLCODE=-311 in Cobol SP-DB2. COBOL Programming 2
Search our Forums:

Back to Top