Google Search - Blog...........

ABAP - Report Program To Create A Return Order Using BAPI BAPI_CUSTOMERRETURN_CREATE

This snippet is for creation of a Return Order using BAPI. Here Return Order is created based on the customer Invoice number. Vendor sends a flat file (CSV format) to the R/3 where an interface updates the corresponding information into the custom table and from the custom table corresponding Return orders will be processed.
*&---------------------------------------------------------------------*
*& Form call_rep_vabapi
*&---------------------------------------------------------------------*
* Return Order Creation for Reprocessing
*----------------------------------------------------------------------*FORM call_rep_vabapi . CONSTANTS: lc_ag TYPE char2 VALUE 'AG',
lc_sh TYPE char2 VALUE 'SH'. REFRESH: gt_itab5,gt_vbrp.
* Selecting the data from Record table SELECT lifnr
vbeln
posnr
augru
cdate
kunnr
kunwe
bstkd
docid
ean11
part_debit
quant_debit
quant_credit
errcode
FROM /bmw/atl_zu_i455
INTO TABLE gt_itab5
WHERE vbeln EQ s_vbeln
AND kunnr EQ pa_kunnr
AND augru EQ s_augru
AND lifnr EQ pa_lifnr. IF sy-subrc EQ gc_zero_num.
SORT gt_itab5 BY vbeln augru kunnr.
ENDIF. REFRESH: gt_vbrp.
* Selecting the data from VBRP for material
SELECT vbeln
posnr
vkorg_auft
vtweg_auft
spart
werks
lgort
matnr
ean11
FROM vbrp
INTO CORRESPONDING FIELDS OF TABLE gt_vbrp
WHERE vbeln EQ s_vbeln. IF sy-subrc EQ gc_zero_num.
SORT gt_vbrp BY vbeln posnr.
ENDIF. LOOP AT gt_itab5 INTO gs_itab5.*------------------------------------------------------------------
* Build partner information
*------------------------------------------------------------------
CLEAR gs_return_partners.
gs_return_partners-partn_role = lc_ag.
gs_return_partners-partn_numb = gs_itab5-kunnr.
APPEND gs_return_partners TO gt_return_partners. gs_return_partners-partn_role = lc_sh.
gs_return_partners-partn_numb = gs_itab5-kunwe.
APPEND gs_return_partners TO gt_return_partners.*------------------------------------------------------------------
* Build order header
*------------------------------------------------------------------* Sales document type
gs_return_header_in-doc_type = gc_yr.
gs_return_header_inx-doc_type = gc_x.*Order Reason
gs_return_header_in-ord_reason = gs_itab5-augru.
gs_return_header_inx-ord_reason = gc_x.* SD document Category
gs_return_header_in-sd_doc_cat = gc_h.
gs_return_header_inx-sd_doc_cat = gc_x.* Reference Document (Invoice)
gs_return_header_in-ref_doc = gs_itab5-vbeln.
gs_return_header_inx-ref_doc = gc_x.* Reference Document Category
gs_return_header_in-purch_no_c = gs_itab5-docid.
gs_return_header_inx-purch_no_c = gc_x.* Reference Document Category
gs_return_header_in-refdoc_cat = gc_m.
gs_return_header_inx-refdoc_cat = gc_x.* Currency
gs_return_header_in-currency = text-035.
gs_return_header_inx-currency = gc_x. READ TABLE gt_vbrp INTO gs_vbrp WITH KEY vbeln = gs_itab5-vbeln
posnr = gs_itab5-posnr
ean11 = gs_itab5-ean11. IF sy-subrc EQ gc_zero_num.
gs_itab5-ean11 = gs_vbrp-matnr.
* Sales organization
gs_return_header_in-sales_org = gs_vbrp-vkorg_auft .
gs_return_header_inx-sales_org = gc_x.
* Distribution channel
gs_return_header_in-distr_chan = gs_vbrp-vtweg_auft.
gs_return_header_inx-distr_chan = gc_x.
* Division
gs_return_header_in-division = gs_vbrp-spart.
gs_return_header_inx-division = gc_x.
* Plant
gs_return_items_in-plant = gs_vbrp-werks.
gs_return_items_inx-plant = gc_x.
* Storage Location
gs_return_items_in-store_loc = gs_vbrp-lgort.
gs_return_items_inx-store_loc = gc_x.
*Material
gs_return_items_in-material = gs_itab2-ean11.
gs_return_items_inx-material = gc_x.
ENDIF.*-----------------------------------------------------------------*
* Build order item(s) *
*-----------------------------------------------------------------* gs_return_items_in-itm_number = gs_itab5-posnr.
gs_return_items_inx-itm_number = gc_x . gs_return_items_in-target_qty = gs_itab5-quant_debit.
gs_return_items_inx-target_qty = gc_x. gs_return_items_in-purch_no_c = gs_itab5-docid.
gs_return_items_inx-purch_no_c = gc_x. IF gs_itab2-augru EQ gc_yw2
OR gs_itab2-augru EQ gc_yw3
OR gs_itab2-augru EQ gc_yw4
OR gs_itab2-augru EQ gc_yw5
OR gs_itab2-augru EQ gc_yw7.
gs_return_items_in-item_categ = gc_yv.
ELSE.
gs_return_items_in-item_categ = gc_yv1.
ENDIF.
gs_return_items_inx-item_categ = gc_x. gs_return_items_in-currency = text-035. gs_return_items_in-ref_doc = gs_itab5-vbeln.
gs_return_items_inx-ref_doc = gc_x. APPEND gs_return_items_in TO gt_return_items_in.
APPEND gs_return_items_inx TO gt_return_items_inx.*Call the BAPI to Create the Return Order
CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE'
EXPORTING
return_header_in = gs_return_header_in
return_header_inx = gs_return_header_inx
IMPORTING
salesdocument = gv_salesdocument
TABLES
return = gt_return
return_items_in = gt_return_items_in
return_items_inx = gt_return_items_inx
return_partners = gt_return_partners
return_schedules_in = gt_bapischdl.* Commit Work
PERFORM error. ENDLOOP.ENDFORM. " call_rep_vabapi

No comments:

Post a Comment