Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
MOVing alphanumeric data to a table col declared as smallint

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

Senior Member


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

PostPosted: Fri Jun 06, 2008 4:05 am    Post subject: MOVing alphanumeric data to a table col declared as smallint
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Fri Jun 06, 2008 4:55 am    Post subject: Re: MOVing alphanumeric data to a table col declared as smal
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

Site Director


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

PostPosted: Fri Jun 06, 2008 5:03 am    Post subject:
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: 1288
Location: Chennai, India

PostPosted: Sat Jun 07, 2008 8:31 pm    Post subject: Reply to: MOVing alphanumeric data to a table col declared a
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    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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Copy 4 byte of data from the last rec... arunsoods DFSORT/ICETOOL 9 Fri Oct 06, 2017 12:15 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts opening a dataset after reading it fr... arunsoods DFSORT/ICETOOL 5 Wed Oct 04, 2017 3:54 pm
This topic is locked: you cannot edit posts or make replies. PS file data should be passed as symb... d_sarlie JCL & VSAM 15 Tue Oct 03, 2017 5:18 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us