‎2008 Aug 28 6:29 AM
hi all,
well i am developing a ALV where the selection screen has a Cost Center group entry...A cost center group can have any no. of cost centers...
in my case the ALV can have variable no. of cost center columns depending on the cost center group...
till no i have created :
... a dynamic empty internal table that contains the dynmaic columns and its layout is like:
Cost element cost center1 cost center2 cost center 3 ..........
... a internal table which contains the data which is to be displayed but not in the format of the dynamic internal table and it layout is like :
cost center cost element amount
well my problem is how i map the data from internal table which contains the data to dynamic internal table ..
‎2008 Aug 28 6:45 AM
hi....
i had the same requirement...
you will have to first create a fieldcatlog using the class which i hav used. then you can create a table for the strusture of the fieldcatlog as done in the code.
To fill the table you will hav to make use of the field symbols and assign statements.
here is a code to make dynamic fieldcatlog and the table structure...
FORM fill_fieldcat_for_set USING p_ifc LIKE ifc
p_iglfinal LIKE igl_final
CHANGING p_ifinal LIKE ifinal.
CLEAR count.
LOOP AT p_iglfinal INTO wa_gl_final.
MOVE-CORRESPONDING wa_gl_final TO wa_final.
COLLECT wa_final INTO p_ifinal.
ENDLOOP.
SORT ifinal BY setname DESCENDING.
LOOP AT ifinal INTO wa_final.
wa_final-col_no = count + 1.
SELECT SINGLE descript FROM setheadert INTO wa_final-setname1
WHERE setclass = '0000'
AND subclass EQ space
AND setname = wa_final-setname
AND langu = sy-langu.
IF wa_final-setname = 'RESIDUAL'.
wa_final-setname1 = 'RESIDUAL'.
ENDIF.
MODIFY ifinal FROM wa_final.
CLEAR wa_final.
count = count + 1.
ENDLOOP.
CLEAR wa_final.
wa_final-col_no = count + 1.
wa_final-setname1 = 'RESIDUAL'.
wa_final-setname = 'ZB_HEADS_RESIDUAL'.
APPEND wa_final TO ifinal.
CLEAR wa_final.
LOOP AT ifinal INTO wa_final.
v_fieldcount1 = wa_final-col_no.
ENDLOOP.
CLEAR xfc.
xfc-col_pos = '1'.
xfc-fieldname = 'GL_CODE' .
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'BEZEI'.
xfc-ref_table = 'T005U'.
xfc-scrtext_l = 'GL Code'.
xfc-scrtext_m = 'GL Code'.
xfc-scrtext_s = 'GL Code'.
xfc-colddictxt = 'L'.
APPEND xfc TO ifc.
CLEAR xfc.
xfc-col_pos = '2'.
xfc-fieldname = 'GL_DESCR' .
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'ADDL_SITE'.
xfc-ref_table = 'ZPROJ_SITE_DETL'.
xfc-scrtext_l = 'GL Description'.
xfc-scrtext_m = 'GL Description'.
xfc-scrtext_s = 'GL Description'.
xfc-outputlen = '40'.
xfc-just = 'C'.
xfc-no_out = 'X'.
xfc-colddictxt = 'L'.
APPEND xfc TO ifc.
count = 2 .
LOOP AT ifinal INTO wa_final.
count = count + 1.
CLEAR xfc.
xfc-col_pos = count.
xfc-fieldname = wa_final-col_no.
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'HSLVT'.
xfc-ref_table = 'GLPCT'.
xfc-scrtext_l = wa_final-setname.
xfc-scrtext_m = wa_final-setname.
xfc-scrtext_s = wa_final-setname.
xfc-outputlen = 27.
xfc-colddictxt = 'L'.
IF rd1 NE space.
xfc-no_out = 'X'.
ENDIF.
xfc-no_out = ' '.
xfc-just = 'C'.
APPEND xfc TO ifc.
CLEAR xfc.
ENDLOOP.
count = count + 1.
CLEAR xfc.
xfc-col_pos = count.
xfc-fieldname = 'TOTAL'.
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'HSLVT'.
xfc-ref_table = 'GLPCT'.
xfc-scrtext_l = 'Total'.
xfc-scrtext_m = 'Total'.
xfc-scrtext_s = 'Total'.
xfc-outputlen = 27.
xfc-colddictxt = 'L'.
xfc-no_out = ' '.
xfc-just = 'C'.
APPEND xfc TO ifc.
CLEAR xfc.
count = count + 1.
CLEAR xfc.
xfc-col_pos = count.
xfc-fieldname = 'INFO' .
xfc-tabname = 'IT_FINAL' .
xfc-outputlen = 4.
xfc-no_out = 'X'.
xfc-scrtext_l = 'Info'.
xfc-scrtext_m = 'Info'.
xfc-scrtext_s = 'Info'.
xfc-colddictxt = 'L'.
APPEND xfc TO ifc.
v_fieldcount = count.
v_fieldcount2 = v_fieldcount - 1.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_tablen.
ASSIGN dy_tablen->* TO <final>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ASSIGN dy_line->* TO <dyn_wa1>.
ENDFORM. " FILL_FIELDCAT_FOR_SET
and for assign statments you can make use of the following code..
LOOP AT p_igl_final
INTO wa_gl_final.
IF wa_gl_final-gl_code+3(1) = '6'.
CLEAR count.
count = 1.
ASSIGN COMPONENT count OF STRUCTURE <dyn_wa> TO <f1>.
<f1> = wa_gl_final-gl_code.
UNASSIGN <f1>.
count = count + 1.
ASSIGN COMPONENT count OF STRUCTURE <dyn_wa> TO <f1>.
READ TABLE iskat INTO wa_skat WITH KEY spras = 'EN'
saknr = wa_gl_final-gl_code.
IF sy-subrc = 0.
<f1> = wa_skat-txt50.
ENDIF.
UNASSIGN <f1>.
CLEAR wa_final.
READ TABLE ifinal INTO wa_final
WITH KEY setname = wa_gl_final-setname.
IF sy-subrc = 0.
count = count + wa_final-col_no.
ENDIF.
ASSIGN COMPONENT count OF STRUCTURE <dyn_wa> TO <f1>.
<f1> = wa_gl_final-glamt.
UNASSIGN <f1>.
COLLECT <dyn_wa> INTO <dyn_table>.
CLEAR <dyn_wa>.
ENDIF.
ENDLOOP.
hope you will understand...
‎2008 Aug 28 6:31 AM
Hi
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/tutorialabap-CodeforDynamicAlv+grid
Regards
Pavan
‎2008 Aug 28 6:45 AM
hi....
i had the same requirement...
you will have to first create a fieldcatlog using the class which i hav used. then you can create a table for the strusture of the fieldcatlog as done in the code.
To fill the table you will hav to make use of the field symbols and assign statements.
here is a code to make dynamic fieldcatlog and the table structure...
FORM fill_fieldcat_for_set USING p_ifc LIKE ifc
p_iglfinal LIKE igl_final
CHANGING p_ifinal LIKE ifinal.
CLEAR count.
LOOP AT p_iglfinal INTO wa_gl_final.
MOVE-CORRESPONDING wa_gl_final TO wa_final.
COLLECT wa_final INTO p_ifinal.
ENDLOOP.
SORT ifinal BY setname DESCENDING.
LOOP AT ifinal INTO wa_final.
wa_final-col_no = count + 1.
SELECT SINGLE descript FROM setheadert INTO wa_final-setname1
WHERE setclass = '0000'
AND subclass EQ space
AND setname = wa_final-setname
AND langu = sy-langu.
IF wa_final-setname = 'RESIDUAL'.
wa_final-setname1 = 'RESIDUAL'.
ENDIF.
MODIFY ifinal FROM wa_final.
CLEAR wa_final.
count = count + 1.
ENDLOOP.
CLEAR wa_final.
wa_final-col_no = count + 1.
wa_final-setname1 = 'RESIDUAL'.
wa_final-setname = 'ZB_HEADS_RESIDUAL'.
APPEND wa_final TO ifinal.
CLEAR wa_final.
LOOP AT ifinal INTO wa_final.
v_fieldcount1 = wa_final-col_no.
ENDLOOP.
CLEAR xfc.
xfc-col_pos = '1'.
xfc-fieldname = 'GL_CODE' .
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'BEZEI'.
xfc-ref_table = 'T005U'.
xfc-scrtext_l = 'GL Code'.
xfc-scrtext_m = 'GL Code'.
xfc-scrtext_s = 'GL Code'.
xfc-colddictxt = 'L'.
APPEND xfc TO ifc.
CLEAR xfc.
xfc-col_pos = '2'.
xfc-fieldname = 'GL_DESCR' .
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'ADDL_SITE'.
xfc-ref_table = 'ZPROJ_SITE_DETL'.
xfc-scrtext_l = 'GL Description'.
xfc-scrtext_m = 'GL Description'.
xfc-scrtext_s = 'GL Description'.
xfc-outputlen = '40'.
xfc-just = 'C'.
xfc-no_out = 'X'.
xfc-colddictxt = 'L'.
APPEND xfc TO ifc.
count = 2 .
LOOP AT ifinal INTO wa_final.
count = count + 1.
CLEAR xfc.
xfc-col_pos = count.
xfc-fieldname = wa_final-col_no.
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'HSLVT'.
xfc-ref_table = 'GLPCT'.
xfc-scrtext_l = wa_final-setname.
xfc-scrtext_m = wa_final-setname.
xfc-scrtext_s = wa_final-setname.
xfc-outputlen = 27.
xfc-colddictxt = 'L'.
IF rd1 NE space.
xfc-no_out = 'X'.
ENDIF.
xfc-no_out = ' '.
xfc-just = 'C'.
APPEND xfc TO ifc.
CLEAR xfc.
ENDLOOP.
count = count + 1.
CLEAR xfc.
xfc-col_pos = count.
xfc-fieldname = 'TOTAL'.
xfc-tabname = 'IT_FINAL'.
xfc-ref_field = 'HSLVT'.
xfc-ref_table = 'GLPCT'.
xfc-scrtext_l = 'Total'.
xfc-scrtext_m = 'Total'.
xfc-scrtext_s = 'Total'.
xfc-outputlen = 27.
xfc-colddictxt = 'L'.
xfc-no_out = ' '.
xfc-just = 'C'.
APPEND xfc TO ifc.
CLEAR xfc.
count = count + 1.
CLEAR xfc.
xfc-col_pos = count.
xfc-fieldname = 'INFO' .
xfc-tabname = 'IT_FINAL' .
xfc-outputlen = 4.
xfc-no_out = 'X'.
xfc-scrtext_l = 'Info'.
xfc-scrtext_m = 'Info'.
xfc-scrtext_s = 'Info'.
xfc-colddictxt = 'L'.
APPEND xfc TO ifc.
v_fieldcount = count.
v_fieldcount2 = v_fieldcount - 1.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_tablen.
ASSIGN dy_tablen->* TO <final>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ASSIGN dy_line->* TO <dyn_wa1>.
ENDFORM. " FILL_FIELDCAT_FOR_SET
and for assign statments you can make use of the following code..
LOOP AT p_igl_final
INTO wa_gl_final.
IF wa_gl_final-gl_code+3(1) = '6'.
CLEAR count.
count = 1.
ASSIGN COMPONENT count OF STRUCTURE <dyn_wa> TO <f1>.
<f1> = wa_gl_final-gl_code.
UNASSIGN <f1>.
count = count + 1.
ASSIGN COMPONENT count OF STRUCTURE <dyn_wa> TO <f1>.
READ TABLE iskat INTO wa_skat WITH KEY spras = 'EN'
saknr = wa_gl_final-gl_code.
IF sy-subrc = 0.
<f1> = wa_skat-txt50.
ENDIF.
UNASSIGN <f1>.
CLEAR wa_final.
READ TABLE ifinal INTO wa_final
WITH KEY setname = wa_gl_final-setname.
IF sy-subrc = 0.
count = count + wa_final-col_no.
ENDIF.
ASSIGN COMPONENT count OF STRUCTURE <dyn_wa> TO <f1>.
<f1> = wa_gl_final-glamt.
UNASSIGN <f1>.
COLLECT <dyn_wa> INTO <dyn_table>.
CLEAR <dyn_wa>.
ENDIF.
ENDLOOP.
hope you will understand...
‎2008 Aug 28 6:49 AM
‎2008 Aug 28 7:46 AM
hi manisha,
well i have the fieldcatalog ,dynamic table(which is blank) and the data which is to be displayed in another internal table....
the structure of both the dynmaic table and internal table that contains data are dfferent....so how do i migrate data from internal table that contains data to dynamic table...
suppose i move or assign fields from internal table that contains data to dynamic table ,then my doubt is at which column of dynamic table will it should be assigned to as the columns are dynamic and i don't know the header of the column...
description:
dynamic table:
cost_element 100001 100002 100003 100004
table that contains data:
cost element cost center amount
ABC 100001 1000
ABC 100003 4000
XYZ 100002 2000
XYZ 100004 30000
PQR 100003 60000
PQR 100004 70000
so the list that should be displayed is like(FINAL O/P):
Cost_element 100001 100002 100003 100004
ABC 1000 4000
XYZ 2000 3000
PQR 60000 70000
shailendra
‎2008 Aug 28 7:50 AM
Hi Shailendra
Refer the below link
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/tutorialabap-CodeforDynamicAlv+grid
or
Thx
‎2008 Aug 29 4:50 AM