Showing posts with label ARTICLE. Show all posts
Showing posts with label ARTICLE. Show all posts

June 29, 2009

Displaying messages in ABAP

It is a good article to display messages in ABAP.

source : http://abaplovers.blogspot.com/2008/02/displaying-messages-in-abap.html

June 28, 2009

ALV using OOPS method - 2

Try it at home...it looks good.

Don't forget to create "Screen 100" and activate PBO Output and PAI Input
*&---------------------------------------------------------------------*
*& Report ZALV_DOUBLECLICK *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*

REPORT zalv_doubleclick .

*"Table declarations...................................................
TABLES: ekko, " Purchasing Document Header
cdhdr, " Change document header
sscrfields. " Fields on selection screens

*"Selection screen elements............................................
SELECT-OPTIONS:
s_ebeln FOR ekko-ebeln, " Purchasing Document Number
s_lifnr FOR ekko-lifnr, " Vendor's account number
s_ekgrp FOR ekko-ekgrp, " Purchasing group
s_bedat FOR ekko-bedat, " Purchasing Document Date
s_udate FOR cdhdr-udate. " Creation date of the change
" document
*" Data declarations...................................................
"--------------------------------------------------------------------

*Field String to hold Purchase Document Number *
"--------------------------------------------------------------------
DATA:
BEGIN OF fs_ebeln,
ebeln(90) TYPE c, " Purchase Document Number
ernam TYPE ekko-ernam, " Name of Person who Created the Object
lifnr TYPE ekko-lifnr, " Vendor's account number
ekgrp TYPE ekko-ekgrp, " Purchasing group
bedat TYPE ekko-bedat, " Purchasing Document Date
END OF fs_ebeln,

"--------------------------------------------------------------------

*Field String to hold Purchase Document Header *
"--------------------------------------------------------------------
BEGIN OF fs_ekko,
ebeln TYPE ekko-ebeln, " Purchasing Document Number
ernam TYPE ekko-ernam, " Name of Person who Created the Object
lifnr TYPE ekko-lifnr, " Vendor's account number
ekgrp TYPE ekko-ekgrp, " Purchasing group
bedat TYPE ekko-bedat, " Purchasing Document Date
END OF fs_ekko,

"--------------------------------------------------------------------

*Field String to hold Account Number and name of the Vendor *
"--------------------------------------------------------------------
BEGIN OF fs_lfa1,
lifnr TYPE lfa1-lifnr, " Account Number of Vendor
name1 TYPE lfa1-name1, " Name1
END OF fs_lfa1,

"--------------------------------------------------------------------

*Field String to hold Change date and the name of the user *
"--------------------------------------------------------------------
BEGIN OF fs_cdhdr,
objectclas TYPE cdhdr-objectclas, " Object Class
objectid TYPE cdhdr-objectid, " Object value
changenr TYPE cdhdr-changenr, " Document change number
username TYPE cdhdr-username, " User name
udate TYPE cdhdr-udate, " Creation date of the change document
END OF fs_cdhdr,

"--------------------------------------------------------------------

*Field String to hold Change document items *
"--------------------------------------------------------------------
BEGIN OF fs_cdpos,
objectclas TYPE cdpos-objectclas," Object class
objectid(10) TYPE c, " Object Value
changenr TYPE cdpos-changenr, " Document change number
tabname TYPE cdpos-tabname, " Table Name
fname TYPE cdpos-fname, " Field Name
value_new TYPE cdpos-value_new, " New contents of changed field
value_old TYPE cdpos-value_old, " Old contents of changed field
END OF fs_cdpos,

"--------------------------------------------------------------------

*Field String to hold Date Element Name *
"--------------------------------------------------------------------
BEGIN OF fs_dataele,
tabname TYPE dd03l-tabname, " Table Name
fieldname TYPE dd03l-fieldname, " Field Name
rollname TYPE dd03l-rollname, " Data element (semantic domain)
END OF fs_dataele,

"--------------------------------------------------------------------

