Sample Source for Debug Examples

Figure 131 shows the source for the main procedure of the program DEBUGEX. Most of the examples and screens shown in this chapter are based on this source. Figure 132 and Figure 133 show the source for the called program RPGPGM and procedure cproc respectively.

The program DEBUGEX is designed to show the different aspects of the ILE source debugger and ILE RPG formatted dumps. The sample dumps are provided in the next chapter.

The following steps describe how the program DEBUGEX was created for use in these examples:

  1. To create the module DBGEX using the source in Figure 131, type:
    CRTRPGMOD MODULE(MYLIB/DBGEX) SRCFILE(MYLIB/QRPGLESRC) DBGVIEW(*ALL)
              TEXT('Main module for Sample Debug Program')

    DBGVIEW(*ALL) was chosen in order to show the different views available.

  2. To create the C module using the source in Figure 133, type:
    CRTCMOD MODULE(MYLIB/cproc) SRCFILE(MYLIB/QCLESRC) DBGVIEW(*SOURCE)
              TEXT('C procedure for Sample Debug Program')
  3. To create the program DEBUGEX, type:
    CRTPGM PGM(MYLIB/DEBUGEX) MODULE(MYLIB/DBGEX MYLIB/CPROC)
               TEXT('Sample Debug Program')

    The first module DBGEX is the entry module for this program. The program will run in a new activation group (that is, *NEW) when it is called.

  4. To create the called RPG program using the source in Figure 132, type:
    CRTBNDRPG PGM(MYLIB/RPGPGM) DFTACTGRP(*NO)
              DBGVIEW(*SOURCE) ACTGRP(*NEW)
              TEXT('RPG program for Sample Debug Program')

    We could have created RPGPGM to run in the OPM default activation group. However, we decided to have it run in the same activation group as DEBUGEX, and since DEBUGEX needs only a temporary activation group, *NEW was chosen for both programs.

