‎2007 May 22 2:24 PM
hello friends,
please see the code below , i m not able to see any output...
&----
*& Report ZALV_OBJECT
*&
&----
*&
*&
&----
REPORT zalv_object.
*******data declaration
DATA: itab_mat TYPE TABLE OF zmaterial,
wa_emp TYPE zmaterial.
SELECT * FROM zmaterial INTO TABLE itab_mat.
*******alv data declaration.
DATA: obj_grid TYPE REF TO cl_gui_alv_grid,
x_save,
gs_variant TYPE disvariant,
gs_layout type lvc_s_layo,
g_repid TYPE sy-repid,
container TYPE REF TO cl_gui_custom_container.
DATA: itab_fieldcatalog TYPE lvc_t_fcat,
wa_fieldcatalog LIKE LINE OF itab_fieldcatalog .
*******start of selection.
START-OF-SELECTION.
CREATE OBJECT container
EXPORTING container_name = 'MYCONT'.
CREATE OBJECT obj_grid
EXPORTING i_parent = container.
PERFORM field_catalog.
PERFORM layout.
PERFORM display_alv.
********form.
FORM field_catalog.
wa_fieldcatalog-fieldname = 'MCOD'.
wa_fieldcatalog-tabname = 'ITAB_MAT'.
wa_fieldcatalog-col_pos = 1.
wa_fieldcatalog-inttype = 'C'.
wa_fieldcatalog-outputlen = 13 .
wa_fieldcatalog-seltext = 'Code of the Material'.
APPEND wa_fieldcatalog TO itab_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'M_DESP'.
wa_fieldcatalog-tabname = 'ITAB_MAT'.
wa_fieldcatalog-col_pos = 2.
wa_fieldcatalog-inttype = 'C'.
wa_fieldcatalog-outputlen = 20.
wa_fieldcatalog-coltext = 'Material Decription'.
wa_fieldcatalog-seltext = 'Description of the Material'.
APPEND wa_fieldcatalog TO itab_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'TYPE_CODE'.
wa_fieldcatalog-tabname = 'ITAB_MAT'.
wa_fieldcatalog-inttype = 'C'.
wa_fieldcatalog-col_pos = 3.
wa_fieldcatalog-outputlen = 8 .
wa_fieldcatalog-coltext = 'Type Cod'.
wa_fieldcatalog-seltext = 'Code of the Material Type'.
APPEND wa_fieldcatalog TO itab_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'PRICE'.
wa_fieldcatalog-tabname = 'ITAB_MAT'.
wa_fieldcatalog-col_pos = 4.
wa_fieldcatalog-inttype = 'I'.
wa_fieldcatalog-outputlen = 10 .
wa_fieldcatalog-coltext = 'Price'.
wa_fieldcatalog-seltext = 'Price of the Material'.
APPEND wa_fieldcatalog TO itab_fieldcatalog.
CLEAR wa_fieldcatalog.
ENDFORM. "field_catalog
&----
*& Form layout
&----
text
----
FORM layout.
gs_layout-grid_title = 'materials'.
g_repid = sy-repid.
gs_variant-report = g_repid.
x_save = 'U'.
ENDFORM. "layout
&----
*& Form display_alv
&----
text
----
FORM display_alv.
CALL METHOD obj_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'ZMATERIAL'
I_DEFAULT = 'X'
IS_LAYOUT = gs_layout
CHANGING
it_outtab = itab_mat[]
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.
*write 😕 sy-subrc.
ENDFORM. "display_alv
‎2007 May 22 2:30 PM
In OO ALV you need to call screen where you have to define custom container in which ALV will be display. Define a screen with custom container.
For the reference please check the SAP standard example report like BCALV_GRID_01 to BCALV_GRID_11.
Regards
Nilesh Shete
‎2007 May 22 2:30 PM
In OO ALV you need to call screen where you have to define custom container in which ALV will be display. Define a screen with custom container.
For the reference please check the SAP standard example report like BCALV_GRID_01 to BCALV_GRID_11.
Regards
Nilesh Shete
‎2007 May 22 3:19 PM
Hi Nilesh,
Will this code will not run in report program,it will run only in the screen module pools....
Thanks.
Regards,
Reema jain.
‎2007 May 22 3:21 PM
It will run in either report or dialog programs.
CALL SCREEN syntax is used in both programming styles.
‎2007 May 22 3:24 PM
Hii john jakabcsin,
Can u give me sample code for displaying alv in report program...
Regards.
Reema Jain
‎2007 May 22 3:42 PM
Reema,
Create a report program called ZSANDBOX and paste in this code:
REPORT Zsandbox.
data: i_vbak type table of vbak.
data: grid1 type ref to cl_gui_alv_grid,
field_catalog type lvc_t_fcat,
grid1_container type ref to cl_gui_custom_container.
data: lt_fieldcat type LVC_T_FCAT.
data: wa_fieldcat type LVC_s_FCAT.
start-of-selection.
select * from vbak into table i_vbak
where erdat > '20041201'
and erdat < '20061216'.
Instantiate the grid container.
create object grid1_container
exporting
container_name = 'CUSTOM_GRID_CONTAINER'.
Instantiate the grid itself within the container.
create object grid1
exporting
i_parent = grid1_container
i_appl_events = 'X'.
DATA: layout TYPE lvc_s_layo.
CALL METHOD grid1->set_table_for_first_display
EXPORTING i_structure_name = 'VBAK'
CHANGING "it_fieldcatalog = gt_fieldcat
it_outtab = i_vbak[].
call screen '0100'.
Then run t-code SE51 and create a screen for program ZSANDBOX and give the scr number as "0100". Add a custom container called 'CUSTOM_GRID_CONTAINER' - activate the screen and run the prog from SE38.
‎2007 May 22 2:32 PM
Reema,
Have you created a screen for the program with a custom control called "MYCONT" on it?
This is required for the ALV grid to display.
‎2007 May 22 2:42 PM
hi,
in your problem i think you are not calling the screen
so please call the screen as
call screen nnnn
and check whether every thing is ok with the screen or not i mean whether it is active or not and name of the container is correct or no....
hope this will help,
regards,