View previous topic :: View next topic
|
Author |
Message |
sanjaykavita
New User
Joined: 13 Aug 2009 Posts: 6 Location: Pune
|
|
|
|
Hi,
Could you please help me with requirment where I need to move CUSTOMER-ID[PIC S9(9) USAGE COMP] value to
alphanumeric field. I tried to achieve this by moving the value between below variables where
WS-CIN-NUM PIC 9(10)
WS-CIN-CHAR PIC X(10)
move CUSTOMER-ID to WS-CIN-NUM
move WS-CIN-NUM to WS-CIN-CHAR
But while movement first digit is getting truncated. (e.g 1234569875 is becoming 0234569875).
While searching in the forum I found that it happes due to comiler option. I am compiling myprogram by moving the element into endevor. Hence not getting any option related to TRUNC. Any help will be much appreciated. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
What value do you have for compiler option TRUNC?
You show 10 digits, but your COMP field only defines nine. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Rohit,
TRUNC(OPT) should never be used when will be excess decimal digits. For 9(9) it would be a maximum, decimal, value of 999,999,999. The field must never contain a figure greater than that (similar for signed). TRUNC(OPT) will either lose or retain that value, depending on the instructions generated, nothing else. This will make it look like it "works" sometimes, and doesn't others. It works all the time, it is just that if using TRUNC(OPT) you promise never to exceed the decimal value represented by the PICture clause.
TRUNC(BIN), or, better, defining the individual field as COMP-5, will retain some 10-digit values, as it allows all bits in the four bytes of storage to be used to express a value, and truncation of that field will be binary (field-size) not decimal (PICture definition).
sanjaykavita,
If you still need assistance, you have to explain the source of that field and the maximum value it can hold. If you change the PICture to 9(10) remember that the field will double in size, which may not be what you want. |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Thanks for further infotmation Bill. |
|
Back to top |
|
|
sanjaykavita
New User
Joined: 13 Aug 2009 Posts: 6 Location: Pune
|
|
|
|
CUSTOMER-ID value I am retrieving from DB2 table and tring to move this value through my program to alphanumeric field for reporting purpose.
CUSTOMER-ID(max lenght of each customer id is 10)
COLUMN DEFINATION IN DB2 TABLE:-
NAME :-CUSTOMER_ID ,, TYPE :- INTEGER ,, LENGTH :- 4
COBOL DECLARATION FOR COLUMN:-
CUSTOMER-ID PIC S9(9) USAGE COMP.
As I am compiling myprogram by moving the element into endevor.
Hence not sure about any option related to TRUNC. Any help will be much appreciated. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Look at the output listing of the compile. The first couple of pages show the settings of all the options you've specified, or which have been set by default.
They are also available in the Compiler Information Bytes in the loadmodule (if you need to know from something you don't have the listing for, for some reason). See the Enterprise COBOL Programming Guide on how to de-code them.
Have you tried to allocate customer number 9 999 999 999 in your db?
With TRUNC(STD) or TRUNC(OPT) and COMP you have a maximum value of 999 999 999 (nine decimal digits). With TRUNC(BIN) and COMP (or with COMP-5) you have a maxium of 2 xxx xxx xxx or 4 xxx xxx xxx (depending on whether a sign is present in the definition). The xxx xxx xxx bit is (power of 2 which has 10 digits starting with 2 and 10 digits starting with 4, minus one). |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Look at the output listing of the compile. The first couple of pages show the settings of all the options you've specified, or which have been set by default.
They are also available in the Compiler Information Bytes in the loadmodule (if you need to know from something you don't have the listing for, for some reason). See the Enterprise COBOL Programming Guide on how to de-code them.
Have you tried to allocate customer number 9 999 999 999 in your db?
With TRUNC(STD) or TRUNC(OPT) and COMP you have a maximum value of 999 999 999 (nine decimal digits). With TRUNC(BIN) and COMP (or with COMP-5) you have a maxium of 2 xxx xxx xxx or 4 xxx xxx xxx (depending on whether a sign is present in the definition). The xxx xxx xxx bit is (power of 2 which has 10 digits starting with 2 and 10 digits starting with 4, minus one). |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
In order to use TRUNC(BIN) when you're compiling with endevor (and when you apparently cannot change compiler options),
insert a line before the ID DIVISION:
or
CBL or PROCESS can start from column 1 but if you have a cobol sequence in cols 1-6 then it should start from col 8. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
However: this may not work for the data (the table can't hold less than 50% of the 10-digit numbers alleged (so far) to be valid), let alone the COBOL program; this may not be possible (compiler options can be "nailed in" at installation time, preventing their being changed); this may not be a good idea (to mix different options of TRUNC in a system is asking for trouble unless perfectly managed).
For a full 10 digits. the column has to hold more digits, not just "10 sometimes". Then any intermediate files, etc.
sanjaykavita,
Can you show an example of the comparison you want to do? |
|
Back to top |
|
|
sanjaykavita
New User
Joined: 13 Aug 2009 Posts: 6 Location: Pune
|
|
|
|
Thanks Marso, Bill Woodger and Rohit. After adding CBL TRUNC(BIN) in my cobol program I am getting desired output. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
OK, but I think it is the wrong thing to do. 2147483647 is the maximum you can have. The DB2 column I believe has a maximum of 4294967295. Any customer id above 2147u483647 is going to give you an "interesting" result.
You've now changed all you COMP/COMP-4/BINARY fields in your program to COMP-5 through the use of TRUNC(BIN). This may not be what you want. You many not notice any difference. There may be a difference which you haven't yet noticed. There may be a difference that you do notice. You may not be able to get this program going "up the line". It is not common (in my experience) that Production code contains CBL/PROCESS cards, and for good reason.
If you customer id is actually less than or equal to 2147483647 you should change the definition from COMP to COMP-5 and ditch the CBL/PROCESS. If less than or equal to 4294967295 you should also remove the sign. If greater than 4294967295 you have more work to do yet.
However, you saw the answer you wanted with your intensive testing, so why should I worry? |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
The trick here is to reach retirement time before the company reaches 2147483647 customers.
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yeah, but some clever-type is using a (modulus-some-prime-number-over-a-million) checkdigit, so they've not got as much time as they think....*
* actually, that's still quite a lot of customers even after that :-) |
|
Back to top |
|
|
|