cancel
Showing results for 
Search instead for 
Did you mean: 

BRFplus :: How to read decision table data in internal table?

sanjana_lingras
Active Participant
0 Kudos

Hi Experts ,

I have a requirement , where I want to read complete decision table in internal table whenever user tries to maintain that particular decision table.

So before maintaining values in the decision table, take backup of decision table into internal table and send mail with attachment.

I have already gone through the available links where it is mentioned to implement interface IF_FDT_DECISION_TABLE~GET_TABLE_DATA.

But I need help on how to write code to read data in internal table using GET_TABLE_DATA method.

Please help with the sample code to read decision table into an internal table.Thanks.

Accepted Solutions (0)

Answers (4)

Answers (4)

gretchen_horn2
Explorer
0 Kudos

Hi Sanjana,  I was able to do this based on the blog by Jocelyn Dart http://scn.sap.com/docs/DOC-65093#comment-655286

I built a very simple Rule Engine as below

Below you can see the structures of the data from the decision table

Below is the rough code that will accomplish updating each simple (not a structure) entry that has a particular value with the new value.

REPORT z_update_decision_table.

* This program will search for a particular value of one field

* in a BRF+ Decision Table and replace this value with a new value.

* Written based on Jocelyn Dart's code that will update the decision table by

* Adding a new row to it.

* http://scn.sap.com/docs/DOC-65093#comment-655286

*

*  Parameters for Day of Week

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT (20) TEXT-p01.

SELECTION-SCREEN POSITION 25.

PARAMETERS: p_coloro TYPE char10.

SELECTION-SCREEN POSITION 40.

SELECTION-SCREEN COMMENT (25) TEXT-p02.

PARAMETERS: p_colorn TYPE char10.

SELECTION-SCREEN END OF LINE.

CONSTANTS:

   lc_dectable_id    TYPE if_fdt_types=>id VALUE '12C5F1DFEC1D1ED5B8C5EE7A8F8D45A4',   "Decision Table ID

   lc_field_color_id TYPE if_fdt_types=>id VALUE '12C5F1DFEC1D1ED5B8C622C6E32105DD'.   "Column FAVORITE_COLOR

DATA:

   lv_timestamp     TYPE if_fdt_types=>timestamp,

   lo_decisiontable TYPE REF TO if_fdt_decision_table,

   lo_admin_data    TYPE REF TO if_fdt_admin_data,

   lv_name          TYPE if_fdt_types=>name,

   lv_text          TYPE if_fdt_types=>text,

   lt_columns       TYPE if_fdt_decision_table=>ts_column,

   lt_rowdata       TYPE if_fdt_decision_table=>ts_row_data,              "Holds the existing row(s)

   lr_cell_value    TYPE REF TO data,

   lv_old_color     TYPE if_fdt_types=>element_text,

   lr_new_color     TYPE REF TO data.

FIELD-SYMBOLS:

   <fs_row_data>   TYPE if_fdt_decision_table=>s_row_data,

   <fs_cell_data>  TYPE if_fdt_decision_table=>s_cell_data,

   <fs_cell_value> TYPE any.

GET TIME STAMP FIELD lv_timestamp.

TRY.

*   Get the Business Rules factory instance ...the beginning of all business rules API

     DATA(lo_factory) = cl_fdt_factory=>if_fdt_factory~get_instance( ).

*   Get the decision table as an expression instance

     lo_decisiontable =

      CAST #( lo_factory->get_expression(

      iv_id = lc_dectable_id

      iv_expression_type_id = if_fdt_constants=>gc_exty_decision_table ) ).

*   Get the columns of the Decision Table

     lo_decisiontable->get_columns(

     IMPORTING

      ets_column = lt_columns ).

*   Get the rows of the Decision Table

     lo_decisiontable->get_rows(

       IMPORTING

         ets_row_data = lt_rowdata ).

   CATCH cx_root.

     WRITE: / |error reading the decision table|.

     EXIT.

ENDTRY.

* Set variable for new color.

lr_new_color = REF #( p_colorn ).

* Replace the old color where found with the new color

* This code will only replace single entries stored in R_VALUE

* instead of Range entries stored in TS_RANGE

