Wednesday 5 February 2020

CRM Bol programming Debugging Tips and Code Snippet on how to read & populate values

This blog explains on how to do basic debugging and write code in CRM. It covers the below topic areas

1. Requirement: To disable one specific field in an Address section

2. Find the UI component

3. Find technical object to do code changes

4. Get value using IF_BOL_BO_PROPERTY_ACCESS

◉ Debug to find where the value is coming from

5. Get value of UI field using me-> context type

◉ Debug to find how this gets populated.

6. Add a default Blank row in CRM UI

1. Requirement: Disable a specific UI element field


For customer overview screen when user clicks on edit to update the address information

Disable a specific field called “Delivery service type” and do not allow to update Phone and email sections as highlighted below.

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

2. Find the UI component


UI component was BP_ADDR

And View value as BP_ADDR/AccountAddressEF

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

3. Find Technical object to do code changes


Use transaction obsp_wd_cmpwb to be able to open the component in backend CRM system

Specific fields can be found in

Context_Nodes > Implementation class > Attributes >STRUCT.FIELDNAME

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

◉ GET_XYZ – This is used to get the data of attribute (XYZ) from the BOL Layer and display it on the UI

◉ SET_XYZ – This is used to set the data of the attribute from the UI to the BOL layer

◉ GET_M_XYZ – This defines the meta data (type) of the attribute

◉ GET_I_XYZ – This defines whether the attribute is editable or non-editable i.e., using Get_I method you can make your field as grade out based up on any condition.

◉ GET_V_XYZ – This defines the content of drop down values, F4 Help etc i.e., you can retrieve the drop-down values based up on your condition.

◉ GET_P_XYZ – This defines the property of attribute whether it’s drop down, text box, F4 help, check box etc. Also, if any follow-up event should trigger the same is mentioned here i.e., you can call specific even handler using P method .

◉ There are two more methods which have recently got added from the above two as mentioned below

◉ GET_A_XYZ – This is used to hide or display the attribute based on the Switch ID.

◉ GET_AC_XYZ – This is used for Field Action Menu Getter

◉ Since I need to make the field disabled, I need to make use of the field value GET_M_DELI_SERV_TYPE

◉ You can find this method in context node Buildaddress> Attributes> STRUCT.DELI_SERV_TYPE which has a set of predefined methods as seen below

The code which was used to set the value as disabled would be GET_I_XYZ

If the icon does not look green as in the above screenshot choose to redefine or one of then options below to activate the method

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Add the source code as below:

METHOD get_i_deli_serv_type.
CALL METHOD super->get_i_deli_serv_type
EXPORTING
iterator    = iterator
RECEIVING
rv_disabled = rv_disabled.

IF zl_bp_addr_accountaddress_impl=>gv_addr_disabled IS NOT INITIAL.
rv_disabled = zl_bp_addr_accountaddress_impl=>gv_addr_disabled.
ENDIF.

ENDMETHOD.

4. Get value of UI field using IF_BOL_BO_PROPERTY_ACCESS


I would like to read the address number value from the UI

To access a specific value coming from the previous or current screen use the BOL property access type as mentioned below where you want to read the value from

In my case I am using ZGO_BOL_PROPERTY  of type IF_BOL_BO_PROPERTY_ACCESS defined in class ZL_BP_ADDR_ACCOUNTCOMMNUM_IMPL where I want to read the attribute address number and address GUID which are attributes in that class.

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

If you check the interface IF_BOL_BO_PROPERTY_ACCESS, it has properties as below:

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

To be able to use the value stored in the property below code needs to be run

// In ZL_BP_ADDR_ACCOUNTEMAILSE_IMPL DO_PREPARE_OUTPUT

DATA: lo_bo        TYPE REF TO  cl_crm_bol_entity,
lv_addr      TYPE ad_addrnum,
lv_addr_guid TYPE bu_address_guid.

IF zl_bp_addr_accountcommnum_impl=>zgo_bol_property IS NOT INITIAL .
lo_bo ?=  zl_bp_addr_accountcommnum_impl=>zgo_bol_property.
ENDIF.

IF lo_bo IS BOUND .
lo_bo->get_property_as_value(
EXPORTING
iv_attr_name =     'ADDRESS_NUMBER'
IMPORTING
ev_result    =       lv_addr
).

lo_bo->get_property_as_value(
EXPORTING
iv_attr_name =     'ADDRESS_GUID'
IMPORTING
ev_result    =       lv_addr_guid
).

ENDIF .

4.1.  Check in debug mode where the value is coming from

You can also navigate to container proxy by using the code as below

ZL_BP_ADDR_ACCOUNTCOMMNUM_IMPL=>ZGO_BOL_PROPERTY

Where ZGO_BOL_PROPERTY is of type IF_BOL_BO_PROPERTY_ACCESS

1. Go to container_proxy
2. Go to Data_Ref
3. Click on data type which opens up
4. Open the attribute_ref
5. Find the address number and address value in there

The above would directly come to container proxy

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Click on Data_ref

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Click on the type below

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Click on Attribute ref

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Find the values

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

5. Get value of UI field using me-> context type


For debugging as a starting point use the implementation class  and find from Context what specific field value are you looking for. Example I am looking to find the address number field as below

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

You can use “Me” and navigate inside to find the values

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Inside “Me” you can find the context Type which can be Z or standard in my case I defined a ZContext

ztyped_context->builaddress->collection_wrapper->

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Get the 3 entities list

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Go to the BUILADDRESS

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Insider collection wrapper you would find collection reference

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Insider collection reference look for below

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Look for entity list as above which shows 3 entries as there are 3 BP addresses on the UI

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Go to one of the entities and it would have container proxy

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Follow the same steps as in 4.1

1. Go to container_proxy
2. Go to Data_Ref
3. Click on data type which opens up
4. Open the attribute_ref
5. Find the address number and address value in there

6. Add a default blank row in the CRM UI table


As you can see below default Blank line was added to the email so the user can enter but no default blank line was added for Mobile Number

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

Now when we add the code as below to method DO_PREPARE_OUTPUT of class ZL_BP_ADDR_ACCOUNTCOMMNUM_IMPL

CALL METHOD super->do_prepare_output
EXPORTING
iv_first_time = iv_first_time.

This would add a default blank line to the component

SAP ABAP Tutorial and Material, SAP ABAP Guides, SAP ABAP Learning, SAP ABAP Certification, SAP ABAP Prep, SAP ABAP Exam Prep

I found CRM debugging quite difficult initially but was helpful to understand once  I understood how to navigate in debug mode.

I hope this article was helpful for someone who is looking to understand how the BOL programming works and the different layers to go through to find the right values in CRM nodes.

No comments:

Post a Comment