Monday, February 7, 2011

Abap Fields Symbols and Get Reference for multiple ALV report

Most of the customized report i created usually have different pattern in a single report such as the report have capability to show multiple type of result in the same sap report.  The user interface usually are always represented with radio button as below.

 

Each choosen radio button will represent a diffrent type of result (different number of column). If you are design your code using Object Oriented ALV, tradisionally you need to have multiple internal table for each result, such as IT01,IT02, IT03,… and you nedd to call ALV method multiple times, depending on number of your internal table and definately in my own opinion it is not good for programming implementation if we always repeating same method for the same purpose !


cl_salv_table=>factory(
                             exporting
                                 list_display = if_salv_c_bool_sap=>true
                            importing
                                 r_salv_table = salv_table
                           changing
                                 t_table = IT01
                             ).

cl_salv_table=>factory(
                              exporting
                                  list_display = if_salv_c_bool_sap=>true
                              importing
                                  r_salv_table = salv_table
                              changing
                                   t_table = IT02
                             ).


cl_salv_table=>factory(
                              exporting
                                  list_display = if_salv_c_bool_sap=>true
                              importing
                                  r_salv_table = salv_table
                              changing
                           t_table = IT03
                          ).

For that purposed, we can implement the GET REFERENCE and FIELDS SYMBOLS to solve this problem. Abap Get Reference is used to get itself reference to a data object and places this into the reference variables. Abap Fields Symbols are symbolics names for other fields. For better explanation feel free to google or click on the link given. here are the steps:
  1. For example for each radio button action, refer chosen internal table using Get Reference method as below.  Then call the Method write_alv. (the itstate,itpk and itba is the internal table. p_kpist,p_kpipk and p_kpi_ba is the radio button. o_state, o_pk and o_ba is the object for created classes.)
data: salv_table type ref to cl_salv_table.
data: display_settings type ref to cl_salv_display_settings.
data: mdo_data type ref to data.
if p_kpist = ‘X’.
        get reference of o_state->itstate into o_state->mdo_data.
       call method o_state->write_alv.
elseif p_kpipk = ‘X’.
      get reference of o_pk->itpk into o_pk->mdo_data.
     call method o_pk->write_alv.
elseif p_kpiba = ‘X’.
    get reference of o_ba->itba into o_ba->mdo_data.
    call method o_ba->write_alv.
endif.

2.  Declare field symbols variables as table which it can be suit on any type of internal table.  use Abap Assign to link the reference variables into fields symbols.
 

Method WriteALV.
   field-symbols: <lt_outtab> type  table.
     assign me->mdo_data->* to <lt_outtab>.
      
    cl_salv_table=>factory(
                            exporting
                                   list_display = if_salv_c_bool_sap=>true
                            importing
                                   r_salv_table = salv_table
                            changing
                              t_table = <lt_outtab>).
endmethod.

FINISH!, now we just need to use single ALV method to handle multiple SAP report. Good Luck!

1 comments:

Firdaus said...

testing commenting

Post a Comment