‎2006 Mar 23 11:58 AM
Hi..
Could somebody please tell me how to add columns at run time into an Alv report...
Thanks in advance..
‎2006 Mar 23 12:13 PM
hi arup,
here is the way...
1. Create your field catalog either manually or automatically using the function module, LVC_FIELDCATALOG_MERGE. Add more rows to the field catalog table (T_FIELDCAT) at run time.
2. Use the field catalog to create a table dynamically using the method below.
DATA: T_OUTPUT TYPE REF TO DATA
FIELD-SYMBOLS: <T_OUTPUT> TYPE TABLE
Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE
Exporting
IT_FIELDCATALOG = T_FIELDCAT
Importing
EP_TABLE = T_OUTPUT
ASSIGN T_OUTPUT->* TO <T_OUTPUT>.
Now the field symbol <T_OUTPUT> is pointing to an output table of the structure that contains the fields which were determined at runtime. Now fill this table with the data and pass <T_OUTPUT> to the method SET_TABLE_FOR_FIRST_DISPLAY and the ALV grid should show the data properly.
However, if you want to access or modify or fill in the data for specific columns, you have to use the ASSIGN COMPONENT statement for the specific field name and do it.
if it is usefull....reward points,
regards,
padma.
‎2006 Mar 23 12:23 PM
Hi,
to add colums dynamically ..in your ALV you'll have to modify the fieldcat and then again call the LIST display FM..
Initially keep the field catalogue with the fielsd that you want to display..
then modify the fieldcatalogue on a usercommand event..
regards
satesh
‎2006 Mar 23 12:29 PM
Hi arup,
1. for adding columns dynamically in alv,
the first thing is that the columns
should come dynamically in
the INTERNAL TABLE.
2. if that is possible, then rest can be easily done.
3. It depends upon what kind of internal table it is.
Is is static ( defined already)
or u are using the concept of dynamic internal table !
4. What u are asking is somewhat difficult !!!
5. The best thing is to keep all posible
list of fields in the internal table,
and hide them (NO_OUT) previously,
and then as and when required,
show them as required !!!
regards,
amit m.
‎2006 Mar 23 12:32 PM
Hi,
Check this Code , here i am adding the columns dynamically.
this code i have a button , first it will display vbeln, posnr. when i click that button my posnr will disappear.
i did it with the help of pf-status,user_command.
check it.
report ztest_alv123 .
type-pools:slis.
data : it_fieldcat type slis_t_fieldcat_alv,
it_fieldcat1 type slis_t_fieldcat_alv.
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
end of itab.
data: begin of itab1 occurs 0,
vbeln like likp-vbeln,
posnr like lips-posnr,
vgbel like lips-vgbel,
vgpos like lips-vgpos,
end of itab1.
data: it_lips like itab1 occurs 0 with header line.
select vbeln
posnr
up to 1000 rows
from vbap
into table itab.
if sy-subrc = 0.
sort itab by vbeln .
select vbeln
posnr
vgbel
vgpos
into table itab1
from lips
for all entries in itab
where vgbel = itab-vbeln
and vgpos = itab-posnr.
endif.
data: x_fieldcat type slis_fieldcat_alv.
x_fieldcat-fieldname = 'VBELN'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 1.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-tabname = 'ITAB'.
x_fieldcat-col_pos = 1.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
perform alv_grid_display.
*&---------------------------------------------------------------------*
*& Form POPUP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EXTAB text
*----------------------------------------------------------------------*
form popup using p_extab type slis_t_extab.
*- Pf status
set pf-status 'POPUP'.
endform. " POPUP
*&---------------------------------------------------------------------*
*& Form HANDLE_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
form handle_user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when 'BACK' or 'CANC' or 'EXIT'.
leave to screen 0.
when '&IC1'.
set parameter id 'AUN' field rs_selfield-value.
call transaction 'VA03' and skip first screen.
when 'BUTTON'.
loop at it_fieldcat into x_fieldcat.
if x_fieldcat-fieldname = 'POSNR'.
x_fieldcat-no_out = 'X'.
modify it_fieldcat from x_fieldcat transporting no_out.
endif.
endloop.
rs_selfield-exit = 'X'.
perform alv_grid_display.
endcase.
endform. "HANDLE_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form alv_grid_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form alv_grid_display .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_pf_status_set = 'POPUP'
i_callback_user_command = 'HANDLE_USER_COMMAND'
it_fieldcat = it_fieldcat
tables
t_outtab = itab
exceptions
program_error = 1
others = 2.
if sy-subrc = 0.
endif.
endform. " alv_grid_displayRegards
Vijay
‎2006 Mar 23 1:17 PM
Arup,
If you want to make it fully dynamically, you can create the internal table dynamically as well. First you create your fieldcatalog You can do it dynamically - fully manual, or semi-dynamically, meaning that you can take an existing structure and add then fields manually. Then you create your internal table and pass it to the ALV along with the fieldcat. Like this:
DATA: dt_outtab TYPE REF TO data.
FIELD-SYMBOLS: <outtab> TYPE STANDARD TABLE.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING i_structure_name = 'ZSOME_EXISTING_STRUCTURE'
i_client_never_display = 'X'
CHANGING ct_fieldcat = t_fcat.
s_fcat-fieldname = 'NEW_FIELD'.
* ...supply all other fieldcat attributes
APPEND s_fcat TO t_fcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = t_fcat
IMPORTING ep_table = dt_outtab.
ASSIGN dt_outtab->* TO <outtab>.
*... create your ALV
CALL METHOD alv->set_table_for_first_display
CHANGING it_outtab = <outtab>
it_fieldcatalog = t_fcat.Hope this helps.
Regards,
Igor
‎2011 Mar 23 10:52 AM
Hello Igor,
I have doubt with create_dynamic_table can i use REUSE_ALV_GRID_DISPLAY FM to display the data ?
regards,
kevin.
‎2007 Mar 06 6:24 AM
Hi,
By using the method CREATE_DYNAMIC_TABLE, I will get the dynamic internal table <OUTTAB>, but with no value. How do I assign value back to this <OUTTAB>. More specifically, how do I assign specific value to specific columns into this dynamic internal table <OUTTAB>?
THanks in advance.
‎2007 Mar 06 6:25 AM
Refer this
Assumption: Structure of the dynamic table should be known before hand.(At least in this program, I am not sure how to do it otherwise. Probably the FIELD-SYMBOL stud programmers can help us out).
report ytest.
data: lt_fieldcatalog type lvc_t_fcat.
data: ls_fieldcatalog type lvc_s_fcat.
field-symbols: <fs_data> type ref to data.
field-symbols: <fs_1>.
field-symbols: <fs_2> type any table.
field-symbols: <fs_3> type ypoll.
data: lt_data type ref to data.
assign lt_data to <fs_data>.
ls_fieldcatalog-fieldname = 'MANDT'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'POLLID'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'TEAM'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'INITIATOR'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'DESCRIPTION'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'APPROVED'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'INITIATED_DATE'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'END_DATE'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
ls_fieldcatalog-fieldname = 'WINNER'.
ls_fieldcatalog-tabname = 'LT_TAB'.
append ls_fieldcatalog to lt_fieldcatalog.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = lt_fieldcatalog
importing
ep_table = <fs_data>
exceptions
generate_subpool_dir_full = 1
others = 2
.
if sy-subrc <> 0.
endif.
assign <fs_data>->* to <fs_1>.
assign <fs_1> to <fs_2>.
loop at <fs_2> assigning <fs_3>.
write: <fs_3>-pollid.
endloop.
‎2007 Mar 06 6:43 AM
‎2007 Mar 06 6:48 AM
you can dynamically change your fcat then call
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING it_fieldcatalog = fcat
IMPORTING ep_table = datatab.
to create your dynamic itab according to fcat
‎2011 Mar 23 11:00 AM
Hi there,
Pls check this,
CONSTANTS : lc_structure TYPE tabname VALUE 'ZSXX.
FIELD-SYMBOLS: <lfs_s_fcat> TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = lc_structure
CHANGING
ct_fieldcat = t_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT t_fieldcat ASSIGNING <lfs_s_fcat>.
CASE <lfs_s_fcat>-fieldname.
WHEN 'PERNR'.
<lfs_s_fcat>-coltext = text-055.
WHEN 'EMP_USERID'.
<lfs_s_fcat>-coltext = text-002.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
In this initially, i'm getting the fieldcatelog from my STRUCTURE.
After that, i need to add some more fields into it. so i'm looping it and appending my values into it.
if there is anymore to done, pls reply
Be Happy!!
Enjoy!!