*Field String to hold Short Text of the Date Element *
"--------------------------------------------------------------------
BEGIN OF fs_text,
rollname TYPE dd04t-rollname, " Data element (semantic domain)
ddtext TYPE dd04t-ddtext, " Short Text Describing R/3 Repository
"Objects
END OF fs_text,

"--------------------------------------------------------------------

*Field String to hold data to be displayed on the ALV grid *
"--------------------------------------------------------------------
BEGIN OF fs_outtab,
ebeln TYPE ekko-ebeln, " Purchasing Document Number
ernam TYPE ekko-ernam, " Name of Person who Created the Object
lifnr TYPE ekko-lifnr, " Vendor's account number
ekgrp TYPE ekko-ekgrp, " Purchasing group
bedat TYPE ekko-bedat, " Purchasing Document Date
werks TYPE lfa1-werks, " Plant
name1 TYPE lfa1-name1, " Name1
username TYPE cdhdr-username, " User name
udate TYPE cdhdr-udate, " Creation date of the change document
ddtext TYPE dd04t-ddtext, " Short Text Describing R/3 Repository
"Objects
value_new TYPE cdpos-value_new, " New contents of changed field
value_old TYPE cdpos-value_old, " Old contents of changed field
END OF fs_outtab,

"--------------------------------------------------------------------

*Internal table to hold Purchase Document Number *
"--------------------------------------------------------------------
t_ebeln LIKE STANDARD TABLE OF fs_ebeln,

"--------------------------------------------------------------------

*Internal table to hold Purchase Document Header *
"--------------------------------------------------------------------
t_ekko LIKE STANDARD TABLE OF fs_ekko,

"--------------------------------------------------------------------

*Temp Internal table to hold Purchase Document Header *
"--------------------------------------------------------------------
t_ekko_temp LIKE STANDARD TABLE OF fs_ekko,

"--------------------------------------------------------------------

*Internal table to hold Account number and Name of the Vendor *
"--------------------------------------------------------------------
t_lfa1 LIKE STANDARD TABLE OF fs_lfa1,

"--------------------------------------------------------------------

*Internal Table to hold Change date and the name of the user *
"--------------------------------------------------------------------
t_cdhdr LIKE STANDARD TABLE OF fs_cdhdr,

"--------------------------------------------------------------------

*Internal Table to hold Change document items *
"--------------------------------------------------------------------
t_cdpos LIKE STANDARD TABLE OF fs_cdpos,

"--------------------------------------------------------------------

*Temp. Internal Table to hold Change document items *
"--------------------------------------------------------------------
t_cdpos_temp LIKE STANDARD TABLE OF fs_cdpos,

"--------------------------------------------------------------------

*Internal Table to hold Data Element Name *
"--------------------------------------------------------------------
t_dataele LIKE STANDARD TABLE OF fs_dataele,

"--------------------------------------------------------------------

*Temp. Internal Table to hold Data Element Name *
"--------------------------------------------------------------------
t_dataele_temp LIKE STANDARD TABLE OF fs_dataele,

"--------------------------------------------------------------------

*Internal Table to hold Short Text of the Date Element *
"--------------------------------------------------------------------
t_text LIKE STANDARD TABLE OF fs_text,

"--------------------------------------------------------------------

*Internal Table to hold data to be displayed on the ALV grid *
"--------------------------------------------------------------------
t_outtab LIKE STANDARD TABLE OF fs_outtab.

"--------------------------------------------------------------------

*C L A S S D E F I N I T I O N *
"--------------------------------------------------------------------
CLASS lcl_event_handler DEFINITION DEFERRED.

*" Data declarations...................................................
"--------------------------------------------------------------------

*Work variables *
"--------------------------------------------------------------------
DATA:
w_ebeln TYPE ekko-ebeln, " Purchasing Document Number
w_lifnr TYPE ekko-lifnr, " Vendor's account number
w_ekgrp TYPE ekko-ekgrp, " Purchasing group
w_value TYPE ekko-ebeln, " Reflected Value
w_space VALUE ' ', " Space
w_flag TYPE i, " Flag Variable
w_variant TYPE disvariant, " Variant

*ALV Grid
w_grid TYPE REF TO cl_gui_alv_grid,

*Event Handler
w_event_click TYPE REF TO lcl_event_handler,

