IBM Support

Example of an ILE RPG Program Using EXTBININT (*YES) on the H Spec

Technote (troubleshooting)


Problem(Abstract)

This document describes how RPG and SQL define a 2-byte binary.

Resolving the problem

The issue here is a mismatch on how RPG and SQL see 2-byte binary. In SQL, the field designated smallint can hold -32767 to +32767. If this field is brought into an RPG program, it is only able to hold 9999 because it is packed data. The following example illustrate this:

You will need to create a table in interactive SQL (STRSQL):

CREATE TABLE JENH/CDIMASTER (CDISUBACCT SMALLINT NOT NULL WITH DEFAULT)

Here is the RPG ILE source:

fCDIMASTER If a e             disk    prefix(f2)            
f                                     rename( CDIMASTER:r1)  
 
/Free                                                      
   Read cdimaster;                                          
 
   f2cdisubacct = 9999;                                    
 
   f2cdisubacct += 1;                                      
   write(e) r1     ;                                        
 
   *Inlr = *on ;                                            
 
/End-Free                                                  


To compile, issue the CRTBNDRPG command on the program or 14 in PDM.

Note: The field CDISUBACCT is defined as a 4-byte binary (BINARY 4 0) in the ILE RPG compile listing. When this code is run, it fails with message MCH1210 - The target for a numeric operation is too small to hold the result.

To circumvent this issue of message MCH1210, use the keyword EXTBININT (*YES) in the H-Specs:

Here is the source code with the EXTBININT.

hEXTBININT (*YES)                                              
fCDIMASTER If a e             disk    prefix(f2)              
f                                     rename( CDIMASTER:r1)    
 /Free                                                        
    Read cdimaster;                                            
    f2cdisubacct = 9999;                                      
    f2cdisubacct += 1;                                        
    write(e) r1     ;                                          
    *Inlr = *on ;                                              
 /End-Free                                                    

Information on the EXTBININT keyword follows:

The EXTBININT keyword is used to process externally-described fields with binary external format and zero decimal positions as if they had an external integer format. If not specified or specified with *NO, an externally-described binary field is processed with an external binary format. If EXTBININT is specified, optionally with *YES, an externally-described field is processed as follows:

DDS Definition RPG External Format
B(n,0) where 1 ≤ n ≤ 4 I(5)
B(n,0) where 5 ≤ n ≤ 9 I(10)

By specifying the EXTBININT keyword, your program can make use of the full range of DDS binary values available. (The range of DDS binary values is the same as for signed integers: -32768 to 32767 for a 5-digit field or -2147483648 to 2147483647 for a 10-digit field.) Note: When the keyword EXTBININT is specified, any externally-described subfields that are binary with zero decimal positions will be defined with an internal integer format.

This will allow the program to process the amount of data that may be required by the SQL table.


Cross reference information
Segment Product Component Platform Version Edition
Operating System IBM i 7.1
Operating System IBM i 6.1

Historical Number

515985466

Document information

More support for: IBM i
Programming (Languages- compilers- tools)

Software version: 5.4.0, 5.4.5, 6.1.0, 7.1.0

Operating system(s): IBM i

Reference #: N1013146

Modified date: 23 April 2012


Translate this page: