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

COBOL Truncation in character move statement


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

New User


Joined: 04 Jan 2009
Posts: 18
Location: Germany

PostPosted: Mon Apr 27, 2009 10:41 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Apr 27, 2009 10:49 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Apr 27, 2009 10:54 am
Reply with quote

Hello,

Is the B variable contained within the data area of the A variable?
Back to top
View user's profile Send private message
CICS Guy

Senior Member


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

PostPosted: Mon Apr 27, 2009 1:43 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Apr 27, 2009 5:12 pm
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon Apr 27, 2009 5:16 pm
Reply with quote

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
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Apr 28, 2009 3:16 am
Reply with quote

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
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Apr 28, 2009 5:27 pm
Reply with quote

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
View user's profile Send private message
Raghu navaikulam

Active User


Joined: 27 Sep 2008
Posts: 193
Location: chennai

PostPosted: Fri May 01, 2009 1:49 am
Reply with quote

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

Code:
XYZ3:5551111111   

Second time
Code:
DISPLAY 'XYZ3:' XYZ3

Code:
XYZ3:5551123243


Can you please give an explanation

Regards
Raghu
Back to top
View user's profile Send private message
CICS Guy

Senior Member


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

PostPosted: Fri May 01, 2009 2:02 am
Reply with quote

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
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Fri May 01, 2009 2:14 am
Reply with quote

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
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top