Binding to a Program

To complete the example, we will create an 'application' consisting of a program CVTHEXPGM which is bound to the service program. It uses a seven-character string which it passes to CVTTOHEX twice, once where the value of the hex string is 10 (that is, convert 5 characters) and again where the value is 14, that is, the actual length.

Note that the program CVTHEXPGM serves to show the use of the service program CVTTOHEX. In a real application the caller of CVTTOHEX would have another primary purpose other than testing CVTTOHEX. Furthermore, a service program would normally be used by many other programs, or many times by a few programs; otherwise the overhead of initial call does not justify making it into a service program.

To create the application follow these steps:

  1. Create the module from the source in Figure 46, by entering:
        CRTRPGMOD MODULE(MYLIB/CVTHEXPGM) SRCFILE(MYLIB/QRPGLESRC)
  2. Create the program by typing
        CRTPGM PGM(MYLIB/CVTHEXPGM)
               BNDSRVPGM(MYLIB/CVTTOHEX)
               DETAIL(*BASIC)

    When CVTHEXPGM is created, it will include information regarding the interface it uses to interact with the service program. This is the same as reflected in the binder language for CVTTOHEX.

  3. Call the program, by typing:
        CALL CVTHEXPGM

    During the process of making CVTHEXPGM ready to run, the system verifies that:

    If either of the above is not true, then an error message is issued.

The output of CVTHEXPGM is shown below. (The input string is 'ABC123*'.)

Result14++++++
Result10++
C1C2C3F1F2         10 character output
C1C2C3F1F2F35C     14 character output
Figure 46. Source for Test Program CVTHEXPGM
      *----------------------------------------------------------------*
      * Program to test Service Program CVTTOHEX                       *
      *                                                                *
      * 1. Use a 7-character input string                              *
      * 2. Convert to a 10-character hex string (only the first five   *
      *    input characters will be used because the result is too     *
      *    small for the entire input string)                          *
      * 3. Convert to a 14-character hex string (all seven input       *
      *    characters will be used because the result is long enough)  *
      *----------------------------------------------------------------*
     FQSYSPRT   O    F   80        PRINTER
      * Prototype for CvtToHex
     D/COPY RPGGUIDE/QRPGLE,CVTHEXPR
     D ResultDS        DS
     D   Result14              1     14
     D   Result10              1     10
     D InString        S              7
     D Comment         S             25
     C                   EVAL      InString = 'ABC123*'

      *----------------------------------------------------------------*
      * Pass character string and the 10-character result field        *
      * using a prototyped call.  Operational descriptors are          *
      * passed, as required by the called procedure CvtToHex.          *
      *----------------------------------------------------------------*
     C                   EVAL      Comment = '10 character output'
     C                   CLEAR                   ResultDS
     C                   CALLP     CvtToHex(Instring : Result10)
     C                   EXCEPT

      *----------------------------------------------------------------*
      * Pass character string and the 14-character result field        *
      * using a CALLB(D). The operation extender (D) will create       *
      * operational descriptors for the passed parameters.  CALLB      *
      * is used here for comparison with the above CALLP.              *
      *----------------------------------------------------------------*
     C                   EVAL      Comment = '14 character output'
     C                   CLEAR                   ResultDS
     C                   CALLB(D)  'CVTTOHEX'
     C                   PARM                    InString
     C                   PARM                    Result14
     C                   EXCEPT
     C                   EVAL      *INLR = *ON

     OQSYSPRT   H    1P
     O                                              'Result14++++++'
     OQSYSPRT   H    1P
     O                                              'Result10++'
     OQSYSPRT   E
     O                       ResultDS
     O                       Comment             +5


[ Top of Page | Previous Page | Next Page | Contents | Index ]