OOP Report Applying ALV Tree Combination and Splitter

ALV Tree

We had to create a report using splitter containers and a ALV tree structure per a client request. Although handling the combination of these two may seem challenging, it is actually rather simple. We quickly constructed a prototype, and it was flawless.

The basic programming skeleton of the prototype described below can be improved in a number of ways, but it should not change. We discovered certain hotly debated subjects online as we developed, and I’ve tried to hone in on them and address them in this piece.

Goal

This article’s goal is to clarify the usage of the TREE MODEL (TREE_STRUCTURE) and SPLITTER CONTAINER in OOPs ABAP report generation that integrates standard events.

The second, and more significant goal, is to permanently dispel our phobia of using Splitter Containers and Tree Models.

Range

  • This article addresses the following typical issues that developers run into:
  • When divided into many sub-containers, the custom container can be used to fill the entire screen.
  • Registering custom events using the tree model’s standard events
  • Customize splitter container widths.

Overview

The report with two containers in the list screen is displayed using the code that follows. The tree model is intended to be contained in the left panel container, while the contents of the left panel document will be displayed in the right container in response to a double click. This example shows how to design a tree structure using sales orders and sales contracts as the antecedent documents. Certain selection screen criteria can be applied to these sales orders in order to choose them. When the leaf node is clicked, the system will show the sales order data in the appropriate container in an ALV format (fig. 1).

Tree ALV

fig. – 1

Program Structure

Step I: Declare all necessary tables and structures
Step II: Declare the references to the different classes
Step III: Event class definition
Step IV: Putting the Event Class into Practice
Step V: The Choosing Screen
Step-VI: Subroutine to obtain the fundamental data for the tree model
Step VII: Design of the Screen
Step VIII: Module for creating different classes of objects. (In the output screen’s PBO)
Step IX: The event registration module. (In the output screen’s PBO)
Step X: The output processing module. (In the output screen’s PBO)

Step-I: Declare all required structures and tables

Tables: vbak,vbap,vbfa.

*&---------------------------------------------------------------------*
*&            Structures and Table Declarations
*&---------------------------------------------------------------------*
Data: ls_vbak type vbak,
lt_vbak type table of vbak,
ls_vbap type vbap,
lt_vbap type table of vbap.

Types: begin of ty_vbfa,
vbelv type vbfa-vbelv, "Preceding SD Document
posnv type vbfa-posnv, "Preceding SD Document Item Number
vbeln type vbfa-vbeln, "Subsequent SD Document
posnn type vbfa-posnn, "Subsequent SD Document Item Number
vbtyp_n type vbfa-vbtyp_n, "Subsequent Document Category
vbtyp_v type vbfa-vbtyp_v, "Preceding Document Category
end of ty_vbfa.

Data: ls_vbfa type ty_vbfa,
lt_vbfa type table of ty_vbfa.

Data: ls_vbfa_copy type ty_vbfa,
lt_vbfa_copy type table of ty_vbfa.

Types: begin of ty_vbak,
vbeln type vbak-vbeln,  "Contract Number
audat type vbak-audat,  "Document Date
ernam type vbak-ernam,  "Name of Person who Created the Object
auart type vbak-auart,  "Sales Document Type
end of ty_vbak.

Data: ls_vbak_cont type ty_vbak,
lt_vbak_cont type table of ty_vbak.

Step II: Declare the references to the different classes

*&---------------------------------------------------------------------*
*&            Type Reference of Various Classes
*&---------------------------------------------------------------------*
Data: ref_split type ref to cl_gui_splitter_container,
ref_cust  type ref to cl_gui_custom_container,
ref_alv1  type ref to cl_gui_alv_grid,
ref_alv2  type ref to cl_gui_alv_grid,
ref_cont1 type ref to cl_gui_container,
ref_cont2 type ref to cl_gui_container.
Data: ref_tree  type ref to cl_simple_tree_model.

Step – III: Definition of event class

