on 08-08-2009 7:49 AM
Dear All,
I want to display the contents of an internal table as the column header in a grid ALV.
This cannot be hard coded, dynamically whatever is there in the internal table has to be displayed..Say now there are three vendors in the internal table, 001 002 003 so there has to be 3 columns in the output with 001 002 003 as headers respectively. How can this be achieved?? Should this be approached through OOP concept??
Kindly help..
Thanks & Regards
Ajai
Thanks everyone !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
use this
data:
w_cat type lvc_s_fcat.
types:
begin of types_s_head,
col1 type string,
col1 type string,
col1 type string,
end of types_s_head.
data : fs_head type types_s_head.
fs_head-col1 = 'Column1'.
fs_head-col2 = 'Column2'.
fs_head-col3 = 'Column3'.
w_cat-fieldname = fs_head-col1.
w_cat-colpos = 1.
append w_cat to t_cat.
w_cat-fieldname = fs_head-col2.
w_cat-colpos =2.
append w_cat to t_cat.
this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try This. This may be helpfull to you
FORM f_get_fieldcat .
CLEAR wa_fieldcat.
wrk_col_pos = wrk_col_pos + 1.
wa_fieldcat-col_pos = wrk_col_pos.
wa_fieldcat-fieldname = 'VTEXT'.
if sy-tabix = 1.
wa_fieldcat-seltext_l = itab-field1.
endif.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wrk_col_pos = wrk_col_pos + 1.
wa_fieldcat-col_pos = wrk_col_pos.
wa_fieldcat-fieldname = 'REGION'.
if sy-tabix =1. =
wa_fieldcat-seltext_l = itab-field12. this will be ur field heading..... (u can read the internal table which contain the field name)
endif.
APPEND wa_fieldcat TO it_fieldcat.
Endform
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please check this.
data: gt_fieldcat type lvc_t_fcat.
data: gp_table type ref to data.
data: gwa_table type ref to data.
field-symbols: <gt_table> type table.
field-symbols: <gwa_table> type any.
field-symbols: <gv_field> type any.
data: gwa_fieldcat type lvc_s_fcat.
data: lv_fieldname type fieldname.
data: lv_var(4) type n.
data: g_container type scrfname value 'CC_CONTAINER',
grid1 type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container.
data : lv_lifnr type lifnr.
types: begin of t_itab,
lifnr type lifnr,
end of t_itab.
data: itab type standard table of t_itab.
data: wa_itab type t_itab.
create the vendor data
do 3 times.
move sy-index to lv_lifnr.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = lv_lifnr
importing
output = wa_itab-lifnr.
append wa_itab to itab.
enddo.
create field-catalog.
loop at itab into wa_itab.
move sy-tabix to lv_var.
concatenate 'VEND_' lv_var into lv_fieldname.
gwa_fieldcat-fieldname = lv_fieldname.
gwa_fieldcat-ref_field = 'LIFNR'.
gwa_fieldcat-ref_table = 'LFA1'.
gwa_fieldcat-coltext = wa_itab-lifnr.
append gwa_fieldcat to gt_fieldcat.
endloop.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = gt_fieldcat
importing
ep_table = gp_table.
ASSIGN gp_table->* TO <gt_table>.
IF <gt_table> IS ASSIGNED.
fill data
CREATE DATA gwa_table LIKE LINE OF <gt_table>.
ASSIGN gwa_table->* TO <gwa_table>.
IF <gwa_table> IS ASSIGNED.
use your vendors to fill the vendors in <gt_table>
LOOP AT itab INTO wa_itab.
ASSIGN COMPONENT sy-tabix OF STRUCTURE <gwa_table>
TO <gv_field>.
IF <gv_field> IS ASSIGNED.
<gv_field> = wa_itab-lifnr.
ENDIF.
ENDLOOP.
IF sy-subrc EQ 0.
APPEND <gwa_table> TO <gt_table>.
ENDIF.
CALL SCREEN '0101'.
ENDIF.
ENDIF.
MODULE status_0101 OUTPUT.
create the container object
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = g_container.
ENDIF.
Edited by: Ankur Parab on Aug 8, 2009 3:13 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
continue...
create the grid.
IF grid1 IS INITIAL.
CREATE OBJECT grid1
EXPORTING
i_parent = g_custom_container.
display data
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_save = 'A'
CHANGING
it_outtab = <gt_table>
it_fieldcatalog = gt_fieldcat.
ELSE.
CALL METHOD grid1->refresh_table_display.
ENDIF.
Regards,
Ankur Parab
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.