Show dynamic table in ALV grid
Hi !
how do I show a dynamic table in ALV GRID ?
I used the following commands:
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fieldcat[]
importing
ep_table = gt_new_table.
assign gt_new_table->* to <l_table>.
create data gs_new_line like line of <l_table>.
assign gs_new_line->* to <l_line>.
I added records into the table
Now I got a dynamic table.
How do I show it in ALV GRID ?
thanks
Adi
Hi,
Check these links
Re: Dynamic table
http://sap.ittoolbox.com/code/d.asp?a=s&d=3038
http://www.sap4.com/codigo-138.html
http://www.sapassist.com/code/d.asp?a=s&d=3365
There is an example in the report BCALV_TABLE_CREATE
report BCALV_TABLE_CREATE.
data: ok_code like sy-ucomm,
g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
grid1 type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container.
data: gt_fieldcat type lvc_t_fcat.
data: gp_table type ref to data.
field-symbols: <gt_table> type table.
parameters: n type i.
if n > 100.
message a000(0k) with 'N <= 100'.
endif.
perform fieldcat_build.
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>.
perform fill_table.
call screen 100.
Similar Messages
-
Dynamic table with alv rows & colums
Hey,
How to create dynamic internal table with alv grid rows & columns with data .TYPE-POOLS : abap.
FIELD-SYMBOLS: <f_dyn_table> TYPE STANDARD TABLE,
<f_dyn_wa>.
DATA: t_dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
wa_xfc TYPE lvc_s_fcat,
t_ifc TYPE lvc_t_fcat.
*get the structure
DATA: $field TYPE lvc_fname,
$counter(2) TYPE n.
DATA: $output_field(25) TYPE c,
$fld_len TYPE i.
FIELD-SYMBOLS: <f_out_field> TYPE ANY.
DATA : $t_idetails TYPE abap_compdescr_tab,
$wa_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( c_struc ).
$t_idetails[] = $ref_table_des->components[].
LOOP AT $t_idetails INTO $wa_xdetails.
CLEAR: wa_xfc, $output_field, $fld_len.
wa_xfc-fieldname = $wa_xdetails-name .
wa_xfc-datatype = $wa_xdetails-type_kind.
wa_xfc-inttype = $wa_xdetails-type_kind.
IF $wa_xdetails-type_kind EQ 'C'
OR $wa_xdetails-type_kind EQ 'N'.
CONCATENATE 'WA_OUTTAB' '-' $wa_xdetails-name
INTO $output_field.
ASSIGN ($output_field) TO <f_out_field>.
IF <f_out_field> IS ASSIGNED.
DESCRIBE FIELD <f_out_field> LENGTH $fld_len
IN CHARACTER MODE.
wa_xfc-intlen = $fld_len.
ENDIF.
ELSE.
wa_xfc-intlen = $wa_xdetails-length.
ENDIF.
wa_xfc-decimals = $wa_xdetails-decimals.
APPEND wa_xfc TO t_ifc.
CLEAR $wa_xdetails.
ENDLOOP.
here if you have any other fields to be added to the dynamic structure based on your requirement, you can add then and apped them to t_ifc. There is a special handling for unicode conversion- so for the numc and char fields the length is passed in a different mothed.
create dynamic internal table and assign to fs*
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_ifc
i_length_in_byte = 'X'
IMPORTING
ep_table = t_dy_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ELSE.
ASSIGN t_dy_table->* TO <f_dyn_table>.
create dynamic work area and assign to fs
CREATE DATA dy_line LIKE LINE OF <f_dyn_table>.
ASSIGN dy_line->* TO <f_dyn_wa>.
ENDIF.
*move the data into <f_dyn_wa> and then append this to output table <f_dyn_table>.
example:-
IF <f_dyn_wa> IS ASSIGNED AND <f_dyn_table> IS ASSIGNED.
MOVE-CORRESPONDING wa_outtab TO <f_dyn_wa>.
APPEND <f_dyn_wa> TO <f_dyn_table>.
endif.
Edited by: Krishna Adabala on Dec 2, 2008 7:57 AM -
Modifying database table in ALV Grid
Hi all.
I need to be able to modify the database table in ALV Grid. Here's the code. The database table, that is displayed is 'zng_so_head', it's internal table is 'res_tab'. In the program i tried to create a button 'CHANGE' on the ALV-toolbar, but when executing the program there's no such button (why?). What code, screens, screen elements, etc. should be added to this program to provide a possibility of changing data of the database table 'zng_so_head' (i mean changing existing data, adding new lines and saving changes)?
CODE:
& Report ZNG_ALV_TC_EDIT_SIMP&
REPORT ZNG_ALV_TC_EDIT_SIMP.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
TABLES: zng_so_head, zng_cust, zng_vendors.
*-- STRUCTURE OF INTERNAL TABLE
TYPES: BEGIN OF in_tab,
so_num TYPE zng_so_head-so_num, "type numc
vend_num TYPE zng_so_head-vend_num, "type numc
cust_num TYPE zng_so_head-cust_num, "type numc
so_date TYPE zng_so_head-so_date, "type dats
END OF in_tab.
*-- INTERNAL TABLE HOLDING LIST DATA
DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
*-- FILLING IN INTERNAL TABLE
SELECT hso_num hvend_num hcust_num hso_date
INTO TABLE res_tab FROM zng_so_head AS h.
*& Form prepare_field_catalog
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'SO_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'SO_NUM'.
ls_fcat-seltext = 'SO_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VEND_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'VEND_NUM'.
ls_fcat-seltext = 'VEND_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'CUST_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'CUST_NUM'.
ls_fcat-seltext = 'CUST_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'SO_DATE'.
ls_fcat-inttype = 'D'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'SO_DATE'.
ls_fcat-seltext = 'SO_DATE'.
APPEND ls_fcat TO pt_fieldcat.
ENDFORM. "prepare_field_catalog
*& Form display_alv
FORM display_alv.
IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING container_name = gc_custom_control_name.
CREATE OBJECT gr_alvgrid
EXPORTING i_parent = gr_ccontainer.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = res_tab[]
it_fieldcatalog = gt_fieldcat.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display.
ENDIF.
ENDFORM. "display_alv
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA object_ref TYPE REF TO lcl_event_handler.
START-OF-SELECTION.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT
MODULE display_alv OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
ENDMODULE. "display_alv OUTPUT
MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ELSE.
CALL METHOD object_ref->handle_toolbar.
ENDIF.
ENDMODULE. "status_0100 INPUT
END OF CODE
Thanks all.Hi,
For the button on the toolbar,here is the code:
CLASS lcl_eh IMPLEMENTATION.
*METHOD: HANDLE_TOOLBAR
*DESCRIPTION: This method provides the necessary detail required to
create an extra button in the toolbar.
METHOD handle_toolbar.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE 0 TO ls_toolbar-butn_type.
MOVE CHANGETO ls_toolbar-text.
MOVE 'ICON_DETAIL' TO ls_toolbar-icon.
MOVE 'CHANGE' TO ls_toolbar-quickinfo.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
Also,if you are using the CHANGE button to record changes in the DB,then in the local class that you have defined,you should use the following method and then write the logic:
*METHOD: HANDLE_USER_COMMAND
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'CHANGE'.
CHECK_CHANGED_DATA
REFRESH_TABLE_DISPLAY
Now call the methods that i have given in my previous post.This function code will be checked at the event you click the button 'CHANGE'.I think you have done this in an ELSE condition in the PAI of the screen.Not too sure if it works in the PAI.
Regards,
Beejal
**Reward if this helps -
Show dynamic columns in ALV table
I have a question that i need to create report in ALV
like this ...
i need to select doc date e.g. from 03.11.2007 to 05.02.2008
and the report is expected to show like this
SO# | cust | sales gp | 2007-11 order amt | 2007-12 order amt | 2008-01 order amt | 2008-02 order amt
____ |_____|________|________________|________________|________________|_________________
| | | | | |
something like that ....
the no. of period column which is depend on the range of selected doc date....
so how to do that ?!?!?hi sky ,
use dynamic table as:-
Declaration for Dynamic Table:-
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_table1> TYPE STANDARD TABLE,
<dyn_wa1>,
<dyn_wa>.
FIELD-SYMBOLS: <l_fs_dyn> TYPE ANY,
<l_fs_bom> TYPE ANY.
*---Dynamic Internal Table
DATA: dy_table TYPE REF TO data,
dy_table1 TYPE REF TO data,
dy_line TYPE REF TO data.
Creation of Dynamic Internal Table:-
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fcat (for which internal table needs to be built)
IMPORTING
ep_table = dy_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2
IF sy-subrc <> 0.
ENDIF.
Population of Dynamic Internal Table:-
CLEAR: l_tabix,
w_tabix.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ASSIGN dy_table->* TO <dyn_table1>.
CREATE DATA dy_line LIKE LINE OF <dyn_table1>.
ASSIGN dy_line->* TO <dyn_wa1>.
LOOP AT it_parent.
l_tabix = sy-tabix.
LOOP AT fcat INTO ls_fcat TO 23."WHERE col_pos <= '19'.
ASSIGN COMPONENT ls_fcat-fieldname
OF STRUCTURE <dyn_wa> TO <l_fs_dyn>.
ASSIGN COMPONENT ls_fcat-fieldname
OF STRUCTURE it_parent TO <l_fs_bom>.
<l_fs_dyn> = <l_fs_bom>.
ENDIF.
ENDLOOP
Thanks & Regards,
Ruchi Tiwari -
Subtotals in dynamic internal table using alv grid
hi experts i have created one dynamic table. The requirement is to display the subtotals in the output using reuse_alv_grid.
Dynamic itab (field-symbols) and ALV event BEFORE_LINE_OUTPUT
the above is the thread related and could any one please provide the sample code for this task.
can any one post the solution for that.
rewards points will be awarded.
khazi* ASSINING STRUCTURE FOR FILD CATLOGS
DATA: DYN_TABLE TYPE REF TO DATA,
DYN_LINE TYPE REF TO DATA,
LS_FIELDCAT TYPE LVC_S_FCAT,
LT_FIELDCAT TYPE LVC_T_FCAT.
LOOP AT LT_DMTAB INTO LS_DMTAB.
CLEAR LS_FIELDCAT.
LS_FIELDCAT-FIELDNAME = LS_DMTAB-SDATE .
LS_FIELDCAT-DATATYPE = 'DEC'.
LS_FIELDCAT-INTTYPE = 'P'.
LS_FIELDCAT-INTLEN = '16' .
LS_FIELDCAT-DECIMALS = '03'.
LS_FIELDCAT-JUST = 'C'.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
ENDLOOP.
*& For grouping the table rows for Under Line
LS_FIELDCAT-FIELDNAME = 'ULFIELD' .
LS_FIELDCAT-DATATYPE = 'INT'.
LS_FIELDCAT-INTTYPE = 'P'.
LS_FIELDCAT-INTLEN = '2' .
LS_FIELDCAT-DECIMALS = ''.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
"* Create dynamic internal table and assign to Field-Symbol
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = LT_FIELDCAT
IMPORTING
EP_TABLE = DYN_TABLE.
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 DYN_TABLE->* TO <LT_AREA_F>.
"* Create dynamic work area and assign to Field Symbol
CREATE DATA DYN_LINE LIKE LINE OF <LT_AREA_F>.
ASSIGN DYN_LINE->* TO <LS_AREA_F>.
You check in Field cat level you will get Check Sub total field will exist
Thanks and regards
Jogu -
Hi Folks,
can any body please give some input on the follwoing.
i want to display material created by and material
created on for each material based on material selection
from selction screen dynamically.
like s_mat = 1, 2,3.
o/p must be
mat1 |creted by | creted on| mat2 |creted by | creted on|mat3 |creted by | creted on|
like if iam inputting 3 materials i need 3*3 = 9 columns in my alv grid o/p.
I have alreaady searched SDN I am not gettting any thing related to my requirement, please post some sample caode as I am new ot OOABAP.
Thanks,
Shwetha.
Moderator message : Not enough re-search before posting, specification dumping not allowed. Thread locked.
Edited by: Vinod Kumar on Nov 24, 2011 1:31 PMmethod handle_data_changed.
data: ls_good type lvc_s_modi,
li_diff type i,
value type p DECIMALS 3,
old_value type p DECIMALS 3,
lw_outtab1 type gt_tab.
clear value.
loop at er_data_changed->mt_good_cells into ls_good.
value = ls_good-value.
old_value = ls_good-value.
if value lt 0 or value gt 1.
MESSAGE 'Value is out of range' TYPE 'I'.
Read table gt_outtab1 into lw_outtab1 index ls_good-row_id .
perform show_alv.
clear ls_good.
ENDIF.
ENDCASE.
ENDLOOP.
I again created the table.. actually data is not changed in the internal table but still it shows the changed value in the alv grid. even in build the table again and call the refersh alv grid method.. -
Dsiplay Dynamic Column in ALV Grid
Hellow everyone,
i am using alv grid to display the stock in detail , I need date and stock qnty with labour hour dynamic , my requriend output is:
LVside HV side Coreside
StockNumber Qnty Date Qnty Date Qnty Date
10000014 14.1 10/11/2011 12.2 11/11/2011
Plz tell me how can iget this , The LVside and HVside is constant and Qnty date label also constant only date and Qnty will change.
ThanksHi venkatesh even my requirment is same,
yes you are correct venkatesh actually i have static column but as you see i am getting the data as per follow
in LVside total Qnty is 14.2 on Date 10.11.2011 of stockNum 100008 , so my requried out put is something like below
StockNum LVside .... ..........................HVside
Qnty | Date Qnty | Date
1000008 14.2 10.11.2011 5.2 11.11.2011
My current Out put is :
StockNum 10.11.2011 .................11.11.2011
1000008 14.2 5.2
my refer code is :
DATA: BEGIN OF i_alv OCCURS 0,
ARBID TYPE AFRU-ARBID,
BUDAT TYPE AFRU-BUDAT,
WERKS TYPE AFRU-WERKS,
LMNGA TYPE AFRU-LMNGA,
AUFNR TYPE AFRU-AUFNR,
KDAUF TYPE AUFK-KDAUF,
KDPOS TYPE AUFK-KDPOS,
VBELN TYPE VBAK-VBELN,
KUNNR TYPE VBAK-KUNNR,
NAME1 TYPE KNA1-NAME1,
MATNR TYPE VBAP-MATNR,
KDKG1 TYPE VBKD-KDKG1,
end of i_alv.
TYPES: BEGIN OF ty_data,
BUDAT TYPE AFRU-BUDAT,
ARBID TYPE AFRU-ARBID,
aufnr TYPE AFRU-AUFNR,
kdauf TYPE AUFK-KDAUF,
name1 TYPE KNA1-NAME1,
matnr TYPE VBAP-MATNR,
kdkg1 TYPE VBKD-KDKG1,
lmnga TYPE AFRU-LMNGA,
END OF ty_data,
tt_data TYPE STANDARD TABLE OF ty_data,
BEGIN OF ty_dyn1, "#EC NEEDED
* ARBID TYPE AFRU-ARBID,
* aufnr TYPE AFRU-AUFNR,
kdauf TYPE AUFK-KDAUF,
name1 TYPE KNA1-NAME1,
matnr TYPE VBAP-MATNR,
kdkg1 TYPE VBKD-KDKG1,
kdkg2 TYPE VBKD-KDKG2,
lmnga TYPE AFRU-LMNGA,
END OF ty_dyn1,
BEGIN OF ty_dyn2, "#EC NEEDED
date TYPE AFRU-LMNGA,
END OF ty_dyn2,
BEGIN OF ty_cols,
date TYPE BUDAT,
END OF ty_cols,
tt_cols TYPE SORTED TABLE OF ty_cols WITH UNIQUE KEY date.
DATA: gt_data TYPE tt_data,
gt_data2 type tt_data,
gt_cols TYPE tt_cols,
gs_col TYPE ty_cols.
thanks -
Hello experts,
is it possible to call an ALV via ( class cl_salv or fm REUSE_ALV_GRID_DISPLAY) with a dynamic table?
This dynamic table has for example one fix column for the material number and dynamic colums for additional data.
One material has 1 additional column, the other material has two additional columns.
So i need an ALV with 3 columns material add_data1 add_data2 (add_data2 of material one is empty this is ok).
To build an itab which can handle this is possible i know.Hello Benjamin,
Maybe you already found a solution for this, but if not (or for others looking for a solution), here is a sample program that creates, fills, and displays a dynamic table:
report ztpar_dynamic_salv.
parameters: p_colnr type i default 3.
start-of-selection.
perform execute.
form execute.
data t_table type ref to data.
** create dynamic table
perform create_dynamic_table using p_colnr
changing t_table.
** fill dynamic table
perform fill_dynamic_table changing t_table.
** display dynamic table
perform display_table using t_table.
endform.
form create_dynamic_table using colnr type i
changing table type ref to data.
data: lo_field type ref to cl_abap_typedescr,
lo_struct type ref to cl_abap_structdescr,
lo_table type ref to cl_abap_tabledescr.
data: t_comp type cl_abap_structdescr=>component_table,
l_comp like line of t_comp.
lo_field ?= cl_abap_typedescr=>describe_by_name( 'CHAR10' ).
do p_colnr times.
move sy-index to l_comp-name.
concatenate 'COLUMN' l_comp-name into l_comp-name.
condense l_comp-name no-gaps.
l_comp-type ?= lo_field.
append l_comp to t_comp.
enddo.
lo_struct = cl_abap_structdescr=>create( p_components = t_comp p_strict = space ).
lo_table = cl_abap_tabledescr=>create( lo_struct ).
create data table type handle lo_table.
endform.
form fill_dynamic_table changing table type ref to data.
field-symbols: <fs_table> type standard table,
<fs_line> type any,
<fs_field> type any.
assign table->* to <fs_table>.
do 5 times.
append initial line to <fs_table> assigning <fs_line>.
do.
assign component sy-index of structure <fs_line> to <fs_field>.
if sy-subrc ne 0.
exit.
endif.
<fs_field> = sy-index.
enddo.
enddo.
endform.
form display_table using i_table type ref to data.
data lo_alv type ref to cl_salv_table.
field-symbols <fs_tab> type any table.
assign i_table->* to <fs_tab>.
try.
cl_salv_table=>factory(
importing
r_salv_table = lo_alv
changing
t_table = <fs_tab> ).
catch cx_salv_msg.
message 'Cannot display result!' type 'E'.
endtry.
lo_alv->display( ).
endform.
Best regards,
Tanguy -
Making cell non editabale (of dynamic table) in alv
Hi,
I am working on a editable alv with a dynamic table <itab> .This table gets populated during runtime.Now I want to make few cell of this table not editabale (only few cell not the full columns) I knwo that the procedure is to
declare my outtab like
TYPES: BEGIN OF gs_outtab.
TYPES: celltab TYPE lvc_t_styl. "field to switch editability
INCLUDE TYPE /npu/edmt_aa_eac.
TYPES: END OF gs_outtab.
and in the celltab i pass the information of cells which will be non editable...But the problem is as my outtab is a dynamic table I cannot INCLUDE IT IN ANOTHER types.
Please help me how to do it???? Or is there any other way of doing it???Hi Priya
Add the field of type lvc_t_styl while creating the field catalog.
Now
DATA lo_table TYPE REF TO data.
cl_alv_table_create=>create_dynamic_table(
EXPORTING
it_fieldcatalog = lt_fieldcat "the field catalog table
IMPORTING
ep_table = lo_table ). "the reference to the table gt_outtab with the style tab
FIELD-SYMBOLS <tab> TYPE ANY TABLE.
ASSIGN lo_table->* TO <tab> .
Now you can fill your <tab>.
Pushpraj -
How to print to tables in ALV grid
hi all
I have 2 internal tables with some values
i want to display the 2 internal tables in the grid one after another with some title
can anyone tell me how to do it
Thank you.i think in grid you can not do like this (By using function module). But you can do it in OO approach for that just check the se38 with alvgrid* and search. you can findout lot of example there. And one more option is there by using alv block but it is a list display.
Just check this sample program of alv block
TYPE-POOLS : SLIS.
TABLES : EKKO,EKPO.
DATA : BEGIN OF IEKKO OCCURS 0,
EBELN LIKE EKKO-EBELN,
AEDAT LIKE EKKO-AEDAT,
END OF IEKKO.
DATA : BEGIN OF IEKPO OCCURS 0,
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MATNR LIKE EKPO-MATNR,
MENGE LIKE EKPO-MENGE,
MEINS LIKE EKPO-MEINS,
END OF IEKPO.
DATA : IFIELDCATEKKO TYPE SLIS_T_FIELDCAT_ALV,
IFIELDCATEKPO TYPE SLIS_T_FIELDCAT_ALV,
WFIELDCAT TYPE SLIS_FIELDCAT_ALV,
ILAYOUT TYPE SLIS_LAYOUT_ALV,
IEVENTHEAD TYPE SLIS_T_EVENT,
IEVENTITEM TYPE SLIS_T_EVENT,
WEVENT TYPE SLIS_ALV_EVENT,
ISORT TYPE SLIS_T_SORTINFO_ALV,
WSORT TYPE SLIS_SORTINFO_ALV.
PARAMETERS : P_NUM(3) TYPE N DEFAULT 10.
PERFORM GET_DATA_EKKO.
PERFORM GET_DATA_EKPO.
PERFORM BUILD_FCAT_HEAD.
PERFORM BUILD_FCAT_ITEM.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_EVENT_TAB.
PERFORM DISPLAY_BLOCK.
*& Form GET_DATA_EKKO
* text
* --> p1 text
* <-- p2 text
FORM GET_DATA_EKKO .
SELECT EBELN AEDAT INTO TABLE IEKKO FROM EKKO UP TO P_NUM ROWS WHERE EBELN LIKE '45000057%'.
ENDFORM. " GET_DATA_EKKO
*& Form GET_DATA_EKPO
* text
* --> p1 text
* <-- p2 text
FORM GET_DATA_EKPO .
IF NOT IEKKO[] IS INITIAL.
SELECT EBELN EBELP MATNR MENGE MEINS INTO TABLE IEKPO FROM EKPO FOR ALL ENTRIES IN IEKKO
WHERE EBELN = IEKKO-EBELN.
ENDIF.
ENDFORM. " GET_DATA_EKPO
*& Form DISPLAY_BLOCK
* text
* --> p1 text
* <-- p2 text
FORM DISPLAY_BLOCK .
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT
IT_FIELDCAT = IFIELDCATEKKO
I_TABNAME = 'IEKKO'
IT_EVENTS = IEVENTHEAD[]
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = IEKKO
EXCEPTIONS
PROGRAM_ERROR = 1
MAXIMUM_OF_APPENDS_REACHED = 2
OTHERS = 3
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
IS_LAYOUT = ILAYOUT
IT_FIELDCAT = IFIELDCATEKPO
I_TABNAME = 'IEKPO'
IT_EVENTS = IEVENTITEM
* IT_SORT =
* I_TEXT = ' '
TABLES
T_OUTTAB = IEKPO
* EXCEPTIONS
* PROGRAM_ERROR = 1
* MAXIMUM_OF_APPENDS_REACHED = 2
* OTHERS = 3
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
* EXPORTING
* I_INTERFACE_CHECK = ' '
* IS_PRINT =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
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.
ENDFORM. " DISPLAY_BLOCK
*& Form BUILD_FCAT_HEAD
* text
* --> p1 text
* <-- p2 text
FORM BUILD_FCAT_HEAD .
WFIELDCAT-FIELDNAME = 'EBELN'.
WFIELDCAT-TABNAME = 'IEKKO'.
WFIELDCAT-SELTEXT_L = 'Pur. Doc no'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKKO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'AEDAT'.
WFIELDCAT-TABNAME = 'IEKKO'.
WFIELDCAT-SELTEXT_L = 'Pur. doc date'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKKO.
CLEAR WFIELDCAT.
ENDFORM. " BUILD_FCAT_HEAD
*& Form BUILD_FCAT_ITEM
* text
* --> p1 text
* <-- p2 text
FORM BUILD_FCAT_ITEM .
WFIELDCAT-FIELDNAME = 'EBELN'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'Pur. Doc no'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'EBELP'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'Pur. Doc item'.
*wfieldcat-do_sum = 'X'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MATNR'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'Material no'.
WFIELDCAT-OUTPUTLEN = 18.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MENGE'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'P.O. Qty'.
wfieldcat-do_sum = 'X'.
*WFIELDCAT-DATATYPE = 'QUAN'.
WFIELDCAT-OUTPUTLEN = 15.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
WFIELDCAT-FIELDNAME = 'MEINS'.
WFIELDCAT-TABNAME = 'IEKPO'.
WFIELDCAT-SELTEXT_L = 'UOM'.
WFIELDCAT-OUTPUTLEN = 3.
APPEND WFIELDCAT TO IFIELDCATEKPO.
CLEAR WFIELDCAT.
ENDFORM. " BUILD_FCAT_ITEM
*& Form BUILD_LAYOUT
* text
* --> p1 text
* <-- p2 text
FORM BUILD_LAYOUT .
ILAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ENDFORM. " BUILD_LAYOUT
*& Form BUILD_EVENT_TAB
* text
* --> p1 text
* <-- p2 text
FORM BUILD_EVENT_TAB .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = IEVENTHEAD
* EXCEPTIONS
* LIST_TYPE_WRONG = 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.
IEVENTITEM = IEVENTHEAD.
READ TABLE IEVENTHEAD INTO WEVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC = 0.
WEVENT-FORM = 'TOPOFPAGEHEAD'.
MODIFY IEVENTHEAD FROM WEVENT INDEX SY-TABIX.
ENDIF.
READ TABLE IEVENTHEAD INTO WEVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC = 0.
WEVENT-FORM = 'USERCOMMAND'.
MODIFY IEVENTHEAD FROM WEVENT INDEX SY-TABIX.
ENDIF.
READ TABLE IEVENTITEM INTO WEVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC = 0.
WEVENT-FORM = 'TOPOFPAGEITEM'.
MODIFY IEVENTITEM FROM WEVENT INDEX SY-TABIX.
ENDIF.
ENDFORM. " BUILD_EVENT_TAB
FORM USERCOMMAND USING PUCOMM LIKE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.
CASE PUCOMM.
WHEN '&IC1'.
WHEN 'OTHERS'.
ENDCASE.
ENDFORM.
FORM TOPOFPAGEHEAD.
DATA : ILIST TYPE SLIS_T_LISTHEADER,
WLIST TYPE SLIS_LISTHEADER.
WLIST-INFO = 'Header data with P.O. no and creating date'.
WLIST-TYP = 'H'.
APPEND WLIST TO ILIST.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ILIST
* I_LOGO =
* I_END_OF_LIST_GRID =
ENDFORM.
FORM TOPOFPAGEITEM.
DATA : ILIST TYPE SLIS_T_LISTHEADER,
WLIST TYPE SLIS_LISTHEADER.
WLIST-INFO = 'Item data with P.O.item material no and qty'.
WLIST-TYP = 'H'.
APPEND WLIST TO ILIST.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ILIST
* I_LOGO =
* I_END_OF_LIST_GRID =
ENDFORM.
regards
shiba dutta -
Two Internal Tables for ALV Grid
Hi Gurus,
I have a little problem here. I have a report to display cost of production. The rows is about 50 displaying amount in dollars (currency fields). I have this in ALV Grid. But my problem is that the last 4 lines of the report are not currency fields like the others, they are quantity fields.
How can i go about to display this last 4 lines in this ALV Grid. They are from different internal tables off course because of the data type.
In short. I just want to display these 2 internal tables in an ALV Grid.
Thanks in Advance.Hi,
u can use ALV Block list to display 2 ALV.
Reffer to the below code.
DATA: v_layout TYPE slis_layout_alv.
DATA: ls_print TYPE slis_print_alv.
PERFORM build_fieldcatalog.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
EXPORTING
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* IT_EXCLUDING =
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = v_layout
it_fieldcat = it_fcat_nlei
i_tabname = 'IT_NLEI_ALV'
it_events = it_event_nlei
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_nlei_alv
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
EXPORTING
is_layout = v_layout
it_fieldcat = it_fcat_vbrp
i_tabname = 'IT_VBRP_ALV'
it_events = it_event_vbrp
* IT_SORT =
* I_TEXT = ' '
TABLES
t_outtab = it_vbrp_alv
EXCEPTIONS
program_error = 1
maximum_of_appends_reached = 2
OTHERS = 3.
ls_print-no_print_selinfos = 'X'. " Display no selection infos
ls_print-no_print_listinfos = 'X'. " Display no listinfos
ls_print-reserve_lines = 2. " Lines reserved for end of page
CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
is_print = ls_print
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
EXCEPTIONS
program_error = 1
OTHERS = 2 -
Hi all
i have the following types:
<begin of type1,
fieldA type i ,
fieldB type i,
<end of type1,
<begin of type2,
fieldC type i
fieldA type i,
<end of type2,
<begin of type3,
fieldA type i,
fieldB type i,
fieldC type i,
<end of type3,
<begin of type4,
fieldA type i
fields1 type type1 occurs 4,
fields2 type type2 occurs 5,
fields3 type type3 occurs 7,
fieldD type i,
<end of type4.
I would like to set a internal table of type4 in an ALV grid. How do you do this? because i thought it could
like to hear from you! And off course << Moderator message - Please do not offer points >>
kind regards
Anton
Edited by: Rob Burbank on Nov 9, 2010 2:03 PMI have found another solution. I make one internal table with all the fields in it. It is not what i like, but it works...
thanks all for your replies!
kind regards
Anton Pierhagen -
Hi,
I am trying to use class CL_ALV_CHANGED_DATA_PROTOCOL to update a database table from an ALV grid.
I have used program BCALV_EDIT_04 as an example.
I am able to successfully processed inserted or deleted lines using the attributes
MT_DELETED_ROWS
MT_INSERTED_ROWS
but I also want to process modified lines.
I was just wondering whether anyone out there has some example code for this.
I can see that there are the following attributes available
MT_MOD_CELLS
MP_MOD_ROWS.
I would ideally like to use MP_MOD_ROWS rather than MT_MOD_CELLS but it is not clear to me what type MP_MOD_ROWS is.
If anyone has any example code for this sort of thing, please let me know.
Thanks,
Rubyhi Ruby,
Yes we can use that *data reference variable *.
It is a variable( something comparable to a pointer ) that points to a int table( table with changed contents )
which ll be created at run-time based on the data type ot the internal table that we pass to the parameter it_outtab of method set_table_for_first_display ...
assign er_data_changed->mp_mod_rows->* to a field-symbol and use it...
Check the below code for example -> method refresh_changed_data
screen flow logic.
PROCESS BEFORE OUTPUT.
MODULE pbo.
PROCESS AFTER INPUT.
MODULE pai.
main program.
* CLASS lcl_event_responder DEFINITION *
CLASS lcl_event_responder DEFINITION.
PUBLIC SECTION.
DATA : ls_changed_cell TYPE lvc_s_modi,
lv_language TYPE spras..
METHODS refresh_changed_data FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed
e_ucomm.
ENDCLASS. "event_responder DEFINITION
TYPES tt_makt TYPE STANDARD TABLE OF makt.
DATA: go_handler TYPE REF TO lcl_event_responder,
go_grid TYPE REF TO cl_gui_alv_grid,
gt_fieldcat TYPE lvc_t_fcat,
gv_language TYPE spras VALUE 'E',
gt_outtab TYPE tt_makt,
gs_tableline TYPE LINE OF tt_makt.
FIELD-SYMBOLS : <changed_rows> TYPE tt_makt.
CALL SCREEN 100.
* MODULE PBO OUTPUT *
MODULE pbo OUTPUT.
SET PF-STATUS 'BASIC'.
PERFORM create_and_init_alv CHANGING gt_outtab[]
gt_fieldcat.
ENDMODULE. "pbo OUTPUT
* MODULE PAI INPUT *
MODULE pai INPUT.
LEAVE PROGRAM.
ENDMODULE. "pai INPUT
FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
pt_fieldcat TYPE lvc_t_fcat.
CHECK go_grid IS NOT BOUND.
CREATE OBJECT go_grid
EXPORTING
i_parent = cl_gui_container=>default_screen.
PERFORM build_display_table.
PERFORM build_fieldcat CHANGING pt_fieldcat.
go_grid->set_table_for_first_display( CHANGING it_fieldcatalog = pt_fieldcat
it_outtab = pt_outtab ).
go_grid->set_ready_for_input( 1 ).
* raises the 'data_changed' event when we select another cell/any action after changing the data
go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
CREATE OBJECT go_handler.
SET HANDLER go_handler->refresh_changed_data FOR go_grid.
ENDFORM. "CREATE_AND_INIT_ALV
FORM build_display_table.
FREE gt_outtab.
SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
ENDFORM. "build_display_table
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'MAKT'
CHANGING
ct_fieldcat = pt_fieldcat.
LOOP AT pt_fieldcat INTO ls_fcat.
ls_fcat-edit = abap_true.
MODIFY pt_fieldcat FROM ls_fcat.
ENDLOOP.
ENDFORM. "build_fieldcat
* CLASS event_responder IMPLEMENTATION *
CLASS lcl_event_responder IMPLEMENTATION.
METHOD refresh_changed_data.
ASSIGN er_data_changed->mp_mod_rows->* TO <changed_rows>.
LOOP AT <changed_rows> INTO gs_tableline.
BREAK-POINT.
ENDLOOP.
ENDMETHOD. "click
ENDCLASS. "event_responder IMPLEMENTATION
Cheers,
Jose. -
Modifying database table through ALV-Grid
Hi all.
I need to modify a database table (ZNG_SO_HEAD) by entering data in ALV-Grid, which displays its internal table (exact copy of ZNG_SO_HEAD), and clicking the button ('CHANGE') on the ALV-toolbar. The ALV is already editable, the button already exists. Here is the code. After changing data in ALV and clicking 'CHANGE' on the toolbar the database table ZNG_SO_HEAD remains unchangeable, but i need to change data in it somehow.
Thanks all.
REPORT zng_alv_tc_edit_simp.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
TABLES: zng_so_head, zng_cust, zng_vendors.
*-- STRUCTURE OF INTERNAL TABLE
TYPES: BEGIN OF in_tab,
mandt TYPE zng_so_head-mandt,
so_num TYPE zng_so_head-so_num, "type numc
vend_num TYPE zng_so_head-vend_num, "type numc
cust_num TYPE zng_so_head-cust_num, "type numc
so_date TYPE zng_so_head-so_date, "type dats
END OF in_tab.
*-- INTERNAL TABLE HOLDING LIST DATA
DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
*DATA wa_res_tab LIKE LINE OF res_tab.
*-- FILLING IN INTERNAL TABLE
SELECT h~mandt h~so_num h~vend_num h~cust_num h~so_date
INTO TABLE res_tab FROM zng_so_head AS h.
* CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* to add new functional buttons to the alv toolbar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
* to implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
* CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
MOVE 3 TO ls_toolbar-butn_type.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar>
METHOD handle_user_command.
DATA:l_valid TYPE c.
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD gr_alvgrid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
MODIFY zng_so_head FROM res_tab.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA object_ref TYPE REF TO lcl_event_handler.
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
>>>>>>done correctly>>>>>>>>>
FORM display_alv.
>>>>>>done correctly>>>>>>>>>
START-OF-SELECTION.
CALL SCREEN 100.
* MODULE STATUS_0100 OUTPUT
MODULE display_alv OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
ENDMODULE. "display_alv OUTPUT
* MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ELSE.
CALL METHOD object_ref->handle_toolbar.
CALL METHOD object_ref->handle_user_command.
ENDIF.
ENDMODULE.Hello Nikolai,
I have written a sample code taking care of all the requirements(button in the toolbar and changes saved in database).I have used SPFLI table and the internal table i_spfli.This code works and the change is also made in the database table.
REPORT SAMPLE.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
Data:i_spfli type table of spfli.
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
DATA:l_valid TYPE c.
DATA: ls_toolbar TYPE stb_button.
METHODS:
to add new functional buttons to the alv toolbar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
to implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE 'ICON_CHANGE' TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar>
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD gr_alvgrid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
MODIFY spfli FROM table i_spfli.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
DATA object_ref TYPE REF TO lcl_event_handler.
select * from spfli into table i_spfli.
Call screen 100.
MODULE STATUS_0100 OUTPUT
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
ENDMODULE. "display_alv OUTPUT
MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
*& Form display_alv
FORM display_alv.
*IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING container_name = gc_custom_control_name.
CREATE OBJECT gr_alvgrid
EXPORTING i_parent = gr_ccontainer.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = i_spfli[]
it_fieldcatalog = gt_fieldcat.
ENDFORM. "display_alv
*& Form prepare_field_catalog
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'CARRID'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'CONNID'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'DEPTIME'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ARRTIME'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
endform.
Hope this helps.
Regards,
Beejal -
How to show check box in ALV grid??
Hi All,
I am using an option edit in the feild catalogue which allows me to change the values in a few columns in the ALV list.
What I want is to be able to show a check box in a few columns which user can check and use the value X in the program for the later processing....
Can somebody tell me how to show a check box in the ALV screen in the changeable format??
Win full point by answering this typical question..
Thanks - Chandanhi go through the fallowing code.
*& Report YGS_ALV_BOM *
REPORT YGS_ALV_BOM .
TABLES : MAST,STKO,STPO.
TYPE-POOLS: SLIS.
TYPES : BEGIN OF TY_MAST,
CHECK_BOX,
MATNR TYPE MAST-MATNR,
WERKS TYPE MAST-WERKS,
STLAN TYPE MAST-STLAN,
STLNR TYPE MAST-STLNR,
STLAL TYPE MAST-STLAL,
END OF TY_MAST.
TYPES : BEGIN OF TY_STKO,
STLTY TYPE STKO-STLTY,
STLNR TYPE STKO-STLNR,
STLAL TYPE STKO-STLAL,
STKOZ TYPE STKO-STKOZ,
BMENG TYPE STKO-BMENG,
BMEIN TYPE STKO-BMEIN,
END OF TY_STKO.
TYPES : BEGIN OF TY_STPO,
LIGHTS,
STLTY TYPE STPO-STLTY,
STLNR TYPE STPO-STLNR,
STLKN TYPE STPO-STLKN,
STPOZ TYPE STPO-STPOZ,
IDNRK TYPE STPO-IDNRK,
MENGE TYPE STPO-MENGE,
MEINS TYPE STPO-MEINS,
END OF TY_STPO.
DATA : IT_MAST TYPE TABLE OF TY_MAST,
WA_MAST TYPE TY_MAST,
IT_STKO TYPE TABLE OF TY_STKO,
WA_STKO TYPE TY_STKO,
IT_STPO TYPE TABLE OF TY_STPO,
WA_STPO TYPE TY_STPO.
DATA : lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_layout TYPE slis_layout_alv,
ls_event TYPE slis_alv_event,
lt_event TYPE slis_t_event,
it_sortinfo type slis_t_sortinfo_alv,
ls_header TYPE slis_listheader,
lt_header TYPE slis_t_listHEADER.
DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
SELECT-OPTIONS : S_MATNR FOR MAST-MATNR.
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM BUILD_FIELDCAT USING LT_FIELDCAT.
PERFORM BUILD_LAYOUT.
END-OF-SELECTION.
PERFORM DISPLAY_DATA.
*& Form GET_DATA
* text
* --> p1 text
* <-- p2 text
form GET_DATA .
REFRESH : IT_MAST.
SELECT MATNR
WERKS
STLAN
STLNR
FROM MAST
INTO CORRESPONDING FIELDS OF TABLE IT_MAST
WHERE MATNR IN S_MATNR.
endform. " GET_DATA
*& Form BUILD_FIELDCAT
* text
* --> p1 text
* <-- p2 text
form BUILD_FIELDCAT USING LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA : L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
REFRESH : LT_FIELDCAT.
L_FIELDCAT-COL_POS = 1.
L_FIELDCAT-FIELDNAME = 'MATNR'.
L_FIELDCAT-TABNAME = 'IT_MAST'.
L_FIELDCAT-REF_FIELDNAME = 'MATNR'.
L_FIELDCAT-REF_TABNAME = 'MAST'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
L_FIELDCAT-COL_POS = 2.
L_FIELDCAT-FIELDNAME = 'WERKS'.
L_FIELDCAT-TABNAME = 'IT_MAST'.
L_FIELDCAT-REF_FIELDNAME = 'WERKS'.
L_FIELDCAT-REF_TABNAME = 'MAST'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
L_FIELDCAT-COL_POS = 3.
L_FIELDCAT-FIELDNAME = 'STLNR'.
L_FIELDCAT-TABNAME = 'IT_MAST'.
L_FIELDCAT-REF_FIELDNAME = 'STLNR'.
L_FIELDCAT-REF_TABNAME = 'MAST'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
endform. " BUILD_FIELDCAT
*& Form BUILD_LAYOUT
* text
* --> p1 text
* <-- p2 text
form BUILD_LAYOUT .
CLEAR LS_LAYOUT.
LS_LAYOUT-BOX_FIELDNAME = 'CHECK_BOX'.
LS_LAYOUT-BOX_TABNAME = 'IT_MAST'.
endform. " BUILD_LAYOUT
*& Form DISPLAY_DATA
* text
* --> p1 text
* <-- p2 text
form DISPLAY_DATA .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* I_STRUCTURE_NAME =
IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = LT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = IT_MAST
* 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.
endform. " DISPLAY_DATA
FORM PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'YSTATUS' OF PROGRAM SY-REPID
EXCLUDING RT_EXTAB.
ENDFORM.
FORM USER_COMMAND USING RF_UCOMM TYPE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
CASE RF_UCOMM.
WHEN '&NEXT'.
PERFORM GET_DATA_BOM .
PERFORM BUILD_FIELDCAT_BOM USING LT_FIELDCAT.
PERFORM BUILD_LAYOUT_BOM.
PERFORM DISPLAY_DATA_BOM.
ENDCASE.
ENDFORM.
*& Form GET_DATA_BOM
* text
* --> p1 text
* <-- p2 text
form GET_DATA_BOM .
CLEAR : WA_STPO,
WA_MAST.
REFRESH : IT_STPO.
DATA : IT_CHECK TYPE TABLE OF TY_MAST.
LOOP AT IT_MAST INTO WA_MAST.
IF WA_MAST-CHECK_BOX EQ 'X'.
APPEND WA_MAST TO IT_CHECK.
ENDIF.
ENDLOOP.
SELECT STLTY
STLNR
STLKN
VGKNT
IDNRK
MENGE
MEINS
FROM STPO
INTO CORRESPONDING FIELDS OF TABLE IT_STPO
FOR ALL ENTRIES IN IT_CHECK
WHERE IDNRK EQ IT_CHECK-MATNR.
CLEAR WA_STPO.
LOOP AT IT_STPO INTO WA_STPO.
SELECT SINGLE * FROM MAST WHERE MATNR EQ WA_STPO-IDNRK.
IF SY-SUBRC = 0.
WA_STPO-LIGHTS = '2'.
ELSE.
WA_STPO-LIGHTS = '1'.
ENDIF.
MODIFY IT_STPO FROM WA_STPO.
ENDLOOP.
endform. " GET_DATA_BOM
*& Form BUILD_FIELDCAT_BOM
* text
* --> p1 text
* <-- p2 text
form BUILD_FIELDCAT_BOM USING LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA : L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
REFRESH : LT_FIELDCAT.
L_FIELDCAT-COL_POS = 1.
L_FIELDCAT-FIELDNAME = 'STLTY'.
L_FIELDCAT-TABNAME = 'IT_STPO'.
L_FIELDCAT-REF_FIELDNAME = 'STLTY'.
L_FIELDCAT-REF_TABNAME = 'STPO'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
L_FIELDCAT-COL_POS = 2.
L_FIELDCAT-FIELDNAME = 'STLNR'.
L_FIELDCAT-TABNAME = 'IT_STPO'.
L_FIELDCAT-REF_FIELDNAME = 'STLNR'.
L_FIELDCAT-REF_TABNAME = 'STPO'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
L_FIELDCAT-COL_POS = 3.
L_FIELDCAT-FIELDNAME = 'STLKN'.
L_FIELDCAT-TABNAME = 'IT_STPO'.
L_FIELDCAT-REF_FIELDNAME = 'STLKN'.
L_FIELDCAT-REF_TABNAME = 'STPO'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
L_FIELDCAT-COL_POS = 4.
L_FIELDCAT-FIELDNAME = 'IDNRK'.
L_FIELDCAT-TABNAME = 'IT_STPO'.
L_FIELDCAT-REF_FIELDNAME = 'IDNRK'.
L_FIELDCAT-REF_TABNAME = 'STPO'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
L_FIELDCAT-COL_POS = 5.
L_FIELDCAT-FIELDNAME = 'MENGE'.
L_FIELDCAT-TABNAME = 'IT_STPO'.
L_FIELDCAT-REF_FIELDNAME = 'MENGE'.
L_FIELDCAT-REF_TABNAME = 'STPO'.
APPEND L_FIELDCAT TO LT_FIELDCAT.
endform. " BUILD_FIELDCAT_BOM
*& Form BUILD_LAYOUT_BOM
* text
* --> p1 text
*<-- p2 text
form BUILD_LAYOUT_BOM .
CLEAR : LS_LAYOUT.
LS_LAYOUT-LIGHTS_FIELDNAME = 'LIGHTS'.
LS_LAYOUT-LIGHTS_TABNAME = 'IT_STPO'.
endform. " BUILD_LAYOUT_BOM
*& Form DISPLAY_DATA_BOM
* text
* --> p1 text
* <-- p2 text
form DISPLAY_DATA_BOM .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND_BOM'
I_CALLBACK_TOP_OF_PAGE = 'TOP9'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
I_BACKGROUND_ID = 'ALV_BACKGROUND'
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = LS_LAYOUT
IT_FIELDCAT = LT_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = IT_STPO
* 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.
endform. " DISPLAY_DATA_BOM
FORM TOP9 .
CLEAR LS_HEADER.
REFRESH LT_HEADER.
LS_HEADER-TYP = 'H'.
LS_HEADER-INFO = 'BILL OF MATERIALS'.
APPEND LS_HEADER TO LT_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = LT_HEADER
I_LOGO = 'ENJOYSAP_LOGO'
* I_END_OF_LIST_GRID =
ENDFORM.
FORM USER_COMMAND_BOM USING RF_UCOMM_BOM LIKE SY-UCOMM
SEL_FIELD TYPE SLIS_SELFIELD.
CASE RF_UCOMM_BOM.
WHEN '&IC1'.
SET PARAMETER ID 'MAT' FIELD WA_STPO-IDNRK.
SET PARAMETER ID 'WRK' FIELD WA_MAST-WERKS.
SET PARAMETER ID 'CSA' FIELD WA_MAST-STLAN.
CALL TRANSACTION 'CS03' AND SKIP FIRST SCREEN.
ENDCASE.
Maybe you are looking for
-
My hp slate 500 tablet turns off if it is remove from it's docking station. This occurred only after I reinstalled the windows 7 operating system and drivers from the recovery disks that came with the unit when I purchased it. I had previously inst
-
Business Components and Database Views - Trouble Creating
I am trying to create a business component that contains a View that I created in my database. When I get to the fnnal step of creating the business component and it begins to generate the XML and Java code, it bombs out and says that the view object
-
When i klick on a link for a video files (for example a .wmv File) it opens a new tab and starts playing it, instead of giving me a dialog what it should do with the File so that i can either download it or play it with an external player. I already
-
How to sign PDF files using Adobe Reader or Acrobat 11
This tutorial, explores the various things to consider when using different signing techniques in Acrobat XI or Adobe Reader XI. How to use an image like your scanned signature when you sign a document will also be covered.
-
Broken Palm and crashed Hard Drive
Help Please! I ran over my Palm Z22 (oops!) and while all the info is still in there and I can turn it on, it does not respond to the touch screen. I can use the buttons for calendar and contacts and the on/off switch. Meanwhile, my computer also