ABAP reads the BRF+ decision table (decision table)

The purpose of
the use of decision tables instead of BRF + SM30 configuration table, there is a demo, not yet production-proven
premise

  • Create a BRF+ application that contains one or more decision tables
  • The decision table only contains simple decisions, the data can only be a single row, and the condition can only be equal to (EQ/=), which is intuitively consistent with SM30
    Insert picture description hereInsert picture description here

Sample code

  • The method has been encapsulated, just pass in the application ID (such as ZMDG_BRF_TEST) and the decision table ID
  • The internal table (parameter ct_act_table) consistent with the structure of the decision table can be passed in to obtain the intuitive data after analysis
zcl_common_fm=>read_brf_descision_table(
exporting
iv_appl_id = 'ZMDG_BP_IDTYPE_CHECK'
iv_table_name = 'DS_ID_TYPE'
importing
et_brf_table = data(lt_brf)

).
  method read_brf_descision_table.

    "----------------parameter list--------------------------
    "    iv_appl_id  type fdt_name brf+应用程序名称
    "    iv_table_name  type fdt_name brf+决策表名称
    "    et_brf_table  type if_fdt_decision_table=>ts_table_data data of the decision table
    "    ct_act_table  type index table optional 含结构的abap内表
    "------------------------------------------------------

    "-------------------------------------------------------
    " goals of this method: replace DDIC cust table definiton
    "-----------------------------------------------------

    "get Brf application and Object GUID
    select single *
    from fdt_admn_0000
    where name = @iv_appl_id
    into @data(ls_appl_header).

    select single *
    from fdt_admn_0000
    where name = @iv_table_name
    into @data(ls_dt_header).

    "read Brf+ data
    data(lo_factory) = cl_fdt_factory=>if_fdt_factory~get_instance( ls_appl_header-application_id ).
    data(lo_decision_table) = cast cl_fdt_decision_table(
          lo_factory->get_expression( iv_id =  ls_dt_header-id )
          ).

    lo_decision_table->if_fdt_decision_table~get_table_data(
    importing
    ets_data     = data(lt_data)
          ).

    et_brf_table = corresponding #( lt_data ).

    "mapping value to actual table
    "the table structure mast be consistent with decision table
    "the conditon must only contains equal
    if ct_act_table is supplied.
      data:lt_data_standard                type standard table of  if_fdt_decision_table=>s_table_data.
      lt_data_standard = lt_data.
      sort lt_data_standard by row_no col_no.

      loop at lt_data_standard assigning field-symbol(<fs_data>).
        at new row_no.
          append initial line to lt_data assigning field-symbol(<fs_act>).
        endat.

        assign component <fs_data>-col_no of structure <fs_act> to field-symbol(<fs_act_field>).
        check sy-subrc eq 0.

        if <fs_data>-r_value is not initial.
          assign <fs_data>-r_value->* to field-symbol(<fs_value>).
          <fs_act_field> = <fs_value>.
        else.
          read table <fs_data>-ts_range assigning field-symbol(<fs_range>) index 1.
          if sy-subrc eq 0.
            if <fs_range>-low is not initial.
              <fs_act_field> = <fs_range>-low.
            else.
              assign <fs_range>-r_low_value->* to <fs_value>.
              <fs_act_field> = <fs_value>.
            endif.
          endif.
        endif.
      endloop.
    endif.
  endmethod.

Read the result
Insert picture description here

Guess you like

Origin blog.csdn.net/u012232542/article/details/108679830