SchwarzIT / sap-usi-logging-api

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

Structure-Container /USI/CL_BAL_DC_STRUCTURE: Includes and structured fields are not recognized #18

Closed NeumannJoerg closed 6 months ago

NeumannJoerg commented 7 months ago

The following code would produce an empty structure container in the log.

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( ).

logger->add_free_text( i_free_text = |This won't work|
                       i_details   = NEW /usi/cl_bal_dc_structure( i_structure = VALUE p0001( begda = sy-datum ) ) ).

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

The reason can be found in method /usi/cl_bal_dc_structure->build_alv_output

    LOOP AT structure_description->get_components( )
        REFERENCE INTO DATA(component)
        WHERE type->kind EQ cl_abap_typedescr=>kind_elem.

      ASSIGN COMPONENT component->name OF STRUCTURE <structure> TO <field>.
      IF sy-subrc NE 0.
        CONTINUE.
      ENDIF.

      INSERT VALUE #( fieldname = component->name
                      value     = <field> )
          INTO TABLE alv_output->*.
    ENDLOOP.
  ENDMETHOD.

The problem is, that structure P0001 contains only includes and that method CL_ABAP_STRUCTDESCR->GET_COMPONENTS will return an internal table, that contains structure descriptions for the included structures, but not their respective fields. image

Since all fields without an elementary type are excluded from the processing, the method will return an empty table, that will then be logged.

=> The results of method CL_ABAP_STRUCTDESCR->GET_COMPONENTS need to be processed by a recursive logic, that will resolve structured types into their respective fields. This should work for included types and for structured fields.

NeumannJoerg commented 6 months ago

Total overhaul of method build_alv_output.

The changes were implemented using TDD. Six new test methods in test class lcl_unit_tests_serialization will prevent a regression in subsequent releases.