Professional Documents
Culture Documents
CRM Programming
Fundamentals
CRM Programming Fundamentals
Contents
1. One Order Object Model................................................................................3
2. One Order Reporting Framework................................................................16
3. Commonly used Function Modules in CRM..............................................19
4. Commonly used BadIs in CRM...................................................................27
5. Copy Control in Business Transactions....................................................30
6. Transaction CRMV_EVENT..........................................................................32
7. Debugging in middleware............................................................................37
8. Error handling in CRM..................................................................................38
9. Overview of Customizing.............................................................................42
10. Helpful Reports...........................................................................................43
CRM Programming Fundamentals
The Item table for One Order document is CRMD_ORDERADM_I. Each Item of a
One Order document has a different GUID. The Header GUID of the Item is stored in
field HEADER of table CRMD_ORDERADM_I.
One-Order Object Model
Administration header and Extension have the same GUID
Administration header Extension
CRMD_ORDERADM_H CRMD_ACTIVITY_H
CRMD_OPPORT_H
CRMD_ORDERADM_I
CRMD_SERVICE_I
Set
CRMD_LINK CRMD_SALES
Link handler
CRMD_SHIPPING
Data Model:-
Extension
CRM Programming Fundamentals
Data model
Orderadm_ Orgma
h Link Handler n
GUI Dat GUI Dat
D a D a
Orderadm_
i HG01 - OG01 Orgma
Heade GUI Dat n
r D a GUI Dat
D a
IG02 OG02
Orderadm_
i
Heade GUI Dat
r D a
CRM Programming Fundamentals
Display or
hide
locator
Maximum /
minimal
display
Display
business
partner
cockpit
Application log:
Settings Compress Work with several Displays error
header data documents in parallel messages
CRM Programming Fundamentals
Service Process
Service process has leading transaction category BUS2000116.
Transaction to maintain service process: CRMD_BUS2000116
Assigned transaction categories: Service, Sales, Business activity.
Service process can be distributed into R/3.
Main partner function category: Sold-to party
Additional customizing for Service Process:
Subject profile (for codes)
Transaction type for confirmation
Service process also contains parts of customizing from Business
Activity and Sales document.
Information available in Service process:
Service Process II
Service process has a specific UI different from sales document or
activity. Fast entry, Item detail, Transaction data buttons are
available and can be used to switch between screens.
The Follow-up documents like, Confirmation from the Service Order can be created as
shown below:
CRM Programming Fundamentals
Then, copy the items as needed. Select the Items & Copy:
Service Confirmation
Service Confirmation has leading transaction category BUS2000117.
Transaction to maintain service confirmation: CRMD_BUS2000117
Assigned transaction categories: Service, Sales, Business activity.
Working times and spare parts from service conformation are
posted to R/3. Main partner function category: Sold-to party.
Additional customizing for Service Confirmation:
Subject profile (for codes)
Confirmation also contains parts of customizing from Business
Activity and Sales document.
Information available in Service Confirmation:
Service Confirmation II
Service confirmation like a service process has a specific UI
different from sales document or activity. Fast entry, Item detail,
Transaction data buttons are available and can be used to switch
between screens.
IPC
CRM system OLTP R/3
CRM Online
Middleware
R/3 Adapter
Plug-In
BW Adapter
BW APO
Middleware RFC
CRM------------>BDOC------------>R/3
DB tables
R/3 CRM
VBAK CRMD_ORDERADM_H
VBAP CRMD_ORDERADM_I
VBEP CRMD_SCHEDLIN
MAEPV/MAAPV CRMD_PRODUCT_I
VBKD CRMD_PRICING
KONV PRCD_COND Workareas:
VBUK/VBUP CRM_JEST*
- lu_orderadm_h_wrk old data (like *VBAK)
* For an overview on the different status see - ls_orderadm_h_wrk local data
Include CRM_STATUS_CON - gs_orderadm_h_wrk global data
Object layer
Object Buffer (OB) Object Work area (OW)
Database layer
Database Buffer (DB) Database Update (DU)
User read
- UI -
Interface save
Interaction
- IL -
Layer
Object - OW - Customizing - CD -
Layer Business Dialo
- OB - logic - CB - g
Modified Method
Data s
Database - DB -
Layer Original
- DU - Data
Update D
task
B
CRM Programming Fundamentals
Transaction to maintain
screen sequence
controlling: CRMV_SSC
CRM Programming Fundamentals
Logic of CRM_ORDER
I II III
CRM_ORDER_READ CRM_ORDER_READ_OW
CRM_ORDER_H_MAINTAIN_OW
CRM_ORDER_MAINTAIN_MULTI_OW CRM_ORDERADM_H_MAINTAIN_OW
CRM_ORDER_MAINTAIN
CRM_ORDER_MAINTAIN_SINGLE_OW
CRM_ORDER_I_MAINTAIN_OW
CRM_ORDERADM_I_MAINTAIN_OW
Naming conventions
As an example we will retrieve Documents, based on the Process type & Sales
organization.
Let us compare with a SELECT statement to make it more understandable. Assume, the
documents are retrieved from table XYZ, so our SELECT statement will be as follows:
Block 2
In One Order Reporting Framework we will select Documents as follows:
CRM Programming Fundamentals
First of all we will build the WHERE clause as mentioned above for the SELECT
statement. It is build using classes & methods. Class CL_CRM_REPORT_QUPART
and Method GET_QUPART_BY_TOKEN is used for this purpose.
Block 1 is built as follows:
The parameter, iv_entityname contains the name of the Segment for which the data will
be retrieved. The parameter values can be found in program
CRM_OBJECT_NAMES_CON.
The parameter, iv_fieldname contains the name of the field for which the Selection
Clause is built.
iv_token, is used to let the system know the type of operand you are passing in the
parameter it_rangetab. In our example, RAN means Range Table. Go to domain
CRM_REPORT_TOKEN to see all possible values.
Parameter it_rangetab contains the range table we are passing to the method. This range
table contains the values the user has entered in the selection screen for Process Type.
Do not use the method call if it_type[] is initial.
The parameter ev_qupart, contains final query built by the method for Block 1.
iv_qupart is of type CRMT_REPORT_QUERYPART_TA.
We need to store all these queryparts in an internal table which can be passed to the
method which does the selection based on these queryparts (WHERE CLAUSE).
So, an internal table say, it_qupart of type CRMT_REPORT_QUERYPART_TA is
created, where the parameter iv_qupart returned by the method is appended.
Now, before building the query part for Sales organization (Block 3), we need to build
Block 2. (Because there is more than one field in WHERE clause).So, how to build Block
2 now:-
Same methods are used as follows:
CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
EXPORTING
iv_token = 'AND'
IMPORTING
ev_qupart = iv_qupart_and-querypart.
Block 3 has to be built now same like Block 1 and appended to internal table it_qupart.
CALL METHOD cl_crm_report_qupart=>get_qupart_by_token
EXPORTING
iv_entityname = 'CL_CRM_REPORT_SET_ORGMAN'
iv_fieldname = 'SALES_ORG'
iv_token = 'RAN'
it_rangetab = it_sales_org[]
IMPORTING
ev_qupart = iv_qupart-querypart.
Now, we do not need Block 2 anymore as we do not have any further fields for selection.
Internal table it_qupart contains the complete WHERE CLAUSE. We will see how this
is used to retrieve the Documents.
Create Object:
lv_locatorlist ?= l_list.
Where,
l_list TYPE REF TO cl_crm_report_ext.
lv_locatorlist TYPE REF TO cl_crm_report_ext_locatorlist.
IMPORTING
et_extension = lt_list.
Where,
ls_requ_columns-column = 'OBJECT_TYPE'.
ls_requ_columns-requested = abap_true.
APPEND ls_requ_columns TO lt_requ_columns.
ls_requ_columns-column = 'OBJECT_ID'.
ls_requ_columns-requested = abap_true.
APPEND ls_requ_columns TO lt_requ_columns.
ls_requ_columns-column = 'PROCESS_TYPE'.
ls_requ_columns-requested = abap_true.
APPEND ls_requ_columns TO lt_requ_columns.)
The function module CRM_STATUS_READ is used to read the status of the document.
ls_status_com-activate = 'X'.
ls_status_com-ref_guid = ls_guid.
ls_status_com-ref_kind = ''.
ls_status_com-status = 'E0029'.
INSERT ls_status_com INTO TABLE lt_status_com.
CRM Programming Fundamentals
CLEAR lt_input_field_names.
INSERT gc_fieldname_activate INTO TABLE lt_input_field_names.
* IV_NO_1O_MAINTAIN = FALSE
* IV_FORCE_1O_MAINTAIN = FALSE
* IV_GET_ACTUAL_EXCPN = FALSE
CHANGING
ct_input_field_names = lt_input_field_names
EXCEPTIONS
not_allowed =1
error_occurred =2
warning_occurred =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.
The structure v_borident should contain the object GUID, Object type and logical
system name.
The internal table it_links is returned by the function module which contains all the
documents linked with the object GUID passed in the structure v_borident.
ls_guid = ls_documents-guid.
INSERT ls_guid INTO TABLE it_guid.
ls_input_field-ref_guid = ls_guid.
CRM Programming Fundamentals
ls_input_field-ref_kind = gc_object_kind-orderadm_h.
ls_input_field-objectname = 'DOC_FLOW'.
ls_input_field-field_names[] = lt_input_field_names[].
ls_input_field-logical_key = '1'.
APPEND ls_input_field TO lt_input_field.
ls_doc_link-objkey_a = ls_guid.
ls_doc_link-objtype_a = gc_object_type-service.
ls_doc_link-objkey_b = ls_documents-material_document.
ls_doc_link-objtype_b = 'BUS2017'.
ls_doc_link-brel_mode = gc_object_kind-orderadm_h.
ls_doc_link-logsys_b = ls_documents-logical_system.
ls_doc_link-reltype = 'VONA'.
ls_doc_link-brel_kind = gc_object_kind-orderadm_h.
ls_doc_link-log_key = '1'.
INSERT ls_doc_link INTO TABLE ls_doc_flow-doc_link.
ls_doc_flow-ref_guid = ls_guid.
ls_doc_flow-ref_kind = gc_object_kind-orderadm_h.
INSERT ls_doc_flow INTO TABLE lt_doc_flow.
The function module which contains the string INTLAY returns data from the
Interaction Layer. For example, if you are processing a document, and you need the
HEADER GUID of the document which is not available in your program, you can use
those FMs which will return the desired data. Because, the Interaction Layer is populated
when we use function modules like CRM_ORDER_READ etc.
* Check whether Activity Header Category Data exists for this Order
CALL FUNCTION 'CRM_ACTIVITY_H_READ_OB'
EXPORTING
iv_guid = iv_header_guid
IMPORTING
es_activity_h_wrk = lx_act_h_wrk
EXCEPTIONS
parameter_error =1
record_not_found =2
at_least_one_record_not_found = 3
OTHERS = 4.
IF sy-subrc <> 0.
CRM Programming Fundamentals
MESSAGE i022(zcrm_dev).
PERFORM update_message USING iv_header_guid.
EXIT.
ENDIF.
* If no Activity Header Exists, then Create (MODE = A)
* If it exists then change with (MODE = B)
IF lx_act_h_wrk IS INITIAL.
lx_act_h-mode = 'A'.
ELSE.
lx_act_h-mode = 'B'.
ENDIF.
lx_act_h-ref_guid = iv_header_guid. "Head GUID
lx_act_h-category = 'ZR1'.
* Input Fields to be changed
lx_input_field_names-fieldname = 'CATEGORY'.
INSERT lx_input_field_names INTO TABLE lit_input_field_names.
lx_input_field_names-fieldname = 'MODE'.
INSERT lx_input_field_names INTO TABLE lit_input_field_names.
* Create/Change Activity Header Category Data
CALL FUNCTION 'CRM_ACTIVITY_H_MAINTAIN_OW'
EXPORTING
is_activity_h_com = lx_act_h
CHANGING
ct_input_field_names = lit_input_field_names
EXCEPTIONS
header_create_error = 1
header_change_error = 2
parameter_error =3
admin_h_reference_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
MESSAGE i022(zcrm_dev).
PERFORM update_message USING iv_header_guid.
EXIT.
ENDIF.
The function module is used to read Header as well as Item details (all segments) by
passing the Header GUID of the document in the parameter IT_HEADER_GUID of
the function module.
To read only Item specific detail, pass the Item GUID of the document in the parameter
IT_ITEM_GUID of the function module.
You can read more than one document details by passing more than one GUID in the
parameter IT_HEADER_GUID.
The function module CRM_ORDER_READ returns data of all the Segments of the
document. To read only specific Segment data, pass the Segment Name in the parameter
IT_REQUESTED_OBJECTS of the function module, to enhance performance.
The function module first try to read required data from OW (work area), if not available
looks at the OB which is the Object Buffer. If still fails, finally it retrieves the data from
Database. So, if you look at standard CRM function modules, you will find, suffixes as
_OW / _OB/ _DB. Based on your requirement from where you want to read the
data, you need to use the respective function module.
Do not forget to use the function module CRM_ORDER_SAVE to save the changes
followed by COMMIT/ROLLBACK work.
Function CRM_ORDER_MAINTAIN
Function module CRM_ORDER_MAINTAIN is used for any action performed for
business transaction.
Recursive calls are not permitted
All extensions and sets are passed to this function module
Multiple documents can be maintained with one call
Input fields (parameter CT_INPUT_FIELDS) are used to identify which fields of the
corresponding set/extension should be changed
The function calls CRM_ORDER_MAINTAIN_MULTI_OW to maintain multiple
documents
CRM_ORDER_MAINTAIN_MULTI_OW separates the documents and calls
CRM_ORDER_MAINTAIN_SINGLE_OW for each of them in case of
creation/change/deletion and CRM_ORDER_COPY_SINGLE_OW in case of copying
or creating follow-up document
CRM_ORDER_MAINTAIN_SINGLE_OW function calls
CRM_ORDER_H_MAINTAIN_OW to maintain header information and
CRM_ORDER_I_MAINTAIN_MULTI_OW to maintain item information
CRM_ORDER_H_MAINTAIN_OW calls in a certain order maintenance function
modules for extensions and sets belonging to header
At the end CRM_ORDER_H_COMPLETE_OW is called and events planned for the
end of header processing are executed
CRM Programming Fundamentals
CRM_ORDER_MAINTAIN_SINGLE_OW
CRM_ORDER_H_MAINTAIN_OW
CRM_ORDER_H_PREPARE_OW
CRM_ORDERADM_H_MAINTAIN_OW
CRM_<OBJECT>_MAINTAIN_OW
.........
CRM_ORDER_H_COMPLETE_OW
CRM_ORDER_I_MAINTAIN_MULTI_OW
CRM_ORDER_I_MAINTAIN_SINGLE_OW
CRM_ORDERADM_I_MAINTAIN_OW
CRM_<OBJECT>_MAINTAIN_OW
.........
CRM_ORDER_I_COMPLETE_SINGLE_OW
CRM_ORDER_I_COMPLETE_MULTI_OW
CRM_ORDER_COMPLETE_SINGLE_OW
CRM_ORDER_COMPLETE_MULTI_OW
CRM_ORDER_FINAL_CALLS_OW
METHOD if_ex_crm_order_fieldcheck~fieldcheck.
INCLUDE crm_direct.
ev_header = is_fieldcheck_com-ref_guid.
IF lv_object_type IS INITIAL.
EXPORTING
iv_guid = ev_header
iv_include_deleted_item = ' '
IMPORTING
ev_header_guid = ev_header
EXCEPTIONS
item_not_found =1
OTHERS = 2.
ev_mode = lv_mode
ev_object_type = lv_object_type
EXCEPTIONS
admin_header_not_found = 0.
ENDIF.
ENDMETHOD.
CRM Programming Fundamentals
For other transaction types (not Activity or Task) the document should
not contain errors in order to create a follow-up transaction.
Method COPY can be used to restrict copying if some criteria are not met.
Other methods are used to copy necessary information from a preceding to a follow-up
document. They have all necessary information as the parameters.
6. Transaction CRMV_EVENT
CRM Programming Fundamentals
In transaction CRMV_EVENT you can configure your own function module which will
be triggered based on the configuration.
Event Handler
PERFORM EXECUTE_CALLBACKS_PLANNED
USING LV_GUID_HDR
IV_EXETIME
LT_PLAN_EXETS <= table with CallBacks
CHANGING LV_CALL_RCODE
LT_EVENT_RCODE.
CRM Programming Fundamentals
reference. And it will trigger for the HEADER segment. You can set whether the function
module should be triggered for header level or at item level. Also, you can set other
attributes as shown above. Please go through the transaction to explore further options.
Have a look at the parameters that can be used in the function module. The parameters
are filled based on the EVENT.
Note: - If you want to update any data in the database table, please take care whether your
function module is handling data at the database level or object buffer level. If you are
working at the object layer but you need to update database table, do not try to update the
tables using CRM_ORDER_MAINTAIN or anything else. Just populate the object buffer
with the data you want to be updated in the database. System will take care of the update.
CRM Programming Fundamentals
Event Handler IV
The execution of a specific event is normally done in a following order:
Events are planned for execution in a CHANGE function module. All
necessary parameters are provided (old/new data, etc.). This is done in
function CRM_EVENT_PUBLISH_OW.
In MAINTAIN function module the execution time of the event is set and all
events planned for that execution time are executed. This is done in function
CRM_EVENT_SET_EXETIME_OW.
When the event is executed it is removed from the internal table with planned
events.
Event table is delivered by SAP and normally should not be changed by the
customers. Only in rare cases when certain functionality requires an
additional event to be added or an existing event to be changed this can be
done after prior consulting with responsible developer.
Events influence the whole transaction processing and may cause
performance problems if they are not properly set up.
CRM Programming Fundamentals
Event Handler
schedlin_i_publish_ow
After_change (old- / new values)
.
.
.
CRM_PRIDOC_UPDATE_EC
CRM_EVENT_SET_EXETIME_OW After_change Orderadm_i
(end_Order_maintain) (old- / new values)
CRM Programming Fundamentals
7. Debugging in middleware
It is important to know how to debug the middleware, since in CRM the documents are
distributed in R/3.
In CRM, before you SAVE the document go to transaction SMQS and De-Register the
R/3 destination. Then SAVE the document.
Now go to transaction SMQ1. You will see the document available in the Outbound
Queue. You can debug the document now. This is the scenario when the document is
transferred from CRM R/3.
If you want to see the BDoc messages go to transaction SMW01. If the document has
not been processed (yellow traffic light), you can reprocess the document.
CRM Programming Fundamentals
Example:-
FORM check_object_for_errors USING iv_obj_guid TYPE crmt_object_guid
iv_obj_kind TYPE crmt_object_kind
CHANGING p_t_msg TYPE bapiret2_t
p_error_occured TYPE crmt_boolean.
DATA:
lt_msg_handle TYPE bal_t_msgh,
*/ (re)init
CLEAR p_error_occured.
CRM Programming Fundamentals
p_error_occured = abap_true.
ENDIF.
ENDIF.
ENDLOOP.
Note:-
The function module CRM_MESSAGE_COLLECT will add message to display in the
window at the top of transaction CRMD_ORDER.
You can use function module *INTLAY* to get the GUID for the document you are
processing. Because the Interaction Layer is populated when there is Function Module
processing like CRM_ORDER_READ, CRM_ORDER_MAINTAIN, etc
9. Overview of Customizing
CRM Programming Fundamentals
Transactions
Item categories
Copying control
Pricing
CRM Programming Fundamentals
Report Function