*& REPORT ZDEMO_TEST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT YDEMO_TEST.
PARAMETERS: P_MATNR TYPE MARA-MATNR.
TYPES: BEGIN OF TYPE_MARA,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
END OF TYPE_MARA.
DATA: T_MARA TYPE STANDARD TABLE OF TYPE_MARA,
W_MARA TYPE TYPE_MARA.
DATA: O_CONTAIN TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
O_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA: T_FCAT TYPE LVC_T_FCAT,
W_FCAT TYPE LVC_S_FCAT.
DATA: DG_PARENT_GRID TYPE REF TO CL_GUI_CONTAINER,
DG_PARENT_HTML TYPE REF TO CL_GUI_CONTAINER,
DG_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT,
DG_HTML_CNTRL TYPE REF TO CL_GUI_HTML_VIEWER.
CLASS LCL_EVENT DEFINITION.
PUBLIC SECTION.
METHODS: EVENT_HANDLE FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
TOP_OF_PAGE1 FOR EVENT TOP_OF_PAGE OF CL_GUI_ALV_GRID IMPORTING E_DYNDOC_ID.
ENDCLASS.
*&---------------------------------------------------------------------*
*& CLASS (IMPLEMENTATION) LCL_EVENT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
CLASS LCL_EVENT IMPLEMENTATION.
METHOD EVENT_HANDLE.
CASE E_COLUMN_ID-FIELDNAME.
WHEN 'MATNR'.
READ TABLE T_MARA INTO W_MARA INDEX E_ROW_ID-INDEX ."TRANSPORTING MATNR.
IF SY-SUBRC EQ 0.
SET PARAMETER ID 'MAT' FIELD W_MARA-MATNR.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
METHOD TOP_OF_PAGE1 .
DATA : DL_TEXT(255) TYPE C. "TEXT
DATA: LV_DATE TYPE CHAR10.
CALL METHOD DG_DYNDOC_ID->ADD_TEXT
EXPORTING
TEXT = 'THIS IS DEMO OF TOP OF PAGE THIS IS DEMO OF TOP OF PAGE THIS IS DEMO OF TOP OF PAGE THIS IS DEMO OF TOP OF PAGE THIS IS DEMO OF TOP OF PAGE THIS IS DEMO OF TOP OF PAGE'
SAP_STYLE = CL_DD_AREA=>HEADING.
CALL METHOD DG_DYNDOC_ID->NEW_LINE.
CONCATENATE SY-DATUM+6(2) SY-DATUM+4(2) SY-DATUM+0(4) INTO LV_DATE SEPARATED BY '.'.
CONCATENATE 'DATE : ' LV_DATE INTO DL_TEXT SEPARATED BY SPACE.
CALL METHOD DG_DYNDOC_ID->ADD_TEXT
EXPORTING
TEXT = DL_TEXT
SAP_STYLE = CL_DD_AREA=>HEADING.
PERFORM F_SET_HEADER_HTML USING DG_DYNDOC_ID.
ENDMETHOD.
ENDCLASS. "LCL_EVENT
START-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& MODULE STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
IF O_CONTAIN IS INITIAL.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'TITLE'.
CREATE OBJECT O_CONTAIN
EXPORTING
CONTAINER_NAME = 'CONT'.
ENDIF.
CREATE OBJECT DG_DYNDOC_ID
EXPORTING STYLE = 'ALV_GRID'.
CREATE OBJECT DG_SPLITTER
EXPORTING
PARENT = O_CONTAIN
ROWS = 2
COLUMNS = 1.
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 DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_HTML.
CALL METHOD DG_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = DG_PARENT_GRID
.
CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
EXPORTING
ID = 1
HEIGHT = 20.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
CREATE OBJECT O_GRID
EXPORTING I_PARENT = DG_PARENT_GRID.
* CALL METHOD O_GRID->REGISTER_EDIT_EVENT
* EXPORTING
* I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
PERFORM F_FETCH.
IF T_MARA IS NOT INITIAL.
PERFORM F_BUILD_FCAT.
PERFORM F_REGISTER_HANDLER.
PERFORM F_DISPLAY_TABLE.
ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*& MODULE USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'EXIT' .
LEAVE PROGRAM.
* WHEN .
WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& FORM F_FETCH
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM F_FETCH .
SELECT
MATNR
ERSDA
ERNAM
FROM MARA INTO TABLE T_MARA UP TO 30 ROWS..
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_BUILD_FCAT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM F_BUILD_FCAT .
W_FCAT-FIELDNAME = 'MATNR'.
W_FCAT-KEY = 'X'.
W_FCAT-COLTEXT = 'MATERIAL NUMBER '.
W_FCAT-HOTSPOT = 'X'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'ERSDA'.
W_FCAT-COLTEXT = 'CREATED DATE '.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
W_FCAT-FIELDNAME = 'ERNAM'.
W_FCAT-COLTEXT = 'NAME '.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_REGISTER_HANDLER
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM F_REGISTER_HANDLER .
DATA: O_HANDLE TYPE REF TO LCL_EVENT.
CREATE OBJECT O_HANDLE.
SET HANDLER O_HANDLE->EVENT_HANDLE FOR O_GRID.
SET HANDLER O_HANDLE->TOP_OF_PAGE1 FOR O_GRID.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_DISPLAY_TABLE
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM F_DISPLAY_TABLE .
CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE = SPACE
I_BYPASSING_BUFFER = 'X'
I_STRUCTURE_NAME = 'TYPE_MARA'
I_SAVE = 'A'
CHANGING
IT_OUTTAB = T_MARA
IT_FIELDCATALOG = T_FCAT
* IT_SORT =
* IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
OTHERS = 4
.
IF SY-SUBRC <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
"DO THESE..{
* INITIALIZING DOCUMENT
CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.
* PROCESSING EVENTS
CALL METHOD O_GRID->LIST_PROCESSING_EVENTS
EXPORTING
I_EVENT_NAME = 'TOP_OF_PAGE'
I_DYNDOC_ID = DG_DYNDOC_ID.
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM F_SET_HEADER_HTML
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM F_SET_HEADER_HTML USING DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.
DATA : DL_LENGTH TYPE I, " LENGTH
DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " BACKGROUND_ID
* CREATING HTML CONTROL
IF DG_HTML_CNTRL IS INITIAL.
CREATE OBJECT DG_HTML_CNTRL
EXPORTING
PARENT = DG_PARENT_HTML.
ENDIF.
* REUSE_ALV_GRID_COMMENTARY_SET
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING
DOCUMENT = DG_DYNDOC_ID
BOTTOM = SPACE
IMPORTING
LENGTH = DL_LENGTH.
* GET TOP->HTML_TABLE READY
CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.
* SET WALLPAPER
CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND
EXPORTING
PICTURE_ID = DL_BACKGROUND_ID.
* CONNECT TOP DOCUMENT TO HTML-CONTROL
DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.
* DISPLAY TOP DOCUMENT
CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT
EXPORTING
REUSE_CONTROL = 'X'
PARENT = DG_PARENT_HTML
EXCEPTIONS
HTML_DISPLAY_ERROR = 1.
IF SY-SUBRC NE 0.
MESSAGE 'ERROR IN DISPLAYING TOP-OF-PAGE' TYPE 'E'.
ENDIF.
ENDFORM.
Serkan AKKAVAK
Computer Engineer BSc
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com
0 Comments