Business Requirements/Scenario
It’s a quite frequent requirement where we need to create ALV report - requirement in which we need to create the output dynamically w.r.t the Selection screen:
For example: If the details of efforts booked by an employee needs to be checked, based on any date range given in the selection screen.
The ALV final table can be regenerated and created w.r.t the field catalog prepared and passed in the method.
We need to follow below explained Coding Tips in order to get the desired result:
1. The Method that we are going to use here is: create_dynamic_table which is a static method in the class cl_alv_table_create
2. The code declaration procedure is given as follows:
Data: fp_fieldcat type lvc_t_fcat,
l_t_data type ref to data,
l_fname type lvc_fname.
Based on the above declaration, by preparing the field catalog data in fp_fieldcat an internal table of similar type will be created with the below method.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fp_fieldcat
IMPORTING
ep_table = l_t_data
e_style_fname = l_fname
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
< Exception Handling>
ENDIF.
Now, after the internal table creation, in order to process data on the same, we create a structure as a work area as shown below :
Data : wa_data type ref to data .
field-symbols : <fs_data> type standard table .
TRY .
ASSIGN l_t_data->* TO <fs_data>.
CATCH cx_sy_assign_cast_illegal_cast
cx_sy_assign_cast_unknown_type
cx_sy_assign_out_of_range.
< MESSAGE Check>.
ENDTRY.
TRY .
CREATE DATA l_data LIKE LINE OF <fs_data>.
CATCH cx_sy_create_data_error.
<MESSAGE Check>.
ENDTRY.
So, now we have a dynamic Internal table and its work area ready to process and populate the data for our Current Report program .
Note: We cannot directly assign the data to the fields in the work Area, rather we need to populate the same with the Dynamic programming technique.