Skip to Content
-1

How to create a ALV tree??

Sep 22, 2017 at 07:19 AM

54

avatar image
Former Member

hi,

I am new to SAP ABAP. This a Demo program I was trying for ALV Tree. But the Tree is not getting displayed. I guess I may have missed out something in the code. Please can you'll guide me with it.

thanks in advance.

REPORT zt_alvtreeekkoekpo.

TYPES : BEGIN OF ty_ekko,
ebeln TYPE ebeln,
bukrs TYPE bukrs,
END OF ty_ekko.

TYPES : BEGIN OF ty_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF ty_ekpo.

TYPES : BEGIN OF ty_sum,
ebeln TYPE ebeln,
bukrs TYPE bukrs,
ebelp TYPE ebelp,
END OF ty_sum.

DATA : gt_ekko TYPE TABLE OF ty_ekko,
gt_ekpo TYPE TABLE OF ty_ekpo,
gt_sum TYPE TABLE OF ty_sum,
gt_fieldcat TYPE lvc_t_fcat,
gt_sort TYPE lvc_t_sort.

DATA : gs_ekko TYPE ty_ekko,
gs_ekpo TYPE ty_ekpo,
gs_sum TYPE ty_sum,
gs_fieldcat TYPE lvc_s_fcat,
gs_sort TYPE lvc_s_sort.

DATA : go_tree TYPE REF TO cl_gui_alv_tree_simple,
go_custom_container TYPE REF TO cl_gui_custom_container,
gv_ok_code TYPE sy-ucomm.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS : p_ebeln TYPE ekko-ebeln.
SELECTION-SCREEN END OF BLOCK b1.

CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'ZTTREE'.

IF go_tree IS INITIAL.
PERFORM init_tree.
ENDIF.
* SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE gv_ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANC'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form INIT_TREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_tree .
PERFORM build_outtab.

PERFORM process_outtab.

PERFORM fieldcat.

PERFORM display_tree.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_OUTTAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_outtab .
SELECT ebeln
bukrs
FROM ekko
INTO TABLE gt_ekko
WHERE ebeln = p_ebeln.

SELECT ebeln
ebelp
FROM ekpo
INTO TABLE gt_ekpo
FOR ALL ENTRIES IN gt_ekko
WHERE ebeln = gt_ekko-ebeln.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form PROCESS_OUTTAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process_outtab .
DATA : lv_index TYPE sy-index.

LOOP AT gt_ekko INTO gs_ekko.
gs_sum-ebeln = gs_ekko-ebeln.
gs_sum-bukrs = gs_ekko-bukrs.

READ TABLE gt_ekpo INTO gs_ekpo WITH KEY ebeln = gs_ekko-ebeln.
IF sy-subrc = 0.
lv_index = sy-index.
LOOP AT gt_ekpo INTO gs_ekpo FROM lv_index WHERE ebeln = gs_ekko-ebeln.
IF gs_ekko-ebeln = gs_ekpo-ebeln.
gs_sum-ebelp = gs_ekpo-ebelp.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fieldcat .
FREE gt_fieldcat.
CLEAR gs_fieldcat.

gs_fieldcat-fieldname = 'EBELN'.
gs_fieldcat-ref_table = 'EKKO'.
gs_fieldcat-ref_field = 'EBELN'.
gs_fieldcat-tabname = 'GT_SUM'.
gs_fieldcat-hotspot = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.

gs_sort-spos = 1.
gs_sort-fieldname = 'EBELN'.
gs_sort-up = 'X'.
gs_sort-subtot = 'X'.
APPEND gs_sort TO gt_sort.
CLEAR gs_sort.

gs_fieldcat-fieldname = 'BUKRS'.
gs_fieldcat-ref_table = 'EKKO'.
gs_fieldcat-ref_field = 'BUKRS'.
gs_fieldcat-tabname = 'GT_SUM'.
gs_fieldcat-hotspot = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.

gs_fieldcat-fieldname = 'EBELP'.
gs_fieldcat-ref_table = 'EKPO'.
gs_fieldcat-ref_field = 'EBELP'.
gs_fieldcat-tabname = 'GT_SUM'.
gs_fieldcat-hotspot = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_TREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_tree .
CREATE OBJECT go_custom_container
EXPORTING
* parent =
container_name = 'CS_CONT'
* style =
* lifetime = lifetime_default
* repid =
* dynnr =
* no_autodef_progid_dynnr =
* EXCEPTIONS
* cntl_error = 1
* cntl_system_error = 2
* create_error = 3
* lifetime_error = 4
* lifetime_dynpro_dynpro_link = 5
* others = 6
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


CREATE OBJECT go_tree
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = go_custom_container
* i_appl_events = space
* i_parentdbg =
* i_applogparent =
* i_graphicsparent =
* i_name =
* i_fcat_complete = SPACE
* EXCEPTIONS
* error_cntl_create = 1
* error_cntl_init = 2
* error_cntl_link = 3
* error_dp_create = 4
* others = 5
.
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 go_tree->set_table_for_first_display
* EXPORTING
* i_structure_name =
* is_variant =
* i_save =
* i_default = 'X'
* is_layout =
* it_special_groups =
* it_list_commentary =
* i_logo =
* i_background_id =
* it_toolbar_excluding =
* it_grouplevel_layout =
* it_except_qinfo =
CHANGING
it_outtab = gt_sum
it_fieldcatalog = gt_fieldcat
* it_filter =
it_sort = gt_sort.

CALL METHOD go_tree->expand_tree
EXPORTING
i_level = 1
* EXCEPTIONS
* failed = 1
* cntl_system_error = 2
* error_in_node_key_table = 3
* dp_error = 4
* node_not_found = 5
* others = 6
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.

10 |10000 characters needed characters left characters exceeded

Hi Palvi, I see you have already closed your question, but wanted to bring to your attention that the tag you chose, SAP Inside Track, was not the correct tag for your question (SAP Inside Track is an event). The list of available tags is here: https://www.sap.com/community/topic.all-content.html#all-content

Next time you post, select the the tag that is most relevant to your question to help get the attention of experts who can help. Other members follow tags based on their area of interest and expertise, and that affects what content gets in front of them via feeds and filters. With that, hopefully you will get a better response and have a better experience next time.

0
* Please Login or Register to Answer, Follow or Comment.

0 Answers