View previous topic :: View next topic
|
Author |
Message |
Haresh
New User
Joined: 04 Jan 2009 Posts: 18 Location: Germany
|
|
|
|
I knew that when a bigger size character is moved to a smaller one, truncation happens, but whether the same applies to the following condition.
A PIC X(35)
B PIC X(27)
Type 1: MOVE A TO B (1:35)
Type 2: MOVE A TO B (37:35)
where variable 'A ' is having a text of 35 bytes length.
The reason its confusing is that we are refering to a memory that doesnt exists, but still its working and i am not getting any errors.
In first type a normal truncation occurs & in second case noting is moved at all.
Could anyone please explain me this behaviour. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You need to post the appropriate actual code for those variables and the output from the compiler for the 2 moves. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Is the B variable contained within the data area of the A variable? |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Haresh wrote: |
but still its working and i am not getting any errors.
In first type a normal truncation occurs & in second case noting is moved at all. |
Well, without more info, you got me......
Code: |
___ Format: reference modification _______________________________________________________________
| |
| >>__ _data-name-1_________________________________________ ____________________________________> |
| |
| >__(__leftmost-character-position__:__ ________ __)___________________________________________>< |
| |_length_| |
| |
|__________________________________________________________________________________________________|
leftmost-character-position
Must be an arithmetic expression. The evaluation of leftmost-character-position must result in a positive nonzero integer that is less than or equal to the number of characters in the data item referenced by data-name-1.
length
The sum of leftmost-character-position and length minus the value 1 must be less than or equal to the number of character positions in data-name-1. If length is omitted, the length used will be equal to the number of character positions in data-name-1 plus 1, minus leftmost-character-position. |
|
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Such BS.
this should not have compiled:
MOVE A TO B (37:35)
37 is greater than the length of B
If there are no compiler errors, then someone has wisely decided to
use a compiler option that allows you to do anything. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
When I try this, I'm getting compile errors just as CICS Guy thought:
Code: |
WORKING-STORAGE SECTION.
01 WS-VARIABLES.
05 A PIC X(35) VALUE
'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'.
05 B PIC X(27).
IBM Enterprise COBOL for z/OS 3.4.1 MF0072 Date 04/27/2009 Ti
SL ----+-*A-1-B--+----2----+----3----+----4----+----5----+----6----+----7-|--+
/
PROCEDURE DIVISION.
S1000-MAIN SECTION.
MOVE A TO B (1 : 35) .
IGYPG3192-E A reference-modification length value caused reference to be made be
the rightmost character of "B". A reference extending to the end of
was assumed.
DISPLAY 'A= ' A.
DISPLAY 'B= ' B.
MOVE A TO B (37 : 35) .
IGYPG3191-E A reference-modifier start value exceeded the number of characters i
"B". A value equal to the number of characters in "B" was assumed.
IGYPG3192-E A reference-modification length value caused reference to be made be
the rightmost character of "B". A reference extending to the end of
was assumed.
DISPLAY 'A= ' A.
DISPLAY 'B= ' B. |
Perhaps if you post the exact code you're using (not the paraphrase you gave us), we can see why the difference. |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Haresh,
Are the values defined as variable fields:
Code: |
WORKING STORAGE.
01 XYZ1 PIC X(35) VALUE '1232439128430483555555555555555555'.
01 XYZ2 PIC X(27) VALUE SPACES.
01 T1 PIC 9(02) VALUE ZEROES.
01 T2 PIC 9(02) VALUE ZEROES.
PROCEDURE DIVISION.
MOVE 35 TO T1
MOVE 27 TO T2
MOVE XYZ1 TO XYZ2(1:T1)
DISPLAY 'XYZ2' XYZ2 |
The above code works without any compilation errors.
On the same time if the following code is executed
Code: |
MOVE XYZ1 TO XYZ2(1:35) |
The error is thrown as expected
Code: |
A REFERENCE-MODIFICATION LENGTH VALUE CAUSED REFERENCE TO BE MADE BEYOND
THE RIGHTMOST CHARACTER OF "XYZ2". A REFERENCE EXTENDING TO THE END OF
"XYZ2" WAS ASSUMED.
|
WTH |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Haresh,
the following code will help you to understand how Reference modification works and how the values get overridden.
Code: |
WORKING STORAGE.
01 X02 PIC X(7) VALUE '0001200'.
01 XYZ1 PIC X(35) VALUE '12324391284304835555555555555555555'.
01 XYZ2 PIC X(27) VALUE SPACES.
01 XYZ3 PIC X(10) VALUE '1111111111'.
01 T1 PIC 9(02) VALUE ZEROES.
01 T2 PIC 9(02) VALUE ZEROES.
01 T3 PIC 9(02) VALUE ZEROES.
PROCEDURE DIVISION.
MOVE 35 TO T1
MOVE 27 TO T2
MOVE 37 TO T3
MOVE XYZ1 TO XYZ2(1:T1)
DISPLAY 'XYZ2:' XYZ2
DISPLAY 'XYZ3:' XYZ3
MOVE SPACES TO XYZ2
MOVE XYZ1 TO XYZ2(T3:T1)
DISPLAY 'XYZ2:' XYZ2
DISPLAY 'XYZ3:' XYZ3 |
SYSOUT
Code: |
XYZ2:123243912843048355555555555
XYZ3:5551111111
XYZ2:
XYZ3:5551123243 |
WTH |
|
Back to top |
|
|
Raghu navaikulam
Active User
Joined: 27 Sep 2008 Posts: 193 Location: chennai
|
|
|
|
Hi Succor
Quote: |
Haresh,
the following code will help you to understand how Reference modification works and how the values get overridden |
I have a doubt. Without any manipulation of the data in the variable XYZ3,
how the value is changing?
Quote: |
01 XYZ3 PIC X(10) VALUE '1111111111' |
First time
Code: |
DISPLAY 'XYZ3:' XYZ3 |
Second time
Code: |
DISPLAY 'XYZ3:' XYZ3 |
Can you please give an explanation
Regards
Raghu |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
Reference modification with variables (T3:T1) instead of numbers (37:35) can alter storage beyond the the actual data area.
Attempting with numbers generates a compile error but the compiler passes the variables because it doesn't know what the values will be at runtime. |
|
Back to top |
|
|
Succor
New User
Joined: 20 Feb 2009 Posts: 96 Location: Bangalore :)
|
|
|
|
Thanks CICS Guy,I was in between of writing an extended reply....and you saved me of that pain.
Quote: |
Raghu :I have a doubt. Without any manipulation of the data in the variable XYZ3, how the value is changing? |
The best way to get an answer to your doubts is to try for a solution.You would have noticed the same output if you would have tried running the code and that to
Quote: |
Without any manipulation |
.
The purpose of keeping XYZ3 in the code was to demonstrate what CICS Guy just mentioned.
WTH |
|
Back to top |
|
|
|