LOOP AT lt_rowdata ASSIGNING <fs_row_data>.

   LOOP AT <fs_row_data>-ts_cell_data ASSIGNING <fs_cell_data>.

     IF lt_columns[ col_no = <fs_cell_data>-col_no ]-object_id = lc_field_color_id.

       lr_cell_value = REF #( <fs_cell_data>-r_value ).

       ASSIGN lr_cell_value->* TO <fs_cell_value>.

       lv_old_color = CAST if_fdt_types=>element_text( <fs_cell_value> )->*.

       IF lv_old_color = p_coloro.

         <fs_cell_data>-r_value = lr_new_color.

       ENDIF.

     ENDIF.

   ENDLOOP.

ENDLOOP.

* Update the Decision Table

TRY.

*   Lock the table

     lo_decisiontable->if_fdt_transaction~enqueue( ).

*   Update the table

     lo_decisiontable->set_rows(

       EXPORTING

         its_row_data = lt_rowdata ).

*   Activate the Decision Table

     lo_decisiontable->if_fdt_transaction~activate( ).

*   Save the Decision Table – if everything was ok

     lo_decisiontable->if_fdt_transaction~save( ).

*   Finally unlock the Decision Table

     lo_decisiontable->if_fdt_transaction~dequeue( ).

   CATCH cx_root.

     WRITE: / |error updating the decision table|.

     EXIT.

ENDTRY.

* Get name and text description of decision table

lo_admin_data ?= lo_decisiontable.

lv_name = lo_admin_data->get_name( iv_timestamp = lv_timestamp ).

lo_admin_data->get_texts(

    EXPORTING iv_timestamp = lv_timestamp

    IMPORTING ev_text = lv_text ).

WRITE: / |Automated Update of Decision Table: | && lv_name.

WRITE: / |Known as: | && lv_text.

gretchen_horn2
Explorer
0 Kudos

whoops...I confused your request with another I read where they wanted to replace all instances of a UserID found in a decision table with a new UserID.  

But...I'm not clear on why do you not use the versioning that is provided?

It shows who made a change and when and what the change was.   You can also retrieve a previous version (the entire decision table) and put it back as the active version.

Jocelyn_Dart
Product and Topic Expert
Product and Topic Expert
0 Kudos

Well done

sanjana_lingras
Active Participant
0 Kudos

hi christian,

I tried the way you explained but facing issue while reading data into internal table format. s_row_data is deep nested structure.

Is there any way we can easily read data into internal table?Thanks.

Hi Tee,

Can you give some more details for the solution you applied?Thanks.

former_member210541
Active Participant
0 Kudos

in method GET_FORMATTED_DT_DATA of class  cl_fdt_dt_excel i made an implicit enhancement and downloaded the table  <lta_ele_tab> using  GUI_DOWNLOAD

0 Kudos

Hi Sanjana,

there is no abbreviation to get the data out of the deep nested structure as shown in the document I referenced. Nevertheless this code works, so you should be able to use it (after adopting it to your specific structure of the decision table)

Concerning the download via the CL_FDT_DT_EXCEL. The method mentioned by might be an option. Nevertheless I would not modify it but copy the code to Z Namespace (both options are not optimal from a maintenance perspective but I would not go for a modification in such a quite central place of BRFplus). I also want to stress that you run into interesting results if you use expressions in cells of the decision table as shown in the screenshot below that you have to deal with somehow

Here another decision table is referenced in the first cell.

BR Christian

former_member210541
Active Participant
0 Kudos

Hi,

We did an implicit enhancement to achieve the same, and it works just fine.

0 Kudos

Hi Sanjana,

I think the document Automating Rate Updates in DSM and BRFPlus may answer your questions. Here you have a code snippet how to fetch the data stored in a decision table. Although the document is about the update you can see on page 8 how to get the row data. On page 9 you will see how to extract the data from the single cells (there is quite some de-referencing to do). If you finally have the data you can directly put it into an internal table.

If it just comes for the backup, it might also be an option to create a "backup" application in BRFplus and just copy your decision table to that application. This for sure does not fulfill the requirement concerning the mail, but saving the data into an internal table might be quite challenging when you think about more sophisticated data in the decision table (ranges within cells or even other

expressions)

Hope that helps

Best Regards

Christian