Skip to Content
author's profile photo Former Member
Former Member

How can I get HEADER in Excel Inplace, using OO CL_GUI_ALV_GRID

Good day. Please tell me what I need to do that in Excel Inplace transmitted header that is collected from the data selection screen? : BEGIN OF itab OCCURS 0 ,
vbeln LIKE likp - vbeln ,
posnr LIKE lips - posnr ,
drop ( 10 ),
END OF itab .

DATA : g_grid TYPE REF TO cl_gui_alv_grid ,
dg_dyndoc_id TYPE REF TO cl_dd_document ,
dg_splitter TYPE REF TO cl_gui_splitter_container ,
dg_parent_grid TYPE REF TO cl_gui_container ,
dg_html_cntrl TYPE REF TO cl_gui_html_viewer ,
dg_parent_html TYPE REF TO cl_gui_container .
*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS :
**event handler
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 .
*Top-of-page event
METHOD top_of_page . "implementation
PERFORM event_top_of_page USING dg_dyndoc_id .
ENDMETHOD . "TOP_OF_PAGE
ENDCLASS . "LCL_EVENT_HANDLER IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Global Definitions
DATA : g_custom_container TYPE REF TO cl_gui_custom_container , "Container1
g_handler TYPE REF TO lcl_event_handler . "handler
DATA : g_container1 TYPE scrfname VALUE 'TEST' ,
gs_layout TYPE lvc_s_layo .
DATA : v_lines TYPE i .
DATA : v_line ( 3 ) TYPE c .
DATA : it_fieldcat TYPE lvc_t_fcat ,

x_fieldcat TYPE lvc_s_fcat ,

ls_vari TYPE disvariant .

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

START-OF-SELECTION .
SELECT vbeln posnr FROM lips UP TO 20 ROWS
INTO CORRESPONDING FIELDS OF TABLE itab .
DESCRIBE TABLE itab LINES v_lines .

END-OF-SELECTION .
CALL SCREEN 100 .
**********************************************************************

FORM create_and_init_alv .
DATA : lt_exclude TYPE ui_functions .
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container1 .
* Create TOP-Document
CREATE OBJECT dg_dyndoc_id
EXPORTING style = 'ALV_GRID' .

* Create Splitter for custom_container
CREATE OBJECT dg_splitter
EXPORTING parent = g_custom_container
rows = 2 columns = 1 .
"i am allocating the space for grid and top of page
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 .
* Set height for g_parent_html
CALL METHOD dg_splitter -> set_row_height
EXPORTING id = 1 height = 20 .
**********************************************************************
CREATE OBJECT g_grid
EXPORTING i_parent = dg_parent_grid .
* Set a titlebar for the grid control
CLEAR gs_layout .
gs_layout - zebra = space .
gs_layout - cwidth_opt = 'X' .
gs_layout - no_rowmark = 'X' .
CREATE OBJECT g_handler .
SET HANDLER g_handler -> top_of_page FOR ALL INSTANCES . PERFORM build_fieldcat .
**Vaiant to save the layout
ls_vari - report = sy - repid .
ls_vari - handle = space .
ls_vari - log_group = space .
ls_vari - username = space .
ls_vari - variant = space .
ls_vari - text = space .
ls_vari - dependvars = space .
**Calling the Method for ALV output
CALL METHOD g_grid -> set_table_for_first_display
EXPORTING is_variant = ls_vari
is_layout = gs_layout
i_save = 'A'
CHANGING it_fieldcatalog = it_fieldcat
it_outtab = itab[] .

* Initializing document
CALL METHOD dg_dyndoc_id -> initialize_document .
* Processing events
CALL METHOD g_grid -> list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'
i_dyndoc_id = dg_dyndoc_id .
ENDFORM . "CREATE_AND_INIT_ALV
*& Form BUILD_FIELDCAT
FORM build_fieldcat .
DATA : l_pos TYPE i .
l_pos = l_pos + 1 .
x_fieldcat - scrtext_m = 'Delivery' ( 024 ).
x_fieldcat - fieldname = 'VBELN' .
x_fieldcat - tabname = 'IT_FINAL' .
x_fieldcat - col_pos = l_pos .
x_fieldcat - no_zero = 'X' .
x_fieldcat - outputlen = '10' .
x_fieldcat - hotspot = 'X' .
APPEND x_fieldcat TO it_fieldcat .
CLEAR x_fieldcat .
l_pos = l_pos + 1 .
x_fieldcat - scrtext_m = 'Item' ( 025 ).
x_fieldcat - fieldname = 'POSNR' .
x_fieldcat - tabname = 'IT_FINAL' .
x_fieldcat - col_pos = l_pos .
x_fieldcat - outputlen = '5' .
APPEND x_fieldcat TO it_fieldcat .
CLEAR x_fieldcat .
l_pos = l_pos + 1 .
x_fieldcat - scrtext_m = 'Drop' ( 025 ).
x_fieldcat - fieldname = 'DROP' .
x_fieldcat - tabname = 'IT_FINAL' .
x_fieldcat - col_pos = l_pos .
x_fieldcat - outputlen = '5' .
x_fieldcat - edit = 'X' .
x_fieldcat - drdn_hndl = '1' .
x_fieldcat - drdn_alias = 'X' .
APPEND x_fieldcat TO it_fieldcat .
CLEAR x_fieldcat .
ENDFORM . " build_fieldcat

