2013 Sep 06 3:49 PM
Hi Experts,
I have got a requirement where i have to display some fixed coloumns and some variable dynamic columns which depend on date range .
Suppose the start date is 01-09-2013 and finish date is 20-09-2013, then the ALV should display 20 more fields other than the existing 10 fields. These 20 fields may vary as per the date range.
I have never worked on this DYnamci ALV and when i googled about for reference i got more confused.
I tried preparing the fieldcat and i have to use resuse_alv_grid_display for ALV display.
For the fixed columns do we need to use the fieldcatlog of slis_t_fieldcat_alv and for dynamic one lvc_t_fcat and does the dynamic one will have all the fields other than dynamic fields ?
Kindly guide how can i achieve this .
Thanks and Regards,
Swarnadeepta
2013 Sep 09 6:37 AM
Hi,
These are some useful links to guide you to create dynamic internal table.
http://wiki.scn.sap.com/wiki/display/ABAP/Dynamic+Internal+table
http://wiki.scn.sap.com/wiki/display/Snippets/Create+Multiple+Dynamic+Tables
after creating dynamic internal table you can start populating data to the same and this internal table in turn can be used to create an alv grid or list display by creating a dynamic field catalog.
Cheers,
Dineshwar
Hi,
These are some useful links to guide you to create dynamic internal table.
http://wiki.scn.sap.com/wiki/display/ABAP/Dynamic+Internal+table
http://wiki.scn.sap.com/wiki/display/Snippets/Create+Multiple+Dynamic+Tables
after creating dynamic internal table you can start populating data to the same and this internal table in turn can be used to create an alv grid or list display by creating a dynamic field catalog.
Cheers,
Dineshwar
2013 Sep 06 5:08 PM
Hi Swarnadeepta,
There can 2 scenarios:
1. One start date & one end date accepted on the selection screen = all rows have same number of columns
2. Start date and end date in each data row = different number of columns for different rows. (Not possible)
Assuming it is the first case, here's how you can achieve this:
Before calling resuse_alv_grid_display (in PBO), while appending fields to the fieldcatalogue (you can use slis_t_fieldcat_alv for all cases), add the first 10 fields which will be present for all dates. For the dynamic fields, you can put a check before appending that particular field to the fieldcatalogue.
The check will be to see if the accepted date range falls in your criteria of dates or not.
Hope this helps.
2013 Sep 06 5:43 PM
Hi ,
Have a look at the attached program y_r_eitan_test_06_03 .
This is a dynamic weekly report .
It might be useful for you.
The idea here is to create a fix ALV but to control the appearance of columns using the "technical" flag .
<st_column_ref>-r_column->set_technical( value = st_alv_hdrc_1-tech ) .
It is using cl_salv_table but the principal can be adopted to REUSE_ALV_GRID_DISPLAY ()
tech(1) type c, " technical field
Regards.
Eitan.
2013 Sep 07 2:16 PM
Hi Swarnadeepta,
In addition to the above solutions.. I have also created the dynamic alv with some static columns and variable columns depending on the parameter where user can put no. Of columns user wants.
For that I just created both slis field catalog and lvc field catalog with description of static columns and looping on the no. Of columns to add up description of variable columns.
In your case you can loop on the difference of date range and create both field catalog... where slis field catalog is used for REUSE_ALV_GRID_DISPLAY and lvc field catalog is use to creat dynamic table using oops class method CREATE_DYNAMIC_TABLE.. this is the theoretical description if you need a coding logic you can update me I will post some dummy code for you.
Regards,
Harshit
2013 Sep 07 3:57 PM
Hi,
Add all the columns to the field catalogue and hide the the fields which should not be displayed by making the fieldcatalog attribute NO_OUT = 'X' .
For eg,
data ls_Fcat type lvc_s_fcat.
data lt_fcat type lvc_t_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = Name of the column in the internal table.
ls_fcat-coltext = Title of the column to be displayed on the alv table.
ls_fcat-no_out = 'X'." To hide the field
APPEND ls_fcat TO lt_fcat.
Fill the field catalog as shown above and pass it to the method SET_TABLE_FOR_FIRST_DISPLAY.
Now only those fields where no_out = ' ' are displayed on the alv table.
Based on the requirement, adjust the attribute to change the fields displayed on the alv table.
Please get back to me if you need sample code snippet or more info on how to achieve this.
2013 Sep 08 7:08 AM
Hi Swarna,
Follow this logic.
data : date_check type c.
perform data_retreival.
perform check_flags.
perform create_field_catalog.
perform display_data.
in the check_flags, set a flag variable for the different conditions
form check_flags.
clear : date_check.
loop at it_data into wa_data. "data table.
if wa_data-start-date = '20130901' and wa_data-finish_date = '20130920'
date_check = 'X'.
endif.
clear wa_data.
endloop.
endform.
In the field catalog creation subroutine, Depending on the value of various check variable, set or clear the no_out attribute of the column.
form create_field_catalog.
data: lv_pos type i.
lv_pos = lv_pos + 1.
clear gw_alv_fieldcat.
gw_alv_fieldcat-fieldname = Name of the column in the internal table that has to be displayed only if the above date condition is met.
gw_alv_fieldcat-tabname = 'IT_DATA'.
gw_alv_fieldcat-seltext_l = text-h02.
gw_alv_fieldcat-col_pos = lv_pos.
gw_alv_fieldcat-outputlen = 12.
if check_date is initial. " If tje condition is not satisfied, hide the column.
gw_alv_fieldcat--no_out = 'X'." To hide the field
endif.
append gw_alv_fieldcat to gt_alv_fieldcat.
CLEAR gw_alv_fieldcat.
2013 Sep 09 5:26 AM
2013 Sep 09 6:37 AM
Hi,
These are some useful links to guide you to create dynamic internal table.
http://wiki.scn.sap.com/wiki/display/ABAP/Dynamic+Internal+table
http://wiki.scn.sap.com/wiki/display/Snippets/Create+Multiple+Dynamic+Tables
after creating dynamic internal table you can start populating data to the same and this internal table in turn can be used to create an alv grid or list display by creating a dynamic field catalog.
Cheers,
Dineshwar
2013 Sep 18 1:16 PM
Thanks all for the solution.
Because of which i was able to solve it.
I took all the fields into two fieldcatalogs ( LVC_t_fieldcat and slis_t_fieldcat_alv).
And i used the fieldcatalog of type lvc_t_fcat for creating the dynamic internal table with the help of the method create_dynamic_table. and then filled up the dynamic internal table.
Passed the fieldcat of type slis_t_fieldcat_alv and dynamic internal table to resue_alv_grid_display for final output display.
and for the logic of date i used one FM DAY_ATTRIBUTES_GET. This FM provides no. of days between the start date and end date . Suppose you pass 01.09.2013 to 03.09.2013.
then the FM will provide an internal table with values as
01.09.2013
02.09.2013
03.09.2013
So looped that internal table and built the fieldcatalog accordingly and it worked fine.
i have attached a text file with some code with the help of which i was able to know how to fill the dynamic internal table.
Best Regards ,
Swarnadeepta
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |