2007 Aug 22 5:07 PM
Hi experts,
I'm having trouble using BAPI_CUSTOMERRETURN_CREATE. and it seems like i'm so hopeless about this. Please i need some help.. below is my code, please let me know where did i got my error and why..tnx!
<b>LOOP AT it_vbap INTO wa_vbap.
bapisditmx-updateflag = 'I'.
bapisditm-ref_doc = wa_vbap-vbeln.
bapisditmx-ref_doc = 'X'.
bapisditm-ref_doc_it = wa_vbap-posnr.
bapisditmx-ref_doc_it = 'X'.
bapisditm-ref_doc_ca = 'B'.
bapisditmx-ref_doc_ca = 'X'.
bapisditm-itm_number = wa_vbap-posnr.
bapisditmx-itm_number = 'X'.
bapisditm-material = wa_vbap-matnr.
bapisditmx-material = 'X'.
bapisditm-item_categ = wa_vbap-pstyv.
bapisditmx-item_categ = 'X'.
bapisditm-po_itm_no = wa_vbap-posex.
bapisditmx-po_itm_no = 'X'.
bapisditm-hg_lv_item = wa_vbap-uepos.
bapisditmx-hg_lv_item = 'X'.
*
bapisditm-plant = wa_vbap-werks.
bapisditmx-plant = 'X'.
bapisditm-target_qty = wa_vbap-kwmeng.
bapisditmx-target_qty = 'X'.
APPEND: bapisditm,
bapisditmx.
CLEAR wa_vbap.
ENDLOOP.
CHECK NOT it_vbak IS INITIAL AND NOT it_vbap IS INITIAL.
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
EXPORTING
return_header_in = bapisdhd1
return_header_inx = bapisdhd1x
convert = 'X'
IMPORTING
salesdocument = scr0100-cbeln
TABLES
return = return
return_items_in = bapisditm
return_items_inx = bapisditmx
return_partners = bapiparnr.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.
IF sy-subrc <> 0.
COMMIT WORK AND WAIT.
ENDIF.</b>
Thanks and Regards,
Mackoy
Item category is the cause of this error. It looks like your item category and the material that you are giving are not compatible. Please verify that you can create a order online with the same data.
2007 Aug 22 5:10 PM
2007 Aug 22 5:11 PM
Hi,
By the way, i encountered this error...
<b>E |V1 |321 |Item category ZAGM is not defined for thi<
E |V4 |248 |Error in SALES_ITEM_IN 000010 <
W |V1 |555 |The sales document is not yet complete: E<</b>
regards,
Mackoy
2007 Aug 22 5:15 PM
Hi
Keep a break point at this point and see what value is coming into the field
wa_vbap-pstyv.
bapisditm-item_categ = wa_vbap-pstyv.
As per the error it says that the Item Category which is getting assigned here does not exist. check with the functional consulatnt for the item category ZAGM, and see.
<b>Reward points for useful Answers</b>
Regards
Anji
2007 Aug 22 7:59 PM
Item category is the cause of this error. It looks like your item category and the material that you are giving are not compatible. Please verify that you can create a order online with the same data.
2007 Aug 22 5:11 PM
I don't see where you are filling the BAPI header structure. Also, what error are you getting? It helps if you tell us the error message.
2007 Aug 22 5:13 PM
Hi Adavi,
No error in populating the header just the item..i dont know why...
Thanks,
Mackoy
2007 Aug 22 5:16 PM
FORM get_update .
DATA: l_itemno(6) TYPE n,
l_partner TYPE parvw,
l_kunnr TYPE kunnr,
l_matnr TYPE matnr,
l_mesg TYPE string,
l_kbetr TYPE p DECIMALS 2.
DATA: l_in_qty LIKE vbap-zmeng,
l_meins LIKE mara-meins,
l_factor LIKE marm-umrez,
l_qty LIKE vbap-zmeng.
CLEAR: v_correct, v_error, v_total.
SORT it_data BY loc div pdpl_order.
LOOP AT it_data.
CLEAR v_index.
v_index = sy-tabix.
*- New SalesOrder
AT NEW pdpl_order.
READ TABLE it_data INDEX v_index.
CLEAR: it_orderh, it_item, it_partner,
it_return, conditions, conditions[],
it_item[], it_partner[], it_return[].
v_total = v_total + 1. "Increment Total SalesOrders counter
CLEAR l_itemno.
l_itemno = '10'.
*- Covert date fields into Internal format
CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
EXPORTING
datum = it_data-date
dtype = 'DATS'
IMPORTING
idate = it_data-date.
*- Populate SalesOrder header data.
CALL FUNCTION 'CONVERSION_EXIT_AUART_INPUT'
EXPORTING
input = it_data-auart
IMPORTING
output = it_data-auart.
it_orderh-doc_type = it_data-auart.
it_orderh-sales_org = it_data-vkorg.
it_orderh-distr_chan = it_data-vtweg.
it_orderh-division = it_data-spart.
it_orderh-doc_number = it_data-vbeln. "No external # assignment allowed
it_orderh-doc_date = it_data-date. "Doc Dt
it_orderh-purch_no_s = it_data-pdpl_order.
it_orderh-ord_reason = it_data-ord_cause. "Order reason
*- Partner data
CLEAR: l_partner, l_kunnr.
*- Convert Partner type into internal format
l_partner = 'SP'. "SoldTo Party
CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
EXPORTING
input = l_partner
IMPORTING
output = l_partner.
*- Convert Customer into internal format
l_kunnr = it_data-kunnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_kunnr
IMPORTING
output = l_kunnr.
it_partner-partn_role = l_partner.
it_partner-partn_numb = l_kunnr.
APPEND it_partner.
CLEAR it_partner.
ENDAT.
*- Item data
it_item-itm_number = l_itemno.
*- Convert material number into internal format
CLEAR l_matnr.
l_matnr = it_data-matnr.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = l_matnr
IMPORTING
output = l_matnr
EXCEPTIONS
length_error = 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.
it_item-material = l_matnr.
*- Insert into Reconciliation table
PERFORM insert_record.
*- Call FM to get new qty based on SAP UOM
CLEAR: l_meins, l_qty, l_in_qty, l_factor.
l_in_qty = it_data-qty.
CALL FUNCTION 'Z_GET_QTY_FROM_UOM'
EXPORTING
matnr = it_data-matnr
in_meins = it_data-uom
in_qty = l_in_qty
IMPORTING
out_meins = l_meins
quantity = l_qty
factor = l_factor.
IF sy-subrc = 0.
it_data-qty = l_qty.
it_data-uom = l_meins.
ENDIF.
*- Call FM to get new qty based on SAP UOM
CLEAR: l_meins, l_qty, l_in_qty.
l_in_qty = it_data-free_qty.
CALL FUNCTION 'Z_GET_QTY_FROM_UOM'
EXPORTING
matnr = it_data-matnr
in_meins = it_data-uom
in_qty = l_in_qty
IMPORTING
out_meins = l_meins
quantity = l_qty
factor = l_factor.
IF sy-subrc = 0.
it_data-free_qty = l_qty.
it_data-uom = l_meins.
ENDIF.
*- Batch
it_item-batch = it_data-batch.
it_item-target_qty = it_data-qty. " * 1000.
it_item-target_qu = it_data-uom.
IF NOT it_item-material IS INITIAL.
APPEND it_item.
*- Pricing Conditions
conditions-itm_number = l_itemno.
conditions-cond_count = '01'.
conditions-cond_type = 'PR00'.
CLEAR l_kbetr.
l_kbetr = it_data-kbetr / 10. "Price (Rate)
IF l_factor > 0.
conditions-cond_value = l_kbetr / l_factor.
ENDIF.
APPEND conditions.
CLEAR conditions.
ENDIF.
*- Discount
IF NOT it_data-discount IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '02'.
conditions-cond_type = 'ZDIS'.
CLEAR l_kbetr.
l_kbetr = it_data-discount / 10.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
*- CD
IF NOT it_data-cd IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '03'.
conditions-cond_type = 'ZCD'.
CLEAR l_kbetr.
l_kbetr = it_data-cd / 10.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
*- Lst
IF NOT it_data-lst IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '04'.
conditions-cond_type = 'ZIN2'.
CLEAR l_kbetr.
l_kbetr = it_data-lst / 10.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
*- Surcharge
IF NOT it_data-sur IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '05'.
conditions-cond_type = 'ZIN5'.
CLEAR l_kbetr.
l_kbetr = it_data-sur / 10.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
**- CST
IF NOT it_data-cst IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '06'.
conditions-cond_type = 'ZIN1'.
CLEAR l_kbetr.
l_kbetr = it_data-cst.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
*- Freight
IF NOT it_data-freight IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '07'.
conditions-cond_type = 'ZFR1'.
CLEAR l_kbetr.
l_kbetr = it_data-freight / 10.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
*- Rounding Off
IF NOT it_data-roff IS INITIAL.
conditions-itm_number = l_itemno.
conditions-cond_count = '08'.
conditions-cond_type = 'ZRND'.
CLEAR l_kbetr.
l_kbetr = it_data-roff / 10.
conditions-cond_value = l_kbetr.
APPEND conditions.
CLEAR conditions.
ENDIF.
IF it_data-free_qty > '0.000'.
*- Increment Item counter.
l_itemno = l_itemno + 10.
it_item-itm_number = l_itemno.
it_item-material = l_matnr.
it_item-item_categ = 'RENN'.
it_item-target_qty = it_data-free_qty. " * 1000.
APPEND it_item.
CLEAR it_item.
ENDIF.
*- Increment Item counter.
l_itemno = l_itemno + 10.
*- At end of SalesOrder
AT END OF pdpl_order.
READ TABLE it_data INDEX v_index.
*- Call the BAPI for Credit Note creation
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
EXPORTING
return_header_in = it_orderh
TABLES
return = it_return
return_items_in = it_item
return_partners = it_partner
return_conditions_in = conditions.
IF sy-subrc = 0.
COMMIT WORK.
CLEAR v_vbeln.
SORT it_return BY type id.
READ TABLE it_return WITH KEY type = 'S'
id = 'V1'.
IF sy-subrc = 0.
v_vbeln = it_return-message_v2.
v_correct = v_correct + 1.
CLEAR l_mesg.
CONCATENATE 'Credit note'(007) v_vbeln 'successfully created.'(008)
INTO l_mesg SEPARATED BY space.
CONDENSE l_mesg.
WAIT UP TO 1 SECONDS.
*- Call VA02 for updating Qty
PERFORM call_va02.
ELSE.
v_error = v_error + 1.
READ TABLE it_return WITH KEY type = 'E'.
IF sy-subrc = 0.
CLEAR l_mesg.
l_mesg = it_return-message.
CONDENSE l_mesg.
ENDIF.
ENDIF.
ENDIF.
*- Populate the output table
CLEAR it_out.
it_out-pdpl_order = it_data-pdpl_order.
it_out-mesg = l_mesg.
APPEND it_out.
CLEAR it_out.
ENDAT.
ENDLOOP.
ENDFORM. " get_update
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |