fhg
Volume 6, Number 35 -- September 27, 2006

Stuffing Five Digits Into Four

Published: September 27, 2006

by Ted Holt

How do you stuff five digits into a four-digit database field? I found out recently that it can be done. Suppose you have a database file with a four-digit binary field.

A          R REC                
A            FIELD4         4B  

If you use the Display File Field Description (DSPFFD) command to view the record layout of the file, you will find that FIELD4 occupies two bytes of storage. Two bytes can hold values from -32,768 to 32,767. (For more about why this is so, see When a 10-Digit Variable Won't Hold a 10-Digit Number.

If you use traditional I/O to try to put a value such as 32,767 into FIELD4, you will be treated to a series of rude messages. Here's a short RPG program.

FSomeFile  o    e             disk               
D value           s              5i 0 inz(32767)
D                                                
 /free                                           
      *inlr = *on;                               
      FIELD4  = value;                           
      write rec;                                 
      return;

(No, you don't have to code the /end-free directive.)

And here are the rude messages you will get when you run the program.


MCH1210 (Receiver value too small to hold result.)
RNQ0103 (The target for a numeric operation is too small to hold the result (C G D F).)


So, how do you load five digits into FIELD4? Use SQL! Here's the same RPG program rewritten with SQL.

D value           s              5i 0 inz(32767) 
D                                                 
C                   eval      *inlr = *on         
C/exec sql                                        
C+  insert into SomeFile (field4)                 
C+     values(:value)                           
C/end-exec                                        
C                   return

SQL inserts the value 32,767 without complaint.

You'll also run into the same behavior when retrieving data from the file. Traditional I/O chokes, but SQL doesn't care.

What interesting times we live in.


RELATED STORY

When a 10-Digit Variable Won't Hold a 10-Digit Number



Sponsored By
WORKSRIGHT SOFTWARE

Do you need area code information?
Do you need ZIP Code information?
Do you need ZIP+4 information?
Do you need city name information?
Do you need county information?
Do you need a nearest dealer locator system?

We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

Just call us and we'll arrange for 30 days FREE use of either
ZIP/CITY or PER/ZIP4.

WorksRight Software, Inc.
Phone: 601-856-8337
Fax: 601-856-9432
E-mail: software@worksright.com
Web site: www.worksright.com



Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

nuBridges:  Leading provider of secure FTP on the iSeries
New Generation Software:  Leading provider of iSeries BI and financial management software
COMMON:  Join us at the Spring 2007 conference, April 29 – May 3, in Anaheim, California

 


 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement