SAP CRM Technical Tutorials by Naval Bhatt

27
8/31/12 SAP CRM Technical Tutorials by Naval Bhatt. 1/27 sapcrmtutorial.blogspot.in SAP CRM tutorials for all : Please feel free to contact me on [email protected]. SAP CRM Technical Tutorials by Naval Bhatt. SAP CRM Technical Tutorials by Naval Bhatt. Sunday, August 26, 2012 Sunday, August 26, 2012 Extend BOL Model BT with custom table type relationship http://wiki.sdn.sap.com/wiki/display/CRM/CRM+Web+Client+UI+Framework SAP CRM 6.0/7.0 Extend the standard BOL model BT with a custom relationship to accomodate your z-table. There's been a few discussions in the forums about finding a way to add a custom table to the standard BOL models. It's a bit tricky, but possible. In this WIKI, I will show you how to enhance the BOl model BT with a new 1..n relationship. The advantages are obvious. Any change in your custom data will register in the BOl layer, you will be abl to capture the BOl Core Reset and Order Init(revert) events, use the BOL model node wizards etc., Enhancing a few standard classes are in order. So, knowing how to enhance the methods using the implicit enhancement points is necessary. In this example, we will create the relationship under the administration header(BTAdminH). Actually, two relationships. One will be a read only relationship(similiar to BTItems) that is linked and the other will be the 1..n relation that corresponds to your database. My custom database ZORD has the following fields. CLIENT type MANDT "Client GUID type CRMT_OBJECT_GUID "guid of table entry(key) REF_GUID type CRMT_OBJECT_GUID "guid of order object EXTERN_CASE_NO type CRMT_OBJECT_ID "end-user usable NOTE type CHAR120 "e nd-us e r us able A structure 'ZORD_STRUCT' that corresponds to the table structure and a table type 'ZORD_STRUCT_TAB' is available. In transaction CRMC_OBJECTS, maintain the API object name of our custom object. In our case, the name is ZORD. This information will be used further below. This will allo us to define our own transaction events. This step is to ensure that the transaction events which we will be defining later on, will be called only when necessary. This step is optional and you should be able to figure out if your scenario needs this or not. For example, if you are extending only the opportunity transaction type, declare ZORD as a sub-object of Opportunity(BUS2000111). Maintain this information in view maintenance CRMV_OBJECT_ASSI We will have to define three basic events in the transaction event model that will take care of our custom objects. These are 1. Initialization -> When the order is being initialized say, during lock/revert scenarios, we want our object to be initialized too. 2. Save -> When the order is being saved, save our data too. 3. Delete -> When the order is deleted, we need to delete corresponding data from our custom table For this, you must identify the correct places to insert our event callback function modules. If not already done, set your user parameterCRM_EVENT_TRACE to "X". Next, do something say, create transactions, modify it, save it and delete it. After each action, look at the events raised in transaction CRMD_EVENT_TRACE. Study this data carefully and decide on the points in which to insert your event callback function modules. For creating the FMs(the signature part), look at the standard FMs (they end with *_EC) defined for the same event in the trace data. Create empty FMs for each of the three events mentioned and study the trace again. We will be calling our custom API class' methods inside these FMs. We will cover this later. For now, create entries in the transaction event handler table and ensure that the FMs are getting called in the correct Link to Content's target Space : Applies to: Summary Intro Step 1 : Studying the event handler model Maintain API Object Name Maintain Object dependency Identify positions for defining custom events for transactions Search Search This Blog Search This Blog babudeep junjuri Options Members (11) Invite your friends Followers:Join to get regular Followers:Join to get regular update update SAP BPM & Workflow tutorials My travel experiences Me & my pursuit of happiness Wandering hermit Photography My other blogs My other blogs Join me on my photography Join me on my photography journey journey

Transcript of SAP CRM Technical Tutorials by Naval Bhatt

Page 1: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

1/27sapcrmtutorial.blogspot.in

SAP CRM tutorials for all : Please feel free to contact me on [email protected].

SAP CRM Technical Tutorials by Naval Bhatt.SAP CRM Technical Tutorials by Naval Bhatt.

Sunday, August 26, 2012Sunday, August 26, 2012

Extend BOL Model BT with custom table typerelationship

http://w iki.sdn.sap.com/wiki/display/CRM/CRM+Web+Client+UI+Framework

SAP CRM 6.0/7.0

Extend the standard BOL model BT with a custom relationship to accomodate your z-table.

There's been a few discussions in the forums about finding a way to add a custom table to the standard BOL models. It's a bit tricky, but possible. In this WIKI, I w ill show

you how to enhance the BOl model BT with a new 1..n relationship. The advantages are obvious. Any change in your custom data w ill register in the BOl layer, you will be able

to capture the BOl Core Reset and Order Init(revert) events, use the BOL model node wizards etc., Enhancing a few standard classes are in order. So, knowing how to

enhance the methods using the implicit enhancement points is necessary.

In this example, we will create the relationship under the administration header(BTAdminH). Actually, two relationships. One will be a read only relationship(similiar to

BTItems) that is linked and the other w ill be the 1..n relation that corresponds to your database.

My custom database ZORD has the following fields.

CLIENT type MANDT "Client

GUID type CRMT_OBJECT_GUID "guid of table entry(key)

REF_GUID type CRMT_OBJECT_GUID "guid of order object

EXTERN_CASE_NO type CRMT_OBJECT_ID "end-user usable

NOTE type CHAR120 "end-user usable

A structure 'ZORD_STRUCT' that corresponds to the table structure and a table type 'ZORD_STRUCT_TAB' is available.

In transaction CRMC_OBJECTS, maintain the API object name of our custom object. In our case, the name is ZORD. This information w ill be used further below. This w ill allow

us to define our own transaction events.

This step is to ensure that the transaction events which we will be defining later on, w ill be called only when necessary. This step is optional and you should be able to

figure out if your scenario needs this or not. For example, if you are extending only the opportunity transaction type, declare ZORD as a sub-object of

Opportunity(BUS2000111). Maintain this information in view maintenance CRMV_OBJECT_ASSI

We will have to define three basic events in the transaction event model that w ill take care of our custom objects. These are

1. Initialization -> When the order is being initialized say, during lock/revert scenarios, we want our object to be initialized too.

2. Save -> When the order is being saved, save our data too.

3. Delete -> When the order is deleted, we need to delete corresponding data from our custom table

For this, you must identify the correct places to insert our event callback function modules. If not already done, set your user parameterCRM_EVENT_TRACE to "X". Next, do

something say, create transactions, modify it, save it and delete it. After each action, look at the events raised in transaction CRMD_EVENT_TRACE. Study this data carefully

and decide on the points in which to insert your event callback function modules. For creating the FMs(the signature part), look at the standard FMs (they end with *_EC)

defined for the same event in the trace data. Create empty FMs for each of the three events mentioned and study the trace again. We will be calling our custom API class'

methods inside these FMs. We will cover this later. For now, create entries in the transaction event handler table and ensure that the FMs are getting called in the correct

Link to Content's target Space :

Applies to:

Summary

Intro

Step 1 : Studying the event handler model

Maintain API Object Name

Maintain Object dependency

Identify positions for defining custom events for transactions

Search

Search This BlogSearch This Blog

babudeep junjuriOptions

Members (11)

Invite your friends

Followers:Join to get regularFollowers:Join to get regularupdateupdate

SAP BPM & Workflow tutorials

My travel experiences

Me & my pursuit of happiness

Wandering hermit Photography

My other blogsMy other blogs

Join me on my photographyJoin me on my photographyjourneyjourney

Page 2: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

2/27sapcrmtutorial.blogspot.in

places for various scenarios.

For example, if I'm extending the Opportunity model, I w ill create these entries - In SPRO, go to CRM->Transactions->Basic Settings->Edit event handler table

Choosing transaction category is opportunity w ill ensure that this FM will be called only for Opportunities

Transaction Category BUS2000111 (Opportunity)

Execution Time 88 (Initialize Document)

Priority 99

Object ZORD (Z Order Extension)

Event INIT

Attribute <*>

Function ZORD_INIT_EC

Perform Function for Document Header X

Perform Function for Document Item blank

Do Not Process Function if Event Error Occurs blank

Call Callback Call Just Once Per Transaction

2. Save

Unlike above, we cannot choose transaction category as Opportunity here! This is because an opportunity save event w ill be raised only when you make changes in the

opportunity relevant fields(eg OPPORT_H), even though you are editing an opportunity. For the below FM to trigger, we w ill have to "remind" the system to do it when

changes are made to our custom objects. So, you will not see this FM in the event trace right now till the coding part is complete. We will cover this further down(Look

further down at the last part of the coding part for the method implementation for METHOD ZORD_RUN_BTIL->if_crm_runtime_btil~maintain_attributes).

Transaction Category BUS20001 (CRM Bus Transactions)

Execution Time 80 (Save Document)

Priority 99

Object ZORD (Z Order Extension)

Event SAVE

Attribute <*>

Function ZORD_SAVE_EC

Perform Function for Document Header X

Perform Function for Document Item blank

Do Not Process Function if Event Error Occurs blank

Call Callback Call Just Once Per Transaction

3. Delete

For deletion also, only generic order delete event can be chosen. Inside this Fm, you should make sure that the scenario is right. For example, make sure that the order

being deleted is an opportunity before making API calls! We will cover this below.

Transaction Category BUS20001 (CRM Bus Transactions)

Execution Time 1 (Immediately)

Priority 90

Object ORDER (General order processing)

Event AFTER_DELETE

Attribute <*>

Function ZORD_DEL_EC

Perform Function for Document Header X

Perform Function for Document Item blank

Do Not Process Function if Event Error Occurs blank

Call Callback Call Just Once Per Transaction

First, we have some customizing work to do. Navigate to the node shown in the picture.Note that the node text may show up as 'Business Transactions' in your case. Or you

may go to SM30 and put 'CRMC_OBJ_BTIL' and choose customizing. You must do each of the three activities shown.

1. Initialization

Step 2 : Customizing - Extend Model BT

Maintain Z-objects

Naval Bhatt Photography .. on Facebook

Pratik Peey ush Dearest Deepak

Shankar Tarun Shahril Nur

Naval Bhatt Photography.. on Facebook

460 people like Naval Bhatt Photography ..

Like

Show More

Naval Bhatt

Photography .. added

a new photo.

August 10 at 8:11pm

▼ 2012 (129)

▼ August (14)

Extend BOL Model BTwith custom table typerelatio...

Extend BOL Model for BPwith Custom Table andImpl...

How to use your customBOL Object forwebclient wi...

Difference betweencustom and componentcontroller...

Transaction launcher

One order framework

ABOUT ONE-CLICKACTIONS.

Post ProcessingFramework

ACTIONS

BTE - BusinessTransaction Event

wande mataram .... :mother country ..

Sales order scenario :CRM -ERP

Sales order Distribution:Required Customizingin ...

SAP CRM Sales :Creating a quotationdirectly in E...

Blog ArchiveBlog Archive

Page 3: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

3/27sapcrmtutorial.blogspot.in

Maintain Z-Relations

Maintain handler classes for Z-objects

► July (26)

► June (18)

► May (11)

► April (9)

► March (28)

► February (13)

► January (10)

pow ered by

Video BarVideo Bar

Getter - Setter methods in Web UI

Using Get and Setter methods you canretrieve data to field and set specificdata to field. Using Get_I method youcan make your field ...

Concepts of BOL programming :Get_current

Get_current and get_iterator how does it works? The data you enter on theWeb UI gets saved in the databasetables via BOL Entities ...

Create a Tree view display in CRMweb UI

This blog gives the steps to create aTree view display in CRM web UI.Below is a screen shot of the sampleimplementation. ...

Scope of the design layer

Scope of the design layer In the UIUframework some UI/Design relevantsettings can be made. These settingshave to be made per view...

CRM – Tables and Transaction Codes

TABLE NAME DESCRIPTIONBUSINESS PARTNERS BUT000 BP:General data Contains BusinessPartner Number, Partner Category,Partne...

Popular PostsPopular Posts

Page 4: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

4/27sapcrmtutorial.blogspot.in

Note:

If you are not w illing to implement the classes, you may skip maintaining the handler classes. You can even directly specify a single 1..n relationship directly under

BTAdminH. The relationships w ill be available, but not usable in the real sense. Then, you can follow this w iki to make do with value nodes.

http://w iki.sdn.sap.com/wiki/display/CRM/How+to+display+a+z-table+in+an+assignment+block

Moving forward, here's a screenshot of the model w ith the new relationships expanded.

We will begin w ith the API class which w ill be responsible for all operations related to our table.

ZL_ZORD_BTIL_API -> Super class: None

Class Attributes

GT_ZORD Static Attribute Private Type ZORD_STRUCT_TAB API Buffer