*Field catalog table
t_fieldcat TYPE lvc_t_fcat.

"--------------------------------------------------------------------

*AT SELECTION-SCREEN EVENT *
"--------------------------------------------------------------------

AT SELECTION-SCREEN ON s_ebeln.

*Subroutine to validate Purchase Document Number.
PERFORM validate_pd_num.

AT SELECTION-SCREEN ON s_lifnr.

*Subroutine to validate Vendor Number.
PERFORM validate_ven_num.

AT SELECTION-SCREEN ON s_ekgrp.

*Subroutine to validate Purchase Group.
PERFORM validate_pur_grp.

"--------------------------------------------------------------------

*START-OF-SELECTION EVENT *
"--------------------------------------------------------------------

START-OF-SELECTION.

* Subroutine to select all Purchase orders.
PERFORM select_po.

CHECK w_flag EQ 0.

* Subroutine to select Object values.
PERFORM select_obj_id.
CHECK w_flag EQ 0.

* Subroutine to select Changed values.
PERFORM select_changed_value.
CHECK w_flag EQ 0.

* Subroutine to Select Purchase Orders.
PERFORM select_pur_doc.

* Subroutine to select Vendor Details.
PERFORM select_vendor.

* Subroutine to select Text for the Changed values.
PERFORM description.
"--------------------------------------------------------------------

*END-OF-SELECTION EVENT *
"--------------------------------------------------------------------

END-OF-SELECTION.

IF NOT t_ekko IS INITIAL.

* Subroutine to populate the Output Table.
PERFORM fill_outtab.

* Subroutine to build Field Catalog.
PERFORM prepare_field_catalog CHANGING t_fieldcat.
CALL SCREEN 100.
ENDIF. " IF NOT T_EKKO...

* CLASS LCL_EVENT_HANDLER DEFINITION

* Defining Class which handles events
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id e_column_id.

ENDCLASS. " LCL_EVENT_HANDLER DEFINITION

* CLASS LCL_EVENT_HANDLER IMPLEMENTATION

* Implementing the Class which can handle events
CLASS lcl_event_handler IMPLEMENTATION .

* ---Handle Double Click
METHOD handle_hotspot_click .

* Subroutine to get the HotSpot Cell information.
PERFORM get_cell_info.

SET PARAMETER ID 'BES' FIELD w_value.

CALL TRANSACTION 'ME23N'.

ENDMETHOD. " HANDLE_HOTSPOT_CLICK

ENDCLASS. " LCL_EVENT_HANDLER
"&---------------------------------------------------------------------
*& Module STATUS_0100 OUTPUT
"&---------------------------------------------------------------------

*PBO Event
MODULE status_0100 OUTPUT.

SET PF-STATUS 'OOPS'.
SET TITLEBAR 'TIT'.

*Subroutine to fill the Variant Structure
PERFORM fill_variant.

IF w_grid IS INITIAL.

CREATE OBJECT w_grid
EXPORTING
* i_shellstyle = 0
* I_LIFETIME =
i_parent = cl_gui_container=>screen0
* I_APPL_EVENTS =
* I_PARENTDBG =
* I_APPLOGPARENT =
* I_GRAPHICSPARENT =
* I_NAME =
* I_FCAT_COMPLETE = SPACE
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. " IF SY-SUBRC 0

CALL METHOD w_grid->set_table_for_first_display
EXPORTING

* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
is_variant = w_variant
i_save = 'A'

i_default = 'X'
* IS_LAYOUT =
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = t_outtab
it_fieldcatalog = t_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. " IF SY-SUBRC 0.

ENDIF. " IF W_GRID IS INITIAL

CREATE OBJECT w_event_click.
SET HANDLER w_event_click->handle_hotspot_click FOR w_grid.

ENDMODULE. " STATUS_0100 OUTPUT
"&---------------------------------------------------------------------
*& Module USER_COMMAND_0100 INPUT
"&---------------------------------------------------------------------

*PAI Event
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
perform free_objects.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
perform free_objects.
LEAVE PROGRAM.
WHEN 'CANCEL'.
perform free_objects.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT

*&---------------------------------------------------------------------*

*& Form free_objects

*&---------------------------------------------------------------------*

* Free Objects

*----------------------------------------------------------------------*

form free_objects .

CALL METHOD w_grid->free

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_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.

endform. " free_objects

"&---------------------------------------------------------------------
*& Form PREPARE_FIELD_CATALOG
"&---------------------------------------------------------------------

*Subroutine to build the Field catalog

*<--P_T_FIELDCAT Field Catalog Table FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat . DATA ls_fcat TYPE lvc_s_fcat. * Purchasing group... ls_fcat-fieldname = 'EKGRP'. ls_fcat-ref_table = 'EKKO'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Purchasing Document Number... ls_fcat-fieldname = 'EBELN'. ls_fcat-ref_table = 'EKKO' . ls_fcat-emphasize = 'C411'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. ls_fcat-hotspot = 'X'. APPEND ls_fcat TO pt_fieldcat . CLEAR ls_fcat . * Name of Person who Created the Object... ls_fcat-fieldname = 'ERNAM'. ls_fcat-ref_table = 'EKKO'. ls_fcat-outputlen = '15' . APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Purchasing Document Date... ls_fcat-fieldname = 'BEDAT'. ls_fcat-ref_table = 'EKKO'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Vendor's account number... ls_fcat-fieldname = 'LIFNR'. ls_fcat-ref_table = 'EKKO'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Account Number of Vendor or Creditor... ls_fcat-fieldname = 'NAME1'. ls_fcat-ref_table = 'LFA1'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. ls_fcat-coltext = 'Vendor Name'(001). ls_fcat-seltext = 'Vendor Name'(001). APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Creation date of the change document... ls_fcat-fieldname = 'UDATE'. ls_fcat-ref_table = 'CDHDR'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. ls_fcat-coltext = 'Change Date'(002). ls_fcat-seltext = 'Change Date'(002). APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * User name of the person responsible in change document... ls_fcat-fieldname = 'USERNAME'. ls_fcat-ref_table = 'CDHDR'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '10'. ls_fcat-coltext = 'Modified by'(003). ls_fcat-seltext = 'Modified by'(003). APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Short Text Describing R/3 Repository Objects... ls_fcat-fieldname = 'DDTEXT'. ls_fcat-ref_table = 'DD04T'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '15'. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * Old contents of changed field... ls_fcat-fieldname = 'VALUE_OLD'. ls_fcat-ref_table = 'CDPOS'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '12'. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. * New contents of changed field... ls_fcat-fieldname = 'VALUE_NEW'. ls_fcat-ref_table = 'CDPOS'. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '12'. APPEND ls_fcat TO pt_fieldcat. CLEAR ls_fcat. ENDFORM. " PREPARE_FIELD_CATALOG "&--------------------------------------------------------------------- *& Form SELECT_PO "&--------------------------------------------------------------------- *Subroutine to select all the Purchase Orders *There are no interface parameters to be passed to this subroutine. FORM select_po . SELECT ebeln " Purchasing Document Number ernam " Name of Person who Created the Object lifnr " Vendor's account number ekgrp " Purchasing group bedat " Purchasing Document Date FROM ekko PACKAGE SIZE 10000 APPENDING TABLE t_ebeln WHERE ebeln IN s_ebeln AND bedat IN s_bedat. ENDSELECT. IF sy-subrc NE 0. w_flag = 1. MESSAGE s401(m8). ENDIF. " IF SY-SUBRC NE 0 ENDFORM. " SELECT_PO "&--------------------------------------------------------------------- *& Form SELECT_OBJ_ID "&--------------------------------------------------------------------- *Subroutine to select Object ID *There are no interface parameters to be passed to this subroutine. FORM select_obj_id . IF NOT t_ebeln IS INITIAL. SELECT objectclas " Object Class objectid " Object value changenr " Document change number username " User name udate " Creation date FROM cdhdr INTO TABLE t_cdhdr FOR ALL ENTRIES IN t_ebeln WHERE objectid EQ t_ebeln-ebeln AND udate IN s_udate AND tcode IN ('ME21N','ME22N','ME23N'). * ENDSELECT. IF sy-subrc NE 0. w_flag = 1. MESSAGE s833(m8) WITH 'Header Not Found'(031). ENDIF. " IF SY-SUBRC NE 0. ENDIF. " IF NOT T_EBELN IS INITIAL ENDFORM. " SELECT_OBJ_ID "&--------------------------------------------------------------------- *& Form SELECT_CHANGED_VALUE *&--------------------------------------------------------------------- *Subroutine to select Changed Values *There are no interface parameters to be passed to this subroutine. FORM select_changed_value . IF NOT t_cdhdr IS INITIAL. SELECT objectclas " Object class objectid " Object value changenr " Document change number tabname " Table Name fname " Field Name value_new " New contents of changed field value_old " Old contents of changed field FROM cdpos PACKAGE SIZE 10000 APPENDING TABLE t_cdpos FOR ALL ENTRIES IN t_cdhdr WHERE objectclas EQ t_cdhdr-objectclas AND objectid EQ t_cdhdr-objectid AND changenr EQ t_cdhdr-changenr. ENDSELECT. IF sy-subrc NE 0. w_flag = 1. MESSAGE s833(m8) WITH 'Item Not Found'(032). ENDIF. " IF SY-SUBRC NE 0. ENDIF. " IF NOT T_CDHDR IS INITIAL t_cdpos_temp[] = t_cdpos[]. ENDFORM. " SELECT_CHANGED_VALUE "&--------------------------------------------------------------------- *& Form SELECT_PUR_DOC "&--------------------------------------------------------------------- *Subroutine to select Purchase Order Details *There are no interface parameters to be passed to this subroutine. FORM select_pur_doc . IF NOT t_cdpos IS INITIAL. SORT t_ebeln BY ebeln. LOOP AT t_cdpos INTO fs_cdpos. READ TABLE t_ebeln INTO fs_ebeln WITH KEY ebeln = fs_cdpos-objectid BINARY SEARCH. IF sy-subrc NE 0. DELETE TABLE t_ebeln FROM fs_ebeln. ENDIF. " IF SY-SUBRC NE 0. ENDLOOP. " LOOP AT T_CDPOS... LOOP AT t_ebeln INTO fs_ebeln. MOVE fs_ebeln-ebeln TO fs_ekko-ebeln. MOVE fs_ebeln-ernam TO fs_ekko-ernam. MOVE fs_ebeln-lifnr TO fs_ekko-lifnr. MOVE fs_ebeln-ekgrp TO fs_ekko-ekgrp. MOVE fs_ebeln-bedat TO fs_ekko-bedat. APPEND fs_ekko TO t_ekko. ENDLOOP. " LOOP AT T_EBELN... t_ekko_temp[] = t_ekko[]. ENDIF. " IF NOT T_CDPOS IS INITIAL ENDFORM. " SELECT_PUR_DOC "&--------------------------------------------------------------------- *& Form SELECT_VENDOR "&--------------------------------------------------------------------- *Subroutine to select Vendor details *There are no interface parameters to be passed to this subroutine. FORM select_vendor . IF NOT t_ekko IS INITIAL. SORT t_ekko_temp BY lifnr. DELETE ADJACENT DUPLICATES FROM t_ekko_temp COMPARING lifnr. SELECT lifnr " Account Number of Vendor or Creditor name1 " Name 1 FROM lfa1 INTO TABLE t_lfa1 FOR ALL ENTRIES IN t_ekko_temp WHERE lifnr EQ t_ekko_temp-lifnr. IF sy-subrc NE 0. MESSAGE s002(m8) WITH 'Master Details'(033). ENDIF. " IF SY-SUBRC NE 0. ENDIF. " IF NOT T_EKKO IS INITIAL ENDFORM. " SELECT_VENDOR "&--------------------------------------------------------------------- *& Form DESCRIPTION "&--------------------------------------------------------------------- *Subroutine to get the description *There are no interface parameters to be passed to this subroutine. FORM description . IF NOT t_cdpos IS INITIAL. SORT t_cdpos_temp BY tabname fname. DELETE ADJACENT DUPLICATES FROM t_cdpos_temp COMPARING tabname fname . SELECT tabname " Table Name fieldname " Field Name rollname " Data element FROM dd03l INTO TABLE t_dataele FOR ALL ENTRIES IN t_cdpos_temp WHERE tabname EQ t_cdpos_temp-tabname AND fieldname EQ t_cdpos_temp-fname. IF NOT t_dataele IS INITIAL. t_dataele_temp[] = t_dataele[]. SORT t_dataele_temp BY rollname. DELETE ADJACENT DUPLICATES FROM t_dataele_temp COMPARING rollname. SELECT rollname " Data element ddtext " Short Text Describing R/3 Repository Objects FROM dd04t INTO TABLE t_text FOR ALL ENTRIES IN t_dataele_temp WHERE rollname EQ t_dataele_temp-rollname AND ddlanguage EQ sy-langu. IF sy-subrc NE 0. EXIT. ENDIF. " IF SY-SUBRC NE 0. ENDIF. " IF NOT T_DATAELE IS INITIAL. ENDIF. " IF NOT T_CDPOS IS INITIAL. ENDFORM. " DESCRIPTION "&--------------------------------------------------------------------- *& Form FILL_OUTTAB "&--------------------------------------------------------------------- *Subroutine to populate the Outtab *There are no interface parameters to be passed to this subroutine. FORM fill_outtab . SORT t_cdhdr BY objectclas objectid changenr. SORT t_ekko BY ebeln. SORT t_lfa1 BY lifnr. SORT t_dataele BY tabname fieldname. SORT t_text BY rollname. LOOP AT t_cdpos INTO fs_cdpos. READ TABLE t_cdhdr INTO fs_cdhdr WITH KEY objectclas = fs_cdpos-objectclas objectid = fs_cdpos-objectid changenr = fs_cdpos-changenr BINARY SEARCH. IF sy-subrc EQ 0. MOVE fs_cdhdr-username TO fs_outtab-username. MOVE fs_cdhdr-udate TO fs_outtab-udate. READ TABLE t_ekko INTO fs_ekko WITH KEY ebeln = fs_cdhdr-objectid BINARY SEARCH. IF sy-subrc EQ 0. MOVE fs_ekko-ebeln TO fs_outtab-ebeln. MOVE fs_ekko-ernam TO fs_outtab-ernam. MOVE fs_ekko-lifnr TO fs_outtab-lifnr. MOVE fs_ekko-ekgrp TO fs_outtab-ekgrp. MOVE fs_ekko-bedat TO fs_outtab-bedat. READ TABLE t_lfa1 INTO fs_lfa1 WITH KEY lifnr = fs_ekko-lifnr BINARY SEARCH. IF sy-subrc EQ 0. MOVE fs_lfa1-name1 TO fs_outtab-name1. ENDIF. " IF SY-SUBRC EQ 0. ENDIF. " IF SY-SUBRC EQ 0. ENDIF. " IF SY-SUBRC EQ 0. MOVE fs_cdpos-value_new TO fs_outtab-value_new. MOVE fs_cdpos-value_old TO fs_outtab-value_old. READ TABLE t_dataele INTO fs_dataele WITH KEY tabname = fs_cdpos-tabname fieldname = fs_cdpos-fname BINARY SEARCH. IF sy-subrc EQ 0. READ TABLE t_text INTO fs_text WITH KEY rollname = fs_dataele-rollname BINARY SEARCH. IF sy-subrc EQ 0. MOVE fs_text-ddtext TO fs_outtab-ddtext. ENDIF. " IF SY-SUBRC EQ 0. ENDIF. " IF SY-SUBRC EQ 0. APPEND fs_outtab TO t_outtab. CLEAR fs_outtab. ENDLOOP. ENDFORM. " FILL_OUTTAB "&--------------------------------------------------------------------- *& Form GET_CELL_INFO "&--------------------------------------------------------------------- *Subroutine to get the Cell Information *--> W_VALUE Holds the value of Hotspot clicked
FORM get_cell_info .

