0% found this document useful (0 votes)
187 views9 pages

OOPS ALV Demo

This document defines a report that displays billing header and item data in ALV grids. It includes event handler classes to handle double clicks and print events. Data is selected from tables ZBILL_HEADER and ZBILL_ITEM and displayed in two ALV grids on separate screens, with logic to handle navigation between them. Field catalogs are defined to customize the column properties of each grid.

Uploaded by

Sachin Adak
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views9 pages

OOPS ALV Demo

This document defines a report that displays billing header and item data in ALV grids. It includes event handler classes to handle double clicks and print events. Data is selected from tables ZBILL_HEADER and ZBILL_ITEM and displayed in two ALV grids on separate screens, with logic to handle navigation between them. Field catalogs are defined to customize the column properties of each grid.

Uploaded by

Sachin Adak
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

REPORT zprit_report.

TABLES : zbill_item , zbill_header.

DATA : gr_alv_grid TYPE REF TO cl_gui_alv_grid,


gr_ccontainer TYPE REF TO cl_gui_custom_container,
gc_dyndoc_id TYPE REF TO cl_dd_document,
gt_bill TYPE TABLE OF zbill_header,
wa_bill TYPE zbill_header,
gt_billitem TYPE TABLE OF zbill_item,
wa_billitem TYPE zbill_item.
SELECT-OPTIONS : s_zbilln FOR zbill_header-zbillno.
*&--------------------------SELECTION QUERY------------------------------------------*
START-OF-SELECTION.
SELECT zbillno zbilltype zbillcateg zsddoccurr zsalesorg zdischa
FROM zbill_header
INTO CORRESPONDING FIELDS OF TABLE gt_bill
WHERE zbillno IN s_zbilln.
CALL SCREEN 2000.
*&--------------------------EVENT HANDLER DEFINITION------------------------------------------*
CLASS event_handler DEFINITION.
PUBLIC SECTION.
METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IM
PORTING e_row e_column,
handle_print_top_of_list FOR EVENT print_top_of_list OF cl_gui_alv_grid.
ENDCLASS.

"event_handler DEFINITION

*&---------------------------------------------------------------------*
*&
Module DISPLAY OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE display OUTPUT.
DATA : lt_fcat TYPE lvc_t_fcat.
IF gr_alv_grid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING
*
parent
container_name
EXCEPTIONS
cntl_error
cntl_system_error

=
= 'C1'
= 1
= 2

create_error
lifetime_error
lifetime_dynpro_dynpro_link
OTHERS
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY
*
WITH SY-MSGV1 SY-MSGV2
ENDIF.

=
=
=
=

3
4
5
6

NUMBER SY-MSGNO
SY-MSGV3 SY-MSGV4.

CREATE OBJECT gr_alv_grid


EXPORTING
i_parent
= gr_ccontainer
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.
PERFORM field_catelog TABLES lt_fcat.
DATA event_obj TYPE REF TO event_handler.
CREATE OBJECT event_obj.
SET HANDLER event_obj->handle_double_click FOR gr_alv_grid.
SET HANDLER event_obj->handle_print_top_of_list for gr_alv_grid.
CALL METHOD gr_alv_grid->set_table_for_first_display
EXPORTING
i_structure_name
= 'ZBILL_HEADER'
CHANGING
it_outtab
= gt_bill
it_fieldcatalog
= lt_fcat
*
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.

" DISPLAY

OUTPUT

*&--------------------------EVENT HANDLER IMPLEMENTAION------------------------------------------*


CLASS event_handler IMPLEMENTATION.
METHOD handle_double_click.
PERFORM handle_double_click USING e_row e_column.
ENDMETHOD.
"handle_double_click
METHOD handle_print_top_of_list.
PERFORM handle_print_top_of_list.
ENDMETHOD.
ENDCLASS.
"event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
*&
Form HANDLE_DOUBLE_CLICK
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_E_ROW text
*
-->P_E_COLUMN text
*----------------------------------------------------------------------*
FORM handle_double_click USING
p_e_row
p_e_column.
READ TABLE gt_bill INTO wa_bill INDEX p_e_row.
IF sy-subrc = 0.
SELECT zbillno zbillitem zactbillqty zsalesunit zbaseuntmeas zbillqty zma
terial
FROM zbill_item
INTO CORRESPONDING FIELDS OF TABLE gt_billitem
WHERE zbillno = wa_bill-zbillno.
ENDIF.
CALL SCREEN 2001.
ENDFORM.

" HANDLE_DOUBLE_CLICK

*&---------------------------------------------------------------------*
*&
Module DISPLAY1 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE display1 OUTPUT.
DATA : gr_alv_grid1 TYPE REF TO cl_gui_alv_grid,
gr_ccontainer1 TYPE REF TO cl_gui_custom_container,

*
*

*
*

*
*

lt_fcat1 TYPE lvc_t_fcat.


IF gr_ccontainer1 IS INITIAL.
CREATE OBJECT gr_ccontainer1
EXPORTING
parent
=
container_name
= 'C2'
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.
CREATE OBJECT gr_alv_grid1
EXPORTING
i_shellstyle
= 0
i_lifetime
=
i_parent
= gr_ccontainer1
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.
PERFORM field_catelog1 TABLES lt_fcat1.
CALL METHOD gr_alv_grid1->set_table_for_first_display
EXPORTING
i_structure_name
= 'ZBILL_ITEM'
CHANGING
it_outtab
= gt_billitem
it_fieldcatalog
= lt_fcat1
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.
ELSE.
CALL METHOD gr_alv_grid1->refresh_table_display
.
IF sy-subrc <> 0.
*
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SYMSGV4.
ENDIF.
.
ENDIF.
ENDMODULE.