GT_ZORD_DEL Static Attribute Private Type ZORD_STRUCT_TAB API Buffer for deleted entities

Note: The GT_ZORD table w ill act as a unified buffer for read and change. GT_ZORD_DEL will hold entries to be deleted on save. Due to this unified buffer nature, it is very

important to refresh this table on Order INIT events.

Methods:

ZORD_CREATE Static Method Public Create

ZORD_MODIFY Static Method Public Modify API data

ZORD_DELETE Static Method Public Delete from API data

ZORD_SAVE Static Method Public Save to DB

ZORD_READ Static Method Public Initial relations reading

ZORD_READ_SINGLE Static Method Public Read single entry

ZORD_INIT Static Method Public Reset buffers

ZORD_DELETE_WITH_ORDER Static Method Public Delete from DB when order is deleted

Step 3: Implementing Handler classes

API Class for our custom Object

Do_prepare_output andOn_new_focus

DO_PREPARE_OUTPUTDO_PREPARE_OUTPUT method istriggered each time the view isprepared after each event. Normallywe redefine this meth...

SAP CRM Cross-applicationAuthorization Objects

OBJECT CLASS Definition /GC1/AUTHAAAB Authorization for GarbageCollector /SAPCND/CC AAABCondition Technique: Authorizatio...

Sample code forDO_CONFIG_DETERMINATIONmethod

This example is to set the visibility of ascreen field based on another field ...METHOD do_config_determination. DATA: lr_btadmin...

How to create POP-UP window in UI

Open the component and then viewwhere the pop up is to be raised. Youmust be raising the popup on someevent... You will need to crea...

Important abap function modules

Useful ABAP Function Modules Thispage is intended to maintaindocumentation of useful functionmodules. This is needed becauseinde...

Total PageviewsTotal Pageviews

2 4 6 4 2

Follow by EmailFollow by Email

Email address... Submit

Page 5: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

5/27sapcrmtutorial.blogspot.in

Method Signatures:

*"* public components of class ZL_ZORD_BTIL_API

*"* do not include other source files here!!!

public section.

class-methods ZORD_CREATE

importing

!IS_KEY type CRMT_OBJECT_GUID

!IS_ATTRIBUTES type ZORD_STRUCT .

class-methods ZORD_MODIFY

importing

!IS_KEY type CRMT_OBJECT_GUID

!IV_HEADER_GUID type CRMT_OBJECT_GUID

!IS_ATTRIBUTES type ZORD_STRUCT

!IT_CHANGED_FIELDS type CRMT_ATTR_NAME_TAB

exporting

!ET_RETURN type BAPIRET2_T

!ET_CHANGED_OBJECTS type CRMT_GENIL_OBJ_INSTANCE_TAB .

class-methods ZORD_DELETE

importing

!IS_KEY type CRMT_OBJECT_GUID

!IV_HEADER_GUID type CRMT_OBJECT_GUID

exporting

!ET_RETURN type BAPIRET2_T

!ET_CHANGED_OBJECTS type CRMT_GENIL_OBJ_INSTANCE_TAB .

class-methods ZORD_SAVE

importing

!IV_HEADER_GUID type CRMT_OBJECT_GUID .

class-methods ZORD_READ

importing

!IV_HEADER_GUID type CRMT_OBJECT_GUID

exporting

!ET_ZORD type ZORD_STRUCT_TAB .

class-methods ZORD_READ_SINGLE

importing

!IV_GUID type CRMT_OBJECT_GUID

exporting

!ET_ZORD type ZORD_STRUCT_TAB .

class-methods ZORD_INIT

importing

!IV_HEADER_GUID type CRMT_OBJECT_GUID optional .

class-methods ZORD_DELETE_WITH_ORDER

importing

!IV_HEADER_GUID type CRMT_OBJECT_GUID optional .

METHOD zord_create.

DATA: ls_zord TYPE zord_struct.

ls_zord = is_attributes.

ls_zord-guid = is_key.

INSERT ls_zord INTO TABLE gt_zord.

ENDMETHOD.

METHOD zord_modify.

FIELD-SYMBOLS: <fs_zord> LIKE LINE OF gt_zord,

<old> TYPE simple,

<new> TYPE simple,

<name> TYPE name_komp.

READ TABLE gt_zord WITH KEY guid = is_key ASSIGNING <fs_zord>.

IF sy-subrc EQ 0.

LOOP AT it_changed_fields ASSIGNING <name>.

ASSIGN COMPONENT <name> OF STRUCTURE <fs_zord> TO <old>.

CHECK sy-subrc = 0.

ASSIGN COMPONENT <name> OF STRUCTURE is_attributes TO <new>.

CHECK sy-subrc = 0.

<old> = <new>.

ENDLOOP.

ENDIF.

ENDMETHOD.

METHOD zord_delete.

DATA: ls_zord LIKE LINE OF gt_zord.

READ TABLE gt_zord WITH KEY guid = is_key INTO ls_zord.

IF sy-subrc EQ 0.

INSERT ls_zord INTO TABLE gt_zord_del.

DELETE gt_zord WHERE guid = is_key.

ENDIF.

ENDMETHOD.

METHOD zord_save.

Method Implementations

Page 6: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

6/27sapcrmtutorial.blogspot.in

DATA: lt_zord TYPE zord_struct_tab,

ls_zord LIKE LINE OF lt_zord.

LOOP AT gt_zord INTO ls_zord WHERE ref_guid = iv_header_guid.

INSERT ls_zord INTO TABLE lt_zord.

ENDLOOP.

IF lt_zord[] IS NOT INITIAL.

MODIFY zord FROM TABLE lt_zord.

ENDIF.

REFRESH lt_zord.

LOOP AT gt_zord_del INTO ls_zord WHERE ref_guid = iv_header_guid.

INSERT ls_zord INTO TABLE lt_zord.

ENDLOOP.

IF lt_zord[] IS NOT INITIAL.

DELETE zord FROM TABLE lt_zord.

ENDIF.

ENDMETHOD.

METHOD zord_read.

DATA: lt_zord TYPE zord_struct_tab,

ls_zord LIKE LINE OF lt_zord.

*Check buffer first

*If entries are found in buffer, no need to check DB as whole buffer is used.

*no special provisions for deleted items

READ TABLE gt_zord WITH KEY ref_guid = iv_header_guid TRANSPORTING NO FIELDS.

IF sy-subrc EQ 0.

et_zord[] = gt_zord[].

DELETE et_zord WHERE ref_guid NE iv_header_guid.

ELSE.

READ TABLE gt_zord_del WITH KEY ref_guid = iv_header_guid TRANSPORTING NO FIELDS.

IF sy-subrc EQ 0.

*deleted entries exist in buffer!! => Table has already been buffered => No DB Read

EXIT.

ELSE.

REFRESH et_zord.

SELECT * FROM zord INTO TABLE et_zord WHERE ref_guid = iv_header_guid.

INSERT LINES OF et_zord INTO TABLE gt_zord.

ENDIF.

ENDIF.

ENDMETHOD.

METHOD zord_read_single.

DATA: lt_zord TYPE zord_struct_tab,

ls_zord LIKE LINE OF lt_zord.

*Check buffer first

*If entries are found in buffer, no need to check DB as whole buffer is used.

*no special provisions for deleted items

READ TABLE gt_zord WITH KEY guid = iv_guid INTO ls_zord.

IF sy-subrc EQ 0.

INSERT ls_zord INTO table et_zord.

ELSE.

SELECT * FROM zord INTO TABLE et_zord WHERE guid = iv_guid.

INSERT LINES OF et_zord INTO TABLE gt_zord.

ENDIF.

ENDMETHOD.

METHOD zord_init.

DATA: lt_zord TYPE zord_struct_tab,

ls_zord LIKE LINE OF lt_zord.

IF iv_header_guid IS NOT INITIAL.

DELETE gt_zord WHERE ref_guid = iv_header_guid.

DELETE gt_zord_del WHERE ref_guid = iv_header_guid.

ELSE.

REFRESH gt_zord.

REFRESH gt_zord_del.

ENDIF.

ENDMETHOD.

METHOD ZORD_DELETE_WITH_ORDER.

DELETE FROM zord WHERE ref_guid = iv_header_guid.

ENDMETHOD.

The names of the classes w ill be derived at runtime following some conventions. Essentially a _RUN_BTIL and a _DESIGN_BTIL is appended to what you have specified in

customizing. So, go ahead and create the classes.

ZORD_SET_DESIGN_BTIL -> Super class: CL_CRM_DESIGNTIME_BTIL

ZORD_DESIGN_BTIL -> Super class: CL_CRM_DESIGNTIME_BTIL

For the design classes, no further changes are required. You may want to redefine the constructor if you wish to validate the

object name.

ZORD_SET_RUN_BTIL -> Super class: CL_CRM_RUNTIME_BTIL

ZORD_RUN_BTIL -> Super class: CL_CRM_RUNTIME_BTIL

Handler classes for our objects

ZORD_SET_RUN_BTIL - Redefined Methods

Page 7: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

7/27sapcrmtutorial.blogspot.in

METHOD if_crm_runtime_btil~read_attributes.

DATA: ls_guid TYPE crmst_guid_btil.

*This is a static read-only relation.

*Inherit GUID from order

TRY.

ir_cont_obj->set_key( iv_ref_guid ).

CATCH cx_crm_cic_duplicate_entry.

ENDTRY.

IF ir_cont_obj->check_attr_requested( ) EQ true.

ls_guid-crm_guid = iv_ref_guid.

me->set_attributes( ir_cont_obj = ir_cont_obj

is_attributes = ls_guid

iv_ref_kind = iv_ref_kind

iv_log_key = iv_ref_guid ).

ENDIF.

*Read underlying relations

IF ir_cont_obj->check_rels_requested( ) EQ true.

me->access_children( ir_cont_obj = ir_cont_obj

ir_data = ir_api_data

iv_ref_guid = iv_ref_guid

iv_ref_kind = iv_ref_kind ).

ENDIF.

*

ENDMETHOD.

METHOD IF_CRM_RUNTIME_BTIL~MAINTAIN_ATTRIBUTES.

DATA: lv_delta TYPE crmt_delta.

***

*This is a read-only relation, nothing much to do here except inherit GUID from Order object

lv_delta = ir_cont_obj->get_delta_flag( ).

IF lv_delta EQ ir_cont_obj->delta_created.

TRY.

ir_cont_obj->set_key( iv_ref_guid ).

CATCH cx_crm_cic_duplicate_entry.

ENDTRY.

ENDIF.

*Take care of underlying relations

me->modify_children( ir_cont_obj = ir_cont_obj

ir_data = ir_api_data

ir_input_fields = ir_input_fields

iv_ref_kind = iv_ref_kind

iv_ref_guid = iv_ref_guid ).

ENDMETHOD.

METHOD MODIFY_CHILDREN .

*Do not redefine this method! Super class will take care of this

ENDMETHOD.

METHOD fieldcheck.

*redefined to prevent system looking for unimplemented FM

*empty, create your own implementation

endmethod.

METHOD if_crm_runtime_btil~read_attributes.

DATA: lr_root_container TYPE REF TO if_genil_container_object,

lv_guid TYPE crmt_object_guid,

lv_first TYPE crmt_boolean VALUE true,

lv_relation TYPE crmt_relation_name.

DATA: lr_zord_i TYPE REF TO zord_struct_tab,

lt_zord_i TYPE zord_struct_tab,

lr_attr_props TYPE REF TO if_genil_obj_attr_properties,

lr_cont_obj TYPE REF TO if_genil_container_object.

FIELD-SYMBOLS: <ls_zord_i> TYPE zord_struct,

<ls_api_data> TYPE crmt_intlay_get,

<lt_api_data> TYPE crmt_intlay_get_tab.

***

CALL METHOD zl_zord_btil_api=>zord_read

ZORD_RUN_BTIL - Redefined methods

Page 8: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

8/27sapcrmtutorial.blogspot.in

CALL METHOD zl_zord_btil_api=>zord_read

EXPORTING

iv_header_guid = iv_ref_guid "Order GUID

IMPORTING

et_zord = lt_zord_i.

CALL METHOD ir_cont_obj->get_parent_relation

IMPORTING

ev_relation_name = lv_relation.

LOOP AT lt_zord_i ASSIGNING <ls_zord_i>.

TRY.

IF lv_first EQ true.

lv_first = false.

lr_cont_obj = ir_cont_obj.

lr_cont_obj->set_key( <ls_zord_i>-guid ).

ELSE.

lr_cont_obj = ir_cont_obj->copy_self_with_structure(

is_object_key = <ls_zord_i>-guid

iv_relation_name = lv_relation ).

CHECK lr_cont_obj IS BOUND.

ENDIF.

CATCH cx_crm_cic_duplicate_entry.

TRY.

lr_cont_obj = me->turn_path( ir_cont_obj = ir_cont_obj

iv_relation_name = lv_relation

is_key = <ls_zord_i>-guid ).

