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
 

 

Data is getting truncated while moving 9(10) to S(9) COMP

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

New User


Joined: 25 Feb 2008
Posts: 4
Location: chennai

PostPosted: Tue Oct 30, 2012 1:57 pm    Post subject: Data is getting truncated while moving 9(10) to S(9) COMP
Reply with quote

Hi All,

Could any one please help me resolve the below query.

I am trying to Move 9(10) to S9(9) COMP. But value is getting truncated.

Code is as below -

MOVE 1234567890 TO WS-VAR2
MOVE WS-VAR2 TO WS-VAR3
DISPLAY 'VAR2 = 'WS-VAR2
DISPLAY 'VAR3 = 'WS-VAR3

Where the variables are declared as -

01 WS-VAR2 PIC 9(10) .
01 WS-VAR3 PIC S9(9) COMP.

The output is coming as -

VAR2 = 1234567890
VAR3 = 234567890

Thanks In Advance!!
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Oct 30, 2012 2:01 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

If you move something with 10 digits into something with 9 digits, wouldn't you expect some truncation?
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Tue Oct 30, 2012 2:02 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

why not look at the manuals to understand
the different PIC clauses
how they relate to the number of significant digits that can be represented
how truncation occurs

manuals links at the top of the page
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Tue Oct 30, 2012 2:05 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

Quote:
If you move something with 10 digits into something with 9 digits, wouldn't you expect some truncation?


naahhh icon_biggrin.gif

the TS probably feels that COBOL belongs to the language category DWIM instead of the DWIW

DWIM : Do What I Mean
DWIW : Do What I Write
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Tue Oct 30, 2012 2:27 pm    Post subject:
Reply with quote

Since WS-VAR3 is COMP, this is one of those not-so-rare cases where the compiler options can affect the results. With TRUNC(STD), the results are as expected (and observed) -- COBOL ensures the value in WS-VAR3 matches the PICTURE size. If you recompile with TRUNC(BIN), COBOL will use the storage area maximum instead of the PICTURE size, and that would allow the value to be stored without truncation.

However, note that it is NEVER a good idea to cause truncation (whether actual or potential) without understanding the potential impact.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Oct 30, 2012 2:41 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

If you go the TRUNC(BIN) route, or have a USAGE of COMP-5, be aware that you will still not be able to store "any" 10-digit value - try something this, for instance, 3000000000.

Also be aware that TRUNC(BIN) and COMP-5 cause more compiler code to be generated.

If you can come up with the slightest hint of what you are trying to actually do, there might be some suggestions. The more you tell, the better the suggestions.
Back to top
View user's profile Send private message
skarthik

New User


Joined: 25 Feb 2008
Posts: 4
Location: chennai

PostPosted: Tue Oct 30, 2012 3:00 pm    Post subject:
Reply with quote

Sorry for the confusion guys. The requirment is -

I need to fetch customer details from DB2-Table based on Customer_id. This Customer _id field is INTEGER in the table, which is found as S9(9) COMP in DCLGEN. The Value of this CUSTOMER-ID coming from the file is X(10), which will be used to fetch the data. The code is -

01 WS-INFLE-CUST-ID PIC X(10)

MOVE WS-INFLE-CUST-ID TO CUSTOMER-IDENT

SELECT *
FROM CUSTOMER_DETAILS A
WHERE
A.CUSTOMER_IDENT = :CUSTOMER-IDENT

Now could you please let me know if there is any way to execute this query without data truncation.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Oct 30, 2012 3:18 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

What does your DB2 documentation say about the maximum value of INTEGER?

What is the maximum value that actually exists now for the Customer ID? For instance, if there is always at least one leading zero, you have no problem currently.

If the Customer ID can extend beyond the maximum value for INTEGER then you have a problem, as the ensuing truncation may cause data for one Customer ID to be assigned to another, or you may create data which cannot be retrieved.

Without knowing the actual data which is possible, no-one can GUARANTEE that this will work, nor that it will always work. If you have Customer ID starting with 3 or higher, then it will not work. The magic value at which it will theoretically stop working is your DB2 limit for INTEGER. It will stop working earlier depending on how you define CUSTOMER-IDENT (COMP-5 or not) or the compiler option previously mentioned by Robert.

