Custom Bol Creation-Corrected

Embed Size (px)

Citation preview

  • 8/11/2019 Custom Bol Creation-Corrected

    1/16

    Create our own BOL Object

    Using the BOL and its uniform application programming interface (API) to access business

    data offers considerable advantages compared to the various APIs typically available forbusiness objects:

    1) The object-oriented BOL API is simple, uniform, and easy to use.

    2) The built-in buffer accelerates your applications.

    3) You can isolate your programs from any interface changes in the underlying businessobject-specific APIs.

    4) Development of SAP CRM applications is easy since the BOL has been designed to work hand-in-han

    with the UI parts of the CRM WebClient UI framework.

    It is possible to enhance the BOL to cover business data not yet supported. After the

    corresponding business objects and query services have been modeled and implemented,you can use them at runtime.

    Usually we are not need to build a BOL object. We will end up changing the existing BOL. I came acrossituation 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 create we need t

    this bol in the custom view and show that on the screen. For now let us see how we can create a custom B

    Let's create a z table . 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.

  • 8/11/2019 Custom Bol Creation-Corrected

    2/16

    OK. Now we need to define two tables. One for the data elements that we are going to use in the BOL a

    another for the hierarchy of the data element that we are going to use in the BOL object. Once these tabledefined 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.

  • 8/11/2019 Custom Bol Creation-Corrected

    3/16

    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 ZBOLOB.

    See the following screen.

  • 8/11/2019 Custom Bol Creation-Corrected

    4/16

    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.

  • 8/11/2019 Custom Bol Creation-Corrected

    5/16

    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 BO

    component to the component set.

    Now we need to create one implementation class and two tables one is Object table and another is Mode

    table. Now let us create all these 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 cla

    methods. While creating views (insert, edit and search) you need to specify specific Super class(not themethods).

    See the following screen shots.

    ZBOL_OBJECT table .

  • 8/11/2019 Custom Bol Creation-Corrected

    6/16

    and ZBOL_MODEL table

    Now we need to define a check table .

    See the following screen shots.

  • 8/11/2019 Custom Bol Creation-Corrected

    7/16

    don't forget to Activate your tables .

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

    See the following screen shot for the structure.

  • 8/11/2019 Custom Bol Creation-Corrected

    8/16

    w add this information in the BOL object Tables. Look at the following infomration I entered in the table. Always ect table needs to have a root object and the other object that are associated to their parent. Here all the object are

    ociated to the root. If you have complex hierarchy then it takes time to do the correct design and come up with the

    formation. Always try to see the existing code in the sap component and try to use that , this way it will be always e

    low.e the following screen shot for the data.

    and for the relation

  • 8/11/2019 Custom Bol Creation-Corrected

    9/16

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

    go to SE24 Transaction Create a new class ZCL_OWN_BOL using the class

    CL_CRM_GENIL_ABSTR_COMPONENT2 as super class. This is very important. If you didnt inheritsuper class they BOL object dont understand your z class module. See the following screen shot for the

    implementation class module creation.

    Now you need to redifine the methods from the super class. Because we are planning this bol object for s

    let us redefine all the methods that are associated for search.See the following screen shot.

  • 8/11/2019 Custom Bol Creation-Corrected

    10/16

    Now you need to change the code in all the above method to fit your bol objects. First let us put our bol tin this Get_Objects and Get_Model. See the following code cut and paste in the right methods.

    *--------------------------------Code For The Methods-----------------------------------------METHOD if_genil_appl_intlay~get_dynamic_query_result.DATA: lr_object TYPE REF TO if_genil_cont_root_object,

    lt_result TYPE TABLE OF zusr_bol_st.

    FIELD-SYMBOLS: TYPE zusr_bol_st.SELECT * FROM zusr_bol_tb INTO TABLE lt_result.

    LOOP AT lt_result ASSIGNING .

    lr_object = iv_root_list->add_object( iv_object_name = 'Root'is_object_key = -bname ).

    CHECK lr_object IS BOUND.

    lr_object->set_query_root( abap_true ).

    ENDLOOP.ENDMETHOD.

    METHOD if_genil_appl_intlay~get_objects.

    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 zusr_bol_tb-bname,

    lr_attr_props TYPE REF TO if_genil_obj_attr_properties,

    l_result TYPE zusr_bol_st,

    lv_name TYPE crmt_ext_obj_name.

    lr_object = iv_root_list->get_first( ).

  • 8/11/2019 Custom Bol Creation-Corrected

    11/16

    lr_msg_cont ?= iv_root_list->get_global_message_container( ).

    WHILE lr_object IS BOUND.

    lv_name = lr_object->get_name( ).

    IF lr_object->check_attr_requested( ) = abap_true.

    lr_object->get_key( IMPORTING es_key = lv_name_obj ).

    SELECT SINGLE * FROM zusr_bol_tb

    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.

    ENDMETHOD.

    METHOD if_genil_appl_model~get_model.

    SELECT * FROM zbol_model

    INTO CORRESPONDING FIELDS

    OF TABLE rt_relation_det.

    ENDMETHOD.

    METHOD if_genil_appl_model~get_object_props.

    SELECT * FROM zbol_object

    INTO CORRESPONDING FIELDS OF TABLE

    rt_obj_props[].

    ENDMETHOD.

  • 8/11/2019 Custom Bol Creation-Corrected

    12/16

    *--------------------------------End Of Code-----------------------------------------------------

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

    Go to the Transaction GENIL_BOL_BROWSER.

    Now give the bol component name. Ours is ZBOLOB.

    See the following screen shots.

    See the following screen shot for the records in the z table. Double click on the Search.

    you should see the Object browse and the dynamic parameter on the right hand side.See the screen shots below.

  • 8/11/2019 Custom Bol Creation-Corrected

    13/16

    i added the following lines to my z table and here you can do the same as you want to add.

    Remove the line in the dynamic Query Parameter using thesign 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.

  • 8/11/2019 Custom Bol Creation-Corrected

    14/16

  • 8/11/2019 Custom Bol Creation-Corrected

    15/16

    w you just hit the find button and get the result from the search .e the following screen shots.

    Once we got the results then this gives us that our BOL object is working.

    Now if you hit the children button you'l get the predefined relation that we define eralier .See the following screen shots.

  • 8/11/2019 Custom Bol Creation-Corrected

    16/16

    Now we can attach the BOL object to the View in the webclient component and we can create a search a

    result view.