Q
Problem solve Get help with specific problems with your technologies, process and projects.

Chain operation error after converting RPG3 to ILE RPG (RPGIV)

RPGIV will 'think of' incoming integer fields as binary, and then will redefine them in the program structures as PACKED. So, when you chain a record, the incoming data has to be converted from integer (which RPGIV thinks is Binary) to packed. This generates an error message. John Blenkinsop explains how to avoid generating an error.

I recently had an old RPG3 program that I ran through IBM's cvtrpgpgm to make it an RPGLE (I added some fields to a file and the field names were longer than 6 characters). It compiled just fine but the first time it ran it gave me the error "The target for a numeric operation is too small to hold the result." The statement that it said was in error was a chain operation. Can you explain why?
RPGIV (ILE RPG) treats binary numeric fields in peculiar ways. See this discussion on the subject by Joe Pluta.

You can see from the article that RPGIV will 'think of' incoming integer fields as binary, and then will redefine...

them in the program structures as PACKED (!). This means that when you CHAIN a record, the incoming data has to be converted from Integer (which RPGIV thinks is Binary) to Packed - and RPG has not allowed enough digits to hold the data. So, it generates the error message.

The best way to get around this is to ALWAYS use an externally-described data structure to hold an incoming record:

D DataIn E DS ExtName( MyFile )

...you don't need any more than that. The record from MYFILE will automatically dump its data into the structure, and RPGIV will obey the record format definition in the EXTNAME keyword, so it will NOT start redefining fields as packed.

This was last published in May 2008

Dig Deeper on RPG iSeries programming

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close