Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Redefine - Moves between redefining item and redefined item

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Manish Kumar Gupta

New User


Joined: 19 Feb 2008
Posts: 6
Location: Bangalore

PostPosted: Wed Jun 02, 2010 1:07 am    Post subject: Redefine - Moves between redefining item and redefined item
Reply with quote

Hi,

I have been asked the following question:

01 Var-1 Pic 9(4) Value 1234.
01 Var-2 Redefines Var-1 Pic 9(2).

What will happen if we move Var-2 to Var-1 and Move Var-1 to Var-2

IBM Manual says that the results are undefined so i said the same thing, but later i thought to give it a try, here are the results:

Initial Display:

Display Var-1 = 1234
Display Var-2 = 12

------------------------------
Move Var-1 to Var-2 (Larger to Smaller)

Display Var-1 = 3434
Display Var-2 = 34

------------------------------

But when i moved Var-2 to Var-1 (Smaller to Larger) results were

Before move i made the values as

Display Var-1 = 1234
Display Var-2 = 12

After move the values were

Display Var-1 = 0000
Display Var-2 = 00

-------------------------------

I tried it with different values but the results followed the same pattern, i am not sure what happened, i would be grateful if someone can explain.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 02, 2010 1:40 am    Post subject:
Reply with quote

Manish,

I know that the programmers guide has the same type of graph:

var1 pic 9(04).
var2 redefines var1 pic 9(02).

var1 starts at address 0001 and continues thru 0004
var2 starts at address 0001 and continues thru 0002.

if you understand the above,
you should be able to answer your own question.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jun 02, 2010 1:53 am    Post subject:
Reply with quote

Hello,

Quote:
I tried it with different values but the results followed the same pattern, i am not sure what happened
Things happened as they should - just what the code said to do.

You might also look at the compiler-generated code to see the actual instructions. . .
Back to top
View user's profile Send private message
Manish Kumar Gupta

New User


Joined: 19 Feb 2008
Posts: 6
Location: Bangalore

PostPosted: Wed Jun 02, 2010 1:59 am    Post subject:
Reply with quote

Thanks for the reply! I would take a deeper look into this, When i said

"I am not sure what happened" i was wondering about the difference in results (moving from larger to smaller / smaller to larger)

I will go thru the compiler generated instruction to understand whats happening when i am moving Smaller Variable into Larger.

Thanks
Back to top
View user's profile Send private message
Manish Kumar Gupta

New User


Joined: 19 Feb 2008
Posts: 6
Location: Bangalore

PostPosted: Wed Jun 02, 2010 2:01 am    Post subject:
Reply with quote

The results shouldn't be same for the two move statements, but i am not able to understand the zeros in the move from Smaller to Larger.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Jun 02, 2010 2:02 am    Post subject:
Reply with quote

Hello,

Look closely at the memory addresses being used as well as the actual instructions . . .
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Jun 02, 2010 2:08 am    Post subject:
Reply with quote

Quote:
I will go thru the compiler generated instruction to understand


stop wasting your time.

read about numeric moves and what constitutes truncation (why and how it is done)
and about justification and zero filling to the left.

while you are at it,
read about alphanumeric moves,
what constitutes truncation,
and about justification and space filling to the right

you are aware, that redefining something is
only allocating the same data area to two reference names.

as I have tried to imply and Dick overtly suggested,
look at the addresses.......................
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Jun 02, 2010 2:09 am    Post subject:
Reply with quote

Manish Kumar Gupta wrote:
"I am not sure what happened" i was wondering about the difference in results (moving from larger to smaller / smaller to larger)

I will go thru the compiler generated instruction to understand whats happening when i am moving Smaller Variable into Larger.
Why not post those generated instructions for both the moves?
I don't have a compiler available and I am curious as to what is generated for the dissimilar size moves.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Jun 02, 2010 3:53 am    Post subject:
Reply with quote

Code:
           DISPLAY 'VAR-1 AT START            ' VAR-1.
           DISPLAY 'VAR-2 AT START            ' VAR-2.
           MOVE VAR-1                  TO  VAR-2.
           DISPLAY 'VAR-1 AFTER MOVE TO VAR-2 ' VAR-1.
           DISPLAY 'VAR-2 AFTER MOVE TO VAR-2 ' VAR-2.
           MOVE VAR-2                  TO  VAR-1.
           DISPLAY 'VAR-1 AFTER MOVE TO VAR-1 ' VAR-1.
           DISPLAY 'VAR-2 AFTER MOVE TO VAR-1 ' VAR-2.
produces
Code:
 000020  DISPLAY
    000432  5820 905C               L     2,92(0,9)               TGTFIXD+92
    000436  58F0 202C               L     15,44(0,2)              V(IGZCDSP )
    00043A  4110 A1A6               LA    1,422(0,10)             PGMLIT AT +414
    00043E  05EF                    BALR  14,15
 000021  DISPLAY
    000440  58F0 202C               L     15,44(0,2)              V(IGZCDSP )
    000444  4110 A190               LA    1,400(0,10)             PGMLIT AT +392
    000448  05EF                    BALR  14,15
 000022  MOVE
    00044A  D201 8000 8002          MVC   0(2,8),2(8)             VAR-2
    000450  96F0 8001               OI    1(8),X'F0'              VAR-2+1
 000023  DISPLAY
    000454  58F0 202C               L     15,44(0,2)              V(IGZCDSP )
    000458  4110 A17A               LA    1,378(0,10)             PGMLIT AT +370
    00045C  05EF                    BALR  14,15
 000024  DISPLAY
    00045E  58F0 202C               L     15,44(0,2)              V(IGZCDSP )
    000462  4110 A164               LA    1,356(0,10)             PGMLIT AT +348
    000466  05EF                    BALR  14,15
 000025  MOVE
    000468  D201 8000 C022          MVC   0(2,8),34(12)           VAR-1
    00046E  D201 8002 8000          MVC   2(2,8),0(8)             VAR-1+2
    000474  96F0 8003               OI    3(8),X'F0'              VAR-1+3
 000026  DISPLAY
    000478  58F0 202C               L     15,44(0,2)              V(IGZCDSP )
    00047C  4110 A14E               LA    1,334(0,10)             PGMLIT AT +326
    000480  05EF                    BALR  14,15
 000027  DISPLAY
    000482  58F0 202C               L     15,44(0,2)              V(IGZCDSP )
    000486  4110 A138               LA    1,312(0,10)             PGMLIT AT +304
    00048A  05EF                    BALR  14,15
Register 8 points to BLW=0 according to the prologue while Register 12 points to the PGT
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed Jun 02, 2010 5:08 am    Post subject:
Reply with quote

Dang.
The move of the large to the small makes so much sense.
But what is in X'34(12)'?
I can only assume the required leading zeros....
Which means that the redefined var-2 now contains those zeros and the following MVC 2(2,8),0(8) puts those zeros into the rear two bytes of var-1.

Thank you "Mr. TANSTAAFL"....giggle......
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Jun 02, 2010 5:18 am    Post subject:
Reply with quote

Dang, forget to switch...grumble...
But not too bad for an old VSE systems programmer...grin....
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7913
Location: Bellevue, IA

PostPosted: Wed Jun 02, 2010 5:29 am    Post subject:
Reply with quote

X 34(12) contains 'F0F0' -- I went back and did a little dump to find out.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Jun 02, 2010 6:44 am    Post subject:
Reply with quote

As I kinda thought.
And, thank you again "Mr. TANSTAAFL"...grin....
Back to top
View user's profile Send private message
anshul_gugnani

New User


Joined: 02 Nov 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Jun 02, 2010 3:39 pm    Post subject:
Reply with quote

Hi,

I could understand the move of var-1 to var-2 but move of var-2 to var-1 is not clear.

When var-2 will be moved to var-1 it should move '0012' to var-1 as it will be padded wid leading zeroes.

Considering this value of var-1 will bw '0012' and value of var-1 will be '00'.

Can someone please explain me the how thew value of var-1 is '0000'

Tried to understand the compiler generated instructions but could not.
Please help.

Thanks.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Wed Jun 02, 2010 5:33 pm    Post subject:
Reply with quote

The "problem" with the move of Var-2 to Var-1 is in the sequence of instructions generated by the compiler. Apparently, the author(s) of the compiler neglected to take into consideration the possibility of overlapping fields in a straight numeric move of shorter to longer lengths. So, the generated code:
Code:
 000025  MOVE
    000468  D201 8000 C022          MVC   0(2,8),34(12)           VAR-1
    00046E  D201 8002 8000          MVC   2(2,8),0(8)             VAR-1+2
    000474  96F0 8003               OI    3(8),X'F0'              VAR-1+3
says, in the sequence generated, to:

1. 468: zero fill the leftmost digits of Var-1 by moving 2 zeros to the first 2 bytes of Var-1, resulting ( because of the redefines ) in values of Var-1 = 0034 and Var-2 = 00

2. 46E: move the 2 bytes of Var-2 to the last 2 bytes of Var-1, resulting in values of Var-1 = 0000 and Var-2 = 00

3. 474: ORing the last byte of Var-1 to insure that it has a proper sign ( x'F' )

The "correct" code SHOULD have been in the sequence:
Code:
 000025  MOVE
    000468  D201 8002 8000          MVC   2(2,8),0(8)             VAR-1+2
    00046E  96F0 8003               OI    3(8),X'F0'              VAR-1+3
    000472  D201 8000 C022          MVC   0(2,8),34(12)           VAR-1

Namely, move Var-2 to Var-1 FIRST, THEN zero fill Var-1 to the left. Perhaps someone should open a problem ticket with IBM related to how the compiler generates code when moving a shorter numeric field to a longer numeric field and the fields overlap.

FWIW, In the case of overlapping fields it "might" be safer to, instead of MOVEing Var-2 to Var-1, to say COMPUTE Var-1 = Var-2. It would be interesting to see the generated code for that.
Back to top
View user's profile Send private message
anshul_gugnani

New User


Joined: 02 Nov 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Jun 02, 2010 5:43 pm    Post subject:
Reply with quote

Hello Ronald,

Thanks a lot for such detailed explaination. You are awesome. icon_smile.gif

Can you please tell how can we see the compiler generated instructions.
we use changeman tool at our shop.

Thanks.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Wed Jun 02, 2010 6:00 pm    Post subject:
Reply with quote

To generate a LISTing of the generated Assembler Code, specify the Compiler Option LIST

If you are not permitted to override the Changeman Options, then, if your shop permits it, you can specify the option INside of your source code. To wit, include the statement

CBL LIST

before the IDENTIFICATION DIVISION header.
Back to top
View user's profile Send private message
anshul_gugnani

New User


Joined: 02 Nov 2009
Posts: 73
Location: Mumbai

PostPosted: Wed Jun 02, 2010 6:54 pm    Post subject:
Reply with quote

Hello Ronald,

When I listed the compiler generated instructions at my shop for the same move statement I found this -
Code:
000026  MOVE                                                             
   000344  5830 912C               L     3,300(0,9)              BLW=0   
   000348  D201 3008 C004          MVC   8(2,3),4(12)            VAR1   
   00034E  D201 300A 3008          MVC   10(2,3),8(3)            VAR1+2 
   000354  96F0 300B               OI    11(3),X'F0'             VAR1+3 


which is diffrent from the instructions mentioned here.

Please suggest. Thanks.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Wed Jun 02, 2010 7:30 pm    Post subject:
Reply with quote

Same thing, just the Load to establish addressability to the piece of WS where the vars are.
Back to top
View user's profile Send private message
Manish Kumar Gupta

New User


Joined: 19 Feb 2008
Posts: 6
Location: Bangalore

PostPosted: Wed Jun 02, 2010 11:02 pm    Post subject:
Reply with quote

Anshul,

If you want to learn assembly language, go through the posts of the following link, you will get the books name.

http://www.ibmmainframes.com/about20894.html
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 Compiler option for override the exte... muralikrishnan_new COBOL Programming 9 Fri Jul 08, 2016 12:09 pm
No new posts Selecting a redefined record layout i... mallik4u Compuware & Other Tools 1 Wed Oct 08, 2014 8:14 am
No new posts Redefine Numeric to Alphanumeric suraaj COBOL Programming 4 Mon Oct 06, 2014 9:16 pm
No new posts Moving DBCS to alphanumeric group item saurabh39 COBOL Programming 5 Wed Apr 16, 2014 2:44 pm
No new posts OUTREC S0C7 issue for particular scen... Skolusu DFSORT/ICETOOL 6 Fri Mar 07, 2014 1:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us