Reading the Data of Decision Table using BRF+ API’s
Hi All,
Let us read the below decision table using BRF+ API code in a report
Using following code you can read the decision table data in a report.Just copy paste the below code.But change the GUID’S ,structures as per your requirement. 🙂
*The application guid
CONSTANTS: gc_appl_id TYPE if_fdt_types=>id VALUE ‘005056C000081EE58CD3919CB9A80957’.
*create a structure as per the Decision table
types:BEGIN OF ts_msg_txt_data,
level type char24,
age type char24,
pricing type char24,
base type char24,
currency_base type char24,
END OF ts_msg_txt_data,
*Create a structure for the row count
BEGIN OF ts_table_data,
row_no TYPE int4,
col_no TYPE int4,
expression_id TYPE if_fdt_types=>id,
r_value TYPE REF TO data,
ts_range TYPE if_fdt_range=>ts_range,
END OF ts_table_data .
* data declarations
DATA: lref_decision_table TYPE REF TO cl_fdt_decision_table,
lref_factory TYPE REF TO if_fdt_factory,
lt_msg_data TYPE if_fdt_decision_table=>ts_table_data,
ls_msg_data LIKE LINE OF lt_msg_data,
lt_table_data_msg TYPE TABLE OF ts_table_data,
ls_table_data_msg TYPE ts_table_data,
ls_table_data1 TYPE ts_table_data,
lt_msg_txt_data type STANDARD TABLE OF ts_msg_txt_data,
ls_msg_txt_data type ts_msg_txt_data,
ls_range_msg TYPE if_fdt_range=>s_range.
*field symbols declaration
FIELD-SYMBOLS :<fs_lv_value> type any,
<fs_lpw_lv_amount> TYPE if_fdt_types=>element_amount.
*Generic factory instance
lref_factory = cl_fdt_factory=>if_fdt_factory~get_instance( gc_appl_id ).
*get the expression the decision table guid
lref_decision_table ?= lref_factory->get_expression(
iv_id = ‘005056C000081EE58D84DE427EE2E957’ ).”
*to get the decision table data based on above expression guid
lref_decision_table->if_fdt_decision_table~get_table_data(
IMPORTING
ets_data = lt_msg_data
).
IF lt_msg_data IS NOT INITIAL.
CLEAR lt_table_data_msg.
* Processing decision table and filling the ls_table_data_msg
LOOP AT lt_msg_data INTO ls_msg_data.
ls_table_data_msg-row_no = ls_msg_data-row_no.
ls_table_data_msg-col_no = ls_msg_data-col_no.
ls_table_data_msg-expression_id = ls_msg_data-expression_id.
ls_table_data_msg-r_value = ls_msg_data-r_value.
ls_table_data_msg-ts_range = ls_msg_data-ts_range.
APPEND ls_table_data_msg TO lt_table_data_msg.
CLEAR ls_table_data_msg.
ENDLOOP.
SORT lt_table_data_msg BY row_no col_no.
* Processing the loop lt_table_data_msg to fill structure as per the decision table
LOOP AT lt_table_data_msg INTO ls_table_data_msg.
ls_table_data1 = ls_table_data_msg.
CASE ls_table_data1-col_no.
* level
when 1.
IF ls_table_data1-ts_range IS NOT INITIAL.
READ TABLE ls_table_data1-ts_range INTO ls_range_msg INDEX 1.
IF sy-subrc = 0.
ASSIGN ls_range_msg-r_low_value->* TO <fs_lv_value>.
ls_msg_txt_data-level = <fs_lv_value>.
ENDIF.
ENDIF.
* age
when 2.
IF ls_table_data1-ts_range IS NOT INITIAL.
READ TABLE ls_table_data1-ts_range INTO ls_range_msg INDEX 1.
IF sy-subrc = 0.
ASSIGN ls_range_msg-r_low_value->* TO <fs_lv_value>.
ls_msg_txt_data-age = <fs_lv_value>.
ENDIF.
ENDIF.
* pricing
when 3.
IF ls_table_data1-r_value IS NOT INITIAL.
ASSIGN ls_table_data1-r_value->* TO <fs_lv_value>.
ls_msg_txt_data-pricing = <fs_lv_value> .
ENDIF.
* base and currency_base
when 4.
IF ls_table_data1-r_value IS NOT INITIAL.
ASSIGN ls_table_data1-r_value->* TO <fs_lpw_lv_amount>.
ls_msg_txt_data-base = <fs_lpw_lv_amount>-number.
ls_msg_txt_data-currency_base = <fs_lpw_lv_amount>-currency .
ENDIF.
endcase.
AT END OF row_no .
APPEND ls_msg_txt_data TO lt_msg_txt_data.
write:/ ls_msg_txt_data-LEVEL,ls_msg_txt_data-AGE,ls_msg_txt_data-PRICING,ls_msg_txt_data-BASE,ls_msg_txt_data-CURRENCY_BASE.
CLEAR ls_msg_txt_data.
ENDAT.
endloop.
endif.
We get the following output in the report
Please find the code in the attachment as well 🙂