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

MOVing alphanumeric data to a table col declared as smallint


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Fri Jun 06, 2008 4:05 am
Reply with quote

Hi,

A field is declared as smallint in a table and the DCLGEN variable is S9(4) COMP.

In our cobol code we had wrongly moved an alphanumeric value (X(8)) to this dclgen variable. The move was successful and finally the value got inserted in the table.

when i checked the table it had some numeric value populated in that column. i really dont know whether to call that as junk or random no.

when EBNKG was moved to that destination field, the table got updated with 32767.

There should be some rules for these type of move's and please help me in understanding this.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Fri Jun 06, 2008 4:55 am
Reply with quote

When a field is defined as S9(4) COMP (which in Mainframe terminology is a signed binary-halfword), the maximum positive value it can retain is +32767 (X'7FFF'), whereas, the maximum negative value it can retain is -32768 (X'8000'). Keep in mind that the ever popular TRUNC compile option is also a factor, unless your compiler supports COMP-5 (known as Native Binary).

When a field is defined as 9(4) COMP, which is an unsigned binary-halfword, the maximum value it can retain is 65535 (X'FFFF').

If you attempt to check whether a binary-field is NUMERIC, you'll get a compile error, because (in this example) an unsigned halfword can retain a value of X'0000' through X'FFFF' and therefore, a NUMERIC check would be illogical.

A halfword is two-bytes and a fullword is four-bytes.

But, you can't move a PIC X value to a binary halfword or fullword, unless you redefine them as PIC X(02) or PIC X(04), respectively.

I'm still scratching my head wondering how (after moving EBNKG to it), the halfword resulted in +32767.

This requires more explanation....

Bill
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jun 06, 2008 5:03 am
Reply with quote

Hello Aaru,

Well, 32767 is the highest positive value that can be stored in a 2-byte comp field (x'7FFF'). If you were to "dump" that column, i suspect you would find that hex value.

In a comp field, every value is "some number". There can be nothing else as every hex value equates to some number in binary.

Your code fell into one of the compiler "black hole"s. It saw the move and said to itself "Self, i can do that". And so it did - as well as it could.

You may want to look at this topic from a while back (you even participated).
http://ibmmainframes.com/viewtopic.php?t=25463&highlight=valid+cobol+move
Near the bottom of the topic is the matrix of moves the compiler believes to be valid. That they are "valid" does not mean that the result will be what one expects.

To learn more particulars, i'd suggest you create some test output by trying combinations of field definitions and values. If you write this into a little file, you can view the results in hex and see what happens for the various moves tested.

What i've done for a long time is to go "overboard" validating that i will not move a field defined as pic x to a numeric field. If i need to get a picx value to numeric, i write code to specifically validate/reformat the content then to do the move.
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Sat Jun 07, 2008 8:31 pm
Reply with quote

Thanks Dick and Bill :D
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top