Midrange News for the IBM i Community


Posted by: Bob Cozzi
Rogue Programmer
Cozzi Productions, Inc.
Chicagoland
Passing Parameters to RPG from Command Entry
has no ratings.
Published: 13 Apr 2016
Revised: 13 Apr 2016 - 2934 days ago
Last viewed on: 25 Apr 2024 (6445 views) 

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.

Passing Parameters to RPG from Command Entry Published by: Bob Cozzi on 13 Apr 2016 view comments

Passing Parameters

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:

Receiving numeric into a Packed(7,0) variable in RPG IV:

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:

  1. Change the definition of the input parameter to 15p5.
  2. Pass the data in hexadecimal notation. e.g., X'0012345F'
  3. Change the definition of the input parameter to Zoned decimal and pass the value surrounded by quotation marks (i.e., as character text).
  4. Create a custom command definition for the program--defining each parameter accurately.

Once you do any of the above, accurately passing numeric values to your programs is accomplished.

 

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS