cancel
Showing results for 
Search instead for 
Did you mean: 

Adding item data in Product tab for sales contract (crm_order_maintain)

Former Member
0 Kudos

Hi, can I use crm_order_maintain to add line items under the product tab for a sales contract while creating or modifying an order. Is there any sample code to add the line items, I could look at. I tried calling this FM from my custom tab and then called CRM_ORDER_SAVE but that did not add the line item. I guess I need to call it from the order_save badi and then call the crm_order_save FM as well from within the BADI. If someone could send me some sample code then I can double check if I am missing something.Am I on the right track to be using this FM for adding a line item under the product tab for the sales contract? Please help. thanks

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi, I've encountered the same problem while I was creating a Sub-Contract from a Master Contract.

In my case the solution was:

first create the Sub-Contract,

CALL FUNCTION 'CRM_ORDER_MAINTAIN'

CHANGING

ct_orderadm_h = i_ctorderadm_h

ct_input_fields = i_ctinput_fields

ct_doc_flow = i_ctdoc_flow

EXCEPTIONS

error_occurred = 1

document_locked = 2

no_change_allowed = 3

no_authority = 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.

ENDIF.

READ TABLE i_ctorderadm_h INTO wa_ctorderadm_h INDEX 1.

APPEND wa_ctorderadm_h-guid TO i_objects_to_save.

in wa_ctorderadm_h-guid now we have the guid of the newly created Sub-Contract.

SELECT SINGLE it_type_to

INTO v_it_type_to " --> target item type

FROM crmc_it_copy_ma

WHERE it_type_from = wa_out_orderadm_i-itm_type.

  • Prepare tables

wa_ctorderadm_i-header =

wa_out_orderadm_i-header. "Retrieved from CRM_ORDER_READ

wa_ctorderadm_i-handle = '0000000001'.

wa_ctorderadm_i-number_int = '0000000001'.

wa_ctorderadm_i-product = wa_out_orderadm_i-product.

wa_ctorderadm_i-ordered_prod =

wa_out_orderadm_i-ordered_prod.

wa_ctorderadm_i-description = wa_out_orderadm_i-description.

wa_ctorderadm_i-itm_type = v_it_type_to.

wa_ctorderadm_i-order_date = sy-datum.

wa_ctorderadm_i-itm_language = sy-langu.

wa_ctorderadm_i-mode = c_a. "c_a = 'A'

wa_ctorderadm_i-header = wa_ctorderadm_h-guid.

APPEND wa_ctorderadm_i TO i_ctorderadm_i.

wa_input_fields-ref_handle = '0000000001'.

wa_input_fields-objectname = 'ORDERADM_I'.

REFRESH i_input_field_names.

wa_input_field_names-fieldname = 'DESCRIPTION'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'HEADER'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'ITM_TYPE'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'MODE'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'NUMBER_INT'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'ORDERED_PROD'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'ORDER_DATE'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_field_names-fieldname = 'PRODUCT'.

APPEND wa_input_field_names TO i_input_field_names.

wa_input_fields-field_names = i_input_field_names.

APPEND wa_input_fields TO i_ctinput_fields.

After that I've called function 'CRM_ORDER_MAINTAIN', to copy the Items from the Master Contract.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'

EXPORTING

it_sales = i_sales

it_schedlin_i = i_schedlin_i

CHANGING

ct_orderadm_i = i_ctorderadm_i

ct_input_fields = i_ctinput_fields

EXCEPTIONS

error_occurred = 1

document_locked = 2

no_change_allowed = 3

no_authority = 4

OTHERS = 5.

Maybe if you're not working with Contracts, the procedure is not properly correct.

I suggest to put a break-point into crm_order_maintain and try to add the Item manually.

If you reproduce exactly the standard, I'm shure it will work.

Lorenzo

Former Member
0 Kudos

Hi...

I tried implementing it in the said manner. But, using CRM_ORDER_MAINTAIN gives a short dump as the standard code already has this FM called when we are in change mode of an order. So, in addition to that, when we again call the FM, it terminates due to recursive call.

Also, tried with CRM_ORDER_MAINTAIN_SINGLE_OW. This returns sy-subrc = 0 but when you view the order, cant find any new line item added to it.

Please help.

Former Member
0 Kudos

Hi, after you have created the order and the Item don't forget to use function CRM_ORDER_SAVE and to commit work.

Former Member
0 Kudos

Hi Chandrakant,

I've a simillar requirement where i'm trying to create a sales order using bapi in crm, my header data is inserted into table crmd_orderadm_h,but my item is not inserted into the crmd_orderadm_i table.

If your program worked can you please send me your code.

Reagards

Sanjeev Pallan

Former Member
0 Kudos

Hi,

Have you been able to add a line item to the order in CRM through your code?

I have a similar requirement and have tried CRM_ORDER_MAINTAIN, and some other FMs. But I am not able to add the item.

Is it possible to get this done? Please share.

Thanks in advance.

former_member927251
Active Contributor
0 Kudos

Hi,

Please call BAPI_TRANSACTION_COMMIT after the call to CRM_ORDER_SAVE in your program.

<b>Reward points if it helps.</b>

Former Member
0 Kudos

Hi,

I have an action in service order which calls a subscreen for user to select products. When products are selected, I will build the product in a hierarchy (parent - child) and call CRM_ORDER_MAINTAIN. Items are showing in the service order but its higher level item is blank.

ls_fldnames-fieldname = 'MODE'.

insert ls_fldnames into table lt_fldnames.

ls_fldnames-fieldname = 'ORDERED_PROD'.

insert ls_fldnames into table lt_fldnames.

  • ls_fldnames-fieldname = 'NUMBER_PARENT'.

ls_fldnames-fieldname = 'PARENT_HANDLE'.

insert ls_fldnames into table lt_fldnames.

ls_fldnames-fieldname = 'ITM_PROC_IDENT'.

insert ls_fldnames into table lt_fldnames.

clear lv_handle.

  • GT_SEL_ITEMS contains selected items

loop at gt_sel_items into gs_sel_items.

CALL METHOD tree1->GET_OUTTAB_LINE

EXPORTING

I_NODE_KEY = gs_Sel_items-nodekey

IMPORTING

E_OUTTAB_LINE = ls_outtab

EXCEPTIONS

NODE_NOT_FOUND = 1

others = 2.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

clear: gs_hier, ls_parent.

  • LT_PARENT_POSNR contain item number of parent node

ls_parent-key = gs_sel_items-nodekey.

read table gt_hier into gs_hier with key node = gs_sel_items-nodekey.

if gs_hier-parent is not initial.

  • item has higher level item

  • get position of higher level item

read table lt_parent into ls_parent with key key = gs_hier-parent.

endif.

add 10 to gv_posnr.

ls_ordm_i-header = gv_hdrguid.

ls_ordm_i-itm_proc_ident = 'SRVC'.

if gs_hier-parent is not initial.

ls_ordm_i-ordered_prod = ls_outtab-sor.

else.

ls_ordm_i-ordered_prod = ls_outtab-svc_act.

endif.

lv_prodid = ls_ordm_i-ordered_prod.

if lv_prodid co '0123456789 '.

unpack lv_prodid to lv_prodid.

endif.

add 1 to lv_handle.

ls_ordm_i-mode = 'A'. "create

ls_ordm_i-handle = lv_handle.

if gs_hier-parent is not initial.

ls_ordm_i-parent_handle = ls_parent-handle.

endif.

insert ls_ordm_i into table lt_ordm_i.

ls_parent-posnr = gv_posnr.

ls_parent-handle = lv_handle.

append ls_parent to lt_parent.

ls_product-ref_handle = lv_handle.

insert ls_product into table lt_product.

  • insert input fields

ls_inputflds-field_names[] = lt_fldnames[].

ls_inputflds-ref_handle = lv_Handle.

ls_inputflds-objectname = 'ORDERADM_I'.

insert ls_inputflds into table lt_inputflds.

endloop.

  • return selected products back to service order's items

CALL FUNCTION 'CRM_ORDER_MAINTAIN'

EXPORTING

it_product_i = lt_product

CHANGING

CT_ORDERADM_I = lt_ordm_i

ct_input_fields = lt_inputflds

EXCEPTIONS

ERROR_OCCURRED = 1

DOCUMENT_LOCKED = 2

NO_CHANGE_ALLOWED = 3

NO_AUTHORITY = 4

OTHERS = 5.

Thks.

Former Member
0 Kudos

Hi,

Please have look at the program crm_test_order_maintain.

Thanks,

Gaurav

Former Member
0 Kudos

Hi,

Any luck with adding item using CRM_ORDER_MAINTAIN? I am doing similar, care to share code?

Cheers.