CALL METHOD w_grid->get_current_cell
IMPORTING

* E_ROW =
e_value = w_value

* E_COL =
* ES_ROW_ID =
* ES_COL_ID =
* ES_ROW_NO =
.
ENDFORM. " GET_CELL_INFO

"&---------------------------------------------------------------------
*& Form VALIDATE_PD_NUM
"&---------------------------------------------------------------------
*Subroutine to validate Purchase Document Number
*There are no interface parameters to be passed to this subroutine.
FORM validate_pd_num .

IF NOT s_ebeln[] IS INITIAL.
SELECT ebeln " Purchase Document Number
FROM ekko
INTO w_ebeln
UP TO 1 ROWS
WHERE ebeln IN s_ebeln.

ENDSELECT.

IF sy-subrc NE 0.
CLEAR sscrfields-ucomm.
MESSAGE e717(m8).
ENDIF. " IF SY-SUBRC NE 0
ENDIF. " IF NOT S_EBELN[]...

ENDFORM. " VALIDATE_PD_NUM

"&---------------------------------------------------------------------
*& Form VALIDATE_VEN_NUM
"&---------------------------------------------------------------------

*Subroutine to validate Vendor Number

*There are no interface parameters to be passed to this subroutine.
FORM validate_ven_num .

IF NOT s_lifnr[] IS INITIAL.
SELECT lifnr " Vendor Number
FROM lfa1
INTO w_lifnr
UP TO 1 ROWS
WHERE lifnr IN s_lifnr.