*&---------------------------------------------------------------------*
*&                       Event Class
*&---------------------------------------------------------------------*
class lcl_event_handler definition.
public section.
methods: node_dc for event node_double_click of cl_simple_tree_model
importing node_key sender.
endclass.

Step – IV: Implementation of Event Class

class lcl_event_handler implementation.
method: node_dc.

Data: lt_children type tm_nodekey,
v_so        type vbeln,
v_item      type posnr.

Data: ls_layout type lvc_s_layo.
* 'sender' is an implicit event parameter that is provided by
* ABAP Objects runtime system. It contains a reference to the
* object that fired the event. You may directly use it to
* call methods of this instance.

CALL METHOD SENDER->NODE_GET_LAST_CHILD
EXPORTING
NODE_KEY       = node_key
IMPORTING
CHILD_NODE_KEY = lt_children.

* ‘Level_count’ in expand_node method determines in which level of the tree
* we want the double_click method to be triggered.

if lt_children is not initial.
CALL METHOD SENDER->EXPAND_NODE
EXPORTING
NODE_KEY            = node_key
LEVEL_COUNT         = 2.
endif.

split node_key at space into v_so v_item.

refresh: lt_vbap.

select * from vbap
into table lt_vbap
where vbeln = v_so.

if sy-subrc = 0.

ls_layout-grid_title = text-002.
ls_layout-zebra      = 'X'.
ls_layout-smalltitle = ''.
ls_layout-cwidth_opt = 'X'.

CALL METHOD REF_ALV2->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME              = 'VBAP'
IS_LAYOUT                     = ls_layout
CHANGING
IT_OUTTAB                     = lt_vbap.

CALL METHOD REF_ALV2->REFRESH_TABLE_DISPLAY.

endif.

endmethod.
endclass.

Step – V:  Selection Screen

*&---------------------------------------------------------------------*
*&                   Selection Screen
*&---------------------------------------------------------------------*
selection-screen: begin of block b1 with frame title text-001.
select-options: s_vbeln for vbak-vbeln, "Document Number
s_audat for vbak-audat, "Document Date
s_ernam for vbak-ernam. "Name who Created the Object
selection-screen: end of block b1.

Step-VI: Subroutine to obtain the fundamental data for the tree model

*&---------------------------------------------------------------------*
*&                   Start Of Selection
*&---------------------------------------------------------------------*
start-of-selection.
perform Get_Data.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       Get All the display relevant Data for Tree Structure
*----------------------------------------------------------------------*
FORM GET_DATA .

select vbeln audat ernam auart
from vbak
into table lt_vbak_cont
where vbeln in s_vbeln and
audat in s_audat and
ernam in s_ernam.

if sy-subrc <> 0.
message E001(ZMSG) with 'No Record Found' display like 'I'.
elseif sy-subrc = 0.

select vbelv posnv vbeln posnn vbtyp_n vbtyp_v
from vbfa
into table lt_vbfa
for all entries in lt_vbak_cont
where vbelv = lt_vbak_cont-vbeln and
vbtyp_n = 'C' and
vbtyp_v = 'G'.

if lt_vbfa is initial.
message E002(ZMSG) with 'No Subsequent Record Found' display like 'I'.
else.
select * from vbak
into table lt_vbak
for all entries in lt_vbfa
where vbeln = lt_vbfa-vbeln.

select * from vbap
into table lt_vbap
for all entries in lt_vbak
where vbeln = lt_vbak-vbeln.

endif.
endif.
ENDFORM.

Step – VII: Screen Design

call screen 0100.
Splitter Container

* The container should be drawn as large as possible. Also, the Lines/columns in the attributes tab of the screen painter are to be filled with the value 240 to get the full-screen splitter container.

OOPs ALV Report

Step – VIII: Module for object creation of various classes. (In PBO of output screen)

Create one module in the flow logic of the screen.

*&---------------------------------------------------------------------*
*&      Module  OBJECT_CREATION  OUTPUT
*&---------------------------------------------------------------------*
*       Object Creation for Classes
*----------------------------------------------------------------------*
MODULE OBJECT_CREATION OUTPUT.

CREATE OBJECT REF_CUST
EXPORTING
CONTAINER_NAME    = 'SPLIT_CONT'.

CREATE OBJECT REF_SPLIT
EXPORTING
PARENT            = ref_cust
ROWS              = 1
COLUMNS           = 2.

CALL METHOD REF_SPLIT->GET_CONTAINER
EXPORTING
ROW       = 1
COLUMN    = 1
RECEIVING
CONTAINER = ref_cont1.

The SET_COLUMN_WIDTH method can be used to change the splitter container’s width. As needed, pass the breadth.

CALL METHOD REF_SPLIT->SET_COLUMN_WIDTH
EXPORTING
ID                = 1
WIDTH             = 22.

CALL METHOD REF_SPLIT->GET_CONTAINER
EXPORTING
ROW       = 1
COLUMN    = 2
RECEIVING
CONTAINER = ref_cont2.

CREATE OBJECT REF_TREE
EXPORTING
NODE_SELECTION_MODE   = cl_simple_tree_model=>node_sel_mode_single.

CALL METHOD REF_TREE->CREATE_TREE_CONTROL
EXPORTING
PARENT                = ref_cont1.

CREATE OBJECT REF_ALV2
EXPORTING
I_PARENT  = ref_cont2.

ENDMODULE.                 " OBJECT_CREATION  OUTPUT

Step – IX: Module for event registration. (In PBO of output Screen)

ALV Tree
*&---------------------------------------------------------------------*
*&      Module  EVENT_REGISTRATION  OUTPUT
*&---------------------------------------------------------------------*
*       Double Click Event Registration

*§4a. Frontend registration(i):  get already registered tree events.
*................................................................
* The following four tree events registers ALV Tree in the constructor
* method itself.
*    - cl_gui_column_tree=>eventid_expand_no_children
* (needed to load data to frontend when a user expands a node)
*    - cl_gui_column_tree=>eventid_header_context_men_req
* (needed for header context menu)
*    - cl_gui_column_tree=>eventid_header_click
* (allows selection of columns (only when item selection activated))
*   - cl_gui_column_tree=>eventid_item_keypress
* (needed for F1-Help (only when item selection activated))
*
* Nevertheless you have to provide their IDs again if you register
* additional events with SET_REGISTERED_EVENTS (see below).
* To do so, call first method  GET_REGISTERED_EVENTS (this way,
* all already registered events remain registered, even your own):

* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.
*----------------------------------------------------------------------*
MODULE EVENT_REGISTRATION OUTPUT.
Data: lt_events type cntl_simple_events,
ls_event type cntl_simple_event.

Data: event_handler type ref to lcl_event_handler.

CALL METHOD REF_TREE->GET_REGISTERED_EVENTS
IMPORTING
EVENTS = lt_events.

ls_event-eventid = cl_simple_tree_model=>eventid_node_double_click.
append ls_event to lt_events.

CALL METHOD REF_TREE->SET_REGISTERED_EVENTS
EXPORTING
EVENTS                    = lt_events.

create object event_handler.
set handler event_handler->node_dc for ref_tree.

ENDMODULE.                 " EVENT_REGISTRATION  OUTPUT

Step – X: Module for output processing. (In PBO of output Screen)

OOPs ALV for Hierarchy Tree
*&---------------------------------------------------------------------*
*&      Module  PROCESSING_OUTPUT  OUTPUT
*&---------------------------------------------------------------------*
*       Processing Output of the Table
*----------------------------------------------------------------------*
MODULE PROCESSING_OUTPUT OUTPUT.

Data: ls_node type treemsnodt.

CALL METHOD REF_TREE->ADD_NODE
EXPORTING
NODE_KEY                = 'ROOT'
ISFOLDER                = 'X'
TEXT                    = 'Orders'
EXPANDER                = 'X'.

loop at lt_vbak into ls_vbak.

ls_node-node_key = ls_vbak-vbeln.

