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
 

 

COBOL Truncation in character move statement

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: COBOL Truncation in character move statement
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

Site Director


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

PostPosted: Mon Apr 27, 2009 10:49 am    Post subject:
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

Site Director


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

PostPosted: Mon Apr 27, 2009 10:54 am    Post subject:
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: 2150
Location: At my coffee table

PostPosted: Mon Apr 27, 2009 1:43 pm    Post subject: Re: COBOL Truncation in character move statement
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: 6967
Location: porcelain throne

PostPosted: Mon Apr 27, 2009 5:12 pm    Post subject:
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: 8057
Location: East Dubuque, Illinois, USA

PostPosted: Mon Apr 27, 2009 5:16 pm    Post subject:
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    Post subject: Reply to: COBOL Truncation in character move statement
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    Post subject: Reply to: COBOL Truncation in character move statement
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: 186
Location: chennai

PostPosted: Fri May 01, 2009 1:49 am    Post subject: Reply to: COBOL Truncation in character move statement
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: 2150
Location: At my coffee table

PostPosted: Fri May 01, 2009 2:02 am    Post subject:
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    Post subject: Reply to: COBOL Truncation in character move statement
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    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
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts COBOL Code Parsers and Lineage Establ... balimanja COBOL Programming 2 Tue May 02, 2017 3:30 am
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts COBOL Programming Sandpit? jodrisco COBOL Programming 6 Wed Apr 12, 2017 3:47 am


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