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
it_fieldcatalog = fp_fieldcat
ep_table = l_t_data
e_style_fname = l_fname
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
< Exception Handling>
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 .
ASSIGN l_t_data->* TO <fs_data>.
< MESSAGE Check>.
CREATE DATA l_data LIKE LINE OF <fs_data>.
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.