General logging tool for SAP ABAP RFC interface: ABAP FM logger

Time:2020-9-24

I wanted to write a general tool to record the log of function modules for a long time. When I first tried, I didn’t think of a solution to the problem of too large insert code. Some group friends in the reminder, learned that you can use the macro to deal with this problem. However, I was busy at that time and didn’t start writing. Later, I gradually forgot. I think of it again recently. It took 2 days to complete a preliminary implementation. Introduce to you, hope to have reference value.

 

Link to this article:https://www.cnblogs.com/hhelibeb/p/13560754.html

brief introduction

target

The tool has several objectives:

  1. The log data is stored in a unified log table to avoid creating a log table for each interface, thus reducing the repeated workload.
  2. A general code is used to realize the log storage, and the function can be switched through the configuration table.
  3. The log is stored in JSON format and provides some index query function.
  4. Allows data to be reprocessed based on the unique ID of the log (similar to transaction code we19).

At present, goals 1 and 2 have been achieved, 3 and 4 parts have been achieved and are still in the process of improvement.

principle

The basic principle is to use some dynamic programming technology to get the parameter value when the function is running, and convert it into JSON data and store it in the table.

The log uses a unique ID as the primary key.

During reprocessing, ABAP variables are generated dynamically according to log records, and values are obtained from JSON, assigned to variables, and FM recorded in log is called dynamically.

The amount of code is still very small, only a few hundred lines, you can read the included file zafl_ Macro and class ZCL_ AFL_ Utilites for more details.

For ABAP dynamic programming, if there is something that you don’t understand, you can refer to: this series of articles:Dynamic Programming in ABAP

Project address

Project Name: ABAP FM logger

GitHub address:https://github.com/hhelibeb/abap-fm-logger

Please useABAPGITInstall, if you feel helpful, welcome star

use

This paper introduces the usage of ABAP FM logger, including code, configuration, report, etc.

report form

The logs are stored in table zafl_ Log, report programZAFL_VIEWERCan be used for query / reprocessing logs

 

Click on the JSON field to see the parameter details.

Select the log line and click “process selected item” in the toolbar. The program will try to call the corresponding interface again using the parameter record of the selected log.

 

 

Log storage

Only two copy and paste are needed to complete the code part, which is very simple:

1, add include fileZAFL_MACROSGo to the function group of the FM that needs to log,

FUNCTION-POOL zzxxxx.
INCLUDE zafl_macros.

 

2, call the corresponding macro in the function.

FUNCTION z_fm.
  
**To initialize the logger, you need to call it at the beginning of FM
  /afl/log_init.

**Optional, specify up to 3 fields for searching (such as company code, material number, etc.)
  /afl/set_custom_fields 'cust field1' 'cust field2' 'cust field3'. 

**Optional, record status code, such as S / E, up to 2 bits
  /afl/set_status 'S' 'message'.

**To save the log, it must be at the end of FM
  /afl/save.

ENDFUNCTION.

Here, / AFL / log_ Init and / AFL / save are required, while / AFL / set_ custom_ Fields and / AFL / set_ Status provides some flexibility to choose whether to call or not on demand.

to configure

surfaceZAFL_CONFIGFor configuring ABAP FM logger, options include,

  • Fname: function module name.
  • Enabled: if checked, the logging function is enabled.
  • Export: if checked, enable the record of export parameter.
  • Import: if checked, enable the record of import parameter.

You can also specify the display names (cust) of the three index fields_ Name), they will affect zafl_ The display effect in viewer.
The configuration can be maintained using transaction sm30.

To be improved

At present, two problems need to be improved,

  • If the interface contains curr type field, although logging can be performed normally, the value of curr type field in the log cannot be read during reprocessing.
  • There is no function of searching logs by field values (similar to transaction code we10).

I hope it can be improved in the near future.

 

(Note: strictly speaking, it should be called the function module interface general logging tool. The RFC in the title is for searching keywords, so the official name of this tool is also called ABAP FM logger.)