concatenate 'Sales Order#' ':' ls_vbak-vbeln
into ls_node-text
separated by space.

CALL METHOD REF_TREE->ADD_NODE
EXPORTING
NODE_KEY                = ls_node-node_key
RELATIVE_NODE_KEY       = 'ROOT'
RELATIONSHIP            = cl_simple_tree_model=>relat_last_child
ISFOLDER                = 'X'
TEXT                    = ls_node-text
EXPANDER                = 'X'.

endloop.

loop at lt_vbap into ls_vbap.

concatenate ls_vbap-vbeln ls_vbap-posnr
into ls_node-node_key
separated by space.

ls_node-relatkey = ls_vbap-vbeln.

concatenate ls_vbap-posnr ls_vbap-matnr
into ls_node-text
separated by space.

CALL METHOD REF_TREE->ADD_NODE
EXPORTING
NODE_KEY                = ls_node-node_key
RELATIVE_NODE_KEY       = ls_node-relatkey
RELATIONSHIP            = cl_simple_tree_model=>relat_last_child
ISFOLDER                = ''
TEXT                    = ls_node-text
EXPANDER                = ''.

endloop.
ENDMODULE.                 " PROCESSING_OUTPUT  OUTPUT

Change the design, but feel free to copy or refer to the included code. I would prefer to advise using the local class to help construct the complete report, or at the very least, using some modularization techniques. I utilized several PBO modules, which is strongly discouraged for any real-time object.

There are numerous different methods for creating tree topologies. There are a ton of documents available online. I chose the most straightforward method (the class name is, ironically, “cl_simple_tree_model”).Splitter containers have been extensively studied, although they are rarely utilized unless there are very particular needs.But all this claim is “Old wine in a new bottle,” that is all. I hope this eliminates our reluctance to use tree models and splitter containers.

alv reports in sap abap, alv report in sap abap, interactive alv report in sap abap, what is alv report in sap abap, alv full form in computer, alv full form in sap, alv full form
OOPs ABAP Tutorial
Selection Screen
Output Items on Screen
Increased List

Every post we write is the result of extensive planning, testing, and writing.It would be greatly appreciated by our team if you could forward this link to at least five friends or coworkers who you believe would find our content useful.In order to benefit everyone, keep our staff engaged, and ensure that our effort is not lost in the vast internet, we want our articles to be seen by as many people as possible.

Salesforce training modules

A World of History and Culture: Exploring the Past

Related Posts

Step by Step Guide to Install SAP Web IDE Personal Edition

Installing the SAP Web IDE personal edition did not require the use of any additional guides. However, there isn’t a single online guide that explains how to get over every…

Leave a Reply

Your email address will not be published. Required fields are marked *

You Missed

OOP Report Applying ALV Tree Combination and Splitter

  • By Varad
  • October 6, 2024
  • 2 views

SAP Fiori Tutorial. Part VI. How to Troubleshoot SAP Fiori Errors?

  • By Varad
  • October 5, 2024
  • 2 views
SAP Fiori Tutorial. Part VI. How to Troubleshoot SAP Fiori Errors?

Part 11 of Core Data Services: How Do I Use CDS View in the KPI Fiori Apps for Smart Business Services?

  • By Varad
  • October 4, 2024
  • 5 views
Part 11 of Core Data Services: How Do I Use CDS View in the KPI Fiori Apps for Smart Business Services?

SAP Fiori. Chapter 12: SAP Fiori Launchpad Tcode: Uses and Upkeep

  • By Varad
  • October 3, 2024
  • 5 views
SAP Fiori. Chapter 12:  SAP Fiori Launchpad Tcode: Uses and Upkeep

Step by Step Guide to Install SAP Web IDE Personal Edition

  • By Varad
  • October 2, 2024
  • 4 views
Step by Step Guide to Install SAP Web IDE Personal Edition

“A Strategic View of SAP Fiori: Insights from a Space Level Perspective”

  • By Varad
  • October 1, 2024
  • 7 views
“A Strategic View of SAP Fiori: Insights from a Space Level Perspective”