Simple Tree using custom container
Hi all,
I am facing a problem, I am preparing a simple tree in a custom container of using two table such as mchb and mska, from these table i am selecting fields wearks ,matrn ,veblen, quantity , lgort (storage location) and made a internal table, for using this fields I sorted three times with werks for plant than storage location for those plant which was sorted than material comes for all sorted plant and storage location ,for all sorting I made node for all i was using CONCATENATE command using index take all values of sorting make local index for all sorting, now i want to make when i double-click on material i want all field come in my tablecontrol which is there and than I want a pop-up window comes for further processing.
plese help me.
Ankur Garg.
Hi Ankur,
Refer the standard program SAPSIMPLE_TREE_CONTROL_DEMO in SE38.
Refer the following code in the include SIMPLE_TREE_CONTROL_DEMOCL1.
CLASS LCL_APPLICATION DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_NODE_DOUBLE_CLICK
FOR EVENT NODE_DOUBLE_CLICK
OF CL_GUI_SIMPLE_TREE
IMPORTING NODE_KEY,
HANDLE_EXPAND_NO_CHILDREN
FOR EVENT EXPAND_NO_CHILDREN
OF CL_GUI_SIMPLE_TREE
IMPORTING NODE_KEY.
ENDCLASS.
CLASS LCL_APPLICATION IMPLEMENTATION.
METHOD HANDLE_NODE_DOUBLE_CLICK.
" this method handles the node double click event of the tree
" control instance
" show the key of the double clicked node in a dynpro field
G_EVENT = 'NODE_DOUBLE_CLICK'.
G_NODE_KEY = NODE_KEY.
ENDMETHOD.
<b>Reward points if it helps.</b>
Message was edited by: Amit Mishra
Similar Messages
-
Hi all,
I have read that you use Custom container class for oops alv. But i have not found an answer as to why do we have to use the class.
Can't we just use ALV class only (Cl_gui_alv_grid) ?.
Regards
VarunYou can only create a grid display in a container...while creating the object for grid contol you have to pass the object reference of the custom container...check out the following for details...
*& Report ZTEST_DEMO_ALV
report ztest_demo_alv.
class cl_event_reciever definition deferred.
data:
wa_vbak type vbak.
data:
i_vbak type standard table of vbak,
i_vbap type standard table of vbap.
data:
v_container1 type scrfname value 'CONT1',
v_grid1 type ref to cl_gui_alv_grid,
v_custom_container1 type ref to cl_gui_custom_container,
v_container2 type scrfname value 'CONT2',
v_grid2 type ref to cl_gui_alv_grid,
v_custom_container2 type ref to cl_gui_custom_container,
ok_code type syucomm,
v_event_reciever type ref to cl_event_reciever.
* CLASS cl_event_reciever DEFINITION
class cl_event_reciever definition.
public section.
methods:
handle_double_click for event double_click of cl_gui_alv_grid
importing e_row e_column.
endclass. "cl_event_reciever DEFINITION
* CLASS cl_event_reciever IMPLEMENTATION
class cl_event_reciever implementation.
method handle_double_click.
read table i_vbak
into wa_vbak
index e_row.
if sy-subrc = 0.
select * from vbap
into table i_vbap
where vbeln = wa_vbak-vbeln.
if sy-subrc = 0.
set screen 00.
leave to screen 100.
endif.
endif.
endmethod. "handle_double_click
endclass. "cl_event_reciever IMPLEMENTATION
select-options:
s_vbeln for wa_vbak-vbeln.
start-of-selection.
select * from vbak
into table i_vbak
up to 50 rows
where vbeln in s_vbeln.
if sy-subrc <> 0.
message i000(z_zzz_ca_messages) with 'No data found!'.
leave list-processing.
endif.
end-of-selection.
call screen 100.
*& Module STATUS_0100 OUTPUT
* text
module status_0100 output.
set pf-status '100'.
* SET TITLEBAR 'xxx'.
if v_custom_container1 is not bound.
create object v_custom_container1
exporting container_name = v_container1.
create object v_grid1
exporting i_parent = v_custom_container1.
call method v_grid1->set_table_for_first_display
exporting
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
i_structure_name = 'VBAK'
* is_variant =
* i_save =
* i_default = 'X'
* is_layout =
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
changing
it_outtab = i_vbak
* it_fieldcatalog =
* it_sort =
* it_filter =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
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 v_event_reciever.
set handler v_event_reciever->handle_double_click for v_grid1.
endif.
if v_custom_container2 is not bound
and i_vbap is not initial.
create object v_custom_container2
exporting container_name = v_container2.
create object v_grid2
exporting i_parent = v_custom_container2.
call method v_grid2->set_table_for_first_display
exporting
* i_buffer_active =
* i_bypassing_buffer =
* i_consistency_check =
i_structure_name = 'VBAP'
* is_variant =
* i_save =
* i_default = 'X'
* is_layout =
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
changing
it_outtab = i_vbap
* it_fieldcatalog =
* it_sort =
* it_filter =
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
endif.
if v_custom_container2 is bound.
call method v_grid2->refresh_table_display.
endif.
endmodule. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
module user_command_0100 input.
case ok_code.
when 'BACK'.
if v_grid1 is bound.
call method v_grid1->free.
endif.
if v_grid2 is bound.
call method v_grid2->free.
endif.
set screen 00.
leave screen.
endcase.
endmodule. " USER_COMMAND_0100 INPUT -
How to get custom PF status in ALV using cl_salv_table (Using a container)
I created a screen and inside that a container.I tried for an ALV display using CL_SALV_TABLE in the cvontainer. It's working. when I opted for default PF status.It's working. But when I tried for custom PF status using SET_SCREEN_STATUS method, it's throwing some exception. But it's working if I don't use a container .
In both the cases I copied PF status into my program from some standard program.Then added some functionality.I f you are using Screen and container use CLass:
CL_GUI_ALV_CONTAINER
CL_GUI_ALV_GRID
METHOD-->SET_TABLE_FOR_FIRST_DISPLAY " to display Alv.
Create PF-STATUS in PBO of screen.
[Change standard PF|https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/change%252balv%252bstandard%252btoolbar%252band%252brespond%252bit]
EXCLUDE Certain buttons on standard toolbar:
DATA: lt_exclude TYPE ui_functions,
ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_filter.
APPEND ls_exclude TO lt_exclude.
CLEAR ls_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
APPEND ls_exclude TO lt_exclude.
pass lt_exclude to METHOD-->SET_TABLE_FOR_FIRST_DISPLAY
Regards,
Gurpreet -
Displaying ALV output in whole screen when using with custom container
I have created a custom container and displaying output of a table in the ALV format using call method grid->set_table_for_first_display. But the output does not display in the entire screen. I want the output to cover the whole screen depending on user screen resolution. The code is given below for reference.
create object grid
exporting
i_parent = g_custom_container.
call method grid->set_table_for_first_display
exporting
IS_VARIANT = ld_variant
I_SAVE = 'A'
is_layout = layout_alv_grid
changing
it_outtab = final_display_itab
it_fieldcatalog = itab_fieldcatalogHello,
DATA: go_splitter TYPE REF TO cl_gui_splitter_container,
go_container TYPE REF TO cl_gui_container,
go_grid TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT go_splitter
EXPORTING
parent = cl_gui_container=>default_screen
rows = 1
columns = 1
metric = '0001'.
go_container = go_splitter->get_container( row = 1 column = 1 ).
CREATE OBJECT go_grid
EXPORTING
i_parent = go_container.
Regards,
Ernst -
Dynamically change in size of the custom container using ALV GRID (OOPS)
Hi Gurus!!!!
I have an issue with the output of the report which is developed using ALV GRID (OOPS). I have used the custom container occupying full screen (Screen painter). When I execute the report using my PC the output displays report as expected in full screen. The problem is when we execute this report in 19 INCH monitor then there is always gap below the report.
As per my understanding we should have a code to change the size of custom container dynamically.
Please suggest some help on this.
Thanks,
Hemal ShahHi,
If you set the attributes, Resizing - Vertical and Horizontal for the customer container, than system will resize the size of the custome continer as per the resolution.
Hope it helps,
Sumana -
Could Customer container be used in BDC input?
Could Customer container be used in BDC input?
Since I am not able to connect sap right now, so put in here. Every advice will be appreicated.Thanks Rav for your quick reply.
We are working on one customized-infotype in SAP-HR, and container is created in this infotype for maitain text document. Then later, key-user will use BDC to maitain this infotype in PA30.
So Could you please adivce further which or which kind BAPI could be used here?
we use below code to create container in screen.
CREATE OBJECT container
EXPORTING
container_name = 'CUSTOM'
EXCEPTIONS
OTHERS = 1.
CASE sy-subrc.
WHEN 0.
ENDCASE.
CALL METHOD container->set_visible
EXPORTING
visible = 'X'. -
Tree with custom labels crashes during scrolling
We have a tree that uses custom icons for different
folder/data types. The tree contains about 150 items of around 15
types. The icons are assigned correctly and the tree works just
fine.
However: If we scroll the tree up and down, it eats up some
resource, and after a couple of seconds of constant back and forth
scrolling the app hangs up completely.
The icons are embedded btw. If we don's use custom icons,
then we don't get a crash here.
Any idea what's going wrong here? What can be done to fix it?
Thanks
Klaus
P.S. To create the we use a label function like this:
public static function treeLabel(item:Object):String
var node:XML = XML(item);
var cType:String = [email protected]();
if(Assets.getInstance().hasOwnProperty("icon"+cType))
var icon:Class = Assets.getInstance()["icon"+cType];
_application.portalTree.setItemIcon(node, icon, icon);
return [email protected]();Ok, just to answer this question myself:
Don't set icons in the labelFunction. The proper and only way
to do this is to use the iconFunction inherited from the list
control!
Klaus -
HTML BANNER in screen custom container..
Can someone please give me simple example code or steps to add an HTML banner into a custom container??
check this class CL_DD_DOCUMENT.
and Prorams DD_STYLE_TABLE.
check this blog..
TOP_OF_PAGE in ALV Using CL_GUI_ALV_GRID -
Binding a subtree using custom State- and ObjectFactory
Hi,
first of all a very short example to illustrate my idea. I know that it would be complete rubbish to store the kind of data in the example in multiple classes and ldap entries. Currently I'm working with much larger objects that must be written according to special schema definitions. This example is really only for illustration!
LDAP-Schema:
objectclass ( 1.3.6.1.4.1... NAME 'myperson'
SUP top STRUCTURAL
MUST ( cn $ sn ) MAY ( email ) )
objectclass ( 1.3.6.1.4.1... NAME 'myphoto'
SUP top STRUCTURAL
MUST ( cn $ jpegPhoto ) )
Java-Classes:
class MyPhoto {
byte[] photo;
class MyPerson {
String cn;
String sn;
String email;
MyPhoto photo; // This is the really relevant line :)
}Now to the question:
Is it possible to bind multiple java objects with one call to bind and to get a subtree by using custom State- and ObjectFactory-Classes?
Structure of the LDAP-Database
dn: cn=John Doe
{ cn=John Doe
sn=Doe
[email protected] }
dn: cn=TheLogo, cn=John Doe // Child of cn=John Doe
{ cn=TheLogo // The cn is the same for all MyPhoto entries
// its only use is for building the dn
jpegPhoto=[some binary data] }I tried to solve the problem with a kind of recursion. When my StateFactory is called to bind an Object of Class MyPerson it builds the appropriate AttributeList. Before it returns, it calls bind for the Object of class MyPhoto with the dn: "cn=TheLogo,cn=John Doe".
Of course this doesn't work because the entry for cn="John Doe" doesn't exist at this time. Now I don't know what to do. A possible solution would be to create everything by hand, but then I wouldn't have to use custom StateFactories at all. But if there is a simple solution to my problem I would like to use my own StateFactory instead of having to implement a persistance manager on my own.
I hope you understand what I want to do and why it doesn't work out. If you don't please ask and I will try to clarify.Hello,
A provisional solution is to use an external controller. For this approach to work, each class has to provide the list of objects being part of its properties. I have prepared two interfaces for this purpose:
public interface HasSubordinates {
Enumeration getSubordinates();
boolean hasSubordinates();
public interface Storable extends HasSubordinates {
String getIdentifier();
Then, you can use the controller to recursively get the object "tree" and store it in the directory (either using objects that implement the DirContext interface or using StateFactories - the last one is the one I have used)
The code for the Controller is the following:
import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.spi.*;
import java.util.*;
import java.io.IOException;
public class DatabaseAccessController {
// Constants
final static String ldapServerName = "localhost";
final static String rootdn = "cn=juanluis, o=niaf";
final static String rootpass = "secret";
final static String rootContext = "o=niaf";
private DirContext initialContext;
private static Properties env = new Properties();
static {
env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
env.put( Context.STATE_FACTORIES, "database.PersonStateFactory:database.AddressStateFactory");
env.put( Context.PROVIDER_URL, "ldap://"+ ldapServerName+"/"+rootContext);
env.put( Context.SECURITY_PRINCIPAL, rootdn );
env.put( Context.SECURITY_CREDENTIALS, rootpass );
public DatabaseAccessController() {
try {
initialContext = new InitialDirContext( env );
} catch( Exception e ) {
e.printStackTrace();
public void store( Storable object ) {
try {
store( object, initialContext );
} catch( NamingException ne ) {
ne.printStackTrace();
private void store( Storable object, DirContext ctx ) throws NamingException{
DirStateFactory.Result result = DirectoryManager.getStateToBind( object, null, null, env, null );
Attributes attributes = result.getAttributes();
DirContext new_ctx = ctx.createSubcontext( dn(object), attributes );
if( object.hasSubordinates() ) {
Enumeration subordinates = object.getSubordinates();
while( subordinates.hasMoreElements() ) {
try {
store( (Storable)subordinates.nextElement(), new_ctx );
} catch( Exception e ) {
e.printStackTrace();
private String dn( Storable object ) {
return "cn="+object.getIdentifier();
This is an example of how it should work on two objects:
public class Person implements Storable{
String name;
String surname;
Address address;
public Person(String n, String sn, Address addr) {
name = n;
surname = sn;
address = addr;
public boolean hasSubordinates() {
return true;
public Enumeration getSubordinates() {
Hashtable h = new Hashtable();
h.put("address", address );
return h.elements();
public String getIdentifier() {
return name + " "+ surname;
public class Address implements Storable {
String street;
int number;
Attributes attrs;
public Address( String s, int n) {
street = s;
number = n;
public boolean hasSubordinates() {
return false;
public Enumeration getSubordinates() {
return null;
public String getIdentifier() {
return street + number;
And here it is the program that access to the directory:
public class TestLDAP {
public TestLDAP() {
public static void main(String[] args) {
try {
System.out.println("Creating controller...");
DatabaseAccessController controller = new DatabaseAccessController();
System.out.println("Controller created");
Person person = new Person("Juan Luis", "Manas", new Address("Street in Madrid", 33 ));
System.out.println("Storing object in the directory...");
controller.store(person);
System.out.println("object stored successfully!");
} catch( Exception e ) {
e.printStackTrace();
}���
If you find a better way of performing the storage of complex objects in the directory, please, let me know.
Regards,
Juan Luis -
Can anyone tell me how to Copy a node on an ALV Tree using context menu ?
Hello Vidya
The sample report ZUS_SDN_ALVTREE_CTXMENU demonstrates how to copy nodes on an ALV tree.
Before showing the entire coding I would like to point out a few crucial parts of the coding:
(1) Defintion of OUTTAB list
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
The OUTTAB list contains two additional fields holding the tree key (LVC_NKEY) and the node type.
(2) The main logic of the report is implemented in event handler method handle_node_ctxmenu_sel.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
" Note: similar logic like in routine CREATE_HIERARCHY
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
*& Report ZUS_SDN_ALVTREE_CTXMENU
*& Based on: BCALV_TREE_03
REPORT zus_sdn_alvtree_ctxmenu.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_repid TYPE syst-repid,
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_alvtree TYPE REF TO cl_gui_alv_tree.
DATA:
gt_outtab TYPE ty_t_outtab, " Sales Document
gt_fcat TYPE lvc_t_fcat.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
* §2. Define an event handler method to build up a context menu
* (postfix of event name: _CONTEXT_MENU_REQUEST).
* This event is fired each time the user klick with the right
* mouse button on a node.
CLASS-METHODS:
handle_node_ctxmenu_req
FOR EVENT node_context_menu_request OF cl_gui_alv_tree
IMPORTING
node_key
menu,
* §3. Define an event handler method to respond to a function code
* triggered by your menu (postfix: _CONTEXT_MENU_SELECTED).
* This event is fired when the user selects an entry of the
* build up context menu.
handle_node_ctxmenu_sel
FOR EVENT node_context_menu_selected OF cl_gui_alv_tree
IMPORTING
node_key
fcode
sender.
* '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.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
* §4. Implement your event handler methods.
METHOD handle_node_ctxmenu_req.
* Event parameter 'menu' holds a reference to the standard context
* menu of ALV Tree (functions 'Expand'/'Collapse' on nodes).
* You may either append your own functions (separated by a line)
* or clear the menu if you do not want to allow standard functions.
* In this case the standard menu is cleared.
CALL METHOD menu->clear.
* The next line defines one line of the context menu.
CALL METHOD menu->add_function
EXPORTING
fcode = 'DEL_SUBTREE'
text = 'Delete Subtree'(901). "Delete Subtree
CALL METHOD menu->add_function
EXPORTING
fcode = 'COPY_SUBTREE'
text = 'Copy Subtree'(902). "Copy Subtree
ENDMETHOD. "handle_node_ctxmenu_req
METHOD handle_node_ctxmenu_sel.
* At this point of execution, the user selected a menu entry of the
* menu build up in event handler method handle_node_cm_req.
* Query your own function codes and react accordingly.
DATA:
l_rc TYPE c,
ld_ntype TYPE lvc_value,
ld_parent_key TYPE lvc_nkey,
ld_node_key TYPE lvc_nkey,
lt_subtree TYPE lvc_t_nkey,
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
CASE fcode.
WHEN 'DEL_SUBTREE'.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
textline1 = 'Do you really want to delete'(902)
textline2 = 'this node and all its subnodes?'(903)
titel = 'Confirmation'(904)
cancel_display = ' '
IMPORTING
answer = l_rc.
IF l_rc EQ 'J'.
CALL METHOD sender->delete_subtree
EXPORTING
i_node_key = node_key.
* Do not forget to refresh the display when you change the contents
* of your list.
CALL METHOD sender->frontend_update.
ENDIF.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
IF ( ld_ntype = 'VKORG' ).
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' ).
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' OR
ld_ntype = 'SPART' ).
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH_TREE'
* IMPORTING
* RC =
ENDCASE.
ENDMETHOD. "handle_node_ctxmenu_sel
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
PERFORM init_controls.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
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 SCREEN '0100'.
* NOTE: no screen elements, ok_code -> gd_okcode
** PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
** PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE. " facilitate manual entries
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
when 'REFRESH_TREE'.
CALL METHOD go_alvtree->update_calculations
* EXPORTING
* NO_FRONTEND_UPDATE =
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
DATA:
ls_hierarchy_header TYPE treev_hhdr.
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
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.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size screen
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
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 tree control
CREATE OBJECT go_alvtree
EXPORTING
parent = go_docking
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = ' '
no_html_header = 'X'
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.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
PERFORM build_hierarchy_header CHANGING ls_hierarchy_header.
* Hide columns and sum up values initially using the fieldcatalog
PERFORM build_fieldcatalog.
* IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
* (even after this method call). You can change data of your table
* by calling methods of CL_GUI_ALV_TREE.
* Furthermore, the output table 'gt_outtab' must be global and can
* only be used for one ALV Tree Control.
CALL METHOD go_alvtree->set_table_for_first_display
EXPORTING
is_hierarchy_header = ls_hierarchy_header
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_outtab. "table must be empty !
PERFORM init_tree.
ENDFORM. " INIT_CONTROLS
*& Form INIT_TREE
* text
* --> p1 text
* <-- p2 text
FORM init_tree .
PERFORM create_hierarchy.
PERFORM register_events.
* Update calculations which were initially defined by field DO_SUM
* of the fieldcatalog. (see build_fieldcatalog).
CALL METHOD go_alvtree->update_calculations.
* Send data to frontend.
CALL METHOD go_alvtree->frontend_update.
ENDFORM. " INIT_TREE
*& Form build_hierarchy_header
* text
* <--P_LS_HIERARCHY_HEADER text
FORM build_hierarchy_header
CHANGING
cs_hierarchy_header TYPE treev_hhdr.
cs_hierarchy_header-heading =
'SalesOrg/DistChannel/Division'(300).
cs_hierarchy_header-tooltip = 'Customer: Master Sales Data'(400).
cs_hierarchy_header-width = 45.
cs_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form build_fieldcatalog
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
REFRESH: gt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT gt_fcat INTO ls_fcat.
CASE ls_fcat-fieldname.
WHEN 'VBELN' OR
'AUDAT' OR
'AUART' OR
'WAERK' OR
'VKORG' OR
'VTWEG' OR
'SPART' OR
'BSTNK' OR
'KUNNR'.
WHEN 'NETWR'.
ls_fcat-do_sum = 'X'.
ls_fcat-h_ftype = 'SUM'. " or: 'MAX' / 'AVG'
WHEN OTHERS.
ls_fcat-tech = 'X'.
ENDCASE.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.
ENDFORM. " build_fieldcatalog
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
FORM create_hierarchy .
* define local data
DATA:
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
" Select data
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE lt_outtab
UP TO 1550 ROWS.
" sort table according to conceived hierarchy
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
* Define one top node. In this way it is possible to calculate
* values for the whole hierarchy.
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = 'Sales Documents'
IMPORTING
e_new_node_key = ld_top_key.
CLEAR: ls_outtab.
ls_outtab-nkey = ld_top_key.
ls_outtab-ntype = 'ROOT'.
MODIFY gt_outtab FROM ls_outtab INDEX 1
TRANSPORTING nkey ntype.
LOOP AT lt_outtab INTO ls_outtab.
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form ADD_SALES_ORG
* text
* -->P_LS_OUTTAB text
* -->P_LD_TOP_KEY text
* <--P_LD_VKORG_KEY text
FORM add_sales_org
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vkorg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " ADD_SALES_ORG
*& Form add_DISTRIB_CHAN
* text
* -->P_LS_OUTTAB text
* -->P_LD_VKORG_KEY text
* <--P_LD_VTWEG_KEY text
FORM add_distrib_chan
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vtweg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_DISTRIB_CHAN
*& Form add_division
* text
* -->P_LS_OUTTAB text
* -->P_LD_VTWEG_KEY text
* <--P_LD_SPART_KEY text
FORM add_division
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-spart.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_division
*& Form add_complete_line
* text
* -->P_LS_OUTTAB text
* -->P_LD_SPART_KEY text
* <--P_LD_LAST_KEY text
FORM add_complete_line
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
WRITE us_outtab-kunnr TO ld_nodetext+0 NO-ZERO.
WRITE us_outtab-audat TO ld_nodetext+20 DD/MM/YYYY.
CONDENSE ld_nodetext.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = us_outtab " !!!
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
FORM register_events .
DATA:
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
* 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):
CALL METHOD go_alvtree->get_registered_events
IMPORTING
events = lt_events.
* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.
* Register additional events for your own purposes:
* §5. Register first context menu event on frontend (with postfix
* (_REQUEST). The second is registered automatically.
ls_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND ls_event TO lt_events.
* register events on frontend
CALL METHOD go_alvtree->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
* §6. Register both context menu events on backend (ABAP Objects
* event handling).
SET HANDLER:
lcl_eventhandler=>handle_node_ctxmenu_req FOR go_alvtree,
lcl_eventhandler=>handle_node_ctxmenu_sel FOR go_alvtree.
ENDFORM. " register_events
Regards,
Uwe -
ALV Tree using Function Modules
Hi,
I want a simple example of ALV Tree using Function Modules which can display multiple Columns in the Hierarchically arranged fashion along with nodes & icons.
Also should be able to handle the events.
Thanks in Advance..Hi Ramesh,
Here is a example of alv tree
*& Report BCALV_TREE_DEMO *
report bcalv_tree_demo.
class cl_gui_column_tree definition load.
class cl_gui_cfw definition load.
data tree1 type ref to cl_gui_alv_tree.
data mr_toolbar type ref to cl_gui_toolbar.
include <icon>.
include bcalv_toolbar_event_receiver.
include bcalv_tree_event_receiver.
data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.
data: gt_sflight type sflight occurs 0, "Output-Table
gt_fieldcatalog type lvc_t_fcat, "Fieldcatalog
ok_code like sy-ucomm. "OK-Code
start-of-selection.
end-of-selection.
call screen 100.
*& Module PBO OUTPUT
* process before output
module pbo output.
set pf-status 'MAIN100'.
if tree1 is initial.
perform init_tree.
endif.
call method cl_gui_cfw=>flush.
endmodule. " PBO OUTPUT
*& Module PAI INPUT
* process after input
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.
call method cl_gui_cfw=>flush.
endmodule. " PAI INPUT
*& Form build_fieldcatalog
* build fieldcatalog for structure sflight
form build_fieldcatalog.
* get fieldcatalog
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'SFLIGHT'
changing
ct_fieldcat = gt_fieldcatalog.
* change fieldcatalog
data: ls_fieldcatalog type lvc_s_fcat.
loop at gt_fieldcatalog into ls_fieldcatalog.
case ls_fieldcatalog-fieldname.
when 'CARRID' or 'CONNID' or 'FLDATE'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-key = ''.
when 'PRICE' or 'SEATSOCC' or 'SEATSMAX' or 'PAYMENTSUM'.
ls_fieldcatalog-do_sum = 'X'.
endcase.
modify gt_fieldcatalog from ls_fieldcatalog.
endloop.
endform. " build_fieldcatalog
*& Form build_hierarchy_header
* build hierarchy-header-information
* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
form build_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
p_hierarchy_header-heading = 'Hierarchy Header'. "#EC NOTEXT
p_hierarchy_header-tooltip =
'This is the Hierarchy Header !'. "#EC NOTEXT
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ''.
endform. " build_hierarchy_header
*& Form exit_program
* free object and leave program
form exit_program.
call method tree1->free.
leave program.
endform. " exit_program
*& Form build_header
* build table for html_header
* --> p1 text
* <-- p2 text
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 = 'ALV-tree-demo: flight-overview'. "#EC NOTEXT
append ls_line to pt_list_commentary.
* STATUS LINE: TYPE S
clear ls_line.
ls_line-typ = 'S'.
ls_line-key = 'valid until'. "#EC NOTEXT
ls_line-info = 'January 29 1999'. "#EC NOTEXT
append ls_line to pt_list_commentary.
ls_line-key = 'time'.
ls_line-info = '2.00 pm'. "#EC NOTEXT
append ls_line to pt_list_commentary.
* ACTION LINE: TYPE A
clear ls_line.
ls_line-typ = 'A'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'actual data'. "#EC NOTEXT
append ls_line to pt_list_commentary.
p_logo = 'ENJOYSAP_LOGO'.
endform.
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
form create_hierarchy.
data: ls_sflight type sflight,
lt_sflight type sflight occurs 0.
* get data
select * from sflight into table lt_sflight
UP TO 200 ROWS .
sort lt_sflight by carrid connid fldate.
* add data to tree
data: l_carrid_key type lvc_nkey,
l_connid_key type lvc_nkey,
l_last_key type lvc_nkey.
loop at lt_sflight into ls_sflight.
on change of ls_sflight-carrid.
perform add_carrid_line using ls_sflight
changing l_carrid_key.
endon.
on change of ls_sflight-connid.
perform add_connid_line using ls_sflight
l_carrid_key
changing l_connid_key.
endon.
perform add_complete_line using ls_sflight
l_connid_key
changing l_last_key.
endloop.
* calculate totals
call method tree1->update_calculations.
* this method must be called to send the data to the frontend
call method tree1->frontend_update.
endform. " create_hierarchy
*& Form add_carrid_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
form add_carrid_line using ps_sflight type sflight
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_sflight type sflight.
* set item-layout
data: lt_item_layout type lvc_t_layi,
ls_item_layout type lvc_s_layi.
ls_item_layout-t_image = '@3P@'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
append ls_item_layout to lt_item_layout.
* add node
l_node_text = ps_sflight-carrid.
call method tree1->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key.
endform. " add_carrid_line
*& Form add_connid_line
* add hierarchy-level 2 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
form add_connid_line using ps_sflight type sflight
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_sflight type sflight.
* set item-layout
data: lt_item_layout type lvc_t_layi,
ls_item_layout type lvc_s_layi.
ls_item_layout-t_image = '@3Y@'.
ls_item_layout-style =
cl_gui_column_tree=>style_intensified.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
append ls_item_layout to lt_item_layout.
* add node
l_node_text = ps_sflight-connid.
call method tree1->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_sflight
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key.
endform. " add_connid_line
*& Form add_cmplete_line
* add hierarchy-level 3 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
form add_complete_line using ps_sflight type sflight
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value.
* set item-layout
data: lt_item_layout type lvc_t_layi,
ls_item_layout type lvc_s_layi.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.
ls_item_layout-editable = 'X'.
append ls_item_layout to lt_item_layout.
l_node_text = ps_sflight-fldate.
call method tree1->add_node
exporting
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = ps_sflight
i_node_text = l_node_text
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key.
endform. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
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_expand_no_children.
append l_event to lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
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_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_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.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
* set Handler
data: l_event_receiver type ref to lcl_tree_event_receiver.
create object l_event_receiver.
set handler l_event_receiver->handle_node_ctmenu_request
for tree1.
set handler l_event_receiver->handle_node_ctmenu_selected
for tree1.
set handler l_event_receiver->handle_item_ctmenu_request
for tree1.
set handler l_event_receiver->handle_item_ctmenu_selected
for tree1.
endform. " register_events
*& Form change_toolbar
* text
* --> p1 text
* <-- p2 text
form change_toolbar.
* get toolbar control
call method tree1->get_toolbar_object
importing
er_toolbar = mr_toolbar.
check not mr_toolbar is initial.
* add seperator to toolbar
call method mr_toolbar->add_button
exporting
fcode = ''
icon = ''
butn_type = cntb_btype_sep
text = ''
quickinfo = 'This is a Seperator'. "#EC NOTEXT
* add Standard Button to toolbar (for Delete Subtree)
call method mr_toolbar->add_button
exporting
fcode = 'DELETE'
icon = '@18@'
butn_type = cntb_btype_button
text = ''
quickinfo = 'Delete subtree'. "#EC NOTEXT
* add Dropdown Button to toolbar (for Insert Line)
call method mr_toolbar->add_button
exporting
fcode = 'INSERT_LC'
icon = '@17@'
butn_type = cntb_btype_dropdown
text = ''
quickinfo = 'Insert Line'. "#EC NOTEXT
* set event-handler for toolbar-control
create object toolbar_event_receiver.
set handler toolbar_event_receiver->on_function_selected
for mr_toolbar.
set handler toolbar_event_receiver->on_toolbar_dropdown
for mr_toolbar.
endform. " change_toolbar
*& Form init_tree
* text
* --> p1 text
* <-- p2 text
FORM init_tree.
* create fieldcatalog for structure sflight
perform build_fieldcatalog.
* 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'.
if sy-batch is initial.
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.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
endif.
* create tree control
create object tree1
exporting
parent = l_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
no_html_header = ''
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.
if sy-subrc <> 0.
message x208(00) with 'ERROR'. "#EC NOTEXT
endif.
* create Hierarchy-header
data l_hierarchy_header type treev_hhdr.
perform build_hierarchy_header changing l_hierarchy_header.
* 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.
* create emty tree-control
call method tree1->set_table_for_first_display
exporting
is_hierarchy_header = l_hierarchy_header
it_list_commentary = lt_list_commentary
i_logo = l_logo
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
changing
it_outtab = gt_sflight "table must be emty !!
it_fieldcatalog = gt_fieldcatalog.
* create hierarchy
perform create_hierarchy.
* add own functioncodes to the toolbar
perform change_toolbar.
* register events
perform register_events.
* adjust column_width
call method tree1->COLUMN_OPTIMIZE.
ENDFORM. " init_tree
regards,
venu. -
Help or tutorials about ABAP UI programming such as Tree and dock container
Hi,
I'm looking for help, tutorials or any ressources I can explore to undertsand how to work in ABAP with controls, containers, tree and so on.
Each time I do a search on help.sap.com, I found help on a detailed object such as tree or docking container but I never found a global view. I would like to understand the big picture, have an averview of all involved concept. For example, if I want the user screen to be splitted in 2 parts, one that will display a tree, the other one that will display "simple" screen painter trees that will change depending on what user choose using the tree on the left. How do I need to proceed ?
I'm sorry if I have not a more precise question because I don't found where to begin.
Thanks for help
Regards
MorganHi Morgan,
You can start going thorugh the concepts from help.sap.com. Have a look at the following link:
http://help.sap.com/erp2005_ehp_04/helpdata/EN/1b/337930a63011d2bd6b080009b4534c/frameset.htm
You will get the entire set of Example codes in the Transaction Code : ABAPDOCU.
You can also look for examples for Dialog Programing in SE38 using the DEMODYNPRO*.
Have a look at the Package : SLIS. This is a one point of all examples and demo of SAP Control Framework and ALV Functionality.
Hope this helps.
Thanks,
Samantak. -
Docking Container - Custom Container
Hi Friends,
I have the following doubts.
1. What all are the advantages of Docking and Custom Container.
2. Under what scenario's we use Docking over Custom Container.
3. I want to have 2 ALV GRID's in one screen one below another. Shall I use Docking Container?
internal table I_MARA with 10 records and I_MARC with 20 records.
Explain how to achieve this using Docking Container with code.
Regards,
Viji.hi vijayalakshmi
you can use 2 custom containers in that screen for two ALV grid
*& Report ZLISTBOX1 *
REPORT zlistbox1 .
*parameters: date like sy-datum.
TABLES: lfa1,ekko.
TYPE-POOLS: slis,sdydo.
*select-options: vendor for lfa1-lifnr.
DATA: itab TYPE TABLE OF ekko,
identity TYPE REF TO cl_gui_custom_container,
l_list TYPE slis_t_listheader,
l_logo TYPE sdydo_value,
l_identity TYPE REF TO cl_gui_custom_container,
l_tree TYPE REF TO cl_gui_alv_tree_simple,
tree TYPE REF TO cl_gui_alv_tree_simple,
fcat TYPE lvc_t_fcat,
sort_b TYPE lvc_t_sort,
sort_w TYPE lvc_s_sort.
CALL SCREEN 100.
*& Module USER_COMMAND_0100 INPUT
text
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'DISPLAY'.
PERFORM col_head.
PERFORM output.
PERFORM sort.
IF l_identity IS INITIAL.
CREATE OBJECT l_identity
EXPORTING
container_name = 'LOGO'.
CREATE OBJECT l_tree
EXPORTING
i_parent = l_identity.
PERFORM logo USING l_logo.
CALL METHOD l_tree->create_report_header
EXPORTING
it_list_commentary = l_list
i_logo = l_logo.
ENDIF.
IF identity IS INITIAL.
CREATE OBJECT identity
EXPORTING
container_name = 'JANAGAR'.
CREATE OBJECT tree
EXPORTING
i_parent = identity.
CALL METHOD tree->set_table_for_first_display
CHANGING
it_outtab = itab
it_fieldcatalog = fcat
it_sort = sort_b.
ENDIF.
*refresh itab.
CALL METHOD tree->refresh_table_display.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form logo
text
-->P_LOGO text
FORM logo USING p_logo.
p_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "logo
*& Form col_head
text
FORM col_head.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_BUFFER_ACTIVE =
i_structure_name = 'EKKO'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME = ITAB
CHANGING
ct_fieldcat = fcat.
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "col_head
*& Form output
text
FORM output.
SELECT * FROM ekko INTO TABLE itab WHERE lifnr = lfa1-lifnr.
ENDFORM. "output
*& Form sort
text
FORM sort.
sort_w-spos = 1.
sort_w-fieldname = 'EBELN'.
APPEND sort_w TO sort_b.
sort_w-spos = 2.
sort_w-fieldname = 'AEDAT'.
APPEND sort_w TO sort_b.
sort_w-spos = 3.
sort_w-fieldname = 'BUKRS'.
APPEND sort_w TO sort_b.
ENDFORM. "sort
cheers
s.janagar -
Hi All,
Please anyone suggest me, how can I use text-editor in ALV container?
Means when i execute the program, i want to see editor screen.
Thanks
Amitsee
Custom Controls
A custom control is an area on a screen. You create them in the Screen Painter, and, like all other screen objects, they have a unique name. You use custom controls to embed controls. Controls are software components of the presentation server. Depending on the used SAP GUI, these are either ActiveX Controls or JavaBeans. They allow you to perform tasks, such as editing texts, locally on the presentation server. The control is driven by the application logic, which still runs on the application server.
The SAP Control Framework
The controls on the presentation server and the ABAP application programs on the application server communicate using the SAP Control Framework. The SAP Control Framework is programmed in ABAP Objects . It contains global classes that can be found in the class library under Basis ® Frontend Services. These classes encapsulate the communication between the application server and presentation server, which is implemented using Remote Function Call.
All application controls are encapsulated in a global class. You can find the SAP Basis controls in the Class Browser under Basis ® Frontend Services or Basis ® Component Integration. Programs that use controls on a screen work with the methods and events of the global classes that encapsulates them.
Container Controls
Before you can work with a custom control on a screen, you must assign a SAP Container Control to it. Container controls are instances of special global classes from the SAP Control Framework. The global class for custom controls is called CL_GUI_CUSTOM_CONTAINER. To link a custom control to a container control, pass the custom control name to the constructor of the container control when you instantiate it using CREATE OBJECT.
As well as using custom containers, you can link controls to a screen using a SAP Docking Container. This is encapsulated in the global class CL_GUI_DOCKING_CONTAINER. The SAP Docking Container does not place the control within a screen. Instead, it attaches it to one of the four edges. You can nest containers. For example, you can use the SAP Splitter Container (classes CL_GUI_EASY_SPLITTER_CONTAINER or CL_GUI_SPLITTER_CONTAINER) within other containers. This allows you to split a custom control or docking control into more than one area, allowing you to embed more than one control.
Application Controls
You must also create instances for the application controls that you want to place within your container - for example, a SAP Textedit Control (class CL_GUI_TEXTEDIT) or a SAP Tree Control (for which there is more than one global class - an example is CL_GUI_SIMPLE_TREE). When you instantiate the control, you pass a reference to the container in which you want to place it to the PARENT parameter of its constructor method. The container may be an instance of the class CL_GUI_CUSTOM_CONTAINER, but can also be an instance of one of the other SAP Container controls.
Control Methods
For information about control methods and their documentation, refer to the class definitions in the Class Builder or the SAP Library documentation. To minimize the network load between the application and presentation servers, method calls are buffered in the automation queue before being sent to the presentation server at defined synchronization points. One of the automatic synchronization points is the end of PBO processing. You can force a synchronization point in your program by calling a method that is not buffered, or by calling the static method FLUSH.
Control Events
Unlike screens, on which user interaction triggers the PAI event and control returns to the application server, user interaction on controls is not automatically passed back to the application server. If you want an event to be passed back to the application server, you must register it in your program using the special method SET_REGISTERED_EVENTS. For a list of the events that you can register for each control, refer to its wrapper class in the Class Builder. You can register two kinds of event handling using SET_REGISTERED_EVENTS:
System Events (Default)
The event is passed to the application server, but does not trigger the PAI. If you have registered an event handler method in your ABAP program for the event (using the SET HANDLER statement), this method is executed on the application server.
Within the event handler method, you can use the static method SET_NEW_OK_CODE of the global class CL_GUI_CFW to set a function code and trigger the PAI event yourself. After the PAI has been processed, the PBO event of the next screen is triggered.
The advantage of using this technique is that the event handler method is executed automatically and there are no conflicts with the automatic input checks associated with the screen. The disadvantage is that the contents of the screen fields are not transported to the program, which means that obsolete values could appear on the next screen. You can work around this by using the SET_NEW_OK_CODE method to trigger field transport and the PAI event after the event handler has finished.
Application Events
The event is passed to the application server, and triggers the PAI. The function code that you pass contains an internal identifier. You do not have to evaluate this in your ABAP program. Instead, if you want to handle the event, you must include a method call in a PAI dialog module for the static method DISPATCH of the global class CL_GUI_CFW. If you have defined an event handler method in your ABAP program for the event (using the SET HANDLER statement), the DISPATCH method calls it. After the event handler has been processed, control returns to the PAI event after the DISPATCH statement and PAI processing continues.
The advantage of this is that you can specify yourself the point at which the event is handled, and the contents of the screen fields are transported to the application server beforehand. The disadvantage is that this kind of event handling can lead to conflicts with the automatic input checks on the screen, causing events to be lost.
Related Information
For further information about controls, and in particular, help on troubleshooting and optimizing synchronization, refer to BC Controls Tutorial and BC SAP Control Framework.
Example
The following example shows the difference between system and application events.
REPORT demo_custom_control .
Declarations *****************************************************
CLASS event_handler DEFINITION.
PUBLIC SECTION.
METHODS: handle_f1 FOR EVENT f1 OF cl_gui_textedit
IMPORTING sender,
handle_f4 FOR EVENT f4 OF cl_gui_textedit
IMPORTING sender.
ENDCLASS.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
DATA: init,
container TYPE REF TO cl_gui_custom_container,
editor TYPE REF TO cl_gui_textedit.
DATA: event_tab TYPE cntl_simple_events,
event TYPE cntl_simple_event.
DATA: line(256) TYPE c,
text_tab LIKE STANDARD TABLE OF line,
field LIKE line.
DATA handle TYPE REF TO event_handler.
Reporting Events ***************************************************
START-OF-SELECTION.
line = 'First line in TextEditControl'.
APPEND line TO text_tab.
line = '----
APPEND line TO text_tab.
line = '...'.
APPEND line TO text_tab.
CALL SCREEN 100.
Dialog Modules *****************************************************
MODULE status_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
IF init is initial.
init = 'X'.
CREATE OBJECT:
container EXPORTING container_name = 'TEXTEDIT',
editor EXPORTING parent = container,
handle.
event-eventid = cl_gui_textedit=>event_f1.
event-appl_event = ' '. "system event
APPEND event TO event_tab.
event-eventid = cl_gui_textedit=>event_f4.
event-appl_event = 'X'. "application event
APPEND event TO event_tab.
CALL METHOD: editor->set_registered_events
EXPORTING events = event_tab.
SET HANDLER handle->handle_f1
handle->handle_f4 FOR editor.
ENDIF.
CALL METHOD editor->set_text_as_stream
EXPORTING text = text_tab.
ENDMODULE.
MODULE cancel INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'INSERT'.
CALL METHOD editor->get_text_as_stream
IMPORTING text = text_tab.
WHEN 'F1'.
MESSAGE i888(sabapdocu) WITH text-001.
WHEN OTHERS.
MESSAGE i888(sabapdocu) WITH text-002.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
SET SCREEN 100.
ENDMODULE.
Class Implementations **********************************************
CLASS event_handler IMPLEMENTATION.
METHOD handle_f1.
DATA row TYPE i.
MESSAGE i888(sabapdocu) WITH text-003.
CALL METHOD sender->get_selection_pos
IMPORTING from_line = row.
CALL METHOD sender->get_line_text
EXPORTING line_number = row
IMPORTING text = field.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING new_code = 'F1'.
CALL METHOD cl_gui_cfw=>flush.
ENDMETHOD.
METHOD handle_f4.
DATA row TYPE i.
MESSAGE i888(sabapdocu) WITH text-004.
CALL METHOD sender->get_selection_pos
IMPORTING from_line = row.
CALL METHOD sender->get_line_text
EXPORTING line_number = row
IMPORTING text = field.
CALL METHOD cl_gui_cfw=>flush.
ENDMETHOD.
ENDCLASS.
The layout of screen 100 is:
The screen contains an output field field and a custom control called textedit.
The flow logic of screen 100 is:
PROCESS BEFORE OUTPUT.
MODULE status_0100.
PROCESS AFTER INPUT.
MODULE cancel AT EXIT-COMMAND.
MODULE user_command_0100.
The GUI status SCREEN_100 has the functions BACK, EXIT, and CANCEL (all with type E) and the function INSERT (normal function).
There is a local class event_handler defined in the program. It contains event handler methods for the F1 and F4 events of global class CL_GUI_TEXTEDIT. When you run the program, the classes CL_GUI_CUSTOM_CONTROL, CL_GUI_TEXTEDIT, and event_handler are instantiated in the PBO of screen 100.
The container control is linked to the custom control on the screen, and the instance of the textedit control is linked to this container. The F1 and F4 events of the textedit control are registered using the SET_REGISTERED_EVENTS method to ensure that they are passed to the application server when they occur. F1 is defined as a system event, F4 as an application event. The event handler methods of the handle instance of the class event_handler are registered as handlers for the events.
Before screen 100 is displayed, the program fills the textedit control with the contents of table text_tab . The user can edit the text while the screen is displayed. If the user chooses INSERT, the PAI event is triggered and the current text from the textedit control is copied into table text_tab.
If the user chooses F1 on the textedit control, the handle_f1 method is executed. This assigns the contents of the line to the field field: The method SET_NEW_OK_CODE triggers the PAI event. It is this that ensures that the PBO is processed, and the contents of field are sent to the screen.
If the user chooses F4 on the textedit control, the PAI event is triggered. The DISPATCH method is called, and this triggers the method handle_f4. This assigns the contents of the line to the field field: Since the PAI processing continues after the event, the PBO event follows, and the field contents are transferred to the screen.
The contents of the textedit control are not passed to the internal table text_tab either after F1 or after F4. The contents of the textedit control are therefore overwritten in the PBO event with the previous contents of text_tab.
http://help.sap.com/saphelp_nw2004s/helpdata/en/2a/755b94ca5911d299af5c9604c10e27/content.htm -
Display data in a custom container
Hi All,
My requirment is to just display data in a custom container.
I could able to display data in change mode but not display mode.Can you please let me now how can i do that.
Thanks in Advance
KVIm using cl_gui_custom_container.
In PBO
here is my code whihc is fine for Change/Edit mode.
create control container
CREATE OBJECT g_editor_container
EXPORTING
container_name = 'DISP_CONT'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
do nothing
ENDIF.
create calls constructor, which initializes, creats and links
a TextEdit Control
CREATE OBJECT g_editor
EXPORTING
parent = g_editor_container
wordwrap_mode = cl_gui_textedit => wordwrap_at_fixed_position
wordwrap_to_linebreak_mode = cl_gui_textedit=>TRUE
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
do nothing
ENDIF.
In PAI
CALL METHOD g_editor->get_text_as_r3table
IMPORTING
table = Text_table
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ENDIF.
Text_table contains messages which r supposed to be displayed.
Based on certain logical operations i will display the messages.
Maybe you are looking for
-
Cannot load OSX after installing Windows 8.1
Can someone please help?? I have tried to install Windows 8.1 using Bootcamp but cannot get into Mac OSX anymore. I have a Mid 2011 27" iMac which should be compatible with Bootcamp 5 and Windows 8.1. (according to Apple's own info). On startup I get
-
Equium M50 will not recognise the LAN port - error: Network Cable unplugged
I own a Toshiba Equium M50 and have problems with the Marvell Yukon 88E8036 PCI-E Fast Ethernet Controller. I used to connect via an 'ADDON' Modem/ADSL Switch and had no problems. I then replaced the ADDON with a 'NETGEAR' DG834G ADSL Modem/Router to
-
Background job failing - ECC 6.0, Solution Manager 7.0
Dear All, Four days back, I have installed the Solution Manager 7.0 and ECC 6.0 on HPUX IA64 hardware with database as Oracle 10.2.0.2.0 (Unicode). In both server, latest kernel patch has been applied. The Support package versions are (both server):
-
I have an iMac with OSX 10.0 and a NAS Drobo 5N which has a Time Machine share. It will backup my local machine fine, but how do I get a backup of the NAS folders and exclude the Time Machine folder?
-
Jpg to png in J2ME device..
I am considering doing a converter that could read JPG images from server and converts then to PNG and shows on device. I wonder what is the basic approach in case like this. I know there is already made solutions for this, but I want to make one in