Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Call method set_table_for_first_display in SAP Query code (SQ02)

rafael_lopez011
Explorer
0 Likes
1,169

Hi,

I am trying to call method set_table_for_first_display in the code of an Infoset. I am able to GENERATE the Infoset but when I trying to run SAP Query with the Infoset I get an error.

I tried CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' and it works. I put the Call of the Function Moddule in START-OF-SELECTION Code Section. I am trying to do the same with the call screen but it is not working.

Can you tell me if this is possible?

This is the example:

Code Sections: DATA

CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.
DATA tree1 TYPE REF TO cl_gui_alv_tree_simple.
INCLUDE <icon>.
INCLUDE bcalv_simple_event_receiver.
DATA: gt_mara TYPE mara OCCURS 0, " Output-Table
gt_fieldcatalog TYPE lvc_t_fcat, " Field Catalog
gt_sort TYPE lvc_t_sort, " Sorting Table
ok_code LIKE sy-ucomm. " OK-Code

Code Section: START-OF-SELECTION

END-OF-SELECTION.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* This subroutine is used to build the field catalog for the ALV list
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
* get fieldcatalog
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'MARA'
CHANGING
ct_fieldcat = gt_fieldcatalog .

ENDFORM. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_OUTTAB
*&---------------------------------------------------------------------*
* Retrieving the data from the table and filling it in the output table
* of the ALV list
*----------------------------------------------------------------------*
FORM build_outtab.
SELECT * FROM mara INTO TABLE gt_mara.
ENDFORM. " BUILD_OUTTAB
*&---------------------------------------------------------------------*
*& Module PBO OUTPUT
*&---------------------------------------------------------------------*
* This subroutine is used to build the ALV Tree
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
IF tree1 IS INITIAL.
PERFORM init_tree.
ENDIF.
SET PF-STATUS 'ZSTATUS'.
ENDMODULE. " PBO OUTPUT
*&---------------------------------------------------------------------*
*& Module PAI INPUT
*&---------------------------------------------------------------------*
* This subroutine is used to handle the navigation on the screen
*----------------------------------------------------------------------*
MODULE pai INPUT.
CASE ok_code.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CLEAR ok_code.
ENDMODULE. " PAI INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
* free object and leave program
*----------------------------------------------------------------------*
FORM exit_program.
CALL METHOD tree1->free.
LEAVE PROGRAM.
ENDFORM. " exit_program
*&---------------------------------------------------------------------*
*& Form register_events
*&---------------------------------------------------------------------*
* Handling the events in the ALV Tree control in backend
*----------------------------------------------------------------------*
FORM register_events.
* define the events which will be passed to the backend
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event.
* define the events which will be passed to the backend
l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
APPEND l_event TO lt_events.
CALL METHOD tree1->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
* set Handler
DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->on_add_hierarchy_node
FOR tree1.
ENDFORM. " register_events
*&---------------------------------------------------------------------*
*& Form build_header
*&---------------------------------------------------------------------*
* build table for header
*----------------------------------------------------------------------*
FORM build_comment USING
pt_list_commentary TYPE slis_t_listheader
p_logo TYPE sdydo_value.
DATA: ls_line TYPE slis_listheader.
*
* LIST HEADING LINE: TYPE H
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'BoM TREE DEMO for Site Enablement'.
APPEND ls_line TO pt_list_commentary.
p_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "build_comment
*&---------------------------------------------------------------------*
*& Form init_tree
*&---------------------------------------------------------------------*
* Building the ALV-Tree for the first time display
*----------------------------------------------------------------------*
FORM init_tree.
PERFORM build_fieldcatalog.
PERFORM build_outtab.

* create container for alv-tree
DATA: l_tree_container_name(30) TYPE c,
l_custom_container TYPE REF TO cl_gui_custom_container.
l_tree_container_name = 'TREE1'.
CREATE OBJECT l_custom_container
EXPORTING
container_name = l_tree_container_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
* create tree control
CREATE OBJECT tree1
EXPORTING
i_parent = cl_gui_container=>screen0
i_node_selection_mode =
cl_gui_column_tree=>node_sel_mode_multiple
i_item_selection = 'X'
i_no_html_header = ''
i_no_toolbar = ''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
illegal_node_selection_mode = 5
failed = 6
illegal_column_name = 7.
* create info-table for html-header
DATA: lt_list_commentary TYPE slis_t_listheader,
l_logo TYPE sdydo_value.
PERFORM build_comment USING
lt_list_commentary
l_logo.
* repid for saving variants
DATA: ls_variant TYPE disvariant.
ls_variant-report = sy-repid.
* register events
PERFORM register_events.
* create hierarchy
CALL METHOD tree1->set_table_for_first_display
EXPORTING
it_list_commentary = lt_list_commentary
i_logo = l_logo
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
CHANGING
it_sort = gt_sort
it_outtab = gt_mara
it_fieldcatalog = gt_fieldcatalog.
* expand first level
CALL METHOD tree1->expand_tree
EXPORTING
i_level = 1.
* optimize column-width
CALL METHOD tree1->column_optimize
EXPORTING
i_start_column = tree1->c_hierarchy_column_name
i_end_column = tree1->c_hierarchy_column_name.
ENDFORM. " init_tree

1 REPLY 1
Read only

Sandra_Rossi
Active Contributor
0 Likes
824

You say "it is not working". Can you explain the symptoms and what you expect?