Using Compiler Directives for Debugging

You can conditionally compile entire sections of a program by using the five compiler directives:

  • #IF

  • #ELSE

  • #END-IF or #ENDIF

  • #IFDEF

  • #IFNDEF

Use the value of a substitution variable, declared by a #DEFINE command, to activate or deactivate a set of statements, as shown in the following example:

#define DEBUG_SESSION Y
#if DEBUG_SESSION = 'Y'
begin-procedure dump_array
   let #i = 0
   while #i < #counter
      ! Get data from the array
      get $state $city $name $phone from customer_array(#i)
      print $state (,1)
      print $city  (,7)
      print $name  (,24)
      print $phone (,55)
      position (+1)
      add 1 to #i
   end-while
end-procedure ! dump_array
#end-if

The dump_array procedure is used only for debugging. Because DEBUG_SESSION is defined as Y, the dump_array procedure is included in the program. Later, you can change DEBUG_SESSION to N and exclude the dump_array procedure from the program.