CATCH cx_crm_genil_general_error.

CONTINUE.

ENDTRY.

CATCH cx_crm_genil_model_error.

CONTINUE.

ENDTRY.

IF lr_cont_obj->check_attr_requested( ) EQ true.

me->set_attributes( ir_cont_obj = lr_cont_obj

is_attributes = <ls_zord_i>

iv_ref_kind = iv_ref_kind

iv_log_key = <ls_zord_i>-guid ).

lr_attr_props = lr_cont_obj->get_attr_props_obj( ).

lr_attr_props->set_all_properties( if_genil_obj_attr_properties=>changeable ).

lr_attr_props->set_property_by_idx( iv_index = 1

iv_value = if_genil_obj_attr_properties=>read_only ). "Client

lr_attr_props->set_property_by_idx( iv_index = 2

iv_value = if_genil_obj_attr_properties=>technical ). "GUID

lr_attr_props->set_property_by_idx( iv_index = 3

iv_value = if_genil_obj_attr_properties=>technical ). "REF_GUID

ENDIF.

IF lr_cont_obj->check_rels_requested( ) EQ true.

me->get_foreign_id( ir_cont_obj = lr_cont_obj

is_data = <ls_zord_i> ).

ENDIF.

ENDLOOP.

ENDMETHOD.

*

METHOD if_crm_runtime_btil~maintain_attributes.

INCLUDE crm_mode_con.

DATA: lv_delta TYPE crmt_delta.

DATA: ls_changed_object TYPE crmt_genil_obj_instance.

DATA: lt_names TYPE crmt_attr_name_tab.

DATA: lr_attr_props TYPE REF TO if_genil_obj_attr_properties.

FIELD-SYMBOLS: <ls_api_data> TYPE crmst_order_maintain,

<lv_name> TYPE name_komp.

***

DATA: lv_props_obj TYPE REF TO if_genil_obj_attr_properties,

lt_changed_attr TYPE crmt_attr_name_tab,

ls_attributes TYPE zord_struct,

lv_guid TYPE crmt_object_guid,

* lt_return TYPE bapiret2_t,

* lv_msg_cont TYPE REF TO cl_crm_genil_bapi_mess_cont,

ls_obj_inst TYPE crmt_genil_obj_instance,

lv_header TYPE REF TO if_genil_container_object,

lv_header_guid TYPE crmt_genil_object_guid,

ls_header_attr TYPE crmst_guid_btil.

CHECK ir_cont_obj->get_name( ) = 'ZORD'.

ls_obj_inst-object_name = 'ZORD'. "#EC NOTEXT

* retrieve the GUID of the header

lv_header = ir_cont_obj->get_parent( ).

CALL METHOD lv_header->get_key

IMPORTING

es_key = lv_header_guid.

CALL METHOD lv_header->get_attributes

IMPORTING

es_attributes = ls_header_attr.

* retrieve the delta flag

lv_delta = ir_cont_obj->get_delta_flag( ).

* branch according to the delta flag. Dependent objects may be created, modified, or deleted.

Page 9: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

9/27sapcrmtutorial.blogspot.in

CASE lv_delta.

WHEN if_genil_cont_simple_object=>delta_changed.

* retrieve the attribute property object to get the modify details

lv_props_obj = ir_cont_obj->get_attr_props_obj( ).

* which attributes were modified?

CALL METHOD lv_props_obj->get_name_tab_4_property

EXPORTING

iv_property = if_genil_obj_attr_properties=>modified

IMPORTING

et_names = lt_changed_attr.

CALL METHOD ir_cont_obj->get_key

IMPORTING

es_key = lv_guid.

CALL METHOD ir_cont_obj->get_attributes

IMPORTING

es_attributes = ls_attributes.

* call the API

CALL METHOD zl_zord_btil_api=>zord_modify

EXPORTING

is_key = lv_guid

iv_header_guid = lv_header_guid

is_attributes = ls_attributes

it_changed_fields = lt_changed_attr.

* IMPORTING

* et_return = lt_return

* et_changed_objects = lt_changed_objects.

ls_obj_inst-object_id = cl_crm_genil_container_tools=>build_object_id( lv_guid ).

* add object to the changed objects list

INSERT ls_obj_inst INTO TABLE gr_intlay->gt_changed_objects.

WHEN if_genil_cont_simple_object=>delta_created.

* get the attribute structure

CALL METHOD ir_cont_obj->get_attributes

IMPORTING

es_attributes = ls_attributes.

** build the key

* CALL FUNCTION 'GUID_CREATE'

* IMPORTING

* ev_guid_16 = lv_guid.

ir_cont_obj->get_key( IMPORTING es_key = lv_guid ).

ls_attributes-ref_guid = lv_header_guid.

* call the API

CALL METHOD zl_zord_btil_api=>zord_create

EXPORTING

is_key = lv_guid

is_attributes = ls_attributes.

* IMPORTING

* et_return = lt_return.

ls_attributes-guid = lv_guid.

ir_cont_obj->set_attributes( ls_attributes ).

* set new key

TRY.

ir_cont_obj->set_key( lv_guid ).

CATCH cx_crm_genil_duplicate_key.

ENDTRY.

ls_obj_inst-object_id = cl_crm_genil_container_tools=>build_object_id( lv_guid ).

INSERT ls_obj_inst INTO TABLE gr_intlay->gt_changed_objects.

WHEN if_genil_cont_simple_object=>delta_deleted.

* get object key

CALL METHOD ir_cont_obj->get_key

IMPORTING

es_key = lv_guid.

* call the API

CALL METHOD zl_zord_btil_api=>zord_delete

EXPORTING

is_key = lv_guid

iv_header_guid = lv_header_guid.

* IMPORTING

* et_return = lt_return

* et_changed_objects = lt_changed_objects.

ls_obj_inst-object_id = cl_crm_genil_container_tools=>build_object_id( lv_guid ).

INSERT ls_obj_inst INTO TABLE gr_intlay->gt_changed_objects.

ENDCASE.

*Tell the Order API that a change has happened

*This will register our object for save (The FM we registered for SAVE event in event handler table)

CALL FUNCTION 'CRM_EVENT_PUBLISH_OW'

EXPORTING

iv_obj_name = 'ZORD'

iv_guid_hi = lv_header_guid

iv_kind_hi = gc_object_kind-orderadm_h

iv_event = gc_event-after_change.

ENDMETHOD.

Remember the three event callback function modules that we registered in the transaction event handler table? Call the correct API methods inside each FM.

