cancel
Showing results for 
Search instead for 
Did you mean: 

Create the schedule lines from CRM_ORDER_MAINTAIN

thangam_perumal
Contributor
0 Kudos
392

Hi Team,

          I have one requirement to create multiple schedule line with help of FM CRM_ORDER_MAINTAIN

Actually issue is , only one line item is updating rest of the items are not updated .

Short dump is happening from crmd_billing table.After coming out from this program if i run program with same data, again first line item is updating.

I dont know where i making mistake , Kindly anyone help me out.

Below mentioning my code

LOOP AT gt_schdule INTO gs_schdule.

       ls_fieldnames-fieldname = 'ITM_PROC_IDENT'.
       INSERT ls_fieldnames INTO TABLE lt_fieldnames.
       CLEAR ls_fieldnames.

       ls_fieldnames-fieldname = 'ORDERED_PROD'.
       INSERT ls_fieldnames INTO TABLE lt_fieldnames.
       CLEAR ls_fieldnames.

       ls_fieldnames-fieldname = 'MODE'.
       INSERT ls_fieldnames INTO TABLE lt_fieldnames.
       CLEAR ls_fieldnames.

       ls_input_fields-ref_handle   = gv_handle.
       ls_input_fields-objectname   = 'ORDERADM_I'.
       ls_input_fields-field_names  = lt_fieldnames.
       INSERT ls_input_fields INTO TABLE ct_input_fields1.
       CLEAR: ls_input_fields,lt_fieldnames[].

       ls_orderadm_i-handle         = gv_handle.
*  ls_orderadm_i-number_int     = '0000000001'.
*      ls_orderadm_i-header_handle  = gv_handle.
       ls_orderadm_i-ordered_prod   = gs_schdule-matnr.
       ls_orderadm_i-itm_proc_ident   = 'SALS'.
       ls_orderadm_i-header   = gv_guid.
       ls_orderadm_i-mode   = 'A'.
*  ls_orderadm_i-description    = ls_final-product_decription.

       INSERT ls_orderadm_i INTO TABLE lt_orderadm_i.
       CLEAR ls_orderadm_i.


       ls_fieldnames = 'QUANTITY'.
       INSERT ls_fieldnames INTO TABLE lt_fieldnames.
       CLEAR ls_fieldnames.

       ls_input_fields-ref_handle   = gv_handle.
       ls_input_fields-objectname   = 'SCHEDLIN'.
       ls_input_fields-ref_kind     = 'B'.
       ls_input_fields-field_names  = lt_fieldnames.
       INSERT ls_input_fields INTO TABLE ct_input_fields1.
       CLEAR: ls_input_fields,lt_fieldnames[].

       ls_schledlines-quantity      = gs_schdule-qty.
       ls_schledlines-mode      = 'A'.
       ls_schledlines-handle        = gv_handle.
       INSERT ls_schledlines INTO TABLE lt_shchledlines.
       CLEAR ls_schledlines.

       ls_schedlin_i-ref_handle   = gv_handle.
       ls_schedlin_i-schedlines   = lt_shchledlines.
       INSERT ls_schedlin_i INTO TABLE lt_schedlin_i.
       CLEAR ls_schedlin_i.
       CLEAR: lt_shchledlines[],gs_schdule.


   CALL FUNCTION 'CRM_ORDER_MAINTAIN'
     EXPORTING
       it_schedlin_i     = lt_schedlin_i
       IMPORTING
       et_exception      = et_exception
     CHANGING
       ct_orderadm_h     = lt_orderadm_h
       ct_orderadm_i     = lt_orderadm_i
       ct_input_fields   = ct_input_fields1
     EXCEPTIONS
       error_occurred    = 1
       document_locked   = 2
       no_change_allowed = 3
       no_authority      = 4
       OTHERS            = 5.


   IF lt_orderadm_h[]  IS NOT INITIAL.

     REFRESH : lt_object_guid[].
     FREE lt_object_guid[].

     READ TABLE lt_orderadm_h INTO ls_orderadm_h INDEX 1.

     ls_object_guid = ls_orderadm_h-guid.
     APPEND ls_object_guid TO lt_object_guid.
     CLEAR ls_object_guid.
     CALL FUNCTION 'CRM_ORDER_SAVE'
       EXPORTING
         it_objects_to_save = lt_object_guid
       IMPORTING
         et_saved_objects   = lt_exporting
       EXCEPTIONS
         document_not_saved = 1
         OTHERS             = 2.
     IF sy-subrc = 0.
       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

       IF sy-subrc <> 0.
         CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
       ENDIF.
     ENDIF.
   ENDIF.
gv_handle = gv_handle + 1.

free : ct_input_fields1[],lt_schedlin_i[],lt_orderadm_i[],lt_orderadm_h[],lt_shchledlines[].
     ENDLOOP.

Accepted Solutions (0)

Answers (1)

Answers (1)

kapilpatil
Active Contributor
0 Kudos

Hi,

To understand your issue, please can you tell me:

1. Do you want to create schedule lines for multiple lines items linked to same contract header?

2. Are you processing multiple such contract headers ?

Ideally you should call FM CRM_ORDER_MAINTAIN only once for a contract header (with multiple line items). Pass all the required information in one go and clear the buffer, then process the next contract header.

I hope this helps.

Thanks,

Kapil

thangam_perumal
Contributor
0 Kudos

Hi Kapil,

     Yeah your right ,Need to pass all the required information in one shot . I tried that way also.

Even if i try like that only first item is updating . So that i tired like this but still same issue getting.

Regards,

Thangam Perumal