Interactive ALV Reporting using ABAP Objects in SAP

Go down

Interactive ALV Reporting using ABAP Objects in SAP Empty Interactive ALV Reporting using ABAP Objects in SAP

Post  Admin on Sun Apr 08, 2012 9:45 pm

REPORT Z_OOPS_15_EVENTHANDLR_ALV.

types: begin of ty_ekpo,
ebeln type ebeln,
ebelp type ebelp,
menge type menge_d,
netpr type netpr,
end of ty_ekpo.

data: it_ekpo type standard table of ty_ekpo.
data: wa_ekpo type ty_ekpo.

DATA:CONTROL TYPE SCRFNAME VALUE 'C1',
GRID TYPE REF TO CL_GUI_ALV_GRID,
CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA: IT_FCAT TYPE LVC_T_FCAT,
WA_FCAT TYPE LVC_S_FCAT,
WA_LAYOUT TYPE LVC_S_LAYO.

*---------------------------------------------------------------------*
* CLASS cl_event_receiver DEFINITION
*---------------------------------------------------------------------*
CLASS CL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
METHODS:
D_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN ES_ROW_NO.
ENDCLASS. "event_handler DEFINITION

*---------------------------------------------------------------------*
* CLASS cl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS CL_EVENT_HANDLER IMPLEMENTATION.
METHOD D_CLICK.
READ TABLE IT_EKPO INTO WA_EKPO INDEX E_ROW-INDEX.
CASE E_COLUMN-FIELDNAME.
WHEN 'EBELN'.
SET PARAMETER ID 'BES' FIELD WA_EKPO-EBELN.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDCASE.
CLEAR WA_EKPO.
ENDMETHOD. "D_CLICK
ENDCLASS. "event_handler IMPLEMENTATION



DATA: OBJ_EVENT_HANDLER TYPE REF TO CL_EVENT_HANDLER.



start-of-selection.
select * from ekpo into corresponding fields of table it_ekpo up to 10 rows.
if sy-subrc = 0.
call screen 1111.
endif.


*&---------------------------------------------------------------------*
*& Module STATUS_1111 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module STATUS_1111 output.
SET PF-STATUS 'WWWW'.
IF GRID IS INITIAL.
PERFORM CREATE_CONTAINER.
PERFORM CREATE_GRID.
PERFORM BUILD_LAYOUT.
PERFORM BUILD_FCAT.
PERFORM CALL_DISPLAY_METHOD.
**** Registering GRID object with EVENT_HANDLER method
CREATE OBJECT OBJ_EVENT_HANDLER.
SET HANDLER OBJ_EVENT_HANDLER->D_CLICK FOR GRID.
ELSE.
PERFORM CALL_REFRESH_METHOD.
ENDIF.

endmodule. " STATUS_1111 OUTPUT


*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1111 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module USER_COMMAND_1111 input.
CASE SY-UCOMM.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
endmodule. " USER_COMMAND_1111 INPUT

*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
FORM BUILD_LAYOUT .
* Set a titlebar for the grid control
WA_LAYOUT-GRID_TITLE = 'PO data'.
WA_LAYOUT-CWIDTH_OPT = 'X'.
WA_LAYOUT-ZEBRA = 'X'.
ENDFORM. " BUILD_LAYOUT




*&---------------------------------------------------------------------*
*& Form build_fcat
*&---------------------------------------------------------------------*
FORM BUILD_FCAT .
PERFORM BUILD_FCAT_RECORD USING 0 'EBELN' 'PO' 10.
PERFORM BUILD_FCAT_RECORD USING 1 'EBELP' 'ITEM' 4.
PERFORM BUILD_FCAT_RECORD USING 2 'MENGE' 'QTY' 16.
PERFORM BUILD_FCAT_RECORD USING 3 'NETPR' 'PRICE' 16.
ENDFORM. " build_fcat

*&---------------------------------------------------------------------*
*& Form build_fcat_record
*&---------------------------------------------------------------------*
FORM BUILD_FCAT_RECORD USING COL_POS FIELDNAME COL_TEXT LENGTH.
WA_FCAT-COL_POS = COL_POS.
WA_FCAT-FIELDNAME = FIELDNAME.
WA_FCAT-COLTEXT = COL_TEXT.
IF WA_FCAT-FIELDNAME = 'EBELN'.
WA_FCAT-KEY = 'X'.
ENDIF.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.
ENDFORM. " build_fcat_record



*&---------------------------------------------------------------------*
*& Form CREATE_CONTAINER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form CREATE_CONTAINER .
CREATE OBJECT container
EXPORTING
* PARENT =
container_name = 'C1'
* STYLE =
* LIFETIME = lifetime_default
* REPID =
* DYNNR =
* NO_AUTODEF_PROGID_DYNNR =
* 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.

endform. " CREATE_CONTAINER


*&---------------------------------------------------------------------*
*& Form CREATE_GRID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form CREATE_GRID .
CREATE OBJECT grid
EXPORTING
* I_SHELLSTYLE = 0
* I_LIFETIME =
i_parent = CONTAINER
* I_APPL_EVENTS = space
* 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.

endform. " CREATE_GRID


*&---------------------------------------------------------------------*
*& Form CALL_DISPLAY_METHOD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form CALL_DISPLAY_METHOD .
CALL METHOD grid->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = 'X'
IS_LAYOUT = wa_layout
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = it_ekpo
IT_FIELDCATALOG = it_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.

endform. " CALL_DISPLAY_METHOD


*&---------------------------------------------------------------------*
*& Form CALL_REFRESH_METHOD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form CALL_REFRESH_METHOD .
CALL METHOD grid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
* EXCEPTIONS
* FINISHED = 1
* others = 2
.
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. " CALL_REFRESH_METHOD

Admin
Admin

Posts : 92
Join date : 2012-01-26

http://mysaplab.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum