2008 Jun 10 7:28 AM
Hi All,
I m trying to display ALV in report using classes but i m not able to do it. I have used following classes for alv display along with its method.
1. cl_gui_custom_container
2. cl_gui_alv_grid and its method set_table_for_first_display
I have tried to display in module pool using classes and i have succeeded but now i m trying wid report using the same classes but i m not able to display ALV
Please provide me solution and if there exists another classes to display ALV along wid its methods.
Regards,
Parag
2008 Jun 12 9:26 AM
2008 Jun 10 7:35 AM
Hi,
in the report program also you have to call a screen and in the PBo write the code for display of ALV
Please check the below program:
REPORT z271837_alv_grid_container .
Important Classes : CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER.
*
*Steps To Use ALV Grid in a Program :
*1. Declare reference variables for,
Container (class CL_GUI_CUSTOM_CONTAINER) and
Grid (class CL_GUI_ALV_GRID)
*2. Create Standard Screen and a container on that screen
*3. Call the screen which has been created
*4. Instantiate the container control and the ALV Grid Control in PBO of the screen
Tables
TABLES : mara.
TYPE-POOLS : slis.
Data declarations
DATA : fg_error TYPE flag.
TYPES : BEGIN OF x_mara,
matnr TYPE mara-matnr,
erdda TYPE mara-ersda,
ernam TYPE mara-ernam,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
END OF x_mara.
Declare reference variables:
DATA : cl_grid TYPE REF TO cl_gui_alv_grid,
cl_container TYPE REF TO cl_gui_custom_container.
DATA : it_mara TYPE TABLE OF x_mara,
wa_fieldcat TYPE lvc_s_fcat, " occurs 1.
it_fieldcat TYPE TABLE OF lvc_s_fcat.
Selection Screen.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETER : rb_list TYPE char1 RADIOBUTTON GROUP r1,
rb_grid TYPE char1 RADIOBUTTON GROUP r1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK b2.
START-OF-SELECTION.
CLEAR fg_error.
REFRESH it_mara.
*Get the data which is to be displayed into one internal table
SELECT matnr
ersda
ernam
mtart
matkl
FROM mara
INTO TABLE it_mara
WHERE matnr IN s_matnr.
IF sy-subrc NE 0.
MESSAGE s000(zi) WITH text-s01.
fg_error = 'X'.
EXIT.
ENDIF.
END-OF-SELECTION.
CHECK fg_error IS INITIAL.
build the field catalog
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 1.
wa_fieldcat-SCRTEXT_M = 'Material'.
wa_fieldcat-outputlen = 18.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ERSDA'.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 2.
wa_fieldcat-SCRTEXT_M = 'ERSDA'.
wa_fieldcat-outputlen = 18.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ERNAM'.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 3.
wa_fieldcat-SCRTEXT_M = 'Creator'.
wa_fieldcat-outputlen = 18.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MTART'.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 4.
wa_fieldcat-SCRTEXT_M = 'Material Type'.
wa_fieldcat-outputlen = 18.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATKL'.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 5.
wa_fieldcat-SCRTEXT_M = 'Material Desc'.
wa_fieldcat-outputlen = 50.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
Call the screen with container to display ALV
CALL SCREEN 100.
PBO and PAI modules code along with ALV container and display methods
INCLUDE z271837_alv_grid_container_o01.
----
***INCLUDE Z271837_ALV_GRID_CONTAINER_O01 .
----
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'.
SET TITLEBAR 'xxx'.
******************************************************
Instantiate the container control and the ALV Grid
Control in PBO of the screen
******************************************************
IF cl_container IS INITIAL.
Instantiate the container control
CREATE OBJECT cl_container
EXPORTING
PARENT =
container_name = 'C1_CONTAINER'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Instantiate the ALV grid
CREATE OBJECT cl_grid
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
i_parent = cl_container " Container object created above
I_APPL_EVENTS = space
I_PARENTDBG =
I_APPLOGPARENT =
I_GRAPHICSPARENT =
I_NAME =
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*For displaying the data, call the method "set_table_for_first_display"
*of object reference of CL_GUI_ALV_GRID
CALL METHOD cl_grid->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
it_outtab = it_mara
it_fieldcatalog = it_fieldcat
IT_SORT =
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE user_command_0100 INPUT.
*Refresh grid display
CALL METHOD cl_grid->refresh_table_display.
CASE sy-ucomm.
WHEN 'BACK'.
Comes back to the previous screen
SET SCREEN 0.
WHEN 'EXIT'
OR 'CANCEL'.
Exit from the application/program
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
Reward if useful
Regards
Shiva
2008 Jun 12 9:26 AM