Copyright 2024 - BV TallVision IT

In a development environment the debugger is a great tool, but it has it's limits: when the debugging needs to be done in a background process the actual debugging session cannot address an end-user (the developer in this case). Or when it's performance info the needs to be "logged". Debug information to a logging file...

As a blue-print description: A simple program that can be called from other programs via a perform call. It logs a message and allows viewing of the log, as well as removing the log.

Goal and objectives

A developer needs his or her tools and how to use them. This is merely a tool that allows debugging without debugger (especially handy with background processes).

The blue print

A simple concept is usually the key to a strong solution. Imagine a program that can be called from anywhere which put a log entry (text line) on a text file. Log entries will be date and time-stamped and deviating from the (hardcoded) standard log file is possible (isolate your own stuff from other developers). The program allows reading it and of course clearing (removing) it again. 

The coding below goes into a single program source:

*---------------------------------------------------------
* Report        -  ZULOG
* Description   -  <description (copied from attributes)>
*---------------------------------------------------------
REPORT ZULOG NO STANDARD PAGE HEADING LINE-SIZE 255.

* This report logs an entry into a flat file when routine 
* "ADD_ENTRY" is called. it also shows the entries when
* run from the selection screen. To complete the whole,
* the log file can also be deleted from the selection
* screen. CONSTANTS C_FILE(60) VALUE '_logfile_for_sap_development_testing'. PARAMETERS: P_FILE(60) LOWER CASE DEFAULT C_FILE, P_DELETE AS CHECKBOX. selection-screen skip. selection-screen begin of line. selection-screen comment 1(79) text-c01. selection-screen end of line. selection-screen begin of line. selection-screen comment 1(79) text-c02. selection-screen end of line. selection-screen begin of line. selection-screen comment 1(79) text-c03. selection-screen end of line. selection-screen begin of line. selection-screen comment 1(79) text-c04. selection-screen end of line.

The texts read:

  • C01 - This program allows you to add entries to a log file, display the log file and
  • C02 - clear it again. Run ZULOG directly to display or clear a log file execute:
  • C03 - perform add_entry(zulog) using space 'whatever'. "or
  • C04 - perform add_entry(zulog) using 'alternative_logfilename' 'whatever'
START-OF-SELECTION.

  IF P_DELETE EQ 'X'.
    PERFORM DELETE_LOG.
  ELSE.
    PERFORM SHOW_LOG.
  ENDIF.

TOP-OF-PAGE.
  perform top_of_page.

TOP-OF-PAGE DURING LINE-SELECTION.
  perform top_of_page.

AT USER-COMMAND.
  SY-LSIND = 0.
  PERFORM SHOW_LOG.

AT LINE-SELECTION.
  SY-LSIND = 0.
  PERFORM SHOW_LOG.

form top_of_page.
  WRITE: 'File:', p_file.
  ULINE.
endform.
*---------------------------------------------------------
* FORM delete_log 
*---------------------------------------------------------
FORM DELETE_LOG.
  DELETE DATASET P_FILE.
ENDFORM.
*---------------------------------------------------------
* FORM show_log
*---------------------------------------------------------
FORM SHOW_LOG.
  DATA: L_LOG_LINE(120).
  OPEN DATASET P_FILE FOR INPUT
    IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC NE 0.
    WRITE: / 'Logfile not found: ', P_FILE.
  ELSE.
    WHILE SY-SUBRC EQ 0.
      READ DATASET P_FILE INTO L_LOG_LINE.
      WRITE: / L_LOG_LINE.
    ENDWHILE.
    CLOSE DATASET P_FILE.
  ENDIF.
ENDFORM.
*---------------------------------------------------------
* FORM add_entry 
*---------------------------------------------------------
FORM ADD_ENTRY USING FILENAME ENTRY.
* perform add_entry(zwimlog) using space 'whatever'.

  DATA: L_LINE(250),
        L_FILE(60),
        L_ENTRY(80).

  L_ENTRY = ENTRY.
  CONDENSE L_ENTRY.
  IF FILENAME EQ SPACE.
    L_FILE = C_FILE.
  ELSE.
    L_FILE = FILENAME.
  ENDIF.
  OPEN DATASET L_FILE FOR APPENDING 
    IN TEXT MODE ENCODING DEFAULT.
  WRITE SY-DATUM TO L_LINE DD/MM/YYYY.
  WRITE SY-UZEIT TO L_LINE+11 USING EDIT MASK '__:__:__'.
  CONCATENATE L_LINE L_ENTRY INTO L_LINE
    SEPARATED BY SPACE.
  TRANSFER L_LINE TO L_FILE.
  CLOSE DATASET L_FILE.

ENDFORM.

Pro's and cons

  • Avoid long-winded work arounds to track problems
 

Success story

This program was used by several developers on a 2 year implementation. Similar constructions have been around on nearly implementation I've been on.