" DISPLAY1

OUTPUT

*&---------------------------------------------------------------------*
*&
Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_2000 OUTPUT.
SET PF-STATUS '100'.
SET TITLEBAR '9000'.
ENDMODULE.
" STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*&
Module STATUS_2001 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_2001 OUTPUT.
SET PF-STATUS '301'.
SET TITLEBAR '9001'.
ENDMODULE.
" STATUS_2001 OUTPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
" USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_2001 INPUT

*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_2001 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
" USER_COMMAND_2001 INPUT

INCLUDE zprit_report_field_catelogf01.
*&---------------------------------------------------------------------*
*&
Form HANDLE_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_E_DYNDOC_ID text
*----------------------------------------------------------------------*
form HANDLE_print_TOP_OF_list.
WRITE : 'This ALV contain Bill Header Details'.
*CALL METHOD gc_dyndoc_id->add_picture
* EXPORTING
*
picture_id
= 'CAPGEMINI_LOGO'
**
width
=
**
alternative_text =
**
tabindex
=
*
.
endform.

" HANDLE_TOP_OF_PAGE

*----------------------------------------------------------------------*
form FIELD_CATELOG tables
p_lt_fcat structure lvc_s_fcat.
"Insert correct name for <...>.
DATA ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
*
I_BUFFER_ACTIVE
=
i_structure_name
= 'ZBILL_HEADER1'
*
I_CLIENT_NEVER_DISPLAY
= 'X'
*
I_BYPASSING_BUFFER
=
*
I_INTERNAL_TABNAME
=
CHANGING

ct_fieldcat
= lt_fcat
EXCEPTIONS
inconsistent_interface
= 1
program_error
= 2
OTHERS
= 3
.
IF sy-subrc <> 0.
*
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_fcat INTO ls_fcat.
CASE ls_fcat-fieldname.
WHEN 'ZBILLNO'.
ls_fcat-outputlen = '15'.
ls_fcat-coltext = 'Billing Document'.
MODIFY lt_fcat FROM ls_fcat.
WHEN 'ZBILLTYPE'.
ls_fcat-outputlen = '15'.
ls_fcat-coltext = 'Billing Type'.
MODIFY lt_fcat FROM ls_fcat.
WHEN 'ZBILLCATEG'.
ls_fcat-outputlen = '15'.
ls_fcat-coltext = 'Billing category'.
MODIFY lt_fcat FROM ls_fcat.
WHEN 'ZSDDOCCURR'.
ls_fcat-outputlen = '20'.
ls_fcat-coltext = 'SD document currency'.
MODIFY lt_fcat FROM ls_fcat.
WHEN 'ZSALESORG'.
ls_fcat-outputlen = '20'.
ls_fcat-coltext = 'Sales Organization'.
MODIFY lt_fcat FROM ls_fcat.
WHEN 'ZDISCHA'.
ls_fcat-outputlen = '20'.
ls_fcat-coltext = 'Distribution Channel'.
MODIFY lt_fcat FROM ls_fcat.
ENDCASE.
ENDLOOP.
endform.
" FIELD_CATELOG
*&---------------------------------------------------------------------*
*&
Form FIELD_CATELOG1
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
-->P_LT_FCAT1 text
*----------------------------------------------------------------------*
form FIELD_CATELOG1 tables
p_lt_fcat1 structure lvc_s_fcat.
"Insert correct name for <...>.

DATA ls_fcat1 TYPE lvc_s_fcat.


CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
*
I_BUFFER_ACTIVE
=
i_structure_name
= 'ZBILL_ITEM'
*
I_CLIENT_NEVER_DISPLAY
= 'X'
*
I_BYPASSING_BUFFER
=
*
I_INTERNAL_TABNAME
=
CHANGING
ct_fieldcat
= lt_fcat1
EXCEPTIONS
inconsistent_interface
= 1
program_error
= 2
OTHERS
= 3
.
IF sy-subrc <> 0.
*
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_fcat1 INTO ls_fcat1.
CASE ls_fcat1-fieldname.
WHEN 'ZBILLNO'.
ls_fcat1-outputlen = '15'.
ls_fcat1-coltext = 'Billing Document'.
MODIFY lt_fcat1 FROM ls_fcat1.
WHEN 'ZBILLITEM'.
ls_fcat1-outputlen = '15'.
ls_fcat1-coltext = 'Billing item'.
MODIFY lt_fcat1 FROM ls_fcat1.
WHEN 'ZACTBILLQTY'.
ls_fcat1-outputlen = '15'.
ls_fcat1-coltext = 'Actual billed quantity'.
MODIFY lt_fcat1 FROM ls_fcat1.
WHEN 'ZSALESUNIT'.
ls_fcat1-outputlen = '12'.
ls_fcat1-coltext = 'Sales unit'.
MODIFY lt_fcat1 FROM ls_fcat1.
WHEN 'ZBASEUNTMEAS'.
ls_fcat1-outputlen = '20'.
ls_fcat1-coltext = 'Base Unit of Measure'.
MODIFY lt_fcat1 FROM ls_fcat1.
WHEN 'ZBILLQTY'.
ls_fcat1-outputlen = '20'.
ls_fcat1-coltext = 'Billing quantity in stockkeeping unit'.
MODIFY lt_fcat1 FROM ls_fcat1.
WHEN 'ZMATERIAL'.
ls_fcat1-outputlen = '15'.
ls_fcat1-coltext = 'Material Number'.

MODIFY lt_fcat1 FROM ls_fcat1.


ENDCASE.
ENDLOOP.
endform.
" FIELD_CATELOG1

You might also like