ENDSELECT.

IF sy-subrc NE 0.
CLEAR sscrfields-ucomm.
MESSAGE e002(m8) WITH w_space.
ENDIF. " IF SY-SUBRC NE 0
ENDIF. " IF NOT S_LIFNR[]...

ENDFORM. " VALIDATE_VEN_NUM
"&---------------------------------------------------------------------
*& Form VALIDATE_PUR_GRP
"&---------------------------------------------------------------------

*Subroutine to validate the Purchase Group

*There are no interface parameters to be passed to this subroutine.
FORM validate_pur_grp .

IF NOT s_ekgrp[] IS INITIAL.
SELECT ekgrp " Purchase Group
FROM t024
INTO w_ekgrp
UP TO 1 ROWS
WHERE ekgrp IN s_ekgrp.

ENDSELECT.

IF sy-subrc NE 0.
CLEAR sscrfields-ucomm.
MESSAGE e622(m8) WITH w_space.
ENDIF. " IF SY-SUBRC NE 0
ENDIF. " IF NOT S_EKFRP[]...

ENDFORM. " VALIDATE_PUR_GRP
"&---------------------------------------------------------------------
*& Form FILL_VARIANT
"&---------------------------------------------------------------------

*Subroutine to fill the Variant Structure

*There are no interface parameters to be passed to this subroutine
FORM fill_variant .
*Filling the Variant structure
w_variant-report = sy-repid.
w_variant-username = sy-uname.
ENDFORM. " FILL_VARIANT