Step 4 - Implement Event callback Function Modules

Page 10: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

10/27sapcrmtutorial.blogspot.in

1. Initialization

FUNCTION zord_init_ec.

*"----------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" REFERENCE(IV_HEADER_GUID) TYPE CRMT_OBJECT_GUID OPTIONAL

*"----------------------------------------------------------------------

IF iv_header_guid IS NOT INITIAL.

CALL METHOD ZL_ZORD_BTIL_API=>ZORD_INIT

EXPORTING

iv_header_guid = iv_header_guid.

ENDIF.

ENDFUNCTION.

2. Save

FUNCTION zord_save_ec.

*"----------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" REFERENCE(IV_OBJECT_NAME) TYPE CRMT_OBJECT_NAME

*" REFERENCE(IV_EVENT_EXETIME) TYPE CRMT_EVENT_EXETIME

*" REFERENCE(IV_EVENT) TYPE CRMT_EVENT

*" REFERENCE(IT_HEADER_GUID) TYPE CRMT_OBJECT_GUID_TAB

*"----------------------------------------------------------------------

Data: lv_header_guid type crmt_object_guid.

loop at it_header_guid into lv_header_guid.

CALL METHOD ZL_ZORD_BTIL_API=>ZORD_SAVE

EXPORTING

iv_header_guid = lv_header_guid.

endloop.

ENDFUNCTION.

3. Delete

FUNCTION zord_del_ec.

*"----------------------------------------------------------------------

*"*"Local Interface:

*" IMPORTING

*" REFERENCE(IV_OBJECT_NAME) TYPE CRMT_OBJECT_NAME

*" REFERENCE(IV_EVENT_EXETIME) TYPE CRMT_EVENT_EXETIME

*" REFERENCE(IV_EVENT) TYPE CRMT_EVENT

*" REFERENCE(IV_HEADER_GUID) TYPE CRMT_OBJECT_GUID OPTIONAL

*"----------------------------------------------------------------------

*Use FM "CRM_ORDERADM_H_READ_OB" with include_deleted_header option to ensure that object is relevant to us

* - before calling API method

IF iv_header_guid IS NOT INITIAL.

*Delete from object buffer

CALL METHOD ZL_ZORD_BTIL_API=>ZORD_INIT

EXPORTING

iv_header_guid = iv_header_guid.

*Delete from database

CALL METHOD ZL_ZORD_BTIL_API=>ZORD_DELETE_WITH_ORDER

EXPORTING

iv_header_guid = iv_header_guid.

ENDIF.

ENDFUNCTION.

Page 11: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

11/27sapcrmtutorial.blogspot.in

Posted by Naval Bhatt at 9:01 AM No comments:

Labels: Extend BOL Model BT with custom table type relationship, sap crm tutorial, SAP CRM

Here are a few screens showing the results

Here's the table view after deleting line4 and save.

Results:

+2 Recommend this on Google

Page 12: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

12/27sapcrmtutorial.blogspot.in

tutorials

Friday, August 24, 2012Friday, August 24, 2012

Posted by Naval Bhatt at 10:04 PM No comments:

Labels: Extend BOL Model for BP with Custom Table and Implement GenIL Class, GENIL class,

SAP CRM tutorials, sap crm BOL programming, sap crm tutorial

Extend BOL Model for BP with Custom Table andImplement GenIL Class

Details of how to Extend BOL Model for BP with Custom Table and Implement GenIL Class

are in the below PDF link .

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/4048d161-9ac1-2e10-3bbf-

baef73d78109?QuickLink=index&overridelayout=true

+2 Recommend this on Google

Tuesday, August 21, 2012Tuesday, August 21, 2012

How to use your custom BOL Object for webclient withinassignment block.

We created the BOL object in one of our old blog http://sapcrmtutorial.blogspot.sg/2012/02/create-z-bol-object.html

that meet your personal requirements.

Now that w e have our BOL Object w e might w ant to use it for our purposes.

Let's say that w e w ant to add several f ields to assignment block and

display them on the screen, for instance w e take the f ields from our Z table

that w e use in the creation of our BOL Object.

We also w ant to keep the connection for the original transaction context .

The steps for doing that are :

1) We need to add a f ield to our Z table BP_GUID w hich w ill keep us connected

to the main transaction context .

2) Perform the adjustment for the Z Table.

3) Search for the right BP_GUID that f it to our user account.

4) create new record that contain the details that w e w ant to display for the specif ic

account.

See the follow ing screen shot.

Now w e need to perform some adjustment for our table .

choose the Database Utility from the menu .

See the follow ing screen shot.

How to use your custom BOL Object for webclient within assignment block.

Page 13: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

13/27sapcrmtutorial.blogspot.in

once you choose this option you'll get the next screen :

In our case w e w ill choose the Delete data option becuse w e w ant to create a new record, you also have to know that if

you choose the Save data option there's no 100 percent guarantee that your data in the table w ill be saved , so you

should consider the use of Database Utility very careful.

After w e perform the adjustment and activated the table w e can step forw ard to the next step w hich is the creation of a

new record w ith the details that w e w ant to display on the screen .

First to the record creation w e should f ind the key w hich is the BP_GUID that w ill connect us to the account context .

To f ind the right BP_GUID enter transaction GENIL_BOL_BROWSER and insert the BP_APPL_COND in the component set

f ield.

See the follow ing screen shot.

Page 14: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

14/27sapcrmtutorial.blogspot.in

w hen you enter to the component set choose the predefined search

named BuilEmpSearch

See the follow ing screen shot.

Now w e can look for any partner , in my case i'll choose to search my user and i'll get the compatible BP_GUID w hich is

: DF21EBC73A26F8F1A2B0001F29644FC0

See the follow ing screen shot.

Now let's create a new record in the DataBase table ZUSR_BOL_TB w ith user name, BP_GUID , First and last names.

See the follow ing screen shot.

For now w e finish w ith the database side and w e w iil go to perform some improvement in our BOL object to support the

Page 15: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

15/27sapcrmtutorial.blogspot.in

different searching options.

So let's go to transaction SE24 and put ZCL_OWN_BOL in the input f iled.

click on Local Types button and put the lines inside :

*-------------------------------------------------------------

TYPES: BEGIN OF ty_general_rng ,

sign TYPE bapisign,

option TYPE bapioption,

low TYPE string ,

high TYPE string ,

END OF ty_general_rng .

TYPES:

tt_general_rng TYPE STANDARD TABLE OF ty_general_rng .

