使用 BOL API 创建 SAP CRM IBASE 数据
Posted JerryWang汪子熙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用 BOL API 创建 SAP CRM IBASE 数据相关的知识,希望对你有一定的参考价值。
使用界面:
源代码:
*&---------------------------------------------------------------------*
*& Report ZIBASE_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zibase_create_delete.
PARAMETERS: txt TYPE char40 OBLIGATORY DEFAULT description test,
eid TYPE char30 OBLIGATORY DEFAULT PROGRAM,
oid TYPE comm_product-product_id OBLIGATORY DEFAULT CHILDOBJ8,
fam TYPE comm_product-object_family OBLIGATORY DEFAULT 0401,
cat TYPE COMT_CATEGORY_ID OBLIGATORY DEFAULT OBJ_0401.
DATA: lt_param TYPE crmt_name_value_pair_tab,
ls_param TYPE crmt_name_value_pair,
lr_core TYPE REF TO cl_crm_bol_core,
ls_object TYPE comm_product,
lr_root TYPE REF TO if_bol_entity_col,
entity TYPE REF TO cl_crm_bol_entity.
CHECK zcl_object_generator=>create_object( iv_id = oid iv_family = fam iv_catid = cat ) = abap_true.
ls_param-name = cl_crm_ibase_il_constant=>createparam.
ls_param-value = 01.
APPEND ls_param TO lt_param.
lr_core = cl_crm_bol_core=>get_instance( ).
lr_core->load_component_set(IBASE_ONLY).
CALL METHOD lr_core->root_create
EXPORTING
iv_object_name = cl_crm_ibase_il_constant=>root_object
iv_create_param = lt_param
iv_number = 1
RECEIVING
rv_result = lr_root.
CHECK lr_root IS BOUND.
entity ?= lr_root->get_current( ).
CHECK entity IS BOUND.
IF entity->lock( ) = abap_true.
entity->switch_to_change_mode( ).
ENDIF.
entity->set_property_as_string( iv_attr_name = DESCR iv_value = CONV #( txt ) ).
entity->set_property_as_string( iv_attr_name = EXTID iv_value = CONV #( eid ) ).
"entity->set_property_as_string( iv_attr_name = IBTYP iv_value = 01 ).
lr_core->modify( ).
DATA(lv_ibase_id) = entity->get_property_as_string( IBASE ).
DATA(component) = entity->create_related_entity( FirstLevelComponent ).
CHECK component IS NOT INITIAL.
DATA(obj_comp) = component->create_related_entity( IBCompObj).
CHECK obj_comp IS NOT INITIAL.
obj_comp->set_property_as_string( iv_attr_name = OBJECT_ID iv_value = CONV #( oid ) ).
SELECT SINGLE * INTO ls_object FROM comm_product WHERE product_id = oid.
ASSERT sy-subrc = 0.
obj_comp->set_property_as_string( iv_attr_name = OBJECT_GUID iv_value = CONV #( ls_object-product_guid ) ).
obj_comp->set_property_as_string( iv_attr_name = OBJECT_FAMILY iv_value = CONV #( ls_object-product_guid ) ).
lr_core->modify( ).
DATA(lo_message_container) = entity->get_message_container( ).
CALL METHOD lo_message_container->get_messages
EXPORTING
iv_message_type = if_genil_message_container=>mt_all
IMPORTING
et_messages = DATA(lt_msg1).
LOOP AT lt_msg1 ASSIGNING FIELD-SYMBOL(<msg1>).
WRITE:/ <msg1>-message COLOR COL_NEGATIVE.
ENDLOOP.
CHECK lt_msg1 IS INITIAL.
DATA: ls_header TYPE ibap_head1,
lt_struc_tab TYPE ibap_struc1_tab,
ls_comp TYPE IBAP_DAT1.
"delete component"
ls_header-ibase = lv_ibase_id.
CALL FUNCTION CRM_IBASE_GET_DETAIL
EXPORTING
i_ibase_head = ls_header
IMPORTING
e_struc_ibase_tab = lt_struc_tab
EXCEPTIONS
not_specified = 1
doesnt_exist = 2
no_authority = 3.
CHECK sy-subrc = 0.
READ TABLE lt_struc_tab ASSIGNING FIELD-SYMBOL(<line>) INDEX 1.
ls_comp-instance = <line>-instance.
CALL FUNCTION CRM_IBASE_COMP_DELETE
EXPORTING
i_comp = ls_comp
EXCEPTIONS
DATA_NOT_CONSISTENT = 1
IBASE_LOCKED = 2
NOT_SUCCESFUL = 3
NO_AUTHORITY = 4.
CASE sy-subrc.
WHEN 1.
WRITE: / data not consistent COLOR COL_NEGATIVE.
WHEN 2.
WRITE: / cannot delete locked component COLOR COL_NEGATIVE.
WHEN 3.
WRITE: / deletion not successful COLOR COL_NEGATIVE.
WHEN 4.
WRITE: / no deletion authorization COLOR COL_NEGATIVE.
ENDCASE.
CHECK sy-subrc = 0.
BREAK-POINT.
BREAK-POINT.
DATA(lo_transaction) = lr_core->get_transaction( ).
DATA(lv_changed) = lo_transaction->check_save_needed( ).
CHECK lv_changed EQ abap_true.
DATA(lv_success) = lo_transaction->save( ).
DATA(lo_glb_msg_cont) = lr_core->get_global_message_cont( ).
CALL METHOD lo_glb_msg_cont->if_genil_message_container~get_messages
EXPORTING
iv_message_type = if_genil_message_container=>mt_all
IMPORTING
et_messages = DATA(lt_msg).
LOOP AT lt_msg ASSIGNING FIELD-SYMBOL(<msg>).
WRITE:/ <msg>-message.
ENDLOOP.
IF lv_success = abap_true.
lo_transaction->commit( ).
WRITE:/ IBASE Created Successfully: , lv_ibase_id COLOR COL_NEGATIVE.
ELSE.
lo_transaction->rollback( ).
ENDIF.
BREAK-POINT.
以上是关于使用 BOL API 创建 SAP CRM IBASE 数据的主要内容,如果未能解决你的问题,请参考以下文章
如何使用SAP CRM Marketing Survey创建一个市场问卷调查
Document flow API in SAP CRM and C4C