* MODULE STATUS_0100 OUTPUT
MODULE status_0100 OUTPUT .
SET PF-STATUS 'MAIN100' .
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 EVENT_TOP_OF_PAGE

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 = 'Test Report'
sap_style = cl_dd_area => heading .
CALL METHOD dg_dyndoc_id -> new_line .
CLEAR : dl_text .

CONCATENATE 'Program Name :' sy - repid
INTO dl_text SEPARATED BY space .
PERFORM add_text USING dl_text .
CALL METHOD dg_dyndoc_id -> new_line .
CLEAR : dl_text .

CONCATENATE 'User ID :' sy - uname INTO dl_text SEPARATED BY space .
PERFORM add_text USING dl_text .
CALL METHOD dg_dyndoc_id -> new_line .
CLEAR : dl_text .

MOVE v_lines TO v_line .
CONCATENATE 'No of records :' v_line INTO dl_text SEPARATED BY space .
PERFORM add_text USING dl_text .
CALL METHOD dg_dyndoc_id -> new_line .
CLEAR : dl_text .

WRITE sy - datum TO dl_text .
CONCATENATE 'Date :' dl_text INTO dl_text SEPARATED BY space .
PERFORM add_text USING dl_text .
CALL METHOD dg_dyndoc_id -> new_line .
CLEAR : dl_text .

WRITE sy - uzeit TO dl_text .
CONCATENATE 'Time :' dl_text INTO dl_text SEPARATED BY space .
PERFORM add_text USING dl_text .
CALL METHOD dg_dyndoc_id -> new_line .
* Populating data to html control
PERFORM html .
ENDFORM . " EVENT_TOP_OF_PAGE

*& Form ADD_TEXT
FORM add_text USING p_text TYPE sdydo_text_element .
* Adding text
CALL METHOD dg_dyndoc_id -> add_text
EXPORTING text = p_text
sap_emphasis = cl_dd_area => heading .
ENDFORM . " ADD_TEXT

*& Form HTML
FORM html .
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 .
CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
EXPORTING document = dg_dyndoc_id
bottom = space
IMPORTING length = dl_length .

CALL METHOD dg_dyndoc_id -> merge_document .

CALL METHOD dg_dyndoc_id -> set_document_background
EXPORTING picture_id = dl_background_id .
dg_dyndoc_id -> html_control = dg_html_cntrl .
CALL METHOD dg_dyndoc_id -> display_document
EXPORTING reuse_control = 'X'
parent = dg_parent_html
EXCEPTIONS html_display_error = 1 .
ENDFORM . " HTML
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jul 11, 2015 at 04:17 PM

    Hello Sergey,

    My understanding is you want Field names in excel file download instead of the technical names.

    Like --> Delivery, item. Not like --> VBELN, POSNR.

    If my understanding is correct, why don't your try with Excel template where in your create your template and use it.

    I am also not much familiar with the excel template upload, but you can find lot of documents in SCN about this, just do some research on this, it might help you I guess.

    Managing Templates - SAP List Viewer (ALV) Grid Control (BC-SRV-ALV) - SAP Library

    How to export excel file with template

    Regards,

    TP

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Thanga.

      Thanks for answering.But you did not understand me.

      When i use FM REUSE_ALV_GRID_DISPLAY then HEADER and DATA and NAME FIELD filling on list excel "Header", if I click Excel Inplace(stdr comand in pf-status &VEXCEL).

      But when i use OO CL_GUI_ALV_GRID and click Excel Inplace, fills only NAME FIELD and DATA on excel list "Header". I use cl_gui_splitter_conteiner 2 cl_gui_conteiner.

      1-st container - HTML data - HEADER REPORT + other data(e.g. Name organization. + date + user).

      2-nd container - ALV-grid.

      When i using REUSE_ALV_GRID_DISPLAY then It was parametr - I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE', and data in FORM TOP-OF-PAGE i see in Excel Inplase on list Header.

      When i use CL_GUI_ALV_GRID and event TOP_OF_PAGE for fill 1-st container i not see in Excel Inplase on list excel "Header" data from 1-st container.

      I have tried FM REUSE_ALV_COMMENTARY_WRITE and method cl_gui_alv_grid->SET_HTML_HEADER, but I did not succeed.

      __________________________________________________________________________

      RawHeader: Raw header without formatting - when i use OO, is empty! if i use fm - fill.

      Note 358644 - ALV Export Excel: Recommendations and known errors

        3. Excel inplace

      As of 4. 6C, you can display data in the inplace in almost the same way as in the Grid for ALV Grid Fullscreen and ALV Grid class. However, certain preconditions (for example Excel Templates) must be fulfilled for you to do this. Refer to Note 305900; this gives you the optimal solution for the existing disadvantages of the XXL interface and information about how to download into a local file.

      • Different Excel worksheets are displayed:
      • Format: The formatted output of the table in Excel
      • Header: Format + HTML header data for the ALV Fullscreen
      • Pivot: Data in Pivot format (cross table)
      • Sub1 to Sub10: n-level output of subtotal lines
      • RawData: Raw data without formatting
      • RawHeader: Raw header without formatting
      • In the Excel print dialog, you can choose "Selected pages". Then the system only prints the Excel sheet currently displayed.
      • The Excel print preview and Excel save functions do not work because Excel is running in the inplace.
      • The HEADER sheet is filled only if the application has filled the HTML header of the ALV Fullscreen using the REUSE_ALV_COMMENTARY_WRITE service function module. If "free" HTML was generated using the object reference of a dynamic document, this header cannot be mapped in Excel.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.