source : http://abapreports.blogspot.com/2008/06/double-click-with-alv-oops.html

ALV using OOPS method

This document describes how to create an ALV using OOPS method in few steps. It will help the beginners to start with.

Procedure

Step 1: Create a container. There are 2 containers. They are docking and custom.

For eg.. Create docking container.

Go to SE38.Create a program. Use Pattern button to create object for docking container. Click ABAP Object Pattern radio button.

CREATE OBJECT o_docking

EXPORTING

* PARENT =

* REPID =

* DYNNR =

* SIDE = DOCK_AT_LEFT

* EXTENSION = 50

* STYLE =

* LIFETIME = lifetime_default

* CAPTION =

* METRIC = 0

RATIO = '95'

* NO_AUTODEF_PROGID_DYNNR =

* NAME =

* 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.

Step 2: Create a grid inside the container.

Use Pattern button to create the same. Make the parent of grid as container.

CREATE OBJECT o_grid

EXPORTING

* I_SHELLSTYLE = 0

* I_LIFETIME =

i_parent = o_docking

* 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.

Step 3: Call the function LVC_FIELDCATALOG_MERGE to get the fieldcatalog.

Pass the structure name.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

* I_BUFFER_ACTIVE =

I_STRUCTURE_NAME = 'MARA'

* I_CLIENT_NEVER_DISPLAY = 'X'

* I_BYPASSING_BUFFER =

* I_INTERNAL_TABNAME =

CHANGING

ct_fieldcat = i_fieldcat

* 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.

Step 4: Call the method of grid set_table_for_first_display to display the output.

w_variant-report = sy-repid.

CALL METHOD o_grid->set_table_for_first_display

EXPORTING

* I_BUFFER_ACTIVE =

* I_BYPASSING_BUFFER =

* I_CONSISTENCY_CHECK =

* I_STRUCTURE_NAME =

IS_VARIANT = w_variant

I_SAVE = 'A'

* I_DEFAULT = 'X'

* IS_LAYOUT =

* IS_PRINT =

* IT_SPECIAL_GROUPS =

* IT_TOOLBAR_EXCLUDING =

* IT_HYPERLINK =

* IT_ALV_GRAPHICS =

* IT_EXCEPT_QINFO =

CHANGING

it_outtab = itab

IT_FIELDCATALOG = i_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.

Step 5: Fill the internal table itab with values by using logic.

select * from mara into table itab up to 100 rows.

call screen 9000.

Create a screen by double clicking 9000 in the above line. Fill the description for the screen. In the flow logic, uncomment the PBO and PAI module and create those in main program (for simplicity).

Step 6: Create GUI status as below. Create GUI Title if required.

Step 7: Free the memory occupied once the 'BACK, EXIT' or 'CANCEL' button is clicked. Use Pattern button to call the method 'FREE' of cl_gui_alv_grid.

Complete Code

data : itab type standard table of mara,"Output Internal table

i_fieldcat type standard table of lvc_s_fcat,"Field catalog

wa type mara,

w_variant type disvariant,

o_docking type ref to cl_gui_docking_container,"Docking Container

o_grid type ref to cl_gui_alv_grid."Grid

select * from mara into table itab up to 100 rows.

call screen 9000.

*&---------------------------------------------------------------------*

*& Module STATUS_9000 OUTPUT

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

module STATUS_9000 output.
if o_docking is initial.
SET PF-STATUS 'ZSTATUS'. "GUI Status

SET TITLEBAR 'ZTITLE'. "Title

* Creating Docking Container

CREATE OBJECT o_docking

EXPORTING

RATIO = '95'.

IF sy-subrc eq 0.

* Creating Grid

CREATE OBJECT o_grid

EXPORTING

i_parent = o_docking.

ENDIF.

* Filling the fieldcatalog table

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = 'MARA'

CHANGING

ct_fieldcat = i_fieldcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

w_variant-report = sy-repid.

* Displaying the output

CALL METHOD o_grid->set_table_for_first_display

EXPORTING

IS_VARIANT = w_variant

I_SAVE = 'A'

CHANGING

it_outtab = itab

IT_FIELDCATALOG = i_fieldcat

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_9000 OUTPUT

*&---------------------------------------------------------------------*

*& Module USER_COMMAND_9000 INPUT

*&---------------------------------------------------------------------*

* PAI

*----------------------------------------------------------------------*

module USER_COMMAND_9000 input.

data lv_ucomm type sy-ucomm.

lv_ucomm = sy-ucomm.

CASE lv_ucomm.

WHEN 'CANCEL' OR 'EXIT'.

perform free_objects.

LEAVE PROGRAM.

when 'BACK'.

perform free_objects.

set screen '0'.

leave screen.

ENDCASE.

endmodule. " USER_COMMAND_9000 INPUT

*&---------------------------------------------------------------------*

*& Form free_objects

*&---------------------------------------------------------------------*

* Free Objects

*----------------------------------------------------------------------*

form free_objects .

CALL METHOD o_grid->free

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_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.

CALL METHOD o_docking->free

EXCEPTIONS

CNTL_ERROR = 1

CNTL_SYSTEM_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.

endform. " free_objects

source : https://wiki.sdn.sap.com/wiki/display/Snippets/ABAP-7%20Steps%20to%20create%20OOPS%20ALV(for%20beginners)