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

Data movement to alphanumeric field


IBM Mainframe Forums -> ABENDS & Debugging
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sanjaykavita

New User


Joined: 13 Aug 2009
Posts: 6
Location: Pune

PostPosted: Thu Aug 14, 2014 4:37 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 14, 2014 4:50 pm
Reply with quote

What value do you have for compiler option TRUNC?

You show 10 digits, but your COMP field only defines nine.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Thu Aug 14, 2014 8:37 pm
Reply with quote

Try with
Code:
TRUNC(OPT)
As well as review this,
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3pg20/2.4?

Also, As Bill noticed, the problem is with
Code:
PIC S9(9) USAGE COMP
You need to expand this to store 10 digits.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Aug 14, 2014 9:14 pm
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3076
Location: NYC,USA

PostPosted: Fri Aug 15, 2014 8:55 pm
Reply with quote

Thanks for further infotmation Bill.
Back to top
View user's profile Send private message
sanjaykavita

New User


Joined: 13 Aug 2009
Posts: 6
Location: Pune

PostPosted: Mon Aug 18, 2014 7:05 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 18, 2014 7:19 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 18, 2014 7:22 pm
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Aug 18, 2014 8:07 pm
Reply with quote

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:
Code:
CBL TRUNC(BIN)
or
Code:
PROCESS TRUNC(BIN)

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 18, 2014 8:19 pm
Reply with quote

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

New User


Joined: 13 Aug 2009
Posts: 6
Location: Pune

PostPosted: Mon Aug 18, 2014 9:00 pm
Reply with quote

Thanks Marso, Bill Woodger and Rohit. After adding CBL TRUNC(BIN) in my cobol program I am getting desired output.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Aug 18, 2014 9:36 pm
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Aug 19, 2014 6:16 pm
Reply with quote

The trick here is to reach retirement time before the company reaches 2147483647 customers.
icon_biggrin.gif
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 19, 2014 6:26 pm
Reply with quote

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
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 -> ABENDS & Debugging

 


Similar Topics
Topic Forum Replies
No new posts Help required to reset decimal points... DFSORT/ICETOOL 9
No new posts db2 vs static data COBOL Programming 1
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts External data queue (changes?) CLIST & REXX 0
No new posts Pull data using date difference betwe... DB2 6
Search our Forums:

Back to Top