Autor Tema: TOP_OF_PAGE en ALV con Objetos  (Leído 22619 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado ale12

  • Usuario Completo
  • ***
  • Mensajes: 92
    • Ver Perfil
TOP_OF_PAGE en ALV con Objetos
« en: 16 de Febrero de 2010, 03:23:11 pm »
Hola,

alguien sabe o tiene un ejemplo de un ALV realizado con Objetos y que me pueda decir como hacer una cabecera en el TOP_OF_PAGE????


Gracias.

Desconectado dluis

  • Usuario Jr
  • **
  • Mensajes: 27
    • Ver Perfil
Re: TOP_OF_PAGE en ALV con Objetos
« Respuesta #1 en: 17 de Febrero de 2010, 09:51:29 am »
Hola,

Voy a intentar explicarte mas o menos como hacerlo.

De todas formas al final te adjunto un ejemplo donde puedes hacer un copia pega en un programa Z y mirarlo mas con calma.

Para empezar... buscas donde defines...

CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.


y añades...
Código: [Seleccionar]
    METHODS handle_top_of_page
    FOR EVENT top_of_page OF cl_gui_alv_grid
        IMPORTING e_dyndoc_id.

En... CLASS lcl_event_receiver IMPLEMENTATION.

pones...
Código: [Seleccionar]
  METHOD handle_top_of_page.
    PERFORM event_top_of_page USING e_dyndoc_id.

  ENDMETHOD.                            "top_of_page


Dentro del PERFORM es donde pintas tu cabecera... entiendo que esa parte la controlas.

Ahora viene lo mas importante... en el pbo_output vamos a partir nuestro contenedor en dos partes donde una la dejamos para la cabecera y la otra para el ALV.

Copio el ejemplo entero.

Código: [Seleccionar]
FORM pbo_output.

  DATA: lo_splitter           TYPE REF TO cl_gui_splitter_container.

  DATA: lo_event_receiver     TYPE REF TO lcl_event_receiver.

  DATA: lt_it_toolbar_excluding TYPE ui_functions.


  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'T9001_1'.

  IF go_custom_container IS INITIAL.

    CREATE OBJECT go_custom_container
      EXPORTING
        container_name = g_container_listado.

    CREATE OBJECT go_dyndoc_id
      EXPORTING
        style = 'ALV_GRID'.

    CREATE OBJECT lo_splitter
      EXPORTING
        parent  = go_custom_container
        rows    = 2
        columns = 1.



    CALL METHOD lo_splitter->get_container
      EXPORTING
        row       = 1
        column    = 1
      RECEIVING
        container = go_parent_top.


    CALL METHOD lo_splitter->get_container
      EXPORTING
        row       = 2
        column    = 1
      RECEIVING
        container = go_parent_grid.

    CALL METHOD lo_splitter->set_row_height
      EXPORTING
        id     = 1
        height = 14.

    CREATE OBJECT go_grid_listado
      EXPORTING
        i_parent = go_parent_grid.


************************
    CREATE OBJECT lo_event_receiver.

    SET HANDLER lo_event_receiver->handle_top_of_page
                FOR go_grid_listado.

    SET HANDLER lo_event_receiver->handle_data_changed
                 FOR go_grid_listado.

    SET HANDLER lo_event_receiver->handle_data_changed_finished
                 FOR go_grid_listado.

    SET HANDLER lo_event_receiver->on_hospot FOR go_grid_listado.

    SET HANDLER lo_event_receiver->handle_user_command
                    FOR go_grid_listado.
    SET HANDLER lo_event_receiver->handle_toolbar FOR go_grid_listado.

    CALL METHOD go_grid_listado->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.

    gs_layout-zebra      = 'X'.
    gs_layout-cwidth_opt = 'X'.
    gs_layout-ctab_fname = 'COLOR_CELDAS'.
    gs_layout-no_rowmark = 'X'.
    gs_variant-report  = sy-repid.
    gs_variant-variant = p_vari.


    CLEAR: gt_datos_tmp, gt_datos_tmp[].
    gt_datos_tmp[] = gt_datos[].


    CALL METHOD go_grid_listado->set_table_for_first_display
      EXPORTING                     " i_buffer_active = 'X'
        i_save               = 'A'
        is_variant           = gs_variant
        is_layout            = gs_layout
        it_toolbar_excluding = lt_it_toolbar_excluding
      CHANGING
        it_fieldcatalog      = gt_fieldcat
        it_sort              = gt_sort
        it_outtab            = gt_datos[].

**********************

    CALL METHOD go_dyndoc_id->initialize_document
      EXPORTING
        background_color = cl_dd_area=>col_textarea.

* Processing events
    CALL METHOD go_grid_listado->list_processing_events
      EXPORTING
        i_event_name = 'TOP_OF_PAGE'
        i_dyndoc_id  = go_dyndoc_id.


  ENDIF.

ENDFORM.                    " pbo_output



Y ahora... te dejo un programa para que te sirva de ejemplo, simplemente lo copias y pegas en un programa Z nuevo.

Código: [Seleccionar]

REPORT  z_oo_alv_top_of_page  MESSAGE-ID zz  .
DATA: it_flight TYPE TABLE OF sflight.

DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.

DATA:  g_container TYPE scrfname VALUE 'CONTROL',
o_dyndoc_id  TYPE REF TO cl_dd_document,
o_splitter   TYPE REF TO cl_gui_splitter_container,
o_parent_grid TYPE REF TO cl_gui_container,
o_parent_top TYPE REF TO cl_gui_container,
o_html_cntrl TYPE REF TO cl_gui_html_viewer.

*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_HANDLER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    METHODS:
*Event Handler for Top of page
    top_of_page FOR EVENT top_of_page
           OF cl_gui_alv_grid
           IMPORTING e_dyndoc_id.
ENDCLASS.             "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_HANDLER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD top_of_page.
* Top-of-page event
    PERFORM event_top_of_page USING o_dyndoc_id.

  ENDMETHOD.                            "top_of_page
ENDCLASS.       "LCL_EVENT_HANDLER IMPLEMENTATION

DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
      g_handler TYPE REF TO lcl_event_handler. "handler

START-OF-SELECTION.
  SELECT *
  FROM sflight
  UP TO 20 ROWS
  INTO TABLE it_flight.

END-OF-SELECTION.
  IF NOT it_flight[] IS INITIAL.

    CALL SCREEN 100.

  ELSE.

    MESSAGE i002 WITH 'NO DATA FOR THE SELECTION'(004).

  ENDIF.


*----------------------------------------------------------------------*
*  MODULE STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

  SET PF-STATUS 'STATUS'.

  SET TITLEBAR 'TITLE'.

  IF g_custom_container IS INITIAL.

    PERFORM create_and_init_alv.

  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT


*----------------------------------------------------------------------*
*  MODULE USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE sy-ucomm.

    WHEN 'BACK'.

      LEAVE TO SCREEN 0.

  ENDCASE.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_and_init_alv .

  DATA: g_grid TYPE REF TO cl_gui_alv_grid.

  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = g_container.

* Create TOP-Document
  CREATE OBJECT o_dyndoc_id
    EXPORTING
      style = 'ALV_GRID'.

* Create Splitter for custom_container
  CREATE OBJECT o_splitter
    EXPORTING
      parent  = g_custom_container
      rows    = 2
      columns = 1.

  CALL METHOD o_splitter->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = o_parent_top.

  CALL METHOD o_splitter->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = o_parent_grid.

* Set height for g_parent_html
  CALL METHOD o_splitter->set_row_height
    EXPORTING
      id     = 1
      height = 5.

  CREATE OBJECT g_grid
    EXPORTING
      i_parent = o_parent_grid.

  CREATE OBJECT g_handler.

  SET HANDLER g_handler->top_of_page FOR g_grid.

*Calling the Method for ALV output
  CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = 'SFLIGHT'
    CHANGING
      it_outtab        = it_flight[].


  CALL METHOD o_dyndoc_id->initialize_document
    EXPORTING
      background_color = cl_dd_area=>col_textarea.

* Processing events
  CALL METHOD g_grid->list_processing_events
    EXPORTING
      i_event_name = 'TOP_OF_PAGE'
      i_dyndoc_id  = o_dyndoc_id.


ENDFORM.                     "CREATE_AND_INIT_ALV


*&---------------------------------------------------------------------*
*&      Form  EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->DG_DYNDOC_ID  text
*----------------------------------------------------------------------*
FORM event_top_of_page USING   dg_dyndoc_id TYPE REF TO
cl_dd_document.

  DATA : dl_text(255) TYPE c.  "Text
  CALL METHOD dg_dyndoc_id->add_text
    EXPORTING
      text         = 'Flight Details'
      sap_style    = cl_dd_area=>heading
      sap_fontsize = cl_dd_area=>large
      sap_color    = cl_dd_area=>list_heading_int.

  CALL METHOD dg_dyndoc_id->add_gap
    EXPORTING
      width = 200.

  CALL METHOD o_dyndoc_id->add_picture
    EXPORTING
      picture_id = 'ENJOYSAP_LOGO'.

* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.

  CALL METHOD dg_dyndoc_id->new_line.


  CLEAR : dl_text.

* program ID
  dl_text = 'Program Name :'.

  CALL METHOD dg_dyndoc_id->add_gap.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_heading_int.

  CLEAR dl_text.

  dl_text = sy-repid.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_negative_inv.

* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.


  CLEAR : dl_text.


  CLEAR : dl_text.

* program ID
  dl_text = 'User Name :'.

  CALL METHOD dg_dyndoc_id->add_gap.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_heading_int.

  CLEAR dl_text.

  dl_text = sy-uname.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_negative_inv.

* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.


  CLEAR : dl_text.

* Run Date
  dl_text = 'Run Date :'.

  CALL METHOD dg_dyndoc_id->add_gap.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_heading_int.

  CLEAR dl_text.

* Move date
  WRITE sy-datum TO dl_text.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_negative_inv.

* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.

  CLEAR : dl_text.

*Time
  dl_text = 'Time :'.

  CALL METHOD dg_dyndoc_id->add_gap.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_heading_int.

  CLEAR dl_text.

* Move time
  WRITE sy-uzeit TO dl_text.

  CALL METHOD o_dyndoc_id->add_text
    EXPORTING
      text         = dl_text
      sap_emphasis = cl_dd_area=>heading
      sap_color    = cl_dd_area=>list_negative_inv.

* Add new-line
  CALL METHOD dg_dyndoc_id->new_line.


  PERFORM display.

ENDFORM.                    " EVENT_TOP_OF_PAGE

*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display.

* 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 i999 WITH 'Error in displaying top-of-page'(036).
  ENDIF.
ENDFORM.                    " display


Un saludo y espero que mas o menos te haya aclarado algo.