SchwarzIT / sap-usi-logging-api

An easy-to-use, object-oriented encapsulation around the SAP application log (Transaction SLG1)
Apache License 2.0
22 stars 0 forks source link

ITAB-Container /USI/CL_BAL_DC_ITAB: Includes and structured fields are not recognized #22

Open Codenarski opened 2 months ago

Codenarski commented 2 months ago
DATA(logger) = /usi/cl_bal_factory=>get_instance( )->create_new_logger( i_log_object = 'MY_LOG_OBJECT'
                                                                        i_sub_object = 'MY_SUB_OBJECT' ).
DATA(token)  = logger->claim_ownership( ).

TYPES: BEGIN OF ty_log_line,
         pernr TYPE pernr_d,
         p0000 TYPE p0000,
       END OF ty_log_line,
       ty_log_tab TYPE STANDARD TABLE OF ty_log_line with EMPTY KEY.

SELECT *
  FROM pa0000
  UP TO 1 ROWS
  INTO TABLE @DATA(db_records).

DATA(log_table) = VALUE ty_log_tab( FOR record IN db_records ( pernr = record-pernr
                                                               p0000 = CORRESPONDING #( record ) ) ).

logger->add_message( i_problem_class      = /usi/cl_bal_enum_problem_class=>very_important
                     i_message_type       = /usi/cl_bal_enum_message_type=>error
                     i_message_class      = '5B'
                     i_message_number     = '015'
                     i_details            = NEW /usi/cl_bal_dc_itab(
                                                  i_internal_table = log_table
                                                  i_title          = /usi/cl_bal_tc_report_text_c40=>create(
                                                                         i_text_key = 'L01'
                                                                         i_text     = text-l01 ) ) ).

logger->save( token ).
logger->free( token ).

This leads to p0000 being ignored not being included in the log.

image

image

NeumannJoerg commented 2 months ago

Thanks for reporting this!

I was able to reproduce the error.

The data is serialized and persisted correctly. The problem is caused by method LCL_TABLE_DESCRIPTOR->GET_FIELDCATALOG (local class inside /USI/CL_BAL_DC_ITAB), that does not handle fields having a structured type correctly. Instead of resolving the structured field P0000 into its respective fields it just adds the "field" P0000 to the field catalog, that cannot be displayed by the ALV since it is a structure.

Guess I'll have to adjust the persistency so that included structures are resolved into fields (P0000-PERNR becomes FIELD_01 or some other generated name).

Otherwise we might run into issues with the ALV, since it only supports fieldnames having up to 30 characters. So if you would rename P0000 to something having more than 24 characters, its field PERNR could no longer be displayed by the ALV, since the new name was too long for the fieldcatalog.

I'll fix that as soon as I find the time.