Created by Jerry Wang, last modified on Feb 17, 2015

Perform the report:

Output:



You can search the webClient UI for the order created using the code just now:



And the specified product is inserted correctly into the transaction:

source code:

REPORT z.
 
 
PARAMETERS: prd_id TYPE comm_product-product_id OBLIGATORY DEFAULT 'JERRYTEST_PROD3',
 
            type   TYPE crmt_process_type OBLIGATORY DEFAULT 'TA'.
 
 
DATA: lo_products           TYPE REF TO if_bol_bo_col.
 
CREATE OBJECT lo_products TYPE cl_crm_bol_bo_col.
 
 
"DATA: lv_type     TYPE crmt_process_type VALUE 'TA',
 
"      lv_bor_type TYPE crmt_subobject_category VALUE 'BUS2000115'.
 
 
DATA(lo_prod) = cl_crm_prod_test_accessor2=>get_prod_by_id( prd_id ).
 
 
INCLUDE: crm_object_types_con.
 
 
DATA:
 
  lt_params         TYPE crmt_name_value_pair_tab,
 
  ls_params         TYPE crmt_name_value_pair,
 
  lv_header_guid_c  TYPE string,
 
  lv_header_guid    TYPE crmt_object_guid,
 
  lv_error          TYPE crmt_boolean,
 
  lr_root_ent       TYPE REF TO cl_crm_bol_entity,
 
  lr_root_col       TYPE REF TO if_bol_bo_col,
 
  lr_adm_h          TYPE REF TO cl_crm_bol_entity,
 
  lr_core           TYPE REF TO cl_crm_bol_core,
 
  lr_factory        TYPE REF TO cl_crm_bol_entity_factory,
 
  lr_items          TYPE REF TO cl_crm_bol_entity,
 
  lr_access_erp     TYPE REF TO if_crm_uiu_erp_channel_aspects,
 
  lr_access_bt      TYPE REF TO if_crm_uiu_bt_channel_aspects,
 
  lv_trvog          TYPE trvog_va,
 
  lv_transferred    TYPE crmt_boolean,
 
  lr_nav_descriptor TYPE REF TO cl_crm_ui_descriptor_object,
 
  lr_window         TYPE REF TO cl_bsp_wd_window.
 
 
DATA lv_cfm_quantity2 TYPE REF TO cnfqty.
 
DATA lv_cfm_quantity TYPE f.
 
 
CREATE OBJECT lr_root_col TYPE cl_crm_bol_bo_col.
 
 
lr_core = cl_crm_bol_core=>get_instance( ).
 
 
 
ls_params-name = 'PROCESS_TYPE'.
 
ls_params-value = type.
 
APPEND ls_params TO lt_params.
 
 
lr_factory = lr_core->get_entity_factory( 'BTOrder' ).      "#EC NOTEXT
 
 
 
lr_root_ent = lr_factory->create( lt_params ).
 
 
ASSERT lr_root_ent IS NOT INITIAL.
 
 
*   if the soldto account is already known, enhance the sales doc
 
lr_access_bt = cl_crm_uiu_bt_channel_asp_fac=>get_instance( ).
 
lr_access_bt->if_crm_uiu_channel_aspects~after_create( iv_entity = lr_root_ent ).
 
 
lr_adm_h = lr_root_ent->get_related_entity(
 
iv_relation_name = 'BTOrderHeader' iv_mode = cl_crm_bol_entity=>bypassing_buffer ).
 
IF lr_adm_h IS BOUND.
 
  lr_items = lr_adm_h->get_related_entity(
 
  iv_relation_name = 'BTHeaderItemsExt' iv_mode = cl_crm_bol_entity=>bypassing_buffer ).
 
ENDIF.
 
 
lo_products->add( lo_prod ).
 
CALL METHOD cl_crm_uiu_bt_tools=>add_products_to_btorder
 
  EXPORTING
 
    ir_products_col     = lo_products
 
  IMPORTING
 
    ev_prdtransfer_flag = lv_transferred
 
  CHANGING
 
    cr_btorder          = lr_root_ent
 
    cr_btitems          = lr_items.
 
 
lr_root_col->add( lr_root_ent ).
 
 
cl_crm_prod_test_accessor2=>save( ).
 
 
DATA(lo_admin) = lr_root_ent->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
 
CHECK lo_admin IS NOT INITIAL.
 
DATA(id) = lo_admin->get_property_as_string( 'OBJECT_ID' ).
 
 
WRITE: / 'Generated Order ID: ', id COLOR COL_NEGATIVE.
Copy the code