07-31-2014 6:12 AM
Hi All,
I have developed one report in which i am using ALV OOPS concept to dipsplay the report
data.
I am using following code:
Calling the method of global class as follow:
method:
CREATE OBJECT o_alv
EXPORTING
i_appl_events = 'X'
i_parent = v_custom_container.
IF i_fieldcat IS NOT INITIAL.
v_variant = sy-repid.
CALL METHOD o_alv->set_table_for_first_display
* EXPORTING
* is_layout = v_layout
* i_default = 'X'
* i_save = 'U'
* is_variant = v_variant
CHANGING
it_outtab = i_inventory[]
it_fieldcatalog = i_fieldcat[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
I_inventory[] and i_fieldcat[] contain data but it is not displaying the grid.I dont want any screen in report.
Thanks,
Arpita
07-31-2014 6:40 AM
REUSE_ALV_GRID_DISPLAY and CL_SALV_TABLE are both calling screens as well, the calls are just wrapped inside so you don't have to do it explicitely.
You can't do this without a screen.
Either you can follow this. Here no need to create any custom container in screen 100.Just call it.
DATA lr_alv TYPE REF TO cl_gui_alv_grid.
DATA lt_table TYPE TABLE OF t529a.
SELECT * FROM t529a INTO TABLE lt_table.
CREATE OBJECT lr_alv
EXPORTING
i_parent = cl_gui_container=>screen0.
CALL METHOD lr_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'T529A'
CHANGING
it_outtab = lt_t529a
CALL SCREEN 100.
Regards
Sreekanth
07-31-2014 6:44 AM
Dear Arpita,
There is a concept called SALV!
*&---------------------------------------------------------------------*
*& This code snippet will show how to use the CL_SALV_TABLE to
*& generate the ALV
*&---------------------------------------------------------------------*
REPORT ztest_oo_alv_main.
*
*----------------------------------------------------------------------*
* CLASS lcl_report DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
*
PUBLIC SECTION.
*
* Final output table
TYPES: BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
erdat TYPE erdat,
auart TYPE auart,
kunnr TYPE kunnr,
END OF ty_vbak.
*
DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak.
*
* ALV reference
DATA: o_alv TYPE REF TO cl_salv_table.
*
METHODS:
* data selection
get_data,
*
* Generating output
generate_output.
*
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
* In this section we will define the private methods which can
* be implemented to set the properties of the ALV and can be
* called in the
*
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
ENDCLASS. "lcl_report DEFINITION
*
*
START-OF-SELECTION.
DATA: lo_report TYPE REF TO lcl_report.
*
CREATE OBJECT lo_report.
*
lo_report->get_data( ).
*
lo_report->generate_output( ).
*
*----------------------------------------------------------------------*
* CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
METHOD get_data.
* data selection
SELECT vbeln erdat auart kunnr
INTO TABLE t_vbak
FROM vbak
UP TO 20 ROWS.
*
ENDMETHOD. "get_data
*
*.......................................................................
METHOD generate_output.
* New ALV instance
* We are calling the static Factory method which will give back
* the ALV object reference.
*
* exception class
DATA: lx_msg TYPE REF TO cx_salv_msg.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = t_vbak ).
CATCH cx_salv_msg INTO lx_msg.
ENDTRY.
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
* In this area we will call the methods which will set the
* different properties to the ALV
*
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
* Displaying the ALV
* Here we will call the DISPLAY method to get the output on the screen
o_alv->display( ).
*
ENDMETHOD. "generate_output
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
* In this area we will implement the methods which are defined in
* the class definition
*
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*
*
*
ENDCLASS. "lcl_report IMPLEMENTATION
Please copy post above code and debug first then you will come to know! Hope it helps!
Regards,
Dhruvin
07-31-2014 7:19 AM
Hi Arpita,
Try my code.Please notice the write statement in the last line.
You can use write to activate the standard screen so that you needn't create a new screen.
DATA: l_alv TYPE REF TO cl_gui_alv_grid ,
lt_bkpf TYPE TABLE OF bkpf .
SELECT * FROM bkpf UP TO 10 ROWS INTO TABLE lt_bkpf.
CREATE OBJECT l_alv
EXPORTING
i_parent = cl_gui_container=>screen0.
CALL METHOD l_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'BKPF'
CHANGING
it_outtab = lt_bkpf.
WRITE ' '.
Thanks,
Sam
04-02-2020 5:15 PM
07-31-2014 8:48 AM
Hi Arpita,
Where did you call the method SET_TABLE_FOR_FIRST_DISPLAY???
This method should be called in PBO of the screen. And even you have create a container and include that container in the ALV object (CL_GUI_ALV_GRID).
If ever you want to create ALV Grid without using screen and container, you need to use CL_SALV_TABLE.
Sample code to build ALV_GRID using CL_GUI_ALV_GRID is given below, please refer:
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* Fetching data from database into internal table to display
SELECT MATNR MAKTX FROM MAKT
INTO CORRESPONDING FIELDS OF TABLE GT_OUTPUT
WHERE MATNR IN S_MATNR
AND SPRAS = 'EN'.
*&---------------------------------------------------------------------*
*& END-OF-SELECTION
*&---------------------------------------------------------------------*
END-OF-SELECTION.
* Calling a screen to display ALV Grid
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ZGVK_TEST'. " PF Status
SET TITLEBAR 'ZGVK_TEST'. " Title bar
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module DISPLAY_ALV_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE DISPLAY_ALV_0100 OUTPUT.
* Local internal table * Workara for fieldcatalog
DATA : LT_FLDCAT TYPE LVC_T_FCAT,
LS_FLDCAT TYPE LVC_S_FCAT.
* Filling field catalog for Grid ouptut
* Creating object for Container (CL_GUI_CUSTOM_CONTAINER) in the screen
CREATE OBJECT GR_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER'.
" CONTAINER is container name in the screen
* Creating Object for ALV Grid (CL_GUI_ALV_GRID) to set display
CREATE OBJECT GR_GRID
EXPORTING
I_PARENT = GR_CONTAINER. " Passing above container object
* Setting output table for display in ALV GRID format
GR_GRID->SET_TABLE_FOR_FIRST_DISPLAY(
EXPORTING
I_STRUCTURE_NAME = 'ZGVK_TEST'
" Global tab/structure to build output layout
CHANGING
IT_OUTTAB = GT_OUTPUT " Output table
IT_FIELDCATALOG = LT_FLDCAT " Fieldcatalog table
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.
ENDMODULE. " DISPLAY_ALV_0100 OUTPUT
Regards,
Vijay
07-31-2014 3:20 PM
Hi Arpita.
You can try this code to generate a simple and fast ALV report.
DATA: lr_alv TYPE REF TO cl_salv_table,
lr_alv_cols TYPE REF TO cl_salv_columns,
lr_alv_func TYPE REF TO cl_salv_functions,
lrx_salv_error TYPE REF TO cx_salv_error.
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = lr_alv
CHANGING t_table = YOUR_TABLE_DATA ).
* Configure columns
lr_alv_cols = lr_alv->get_columns( ).
lr_alv_cols->set_optimize( ).
* Active all ALV functions
lr_alv_func = lr_alv->get_functions_base( ).
lr_alv_func->set_all( ).
lr_alv->display( ).
CATCH cx_salv_error INTO lrx_salv_error.
ENDTRY.
Regards.