Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.
People are often confused when passing parameters to an RPG program from Command Entry. Programmers assume that if they declare a parameter as 7p0 and then call the program as follows:
==> call myPgm parm(12345)
The believe the value 12345 is somehow converted to 7p0 format. It is not
The system has to make an assumption about the size of numeric and character values passed as parameters to programs, when programs are called from Command Entry (same is true for submitted jobs that call a program). The following are system defaults:
Data Type | Default Size |
---|---|
Numeric | 15p5 |
Character | 32A |
When the numeric value 12345 is passed as a parameter, the system packs it into a 15p5 work field. That work field is then passed to the program as read-only. It looks like this:
Position: 0 1 1234567890 Packed 00024000 Value 0013500F
When the data is received by the called program it will be in the above form. But the program in our example is expecting a value in 7p0 format. This means the first 4 characters are accessible through the input parameter's variable. Giving the program access to the following data:
Position: 0 1 1234567890 Packed 0002xxxx Value 0013xxxx
If the program receives this information, it will the first 4 bytes only, which contains the packed value X'00000123' and interpret it as the value 12--discarding the number 3 because the sign of the value is normally stored there.
To make this work, you have to do one of the following:
Once you do any of the above, accurately passing numeric values to your programs is accomplished.