Should I pass packed numeric fields when calling RPGLE from CLLE? Or convert them to character pass them and convert them back to numeric in the RPG. If the former is recommended, how is this done?
You can pass packed numeric from CLLE to RPGLE without issue.
The issue is that when calling any program from the command line or submitting a program to run in batch via SBMJOB cmd(CALL MYPGM)
, The IBM i command processor will pass numeric literals as packed(15,5).
call mypgm parm(10 15)
will require that both parameters be defined as packed(15,5). It doesn't matter if MYPGM was written in CL, CLLE, RPG, RPLE, or COBOL..
A related issue is that character literals are passed as char(32) unless the literal value is longer than 32, then it's passed as a character variable of the given size.
The reason for this is that parameters are passed by reference to/from programs. Meaning the caller sets aside storage for the data, and the address of that storage is what's actually passed; not the actual value. So the command processor creates the storage needed and initializes it the given values. Since the command processor has no way of knowing the size of the parameters defined in the program, it uses the defined defaults and it's up to the writer of the called program to conform to the rules.
This leads to all sorts of silly work-a-rounds
call mypgm parm('0010' x'000F' 'AB x')
the above
However the best solution, is to simply create a command front end for any program you want to call from the command line or via SBMJOB CMD()
. With a command defined, the command processor will know exactly what the types and sizes of the program's parameters are.
mycmd parm1(10) parm2(15) parm3('AB')
More information in the Midrange.com wiki