Creating a Program for Source Debugging

In this example you create the program EMPRPT so that you can debug it using the source debugger. The DBGVIEW parameter on either CRTBNDRPG or CRTRPGMOD determines what type of debug data is created during compilation. The parameter provides six options which allow you to select which view(s) you want:
  • *STMT — allows you to display variables and set breakpoints at statement locations using a compiler listing. No source is displayed with this view.
  • *SOURCE — creates a view identical to your input source.
  • *COPY — creates a source view and a view containing the source of any /COPY members.
  • *LIST — creates a view similar to the compiler listing.
  • *ALL — creates all of the above views.
  • *NONE — no debug data is created.
The source for EMPRPT is shown in Figure 2.
  1. To create the object type:
    CRTBNDRPG PGM(MYLIB⁄EMPRPT) DBGVIEW(*SOURCE) DFTACTGRP(*NO)

    The program will be created in the library MYLIB with the same name as the source member on which it is based, namely, EMPRPT. Note that by default, it will run in the default named activation group, QILE. This program object can be debugged using a source view.

  2. To debug the program type:
    STRDBG EMPRPT

    Figure 1 shows the screen which appears after entering the above command.

    Figure 1. Display Module Source display for EMPRPT
                                 Display Module Source
     Program:   EMPRPT         Library:   MYLIB          Module:   EMPRPT
          1        *==============================================================*
          2        * MODULE NAME:    EMPRPT
          3        * RELATED FILES:  EMPMST   (PHYSICAL FILE)
          4        *                 QSYSPRT  (PRINTER FILE)
          5        * DESCRIPTION:    This program prints employee information
          6        *                 from the file EMPMST.
          7        *==============================================================*
          8       FQSYSPRT   O    F   80        PRINTER
          9       FEMPMST    IP   E           K DISK
         10
         11       D TYPE            S              8A
         12       D EMPTYPE         PR             8A
         13       D   CODE                         1A
         14
         15       IEMPREC        01
                                                                            More...
     Debug . . .   _________________________________________________________________
    _______________________________________________________________________________
     F3=End program   F6=Add/Clear breakpoint   F10=Step   F11=Display variable
     F12=Resume       F17=Watch variable   F18=Work with watch   F24=More keys

    From this screen (the Display Module Source display) you can enter debug commands to display or change field values and set breakpoints to control program flow while debugging.

For more information on debugging see Debugging Programs.