REPORT EXAMPLE
*&———————————————————————*
*& Report Z_TEST_REPORT
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT z_test_report.
TABLES zavto.
DATA gi_index_rows TYPE lvc_t_row WITH HEADER LINE.
DATA g_selected_row LIKE lvc_s_row.
DATA: gs_fieldcatalog TYPE lvc_s_fcat OCCURS 0 WITH HEADER LINE,
gv_fcat LIKE LINE OF gs_fieldcatalog,
gs_layout TYPE lvc_s_layo.
DATA: g_container TYPE scrfname VALUE ‘CONT’,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_grid TYPE REF TO cl_gui_alv_grid.
DATA comm LIKE sy–ucomm.
DATA ztab TYPE TABLE OF zavto WITH HEADER LINE.
DATA tab TYPE TABLE OF zavto WITH HEADER LINE.
SELECT-OPTIONS name FOR ztab–name.
SELECT-OPTIONS mass FOR ztab–car_mass.
START-OF-SELECTION.
SELECT * FROM zavto INTO TABLE ztab.
PERFORM retrieve_data.
CALL SCREEN 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘ZSTAT’ EXCLUDING ‘SAVE’.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container EXPORTING container_name = g_container.
CREATE OBJECT g_grid EXPORTING i_parent = g_custom_container.
PERFORM u_prepare_fieldcatalog.
gs_layout–zebra = ‘X’.
* gs_layout-edit = ‘X’. ” Makes all Grid editable
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_fieldcatalog = gs_fieldcatalog[]
it_outtab = ztab[]. ” Data
ELSE.
PERFORM refresh_grid.
ENDIF.
* SET TITLEBAR ‘xxx’.
ENDMODULE. ” STATUS_0100 OUTPUT
MODULE user_command_0100 INPUT.
CASE comm.
WHEN ‘BACK’.
LEAVE TO SCREEN 0.
WHEN ‘BUT1’.
CALL METHOD g_grid->get_selected_rows
IMPORTING
et_index_rows = gi_index_rows[].
PERFORM lock_cell.
SET SCREEN 200.
WHEN ‘REFR’.
PERFORM refresh_grid.
WHEN OTHERS.
ENDCASE.
CLEAR comm.
ENDMODULE. ” USER_COMMAND_0100 INPUT
DATA tab2 TYPE TABLE OF zavto WITH HEADER LINE.
FORM retrieve_name.
READ TABLE gi_index_rows INDEX 1 INTO g_selected_row.
READ TABLE ztab INDEX g_selected_row–index INTO tab2.
SELECT SINGLE * FROM zavto INTO zavto WHERE name = tab2–name.
ENDFORM.
FORM lock_cell.
PERFORM retrieve_name.
CALL FUNCTION ‘ENQUEUE_EZ_REPORT_BLOCK’
EXPORTING
name = tab2–name
EXCEPTIONS
OTHERS = 1.
IF sy–subrc <> 0.
WRITE : sy–uname && ‘заблокировал запись’.
ENDIF.
ENDFORM.
FORM unlock_cell.
PERFORM retrieve_name.
CALL FUNCTION ‘DEQUEUE_EZ_REPORT_BLOCK’
EXPORTING
name = tab2–name.
ENDFORM.
FORM refresh_grid.
SELECT * FROM zavto INTO TABLE ztab WHERE name IN name AND car_mass IN mass.
CALL METHOD g_grid->refresh_table_display.
ENDFORM.
FORM u_prepare_fieldcatalog .
CLEAR gv_fcat.
gv_fcat–fieldname = ‘MANDT’.
gv_fcat–tabname = ‘zavto’.
gv_fcat–col_pos = 0.
gv_fcat–coltext = ‘MANDT’.
gv_fcat–no_out = ‘X’. ” Do not Display Column
INSERT gv_fcat INTO TABLE gs_fieldcatalog.
CLEAR gv_fcat.
gv_fcat–fieldname = ‘name’.
gv_fcat–tabname = ‘zavto’.
gv_fcat–col_pos = 1.
gv_fcat–coltext = ‘Name’.
INSERT gv_fcat INTO TABLE gs_fieldcatalog.
CLEAR gv_fcat.
gv_fcat–fieldname = ‘total_mass’.
gv_fcat–tabname = ‘zavto’.
gv_fcat–col_pos = 2.
gv_fcat–coltext = ‘total mass’.
INSERT gv_fcat INTO TABLE gs_fieldcatalog.
CLEAR gv_fcat.
gv_fcat–fieldname = ‘car_mass’.
gv_fcat–tabname = ‘zavto’.
gv_fcat–col_pos = 3.
gv_fcat–coltext = ‘car mass’.
INSERT gv_fcat INTO TABLE gs_fieldcatalog.
ENDFORM. ” U_PREPARE_FIELDCATALOG
FORM retrieve_data .
SELECT * FROM zavto INTO TABLE ztab
WHERE name IN name
AND
car_mass IN mass.
ENDFORM. ” RETRIEVE_DATA
MODULE status_0200 OUTPUT.
SET PF-STATUS ‘ZSTAT’.
READ TABLE gi_index_rows INDEX 1 INTO g_selected_row.
READ TABLE ztab INDEX g_selected_row–index INTO ztab.
SELECT SINGLE * FROM zavto INTO zavto
WHERE name = ztab–name.
* SET TITLEBAR ‘xxx’.
ENDMODULE. ” STATUS_0200 OUTPUT
MODULE user_command_0200 INPUT.
CASE comm.
WHEN ‘BACK’.
PERFORM unlock_cell.
LEAVE TO SCREEN 100.
PERFORM refresh_grid.
WHEN ‘SAVE’.
MODIFY zavto.
PERFORM unlock_cell.
PERFORM refresh_grid.
WHEN OTHERS.
ENDCASE.
ENDMODULE. ” USER_COMMAND_0200 INPUT
[cc lang=”abap” tab_size=”20″ lines=”40″ noborder=”true”]
REPORT ztest_role.
AUTHORITY-CHECK OBJECT ‘ZSZS_AUTH’ FOR USER sy-uname
ID ‘ACTVT’ DUMMY.
IF sy-subrc = 0.
MESSAGE |USER AUTH YO-YO!:| &amp;&amp; sy-uname &amp;&amp; sy-subrc TYPE ‘I’.
ELSEIF sy-subrc <> 0.
MESSAGE |NOT AUTH USER:| &amp;&amp; sy-uname &amp;&amp; sy-subrc TYPE ‘I’.
LEAVE PROGRAM.
ENDIF.
[/cc]