See the follow ing screen shot:

Now go back to the method list and edit the

method :IF_GENIL_APPL_INTLAY~GET_DYNAMIC_QUERY_RESULT

replace the exisiting code w ith the bellow lines:

*-------------------------------------------------------------------------------------------

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,

lv_dyn_w here TYPE string,

lv_len TYPE i ,

ls_range TYPE ty_general_rng.

DATA: lt_bp_guid TYPE tt_general_rng,

lt_bname_range TYPE tt_general_rng,

lt_name_first TYPE tt_general_rng,

lt_name_last TYPE tt_general_rng.

FIELD-SYMBOLS: <lfs_result> TYPE zusr_bol_st,

<lfs_selection_range> TYPE genilt_selection_parameter.

decomposition of selection parameters and build a dynamic w here condition

LOOP AT it_selection_parameters[] ASSIGNING <lfs_selection_range>.

MOVE: <lfs_selection_range>-sign TO ls_range-sign ,

<lfs_selection_range>-option TO ls_range-option ,

<lfs_selection_range>-low TO ls_range-low ,

<lfs_selection_range>-high TO ls_range-high.

CASE <lfs_selection_range>-attr_name.

WHEN 'BNAME'.

APPEND ls_range TO lt_bname_range[].

CONCATENATE lv_dyn_w here 'bname in lt_bname_range[] and' INTO lv_dyn_w here SEPARATED BY space .

WHEN 'BP_GUID'.

APPEND ls_range TO lt_bp_guid[].

CONCATENATE lv_dyn_w here 'bp_guid in lt_bp_guid[] and' INTO lv_dyn_w here SEPARATED BY space .

WHEN 'NAME_FIRST'.

APPEND ls_range TO lt_name_first[].

CONCATENATE lv_dyn_w here 'name_first in lt_name_first[] and' INTO lv_dyn_w here SEPARATED BY space .

Page 16: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

16/27sapcrmtutorial.blogspot.in

WHEN 'NAME_LAST'.

APPEND ls_range TO lt_name_last[].

CONCATENATE lv_dyn_w here 'name_last in lt_name_last[] and' INTO lv_dyn_w here SEPARATED BY space .

ENDCASE.

ENDLOOP.

TRANSLATE lv_dyn_w here TO UPPER CASE.

lv_len = STRLEN( lv_dyn_w here ) - 4 . "remove the last 'AND' in the condition

lv_dyn_w here = lv_dyn_w here(lv_len) .

CHECK STRLEN( lv_dyn_w here ) > 0.

SELECT * FROM zusr_bol_tb INTO TABLE lt_result[] WHERE (lv_dyn_w here).

CHECK LINES( lt_result[] ) > 0.

LOOP AT lt_result[] ASSIGNING <lfs_result>.

lr_object = iv_root_list->add_object( iv_object_name = 'Root'

is_object_key = <lfs_result>-bname ).

CHECK lr_object IS BOUND.

lr_object->set_query_root( abap_true ).

ENDLOOP.

ENDMETHOD.

*--------------------------------------------------------------------------------------------------------------------

Save and activate your code.

We might w ant to add the BNAME ,NAME_LAST,NAME_FIRST fields to a view that w e w ill create

Personally I choose the BP_HEAD component but you can choose any component that you may use.

OK. So let's get in and execute transaction BSP_WD_CMPWB_NEW and choose BP_HEAD component w ith our

enhancement set w hich is specif ically in my case called ZENH_CRM and hit the display button and go to Runtime

Repository Editor, open the MODELS folder to see w ith w hich BOL component set the BP_HEAD component use.

See the follow ing screen shot.

We can see now that the component BP_HEAD use the Model BP_APPL_COND and w e w ant that our BOL object w ill

appear in the repository of the BP_HEAD component so that w e can use it for our purpose.

To do that w e need to go to the component set definition.

See the follow ing screen shot.

Page 17: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

17/27sapcrmtutorial.blogspot.in

Now choose the appropriate component set w hich is in our case BP_APPL_COND.

See the follow ing screen shot.

Now click on component assignment make new entry and add our BOL object named ZBOLOB.

See the follow ing screen shot.

Don't forget to save the new entry.

After you saved it successfully enter again to BSP_WD_CMPWB_NEW transaction w ith BP_HEAD component and click

on the BOL Model Brow ser tab, w e w ant to check here that w e can see our BOL entity ready for use.

See the follow ing screen shot.

Page 18: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

18/27sapcrmtutorial.blogspot.in

Now w e can see that our BOL entity Root that w e created is ready for use in the enhancement of BP_HEAD component.

We w ill go to Component Structure Brow ser tab and create our view .

See the follow ing screen shot.

We'll choose a name for our view .

See the follow ing screen shot.

Page 19: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

19/27sapcrmtutorial.blogspot.in

After w e named the view w e need to add 2 model nodes, one for BuilHeader and

one For our Root BOL object.

The f irst one is for getting the relevant BP_GUID from the custom controller and get the appropriate f irst name last name

and user name according to our table .

See the follow ing screen shot.

The next step is to add the f ields that w e might use in our view to context w hich w e w orking on.

We start w ith the BuilHeader f ields.

See the follow ing screen shot.

Page 20: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

20/27sapcrmtutorial.blogspot.in

We use also attributes from the Root BOL object .

See the follow ing screen shot.

We got the w hole attributes as show n bellow .

See the follow ing screen shot.

We move to the next step.

Here w e need to define the view type and its properties.

Page 21: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

21/27sapcrmtutorial.blogspot.in

The view type w e choose form view w ithout buttons and in the properties w e make it configurable and that for keep to

our self the option to Add/Remove

Attributes from the view .

See the follow ing screen shot.

Now w e finish the view addition w ith the w izard w e w ill see that our view is listed w ith the other view s in the

component.

See the follow ing screen shot.

Page 22: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

22/27sapcrmtutorial.blogspot.in

After w e added the view w e should create a binding to the custom controller context node BUILHEADER.

So w e put the mouse curser on the context node BUILHEADER pressing the right mouse

Click and create the binding.

See the follow ing screen shot.

Page 23: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

23/27sapcrmtutorial.blogspot.in

We w ill create the binding for our context node to the same context node in the custom controller.

See the follow ing screen shot.

After w e create the appropriate binding w e need to add the attributes to the view .

So w e move to the configuration tab w hen w e w orking on the view and then w e sw itch to edit mode.

We see that w e have the 2 BOL objects that w e added w hen w e w orking w ith the w izard in time of the view creation.

