2009 Sep 09 12:04 PM
I want to create dynamic columns in my table control.....For eg a custom table will store the column name...if 5 record are there then 5 columns should be made in table control.....Please help how can I do that?
2009 Sep 09 12:13 PM
Hi Priya,
Please refer to the below code
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c default 'T001'.
selection-screen end of block b1.
start-of-selection.
perform get_structure.
perform create_dynamic_itab. **********Creates a dyanamic internal table**********
perform get_data.
perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
* Create dynamic internal table and assign to FS
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
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
* Select Data from table.
select * into table <dyn_table>
from (p_table).
endform.
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop
2009 Sep 09 12:15 PM
Field symbols
I do the same with Warehouse
DATA: gp_table TYPE REF TO data.
FIELD-SYMBOLS: <gt_outtab> TYPE table.
FIELD-SYMBOLS: <field_table> TYPE table.
LOOP AT t_magaz.
TRANSLATE t_magaz-lgort TO UPPER CASE.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = t_magaz-lgort.
ls_fieldcat-datatype = 'QUAN'.
ls_fieldcat-outputlen = 14.
ls_fieldcat-coltext = t_magaz-lgort.
APPEND ls_fieldcat TO gt_fieldcat.
ENDLOOP.
FIELD-SYMBOLS: <ls_table>.
FIELD-SYMBOLS: <l_field>.
DATA: txt_field(60).
* creazione tabella di output dinamica
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gt_fieldcat
IMPORTING
ep_table = gp_table.
ASSIGN gp_table->* TO <gt_outtab>.
REFRESH <gt_outtab>.
ASSIGN gp_table->* TO <field_table>.
REFRESH <field_table>.
loop at t_magaz.
concatenate '<ls_table>-' t_magaz-lgort into txt_field.
assign (txt_field) to <l_field>
<l_field> = t_magaz-quantity.
endloop.
APPEND <ls_table> TO <gt_outtab>.
These are scraps from a more complex code, but there is all you need.
2009 Sep 09 12:23 PM
2009 Sep 09 12:42 PM
Hi Priya,
Sorry I misred your post...You can go ahead and do the below coding.
First while designing the code declare all the columns and based on the program logic u can hide the unwanted columns.
in the PBO flow logic use.
LOOP AT SCREEN.
IF SCREEN-NAME = 'ITAB-COLUMN1' OR SCREEN-NAME = 'ITAB-COLUMN3'.
SCREEN-INVISIBLE = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
Let me know if u need any help
Gowri