2009 Oct 15 2:17 PM
Hi all,
I have an requirement like I need to display the fields dynamically based on date range..
Ex: In my final output I am having 3 fields. Plant, date, qty.
In my selection screen I will give the date range. And in the code based on the logic data is fetching and at last I need to display the fields based on the date range. Suppose if I gave 2 months date.
O/p: |plant| date |qty |date |qty|
Suppose 3 months means
O/p: |plant| date |qty |date |qty| date |qty|
If you observe the above 2 o/pu2019s Date and qty fields are repeating based on month range. So is there any FM to generate the fields dynamically..
Hi all,
I have an requirement like I need to display the fields dynamically based on date range..
Ex: In my final output I am having 3 fields. Plant, date, qty.
In my selection screen I will give the date range. And in the code based on the logic data is fetching and at last I need to display the fields based on the date range. Suppose if I gave 2 months date.
O/p: |plant| date |qty |date |qty|
Suppose 3 months means
O/p: |plant| date |qty |date |qty| date |qty|
If you observe the above 2 o/pu2019s Date and qty fields are repeating based on month range. So is there any FM to generate the fields dynamically..
2009 Oct 15 2:27 PM
Hello,
You can create the table dynamically using the method CREATE_DYNAMIC_TABLE of the class CL_ALV_TABLE_CREATE.
For details refer to sample program: BCALV_TABLE_CREATE.
Good Luck !!
2009 Oct 15 2:39 PM
Is it a matter of creating dynamic table, or only dynamic output from static table?
What I mean is: how your table structure look like? Do you know it before runtime? Are field DATE and QTY repeated 12 times?
If so you can easily address those fields using fields symbols and display on screen dynamically. It could be either 2 times or 12 times in one line.
Also how your DATE field is connected to selection screen parameter (date range) and what data it stores?
If it is the matter of creating table fields dynamically simply use DO months TIMES....ENDDO and inside append fields to fieldcatalog . Then use class & method Suhas suggested.
This can also be achieved with [RTTC classes|http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html] but is a litte more advanced.
Regards
Marcin
2009 Oct 15 2:55 PM
Hi,
Try this sample program. It suits your requirement.
Thanks
Venkat.O
REPORT ztest_notepad.
TYPE-POOLS:slis.
DATA: it_fcat TYPE STANDARD TABLE OF lvc_s_fcat,
it_fcatalog TYPE STANDARD TABLE OF slis_fieldcat_alv,
wa_fcat TYPE lvc_s_fcat,
wa_fcatalog TYPE slis_fieldcat_alv.
DATA: it_dyn_tab TYPE REF TO data,
wa_newline TYPE REF TO data.
FIELD-SYMBOLS:
<gt_table> TYPE STANDARD TABLE,
<fs_dyntable>,
<fs_fldval> TYPE ANY,
<l_field> TYPE ANY.
DATA: l_fieldname TYPE lvc_s_fcat-fieldname,
l_fieldtext TYPE lvc_s_fcat-seltext,
l_index TYPE char2.
PARAMETERS:columns TYPE i.
START-OF-SELECTION.
DEFINE fieldcat.
wa_fcat-fieldname = &1.
wa_fcat-tabname = '<GT_TABLE>'.
wa_fcat-seltext = &2.
append wa_fcat to it_fcat.
clear wa_fcat.
END-OF-DEFINITION.
DO columns TIMES.
CLEAR l_index.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
CONCATENATE 'Field' l_index INTO l_fieldtext.
wa_fcat-fieldname = l_fieldname.
wa_fcat-tabname = '<GT_TABLE>'.
wa_fcat-seltext = l_fieldtext.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDDO.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_dyn_tab.
ASSIGN it_dyn_tab->* TO <gt_table>.
CREATE DATA wa_newline LIKE LINE OF <gt_table>.
ASSIGN wa_newline->* TO <fs_dyntable>.
DO 20 TIMES.
DO columns TIMES.
l_index = sy-index.
CONCATENATE 'FIELD' l_index INTO l_fieldname.
ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
<l_field> = sy-index.
ENDDO.
INSERT <fs_dyntable> INTO TABLE <gt_table>.
ENDDO.
LOOP AT it_fcat INTO wa_fcat.
wa_fcatalog-fieldname = wa_fcat-fieldname.
wa_fcatalog-tabname = wa_fcat-tabname.
wa_fcatalog-seltext_m = wa_fcat-seltext.
APPEND wa_fcatalog TO it_fcatalog.
CLEAR wa_fcatalog.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = 'ZTEST_NOTEPAD'
it_fieldcat = it_fcatalog
TABLES
t_outtab = <gt_table>.
2009 Nov 25 2:05 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |