Sunday, March 13, 2011

ALV Splitter Screen Create Header

Steps in creating a header in a splitter screen:


Prerequisite:
1. Read topic.
2. Create your own event class and include method to handle top of page as shown below:


2. Put this code inside the method: This will generate the text in your header.

DATA : DL_TEXT(255TYPE C.
DATA: l_v_proj_name(255TYPE c"VALUE 'Project Name: '.
DATA: l_v_tow_name(255)  TYPE c"VALUE 'Tower Name: '.
DATA: l_v_date(255)      TYPE c"VALUE 'As of: '.

*  CALL METHOD ZCL_ALV2=>O_DYNDOC_ID->ADD_GAP
*    EXPORTING
*    WIDTH = 100.

  CONCATENATE 'Project Name: ' ZCL_MODEL_ZPROJ_CONST=>at_header_ltext
  INTO at_v_proj_name SEPARATED BY SPACE.
*
  CALL METHOD ZCL_ALV2=>O_DYNDOC_ID->add_text"DG_DYNDOC_ID->ADD_TEXT
    EXPORTING
    TEXT = at_v_proj_name
    "SAP_STYLE = CL_DD_AREA=>HEADING
    SAP_EMPHASIS = CL_DD_AREA=>strong
    SAP_FONTSIZE = CL_DD_AREA=>LARGE.
    "SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT."LIST_HEADING_INT.

  CALL METHOD ZCL_ALV2=>O_DYNDOC_ID->new_line."DG_DYNDOC_ID->NEW_LINE.
*
  CONCATENATE 'Tower Name: ' ZCL_MODEL_ZPROJ_CONST=>at_header_ktext
  INTO at_v_tow_name SEPARATED BY SPACE.
*
  CALL METHOD ZCL_ALV2=>O_DYNDOC_ID->add_text"DG_DYNDOC_ID->ADD_TEXT
    EXPORTING
    TEXT = at_v_tow_name
    "SAP_STYLE = CL_DD_AREA=>HEADING
    SAP_EMPHASIS = CL_DD_AREA=>strong
    SAP_FONTSIZE = CL_DD_AREA=>large.
    "SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.

  CALL METHOD ZCL_ALV2=>O_DYNDOC_ID->new_line."DG_DYNDOC_ID->NEW_LINE.

  CONCATENATE  sy-datum+4(2' / ' sy-datum+6(2' / ' sy-datum(4)
  INTO at_v_date.
*
  CONCATENATE 'As of: ' at_v_date "sy-datum
  INTO at_v_date SEPARATED BY SPACE.

  CALL METHOD ZCL_ALV2=>O_DYNDOC_ID->add_text"DG_DYNDOC_ID->ADD_TEXT
    EXPORTING
    TEXT = at_v_date
    "SAP_STYLE = CL_DD_AREA=>HEADING
    SAP_EMPHASIS = CL_DD_AREA=>strong
    SAP_FONTSIZE = CL_DD_AREA=>large.
    "SAP_COLOR = CL_DD_AREA=>LIST_HEADING_INT.


3. Include the ff. code to your main class/program


"this will set you event handler class so that it will be triggered
    DATA: G_HANDLER TYPE REF TO ZCL_EH_PROJ_CONST_ALV.

    CREATE OBJECT:  G_HANDLER.

    at_obj_event_handler ?= G_HANDLER.

    SET HANDLER at_obj_event_handler->HANDLE_TOP_OF_PAGE FOR at_grid1.
    SET HANDLER at_obj_event_handler->HANDLE_PRINT_TOP_OF_PAGE FOR at_grid1.


4. This code will trigger your event


  CALL METHOD O_DYNDOC_ID->INITIALIZE_DOCUMENT
    EXPORTING
    BACKGROUND_COLOR = CL_DD_AREA=>COL_TEXTAREA.

* Processing events <br />
  CALL METHOD at_GRID1->LIST_PROCESSING_EVENTS
    EXPORTING
    I_EVENT_NAME = 'TOP_OF_PAGE'
    I_DYNDOC_ID = O_DYNDOC_ID.

  DISPLAY_OTP( ).


5. Inside Display_otp( ).


* Creating html control
  IF O_HTML_CNTRL IS INITIAL.
    CREATE OBJECT O_HTML_CNTRL
         EXPORTING
              PARENT    = O_PARENT_TOP.
  ENDIF.
  CALL METHOD O_DYNDOC_ID->MERGE_DOCUMENT.
  O_DYNDOC_ID->HTML_CONTROL = O_HTML_CNTRL.
* Display document
  CALL METHOD O_DYNDOC_ID->DISPLAY_DOCUMENT
    EXPORTING
      REUSE_CONTROL      = 'X'
      PARENT             = O_PARENT_TOP
    EXCEPTIONS
      HTML_DISPLAY_ERROR = 1.
  IF SY-SUBRC NE 0.
     MESSAGE 'Error in displaying top-of-page' TYPE 'E' DISPLAY LIKE 'I'."I999     
  ENDIF.

No comments:

Post a Comment