Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Cobol redefines for Signed pictured clause

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Cobol redefines for Signed pictured clause
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: 1344
Location: Israel

PostPosted: Thu Feb 27, 2020 5:29 pm    Post subject:
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: 1344
Location: Israel

PostPosted: Thu Feb 27, 2020 5:50 pm    Post subject:
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: 8526
Location: Dubuque, Iowa, USA

PostPosted: Thu Feb 27, 2020 8:10 pm    Post subject: Reply to: Cobol redefines for Signed pictured clause
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

Active Member


Joined: 29 Apr 2008
Posts: 712
Location: Maryland

PostPosted: Thu Feb 27, 2020 11:45 pm    Post subject: Re: Cobol redefines for Signed pictured clause
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts COBOL batch program using large size ... Akriti Mishra COBOL Programming 3 Thu Mar 26, 2020 11:37 pm
No new posts Trying to submit COBOL PGM - JCL ERRO... sandeep prajapati JCL & VSAM 5 Tue Mar 24, 2020 11:21 pm
No new posts usage of CASE in WHERE clause abdulrafi DB2 10 Wed Mar 18, 2020 4:25 pm
No new posts How to create UUID using COBOL PORYES COBOL Programming 0 Tue Mar 17, 2020 4:43 pm
This topic is locked: you cannot edit posts or make replies. Cobol db2 program going in loop sivasaras COBOL Programming 4 Sat Feb 29, 2020 7:44 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us