‎2010 Apr 06 8:58 AM
Hello Gurus,
I have one requirement for displaying an Dynamic Alv. I have material plant and req plan no ( PBDNR ) from table PBIM based on the material no , plant and pbdnr in the selection screen and I have to fetch data from pbim and pbed. From pbed i need to fetch plnmg ( amount ) value based on the bdzei feched on the pbim table. now there are various amnts based on the date. so when i enter a date range in the selection screen for a particular material i need to get all the amts in on single row for different dates.
So if that material has six amts on six different dates then six column of dates should come.if it is having 3 dates then 3 dates shld come.So the structure is not fixed .
Please tell me if anyone has worked on this.
Regards,
Abhishek.
‎2010 Apr 06 9:32 AM
if u want to know how to create dynamic structure
u need to use this method CALL METHOD cl_alv_table_create=>create_dynamic_table
search for it u will get sample codes for it
But in your case if one material has say 12 entries the internal table will become very large more over it will be difficult to analyze the data
More over Populating the data logic will become complex
I can suggest you to switch to row display for multiple display
keeping rest of the data same
this should serve the purpose as well
more over less efforts will be required to implement the logic
‎2010 Apr 06 9:33 AM
Hi,
First populate the Fieldcatalog with dates in selection scree as below..
w_date = s_datum-low.
DO.
IF w_date <= s_datum-high.
w_col = w_col + 1.
is_fieldcat-col_pos = w_col.
WRITE w_date TO w_datum USING EDIT MASK '__/__/____'.
is_fieldcat-fieldname = w_date.
is_fieldcat-reptext = w_datum.
is_fieldcat-inttype = 'P'.
is_fieldcat-do_sum = c_x.
APPEND is_fieldcat TO it_fieldcat.
CLEAR is_fieldcat.
w_date = w_date + 1.
ELSE.
EXIT.
ENDIF.
ENDDO.
And then create Dynamic intenal Table using below function module.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = r_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ASSIGN r_dyn_table->* TO <t_dyn_table>.
CREATE DATA r_wa_dyn_table LIKE LINE OF <t_dyn_table>.
ASSIGN r_wa_dyn_table->* TO <wa_dyn_table>.
ASSIGN r_wa_dyn_table->* TO <wa_dyn_table1>.
After this u populate the <t_dyn_table> after that display the table using
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'SUB_PF_STATUS'
i_callback_user_command = 'SUB_USER_COMMAND'
it_sort_lvc = it_sort
it_events = it_events
i_grid_title = w_title
is_layout_lvc = is_layout
it_fieldcat_lvc = p_fcat
TABLES
t_outtab = <t_dyn_table>
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Regards,
Srinivas
Edited by: Srininas on Apr 6, 2010 2:03 PM
‎2010 Apr 07 8:16 AM
Thanks srinivas for ur valuable inputs. I have tried to implement this logic in my program and i am stuck in populating the internal table. The table created through the fiedcat is empty. and my final table has data row wise. So please help me how to fill the internal table.
my coding goes like this.
this is how my final internal table is filled.
LOOP AT gt_pbim INTO gwa_pbim.
LOOP AT gt_pbed INTO gwa_pbed WHERE bdzei = gwa_pbim-bdzei.
gwa_final-matnr = gwa_pbim-matnr.
gwa_final-werks = gwa_pbim-werks.
gwa_final-bedae = gwa_pbim-bedae.
gwa_final-versb = gwa_pbim-versb.
gwa_final-pbdnr = gwa_pbim-pbdnr.
gwa_final-bdzei = gwa_pbim-bdzei.
gwa_final-vervs = gwa_pbim-vervs.
gwa_final-pdatu = gwa_pbed-pdatu.
gwa_final-meins = gwa_pbed-meins.
gwa_final-plnmg = gwa_pbed-plnmg.
APPEND gwa_final TO gt_final.
ENDLOOP.
ENDLOOP.
AND NOW I NEED TO FILL <LT_DESTINATION>
loop at gt_final into gwa_final.
loop at gt_fieldcat_ce112 INTO IS_FIELDCAT.
if IS_FIELDCAT-fieldname <> 'MATNR'
AND IS_FIELDCAT-FIELDNAME <> 'WERKS' .
read table gt_final into gwa_final1 with key matnr = gwa_final-matnr
werks = gwa_final-werks
pdatu = IS_FIELDCAT-fieldname.
append <wa> to <lt_destination>.
endif.
endloop.
endloop.
Please help...