HP 3000 Manuals

Intrinsic Calling [ HP RPG/XL Technical Addendum ] MPE/iX 5.0 Documentation


HP RPG/XL Technical Addendum

Intrinsic Calling 

There are system procedures called intrinsics on MPE. You used to have to
use subroutines to access these intrinsics, but now you can use INTR and
IPARM together to access (call) these intrinsics directly from RPG.


CAUTION We recommend that you exercise extreme caution in using the methods described in this update to call I/O intrinsics. Mixing RPG cycle or Calculation Specification I/O with user-driven calls to I/O intrinsics may lead to data corruption. RPG keeps internal flags that reflect the current I/O status of all the files it processes. In some cases, it adjusts record pointers in order to properly serve as an interface to other subsystems. A detailed knowledge of both the RPG cycle and the file system are required to mix calls to I/O intrinsics with RPG cycle and Calculation Specification I/O.
INTR INTR is a new Calculation Specification operator that is followed by an intrinsic name in Factor 2 through the Result Field (columns 33 - 48). If the intrinsic is a function, you can specify a field in Factor 1 to hold the value returned by the intrinsic. If that field has not been defined elsewhere in the program, you can define it using columns 49 - 52. If the value returned by a function intrinsic is numeric type (INTEGER, etc.) you can specify an alphanumeric field in Factor 1. In this case, the data returned is called Alpha-Binary data. See the discussion of Alpha-Binary data below. Condition codes are returned in Resulting Indicators that are set according to >, <, and = values. Location. This feature can be placed anywhere in the Calculation Specifications, but do not spread an INTR IPARM block across Detail and Total Calculation Specifications. That is, an INTR IPARM block must be entirely in the Detail Calculation Specifications or the Total Calculation Specifications. IPARM IPARM is a new Calculation Specification operator that allows the program to pass parameters to an intrinsic being called by the INTR operator. RPG uses the Intrinsic Mechanism to determine the right parameter type and call-by method to use. This is particularly significant for numeric fields. Since RPG internally stores all numeric fields in packed decimal format, RPG does the necessary conversion for you before the call, and if passed by reference, after the call. Refer to the MPE XL Intrinsics Reference Manual for more information about intrinsics. If a parameter is numeric type (INTEGER, etc.) you can specify an alphanumeric field in the Result field. In this case, the data returned is called Alpha-Binary data. See the discussion of Alpha-Binary data below. Default. If a particular parameter in the parameter list can be defaulted, you can skip that parameter by leaving the Result Field blank for that IPARM operation. RPG will get the default value from the Intrinsic Mechanism and supply it for you. If this is an extensible intrinsic (not all parameters are required), you can specify only the required parameters, leaving off a number of default parameters from the end of the list. RPG will correctly communicate this default information to the intrinsic. Location. This feature can be placed anywhere in the Calculation Specifications, but do not spread INTR IPARM blocks across Detail and Total Calculation Specifications. That is, an INTR IPARM block must be entirely in the Detail Calculation Specifications or the Total Calculation Specifications. Alpha-Binary Data Usually, when an intrinsic uses numeric data, such as INTEGER type, you specify an RPG numeric field to represent that data in your RPG program. Since RPG internally stores all numeric data in packed decimal format, automatic decimal-to-binary and binary-to-decimal conversions are done to accurately pass the data between your program and the intrinsic. You can prevent this conversion by specifying an alphanumeric field to hold the data in your RPG program. When you do this, no data conversion is done, and the RPG alphanumeric field holds the bit pattern representation of the intrinsic's INTEGER or other binary-coded data. This data representation is called "Alpha-Binary" because binary-coded data is stored in an RPG alphanumeric field. Use of Alpha-Binary data saves processing time by avoiding numeric data conversions. It is useful when numeric data returned from one intrinsic call is passed directly to another intrinsic call and requires no other processing by the RPG program. For example, if you call the CREATE intrinsic, an INTEGER "pin" number is returned. This number is used in subsequent calls to the ACTIVATE and KILL intrinsics. It is not otherwise used by the RPG program and so does not need to be stored as an RPG numeric field. Therefore, you should specify the "pin" field as alphanumeric (that is, Alpha-Binary) to allow the INTEGER data to pass directly between the intrinsics without conversion. Alpha-Binary data is also useful when intrinsic parameters contain bit fields. That is, you need to test or set one or more bits in a parameter. If the parameter is represented as an Alpha-Binary field in your RPG program, the TESTB, BITON, and BITOF operations can be used to manipulate the bit fields. Since Alpha-Binary data is stored in RPG alphanumeric fields, no numeric data operations, like arithmetic (ADD, SUB, and so on) or output field editing, can be done with it. Example Following are examples of RPG source code that use INTR and IPARM to call intrinsics. C* HPMYPROGRAM(PGNAME); C* /* INTRINSIC NAME EXTENDS INTO RESULT FIELD. */ C* /* EXTENSIBLE - LAST TWO PARMS SKIPPED. */ C* C INTR HPMYPROGRAM C IPARM PGNAME 28 C* NUMCHR := ASCII(NUM, BASE, STR); C* /* FUNCTION RETURNS NUMCHR, DEFINED AS */ C* /* NUMERIC, 4 DIGITS, 0 DEC PLACES. */ C* C NUMCHR INTR ASCII 40 C IPARM NUM C IPARM BASE C IPARM STR C* WHO(,CAP); C* /* SKIP THE FIRST PARAMETER. EXTENSIBLE. */ C* /* CAP IS A 4-BYTE "ALPHA-BINARY" ARRAY. */ C* C INTR WHO C IPARM C IPARM CAP C* C* /* CHECK BITS FOR 'SM' & 'MR' CAPABILITY */ C* C TESTB"0" CAP,1 10 C TESTB"4" CAP,4 11 C* BIN := BINARY(ASCI, LEN); C* /* SETS CONDITION CODE. BIN IS "ALPHA-BINARY". */ C* C BIN INTR BINARY 010203 C IPARM ASCI C IPARM LEN


MPE/iX 5.0 Documentation