In our case w e w ill add the attributes from the Root BOL object.

See the follow ing screen shot.

After w e add the attributes to our view w e need to add our view as an assignment block.

First w e need to add our view to the BPHEADOverview view set , to do this w e w ill go to the

Runtime Repository Editor and w e w ill add our view to the Overview Page of BPHEADOverview view set .

See the follow ing screen shot.

Page 24: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

24/27sapcrmtutorial.blogspot.in

After w e added the view to the BPHEADOverview view set w e w ill go to the configuration tab of BPHEADOverview

view set and sw itch to edit mode and add our view TestBOLroot to the list of view s that appears as an assignment

blocks in the BPHEADOverview view set by click on the arrow button and moving it from the left side to the right side .

See the follow ing screen shot.

After w e handle the addition of adding our view as an assignment block w e need to handle some code addtions for the

right treatment in the attributes in our view .

First w e w ill go to the ROOT context node w ithin our view and redefine

the method IF_BSP_MODEL~INIT.

See the follow ing screen shot.

Page 25: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

25/27sapcrmtutorial.blogspot.in

Put the next ilnes into the method save and aactivate the method.

*-------------------------------------------------------------------------------------------

method IF_BSP_MODEL~INIT.

TYPES: BEGIN OF ltype_attr_struct,

mandt TYPE mandt,

bp_guid TYPE bu_partner_guid,

bname TYPE xubname,

name_last TYPE bu_namep_l,

name_first TYPE bu_namep_f,

END OF ltype_attr_struct.

DATA: lrf_data_struct TYPE REF TO ltype_attr_struct,

lrf_value_node TYPE REF TO cl_bsp_w d_value_node,

lrf_bol_collection TYPE REF TO if_bol_bo_col.

super->if_bsp_model~init( id = id ow ner = ow ner ).

CREATE DATA lrf_data_struct.

CREATE OBJECT lrf_value_node

EXPORTING

iv_data_ref = lrf_data_struct.

CREATE OBJECT lrf_bol_collection TYPE cl_crm_bol_bo_col.

lrf_bol_collection->add( lrf_value_node ).

me->set_collection( lrf_bol_collection ).

endmethod.

*-------------------------------------------------------------------------------------------

After w e add the above lines to the method w e w ill go to the implementation class of our view , w hich is in our case is

ZL_ZBP_HEAD_TESTBOLROOT_IMPL.

w e w ill double click on the class name and w e w ill move to display mode of the class in a w ay that all the method could

be show n.

The f irst thing to do is to w rite our ow n method for performing the right query w hen w e need to display the attributes on

the screen .

After that w e w ill redefine the method DO_PREPARE_OUTPUT.

so let's create a new method named root_query w hich is an Instance Method , and the visibility of it is Private.

put the next lines to the method .

*------------------------------------------------------------------------------------------

METHOD root_query.

DATA: lrf_advanced_query TYPE REF TO cl_crm_bol_dquery_service,

lrf_root_result_collection TYPE REF TO if_bol_entity_col,

lrf_root_result_bol_entity TYPE REF TO cl_crm_bol_entity,

lrf_current_root TYPE REF TO if_bol_bo_property_access,

lrf_current_builheader TYPE REF TO if_bol_bo_property_access,

lt_params TYPE crmt_name_value_pair_tab,

ls_params TYPE crmt_name_value_pair,

ls_builheader_properties TYPE crmst_header_object_buil,

lv_low _value TYPE string ,

ls_root_properties TYPE zusr_bol_st.

ls_params-name = 'MAX_HITS' .

ls_params-value = '1'. "w e don't need in this case more the single record for result

Page 26: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

26/27sapcrmtutorial.blogspot.in

APPEND ls_params TO lt_params.

lrf_current_root ?= me->typed_context->root->collection_w rapper->get_current( ).

CHECK lrf_current_root IS BOUND .

lrf_current_root->get_properties( IMPORTING es_attributes = ls_root_properties ).

CHECK ls_root_properties IS INITIAL .

" means that w e don't have any values in our

"f ields and therfore w i'll excute the query

lrf_current_builheader ?=

me->typed_context->builheader->collection_w rapper->get_current( ).

CHECK lrf_current_builheader IS BOUND .

lrf_current_builheader->get_properties( IMPORTING es_attributes = ls_builheader_properties ).

CHECK ls_builheader_properties-bp_guid IS NOT INITIAL .

lv_low _value = ls_builheader_properties-bp_guid.

lrf_advanced_query = cl_crm_bol_dquery_service=>get_instance( 'Search' ).

lrf_advanced_query->set_query_parameters( it_parameters = lt_params ).

lrf_advanced_query->add_selection_param( iv_attr_name = 'BP_GUID'

iv_sign = 'I'

iv_option = 'EQ'

iv_low = lv_low _value

iv_high = '' ).

lrf_root_result_collection = lrf_advanced_query->get_query_result( ).

IF lrf_root_result_collection IS BOUND . "if w e found something that match our selection

lrf_root_result_bol_entity = lrf_root_result_collection->get_first( ).

lrf_root_result_bol_entity->get_properties( IMPORTING es_attributes = ls_root_properties ).

lrf_current_root->set_properties( is_attributes = ls_root_properties ).

ENDIF.

ENDMETHOD.

*----------------------------------------------------------------------------------------

Save and activate your code .

the next step is to redefine the method DO_PREPARE_OUTPUT.

put the next lines into the method .

*----------------------------------------------------------------------------------------

method DO_PREPARE_OUTPUT.

CALL METHOD SUPER->DO_PREPARE_OUTPUT

EXPORTING

iv_first_time = iv_first_time.

me->ROOT_QUERY( ).

endmethod.

*----------------------------------------------------------------------------------------

save and activate your code .

Now all job is done our BOL object is w roking like a Rolls-Royce and it's time to derive pleasure from .

We w ill go to the w ebclient , choose our account and display it .

w e can see that w e have our attributes show n on the screen .

See the follow ing screen shot.

Page 27: SAP CRM Technical Tutorials by Naval Bhatt

8/31/12 SAP CRM Technical Tutorials by Naval Bhatt.

27/27sapcrmtutorial.blogspot.in

Older PostsHome

Subscribe to: Posts (Atom)

Posted by Naval Bhatt at 8:08 AM No comments:

Labels: How to use your custom BOL Object for webclient within assignment block. custom bol in

assignment block, SAP CRM tutorials, sap crm BOL programming

+2 Recommend this on Google

© Naval bhatt 2012. Awesome Inc. template. Powered by Blogger.