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

Moving character data to smallint in db2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rikdeb

New User


Joined: 19 Jan 2009
Posts: 63
Location: hyderabad

PostPosted: Thu Jul 14, 2016 12:38 am
Reply with quote

Hi All,
Came across a piece of code in one program, where the program is taking user input from online screen and inserting the same in db2 table.
Now,the input field corresponding to the online map is defined as alphanumeric in cobol; say
Code:
IPFLD-FID pic x(03).

The corresponding column in db2, where this value will be inserted is defined as SMALLINT.
When numeric input is keyed thru online, the insertion is good as expected; but if character input is given(for testing purpose,which ideally should not be the case), i am seeing the value is getting changed to numeric and getting inserted. Ex: abc is getting converted to 123 and getting inserted.
Could you throw some light on this.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Jul 14, 2016 2:01 am
Reply with quote

Likely DB2 is stripping off the zones and interpreting the result as binary coded decimal. Do you really mean "abc", or did you mean "ABC"?
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu Jul 14, 2016 3:21 am
Reply with quote

Its because of the collating sequence that has the values 0 through 9 .
Quote:
but if character input is given(for testing purpose, which ideally should not be the case), i am seeing the value is getting changed to numeric and getting inserted. Ex: abc is getting converted to 123 and getting inserted.
Raise a defect and ask to validate before inserting.
Back to top
View user's profile Send private message
rikdeb

New User


Joined: 19 Jan 2009
Posts: 63
Location: hyderabad

PostPosted: Thu Jul 14, 2016 11:35 pm
Reply with quote

Hi Rohit and Akatsukami,
Thanks for your help.Today i tried with both ábc' and 'ABC' .Both the cases it took the value 123. I was trying with random characters like xyz, and it took 789. I think as rohit said ,it is for the collating sequence 0 thru 9.
However i want to know more, how this actually works.I am looking for it in google, but if you have any more information, please pass on the same.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Fri Jul 15, 2016 12:05 am
Reply with quote

You of course know that the characters (as well as everything else) are represented in memory and on mass storage as binary patterns. If you were to edit a data set using the ISPF editor, and set HEX ON, you might see something like this:
Code:

123 abc ABC xyz
---------------
FFF48884CCC4AAA
123012301230789

(Note that space is a character, and occupies one byte.)
The first line is glyphs (displayed or printed characters), one per byte. The third line is the high nybble of each byte, and the fourth is the low nybble.

The high nybble is called, for historical reasons, a "zone"; the three leftmost bytes is the example are "zoned decimal" (COBOL DISPLAY, PL/I CHAR or PIC). When converting to binary (COBOL COMP-5, PL/I FIXED BIN}, the code doing the conversion ignores the zones and interprets the low nybbles as decimal digits.

Knowing this (and EBCDIC mapping of glyphs to binary patterns), you can see why, if each of those three-character fields is moved to a binary field,
the value of the field will be 123, 123, 123, and 789, respectively.
Back to top
View user's profile Send private message
rikdeb

New User


Joined: 19 Jan 2009
Posts: 63
Location: hyderabad

PostPosted: Fri Jul 15, 2016 12:21 am
Reply with quote

Thanks a lot Akatsukami !. Indeed a vry nice & useful explanation.
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 -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
Search our Forums:

Back to Top