In general, you have a potential mess, depending on actual existing/projected values for Customer ID.
Back to top
View user's profile Send private message
skarthik

New User


Joined: 25 Feb 2008
Posts: 4
Location: chennai

PostPosted: Tue Oct 30, 2012 3:59 pm    Post subject:
Reply with quote

Hi Bill,

The customer_id has 10 digits in file and as well as in Table. some of the examples are below-

1130516048
1130516156
1130516219

For the above customers, I need to query the table to get the details. This customers are found in table also.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Oct 30, 2012 4:08 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

OK, try defining CUSTOMER-IDENT with COMP-5 instead of COMP.

I'd not move an X field to a numeric, I'd redefine it as 9(10). Not part of your problem, just "good practice" to me :-)

Note that this will not work "forever" and raise appropriate documentation.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Nov 02, 2012 9:37 am    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

Hi Sarthik,

Look at JPVRoff's thread below in this forum. It might help.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Nov 02, 2012 10:12 am    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

After redefining the sending-field as unsigned display-numeric and recompiling the program using TRUNC(BIN) or defining the receiving-field as COMP-5, change the picture of the receiving binary-fullword field to unsigned. It makes no sense to make it signed as the sending-field isn't.

This will increase the maximum value for the receiving-field from decimal 2147483647 (X'7FFFFFFF') to 4294967295 (X'FFFFFFFF'), which will give you more wiggle room.

Keep in mind that if you use a signed-fullword to view this data (such as in FileAid) and the value exceeds 2147483647, then it will be considered negative. If you use the unsigned approach, someone may raise the issue that this value is negative. With that, thorough documentation must be considered and the users must be made aware.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Nov 02, 2012 9:33 pm    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

If you are unlucky, you get this scenario: your company takes over another company; they have a computer system, and their data is going to be subsumed into yours; they only have a nine-digit account number; someone comes up with the idea of "our numbers are 10 digits, but we'll never get towards the maximum, so we'll add the new data by prefixing their account number with an '8', that'll keep the systems guys happy as they won't have to do much".

Then someone from systems says, "yes, that should be OK" because they don't know that somewhere along the way someone thought that saving six-bytes per entry would be a "good thing".

I'd not suggest TRUNC(BIN), as that will affect any other COMP fields in your program, and some of the stuff generated for TRUNC(BIN) and COMP-5 is very ugly, so I like to keep it down to the minimum. Then you have other programs which may use COMP data from your program, and they'd have to be recompiled as well or risk pickling something.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Fri Nov 16, 2012 3:20 am    Post subject: Reply to: Data is getting truncated while moving 9(10) to S(
Reply with quote

Just thought I'd try this. This is the sort of code you'll get generated each time you MOVE X(10) or 9(10) to a COMP-5 field:


Code:
F299 D2E0 80A8          PACK  736(10,13),168(10,8)    TS2=0        W-X-10       
D202 D2F0 C026          MVC   752(3,13),38(12)        TS2=16       SYSLIT AT +38
D204 D2F3 D2E5          MVC   755(5,13),741(13)       TS2=19       TS2=5
4F30 D2F0               CVB   3,752(0,13)             TS2=16       
F144 D2F3 D2E0          MVO   755(5,13),736(5,13)     TS2=19       TS2=0
4F50 D2F0               CVB   5,752(0,13)             TS2=16       
5C40 C000               M     4,0(0,12)               SYSLIT AT +0
1E53                    ALR   5,3                                 
47C0 B7B0               BC    12,1968(0,11)           GN=60(0009A4)
5A40 C004               A     4,4(0,12)               SYSLIT AT +4
               GN=60    EQU   *                                   
1233                    LTR   3,3                                 
47B0 B7BA               BC    11,1978(0,11)           GN=61(0009AE)
5B40 C004               S     4,4(0,12)               SYSLIT AT +4
               GN=61    EQU   *                                   
9045 8060               STM   4,5,96(8)               W-C-PIC-9-10


And this if you move X(10) to X(10).

Code:
D209 80B8 80A8          MVC   184(10,8),168(8)        W-X-10-1     W-X-10
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 Is the 'prompt' data for the DSLIST p... Willy Jensen TSO/ISPF 2 Tue Dec 06, 2016 4:38 am
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm


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