I have been struggling to pass an integer value as a parameter to the RPG program when calling from IBM i green screen command line.
I have written an RPG program that accepts two input parameters of numeric 3 and numeric 4.
Now, when I call my RPG program from the command line like this CALL PGM(PGM1) PARM((1) (10))
then it’s not receiving the correct value in the input parameters of the program.
What should be the correct way to pass integer(numeric) value to numeric(integer) parameter value
to the RPG program call
from the command line
?
You can use
hexadecimal numbers
to pass anumeric(integer)
value to a parameter in theRPG program
when calling it from thecommand line
.Passing numeric value to a packed decimal numeric field in RPG:
CALL PGM(PGM1) PARM((x'0001F') (x'00010F'))
Here, the first parameter is a 3-length numeric field and passing value 1. The second parameter is a 4-length numeric field with and passing value of 10.
To pass a hexadecimal field you must start with
x
after X within quotes, there must be an even number of positions including theF
.So, passing value 1 to the numeric length 3 would be
x’001F’
whereF
denotes a positive number and it is a signed bit. And as I remember we passD
for negative numbers.However, passing value 10 to numeric length 4 is not
since inside single quotes 0010F is an odd number of digits. So the correct value would bex'0010F'
x'00010F
i.e. add an extra zero in front of the number to make it an even number of positions within single quotes including F after X.Just refer to some examples to understand it a little bit more,
CALL PGM(PGM1) PARM((5.2) (543))
CALL PGM(PGM1) PARM((x'052F') (x'543F'))
CALL PGM(PGM1) PARM((254674)
CALL PGM(PGM1) PARM((x'0254674F'))
Add an extra 0 at the start of the number after x and within quotes so that to make it an even number of digits in the hex value being passed.
Passing 4-byte integer value to integer (10I) field field in RPG:
If you try to pass 1 and 10 respectively
CALL PGM(PGM1) PARM((x'00000001') (x'0000000A'))
Just refer to some other examples to understand it a little more:
Passing value for 3I and 5I and 10I and 20I parameters in RPG
CALL PGM(PGM1) PARM((X'0A') (X'000A') (X'0000000A') (X'000000000000000A'))
CALL PGM(PGM1) PARM((X'01') (X'0001') (X'00000001') (X'0000000000000001'))
CALL PGM(PGM1) PARM((X'12') (X'0012') (X'00000012') (X'0000000000000012'))
You can check convert decimal to hex value here.
Sample program
This is the sample program that you can create at your end and test the above calls for passing Integer values in 3I, 5I, 10I, and 20I parameters in the RPG program: