Você está na página 1de 13

Assume a situation that I need a screen for a component and create a screen for add/ modify and

search the Z table.

In this post let us see how we create a custom BOL object for a Z table. Once this bol is created
we need to add this BOL in the custom view and show that on the screen. For now let us see how
we can create a custom BOL.

Let us create a z table with Name, First Name and Last Name. See the following screen shot for
the table.

Let us use this table and create a bol for this table to add, modify and search data.

OK. Now we need to define two tables. One for the data elements that we are going to use in the
BOL and another for the hierarchy of the data element that we are going to use in the BOL
object. Once these tables are defined then we need to mention the class module that we are going
to use for the BOL object. All these information are configured in the spro for this bol object.
See the following screen shot.
In the above configuration if you enter the Basic setting you will see all the BOL object defined
here. OK for our custom let us define the bol object as ZBOL. See the following screen.

Now select the component Definition (the first one) and click on the new entries. Let us define
the BOL component and add the details. See the following screen.

Add a Component Set Definition. See the follow screen shot.


Now assign the Component definition to the component set definition. See the following screen
shot.

Now the BOL component is assigned to the Component Set definition. You can assign More
than one BOL component to the component set.

Look at the above screen. We need to give one implementation class and two tables one is Object
table and another is Model table. Now let us create these entries object.

One important thing with creating the implementation class is you need to specify super class
for this implementation class and redefine specific methods. For Creation a record, editing the
record (modify) and for Searching you have redefine specific super class methods. While
creating views (insert, edit and search) you need to specify specific Super class (not the
methods).

First let us create the table’s ztest_object and ztest_model copying from crmc_objs_mpil and
crmc_model_mpil. See the following screen shots.
Now we got the tables. We need to change the check table in ztest_model. See the following
screen shot.

Now let us create the data structure and add the structure and the data structure model in this
BOL object tables. For this example this is a plain simple data structure and I am going to add
the hierarchy for search.

See the following screen shot for the structure.


Now add this information in the BOL object Tables. Look at the following information I entered
in the table. Always the object table needs to have a root object and the other object that are
associated to their parent. Here the entire objects are associated to the root. If you have complex
hierarchy then it takes time to do the correct design and come up with the information. Always
try to see the existing code in the sap component and try to use that, this way it will be always
easy to follow. See the following screen shot for the data.

Now enter this information in the model table. Now enter the data structure hierarchy. See the
following screen shot.

In this example we have only one relationship and all the result and search structure belongs to
the root node.
Now let us create the implementation class for this BOL.

Create a new class Z_TEST_BOL_WEBIC using the class


CL_CRM_GENIL_ABSTR_COMPONENT2 as super class. This is very important. If you
didn’t inherit that super class they BOL object don’t understand your z class module. See the
following screen shot for the bol implementation class module creation.

Now you need to redefine the methods from the super class. Because we are planning this bol
object for search let us redefine all the methods that are associated for search. See the following
screen shot.
* select the model from your z table
SELECT * FROM ztest_model
INTO CORRESPONDING FIELDS
OF TABLE rt_relation_det.
DATA: lr_object TYPE REF TO if_genil_container_object,
lr_msg_cont TYPE REF TO cl_crm_genil_global_mess_cont,
lv_name_obj TYPE zstudents-bname,
lr_attr_props TYPE REF TO if_genil_obj_attr_properties,
l_result TYPE zstudents,
lv_name TYPE crmt_ext_obj_name.

* all entries in the root list have the same type/name -> take first
lr_object = iv_root_list->get_first( ).
lr_msg_cont ?= iv_root_list->get_global_message_container( ).
WHILE lr_object IS BOUND.
* make sure we got an entry.
* Note: the object from the root list must be either a root or access object.
* Dependent objects will never be part of the root list.
lv_name = lr_object->get_name( ).
IF lr_object->check_attr_requested( ) = abap_true.
CALL METHOD lr_object->get_key
IMPORTING
es_key = lv_name_obj.
SELECT SINGLE * FROM zstudents
INTO CORRESPONDING FIELDS OF
l_result WHERE bname = lv_name_obj.
lr_object->set_attributes( l_result ).
lr_attr_props = lr_object->get_attr_props_obj( ).
lr_attr_props->set_all_properties( if_genil_obj_attr_properties=>read_only ).

ENDIF.
lr_object = iv_root_list->get_next( ).
ENDWHILE.

DATA: lr_object TYPE REF TO if_genil_cont_root_object,


lt_result TYPE TABLE OF zes_test_tbl,
l_result TYPE zes_test_tbl.

SELECT * FROM zstudents INTO TABLE lt_result.

LOOP AT lt_result INTO l_result.


lr_object = iv_root_list->add_object( iv_object_name = 'TestRoot'
is_object_key = l_result-name ).
lr_object->set_query_root( abap_true ).
ENDLOOP.
SELECT * FROM ztest_object
INTO CORRESPONDING FIELDS OF TABLE
rt_obj_props.

Now compile the code and let us go the the BOL browser and execute this object and see if this
is working.

Go to the Transaction GENIL_BOL_BROWSER.

Now give the bol component name. Ours is ZTBOL. See the following screen shots.
See the following screen shot for the records in the z table. Double click on the TestSearchAdv.
you should see the Object browse and the dynamic parameter on the right hand side. See the
screen shots below.

Now let us use the bol to select the records from this table.

Remove the line in the dynamic Query Parameter using the – sign and click fine this will return
all the records. Double click on the values and you will see the rows. See the following screen
shots.
IF_GENIL_APPL_MODEL~GET_OBJECT_PROPS

Brings all the objects


IF_GENIL_APPL_MODEL~GET_MODEL

Brings Relation between Objects

Above two methods triggers in PBO

Você também pode gostar