2009 Jan 11 9:17 AM
Hi All,
I am having 2 internal tables.
I need to display the data in these 2 internal tables using ALV.
I am using the function module REUSE_ALV_LIST_DISPLAY 2 times for 2 internal tables to display data.
But two outputs are not coming on same screen.
Can any one give me a sample program to use class CL_GUI_ALV_GRID to display 2 List.
Screen for two custom controls I will create.
I just need to display data.
Pls Guide
2009 Jan 11 9:23 AM
2009 Jan 11 9:30 AM
Hi,,
execute the program SAP_CONTROL_INFO. In dat click on ALV Grid Control and select the tab Examples...u can have a range of examples for ALV
2009 Jan 11 9:31 AM
Hi Rishi,
Refer to this sample code:
create a screen with two containers ok.......
REPORT zvg_test_04.
TYPES: BEGIN OF ty_cust,
kunnr LIKE kna1-kunnr,
name1 LIKE kna1-name1,
ort01 LIKE kna1-ort01,
END OF ty_cust,
BEGIN OF ty_vbrk ,
vbeln LIKE vbrk-vbeln,
kunag LIKE vbrk-kunag,
fkdat LIKE vbrk-fkdat,
END OF ty_vbrk.
DATA: gv_container TYPE REF TO cl_gui_custom_container,
gv_alvgrid TYPE REF TO cl_gui_alv_grid,
gv_struct_name TYPE dd02l-tabname,
gv_variant TYPE disvariant.
DATA: wa_layout TYPE lvc_s_layo,
wa_fcatlg TYPE lvc_s_fcat,
it_fcatlg TYPE lvc_t_fcat,
it_cust TYPE TABLE OF ty_cust,
it_vbrk TYPE TABLE OF ty_vbrk.
START-OF-SELECTION.
SELECT kunnr name1 ort01
FROM kna1
INTO TABLE it_cust
UP TO 10 ROWS.
SELECT vbeln kunag fkdat
FROM vbrk
INTO TABLE it_vbrk
UP TO 10 ROWS.
CALL SCREEN 100.
&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
MODULE status_0100 OUTPUT.
SET PF-STATUS 'PF_STATUS'.
--- First ALV ---
Creating Container
IF gv_container IS INITIAL.
PERFORM create_container USING 'CONTAINER01'.
Creating ALV grid
PERFORM create_alvgrid.
Creating Field catalog manually
PERFORM create_fieldcat USING:
'1' 'KUNNR' 'IT_CUST' 'This is Customer Code' 'Cust No',
'2' 'NAME1' 'IT_CUST' 'This is Customer Name' 'Customer Name',
'3' 'ORT01' 'IT_CUST' 'This is Customer City' ' C i t y '.
Displaying the final output
PERFORM display_tab TABLES it_cust.
REFRESH it_fcatlg.
--- Second ALV ---
Creating Container
IF gv_container IS INITIAL.
PERFORM create_container USING 'CONTAINER02'.
Creating ALV grid
PERFORM create_alvgrid.
Creating Field catalog manually
PERFORM create_fieldcat USING:
'1' 'VBELN' 'IT_VBRK' 'This is Billing Document' 'Bill Doc',
'2' 'KUNAG' 'IT_VBRK' 'This is Sold-to party' 'Sold-to-Party',
'3' 'FKDAT' 'IT_VBRK' 'This is Billing Date' 'Date '.
Displaying the final output
PERFORM display_tab TABLES it_vbrk.
ENDIF.
For Creating Field catalog Automatically
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
ENDMODULE. " STATUS_0100 OUTPUT
&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
CALL METHOD cl_gui_cfw=>flush.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
PERFORM exit.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
&---------------------------------------------------------------------
*& Form EXIT
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
FORM exit .
CALL METHOD gv_container->free.
CALL METHOD cl_gui_cfw=>flush.
LEAVE PROGRAM.
ENDFORM. " EXIT
&---------------------------------------------------------------------
*& Form CREATE_CONTAINER
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
-->P_TEXT text
----------------------------------------------------------------------
FORM create_container USING p_text.
CREATE OBJECT gv_container
EXPORTING
container_name = p_text
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc IS NOT INITIAL.
MESSAGE text-003 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
ENDIF.
ENDFORM. " CREATE_CONTAINER
&---------------------------------------------------------------------
*& Form CREATE_ALVGRID
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
FORM create_alvgrid .
CREATE OBJECT gv_alvgrid
EXPORTING
i_parent = gv_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5.
IF sy-subrc IS NOT INITIAL.
MESSAGE text-005 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
ENDIF.
ENDFORM. " CREATE_ALVGRID
&---------------------------------------------------------------------
*& Form DISPLAY_TAB
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
-->P_TAB text
----------------------------------------------------------------------
FORM display_tab TABLES p_tab.
gv_variant-report = sy-repid.
CALL METHOD gv_alvgrid->set_table_for_first_display
EXPORTING
is_variant = gv_variant
i_save = 'A'
CHANGING
it_outtab = p_tab[]
it_fieldcatalog = it_fcatlg
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc IS NOT INITIAL.
MESSAGE text-e05 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE TO LIST-PROCESSING.
ENDIF. "Insert correct name for <...>.
ENDFORM. " DISPLAY_TAB
&---------------------------------------------------------------------
*& Form create_fieldcat
&---------------------------------------------------------------------
text
----------------------------------------------------------------------
-->COL_POS text
-->FIELDNAME text
-->TABNAME text
-->TOOLTIP text
-->REPTEXT text
----------------------------------------------------------------------
FORM create_fieldcat USING col_pos
fieldname
tabname
tooltip
reptext.
wa_fcatlg-col_pos = col_pos.
wa_fcatlg-fieldname = fieldname.
wa_fcatlg-tabname = tabname.
wa_fcatlg-tooltip = tooltip.
wa_fcatlg-reptext = reptext.
APPEND wa_fcatlg TO it_fcatlg.
CLEAR wa_fcatlg.
ENDFORM. "create_fieldcat
For more info refer these links:
hope these solves your problem.
Thanks!!
2015 Feb 17 12:38 PM
zsat_alvoops_final.
TABLES: vbap, vbak.
TYPES : BEGIN OF str1,
mvbeln TYPE vbeln,
mposnr TYPE posnr,
mmatnr TYPE matnr,
mkwmeng TYPE kwmeng,
mmeins TYPE meins,
mpstyv TYPE pstyv,
END OF str1.
DATA: grid TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container,
it_fcat TYPE lvc_t_fcat,
zsat_alvfcat2 TYPE STANDARD TABLE OF str1.
DATA : oit TYPE TABLE OF str1,
v_vkorg TYPE vbak-vkorg,
v_vtweg TYPE vbak-vtweg,
v_vkbur TYPE vbak-vkbur,
v_vkgrp TYPE vbak-vkgrp,
v_erdat TYPE vbak-erdat,
v_bsark TYPE vbak-bsark,
v_spart TYPE vbap-spart,
wa TYPE str1.
SELECT-OPTIONS : s_vkorg FOR v_vkorg,
s_vtweg FOR v_vtweg,
s_vkbur FOR v_vkbur,
s_vkgrp FOR v_vkgrp,
s_erdat FOR v_erdat,
s_bsark FOR v_bsark,
s_spart FOR v_spart.
SELECT vbak~vbeln vbap~posnr vbap~matnr vbap~kwmeng vbap~meins vbap~pstyv
INTO TABLE oit
FROM vbak INNER JOIN vbap ON vbak~vbeln = vbap~vbeln
WHERE ( vbak~vkorg IN s_vkorg ) AND ( vbak~vtweg IN s_vtweg ) AND ( vbak~vkbur IN s_vkbur )
AND ( vbak~vkgrp IN s_vkgrp ) AND ( vbak~erdat IN s_erdat ) AND ( vbak~bsark IN s_bsark ) AND ( vbap~spart IN s_spart ).
CALL SCREEN 9000.
MODULE status_9000 OUTPUT.
SET PF-STATUS 'ZSTATUS'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
container_name = 'CCONTAINER'.
CREATE OBJECT grid
EXPORTING
i_parent = g_custom_container.
ENDIF.
CALL METHOD grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZSAT_ALVFCAT2' * this is the custom structure which has been made in SE11 remember to declare it in this program in DATA.
CHANGING
it_outtab = oit.
ENDMODULE.