ABAP读取BRF+决策表(decision table)

目的
使用BRF+的决策表代替SM30配置表,目前是一个demo,尚未进行生产验证
前提

  • 创建一个BRF+应用程序,包含一个或者多个决策表
  • 决策表仅包含简单决策,数据只能是单行,条件只能是等于(EQ/=),与SM30直观上感觉一致
    在这里插入图片描述在这里插入图片描述

示例代码

  • 方法已封装,传入应用程序ID(如ZMDG_BRF_TEST)以及决策表ID即可
  • 可传入与决策表结构一致的内表(参数ct_act_table),获取解析后的直观数据
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.

读取结果
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u012232542/article/details/108679830
今日推荐