Figure 131. Source for Module DBGEX
      *=================================================================*
      *  DEBUGEX - Program designed to illustrate use of ILE source
      *            debugger with ILE RPG source.  Provides a
      *            sample of different data types and data structures.
      *
      *            Can also be used to produce sample formatted dumps.
      *=================================================================*
      *-----------------------------------------------------------------*
      * The DEBUG keyword enables the formatted dump facility.
      *-----------------------------------------------------------------*
     H DEBUG
      *-----------------------------------------------------------------*
      * Define standalone fields for different ILE RPG data types.
      *-----------------------------------------------------------------*
     D String          S              6A   INZ('ABCDEF')
     D Packed1D0       S              5P 2 INZ(-93.4)
     D ZonedD3D2       S              3S 2 INZ(-3.21)
     D Bin4D3          S              4B 3 INZ(-4.321)
     D Bin9D7          S              9B 7 INZ(98.7654321)
     D DBCSString      S              3G   INZ(G'"BBCCDD"')
     D UCS2String      S              5C   INZ(%UCS2('ucs-2'))
     D CharVarying     S              5A   INZ('abc') VARYING
     D Int3            S              3I 0 INZ(-128)
     D Int5            S              5I 0 INZ(-2046)
     D Int10           S             10I 0 INZ(-31904)
     D Int20           S             20I 0 INZ(-463972)
     D Unsigned3       S              3U 0 INZ(128)
     D Unsigned5       S              5U 0 INZ(2046)
     D Unsigned10      S             10U 0 INZ(31904)
     D Unsigned20      S             20U 0 INZ(463972)
     D Float4          S              4f   INZ(7.2098)
     D Float8          S              8f   INZ(-129.0978652)
     D DBCSString      S              3G   INZ(G'"BBCCDD"')
      *   Pointers
     D NullPtr         S               *   INZ(*NULL)
     D BasePtr         S               *   INZ(%ADDR(String))
     D ProcPtr         S               *   ProcPtr INZ(%PADDR('c_proc'))
     D BaseString      S              6A   BASED(BasePtr)
     D BaseOnNull      S             10A   BASED(NullPtr)
      *
     D Spcptr          S               *
     D SpcSiz          C                   8
      *   Date, Time, Timestamp
     D BigDate         S               D   INZ(D'9999-12-31')
     D BigTime         S               T   INZ(T'12.00.00')
     D BigTstamp       S               Z   INZ(Z'9999-12-31-12.00.00.000000')
      *   Array
     D Arry            S              3S 2 DIM(2) INZ(1.23)
      *   Table
     D TableA          S              3    DIM(3) CTDATA
      *-----------------------------------------------------------------*
      * Define different types of data structures.
      *-----------------------------------------------------------------*
     D DS1             DS                  OCCURS(3)
     D  Fld1                          5A   INZ('ABCDE')
     D  Fld1a                         1A   DIM(5) OVERLAY(Fld1)
     D  Fld2                          5B 2 INZ(123.45)
      *
     D DS2             DS            10    OCCURS(2)
      *
     D DS3             DS
     D  Title                         5A   INZ('Mr.  ')
     D  LastName                     10A   INZ('Jones    ')
     D  FirstName                    10A   INZ('Fred     ')

     D QUALDS          DS                  QUALIFIED
     D  Id_Num                        8S 0
     D  Country                      20A   DIM(10) 
     D LIKE_QUALDS     DS                  LIKEDS(QUALDS)
     D itemInfo        DS                  QUALIFIED              
     D   ID_Num                      10I 0                        
     D   name                        25A                          
     D items           DS                  QUALIFIED              
     D   numItems                    10I 0                        
     D   item                              LIKEDS(itemInfo) DIM(10) 
     D cust            DS                  QUALIFIED DIM(10)
     D   name                        50A                          
     D   parts                             LIKEDS(items)          
      *-----------------------------------------------------------------*
      * Define prototypes for called procedures c_proc and switch
      *-----------------------------------------------------------------*
     D c_proc          PR              *   EXTPROC('c_proc')
     D   size                        10U 0 VALUE
     D   inzval                       1A   CONST
     D Switch          PR
     D   Parm                         1A
      *-----------------------------------------------------------------*
      * Define parameters for non-prototyped call
      *     PARM1 is used when calling RPGPROG program.
      *-----------------------------------------------------------------*
     D PARM1           S              4P 3 INZ(6.666)
     D EXPORTFLD       S              6A   INZ('export') EXPORT
      *=================================================================*
      * Now the operation to modify values or call other objects.
      *=================================================================*
      *-----------------------------------------------------------------*
      * Move 'a's to the data structure DS2.  After the move, the
      * first occurrence of DS2 contains 10 character 'a's.
      *-----------------------------------------------------------------*
     C                   MOVE      *ALL'a'       DS2
      *-----------------------------------------------------------------*
      * Change the occurrence of DS2 to 2 and move 'b's to DS2,
      * making the first 10 bytes 'a's and the second 10 bytes 'b's.
      *-----------------------------------------------------------------*
     C     2             OCCUR     DS2
     C                   MOVE      *ALL'b'       DS2
      *-----------------------------------------------------------------*
      * Fld1a is an overlay field of Fld1.  Since Fld1 is initialized
      * to 'ABCDE', the value of Fld1a(1) is 'A'.  After the
      * following MOVE operation, the value of Fld1a(1) is '1'.
      *-----------------------------------------------------------------*
     C                   MOVE      '1'           Fld1a(1)
      *-----------------------------------------------------------------*
      * Call the program RPGPGM, which is a separate program object.
      *-----------------------------------------------------------------*
     C     Plist1        PLIST
     C                   PARM                    Parm1
     C                   CALL      'RPGPGM'      Plist1
      *-----------------------------------------------------------------*
      * Call c_proc, which imports ExportFld from the main procedure.
      *-----------------------------------------------------------------*
     C                   EVAL      SpcPtr = c_proc(SpcSiz : 'P')
      *-----------------------------------------------------------------*
      * Call a local subprocedure  Switch, which reverses the value of
      * an indicator.
      *-----------------------------------------------------------------*
     C                   EVAL      *IN10 = '0'
     C                   CALLP     Switch(*in10)
      *-----------------------------------------------------------------*
      * After the following SETON operation, *IN02 = 1.
      *-----------------------------------------------------------------*
     C                   SETON                                        020406
     C                   IF        *IN02 = '1'
     C                   MOVE      '1994-09-30'  BigDate
     C                   ENDIF
      *-----------------------------------------------------------------*
      * Put a new value in the second cell of Arry.
      *-----------------------------------------------------------------*
     C                   MOVE      4             Arry
      *-----------------------------------------------------------------*
      *  Now start a formatted dump and return, by setting on LR.
      *-----------------------------------------------------------------*
     C                   DUMP
     C                   SETON                                        LR
      *=================================================================*
      * Define the subprocedure Switch.
      *=================================================================*
     P Switch          B
     D Switch          PI
     D   Parm                         1A
      *-----------------------------------------------------------------*
      * Define a local variable for debugging purposes.
      *-----------------------------------------------------------------*
     D Local           S              5A      INZ('aaaaa')
     C                   IF        Parm = '1'
     C                   EVAL      Parm = '0'
     C                   ELSE
     C                   EVAL      Parm = '1'
     C                   ENDIF
     P Switch          E
      *=================================================================*
      * Compile-time data section for Table.                            *
      *=================================================================*
**
aaa
bbb
ccc
Figure 132. Source for OPM Program RPGPGM
      *=================================================================*
      *  RPGPGM - Program called by DEBUGEX to illustrate the STEP      *
      *           functions of the ILE source debugger.                 *
      *                                                                 *
      *  This program receives a parameter InputParm from DEBUGEX,      *
      *  displays it, then returns.                                     *
      *=================================================================*
     D InputParm       S              4P 3
     C     *ENTRY        PLIST
     C                   PARM                    InputParm
     C     InputParm     DSPLY
     C                   SETON                                        LR
Figure 133. Source for C Procedure cproc
     #include <stdlib.h>
     #include <string.h>
     #include <stdio.h>
     extern char EXPORTFLD[6];
     char *c_proc(unsigned int size, char *inzval)
     {
        char *ptr;
        ptr = malloc(size);
        memset(ptr, *inzval, size );
        printf("import string: %6s.\n",EXPORTFLD);
        return(ptr);
     }


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