Posted: Sat Sep 29, 2007 4:10 pm Post subject: Tool to fix Overweight in delivery line item
RV_INVOICE_CREATE is the function module to create invoice based on delivery .
When you pass delivery number ,it will create invoice ,see the invoice number in vf02,vf03 transaction. and also see the data vbrk,vbrp tables
Code:
REPORT ZWM_OVERWEIGHT_FIX no standard page heading
message-id zwm.
*======================================================================*
* *
* Program Name : ZWM_OVERWEIGHT_FIX *
* *
* Description : Tool to fix Overweight in delivery line item, *
* Used All Function module to cancel invoice , *
* Reverse the goods issue ,Update Delivery qty,Create *
* invoice *
* *
* Author : Seshu Maramreddy
* *
************************************************************************
************************************************************************
*************** D A T A - D E C L A R A T I O N *******************
************************************************************************
data : i_lips like lips occurs 0 with header line,
i_vbap like vbap occurs 0 with header line.
* Variables
data : v_deliv like vbfa-vbelv,
v_invoic like vbfa-vbelv.
* Data Declaration Part for Post Goods Issue
DATA: l_vbeln LIKE likp-vbeln,
l_vbkok LIKE vbkok,
i_prot LIKE prott OCCURS 0 WITH HEADER LINE,
ef_error_any_0 TYPE c,
ef_error_in_item_deletion_0 TYPE c,
ef_error_in_pod_update_0 TYPE c,
ef_error_in_interface_0 TYPE c,
ef_error_in_goods_issue_0 TYPE c,
ef_error_in_final_check_0 TYPE c,
d_return LIKE bapireturn1.
* Internal tables for BAPI Function Module
data : i_cret like BAPIRETURN1 occurs 0 with header line,
i_csucess like BAPIVBRKSUCcESS occurs 0 with header line,
i_ret2 like bapiret2 ,
flag type c,
i_mesg like mesg occurs 0 with header line.
* Data Declaration for Invoice Creation
DATA: VBSK_I LIKE VBSK.
data: d_success type c.
DATA: XKOMFK LIKE KOMFK OCCURS 0 WITH HEADER LINE,
XKOMV LIKE KOMV OCCURS 0 WITH HEADER LINE,
XTHEAD LIKE THEADVB OCCURS 0 WITH HEADER LINE,
XVBFS LIKE VBFS OCCURS 0 WITH HEADER LINE,
XVBPA LIKE VBPAVB OCCURS 0 WITH HEADER LINE,
XVBRK LIKE VBRKVB OCCURS 0 WITH HEADER LINE,
XVBRP LIKE VBRPVB OCCURS 0 WITH HEADER LINE,
XVBSS LIKE VBSS OCCURS 0 WITH HEADER LINE,
XKOMFKGN LIKE KOMFKGN OCCURS 0 WITH HEADER LINE.
************************************************************************
*************** S E L E C T I O N - S C R E E N ******************
************************************************************************
* Selection-screen
Selection-screen : begin of block blk with frame title text-001.
parameters : p_vbeln like vbak-vbeln obligatory.
selection-screen : end of block blk.
************************************************************************
*************** A T - S E L E C T I O N - S C R E E N ***************
************************************************************************
* Validation on Sales order
at selection-screen on p_vbeln.
* Check the data on VBAK Table
select single vbeln from vbak into vbak-vbeln
where vbeln = p_vbeln.
if sy-subrc ne 0.
message e006 with p_vbeln.
endif.
************************************************************************
*************** S T A R T - O F - S E L E C T I O N *******************
************************************************************************
Start-of-selection.
break sreddy.
* Get the Invoice Number corresponding Sales Order Number
perform get_invoice.
* Step 1.
* Cancel the Invoice - Transaction VF11
perform cancel_invoice.
* Reverse the goods issue
perform reverse_goodsissue.
* Get the Order and Delivery Items
perform get_sales_deliv.
* Delivery Change
perform Delivery_change.
* Create Invoice document
perform invoice_create.
************************************************************************
*************** E N D - O F - S E L E C T I O N *******************
************************************************************************
end-of-selection.
if flag = 'X'.
message i012 with p_vbeln.
endif.
*&---------------------------------------------------------------------*
*& Form get_invoice
*&---------------------------------------------------------------------*
* Get Invoice Number
*----------------------------------------------------------------------*
FORM get_invoice.
* Clear Variables
clear : v_deliv,
v_invoic,
flag.
* Get the Delivery Number First
select single vbeln from vbfa into v_deliv
where vbelv = p_vbeln
and vbtyp_n = 'J'.
if sy-subrc ne 0.
message i004 with p_vbeln.
stop.
endif.
* Get the Invoice Number
select single vbeln from vbfa into v_invoic
where vbelv = p_vbeln
and vbtyp_n = 'M'.
if sy-subrc ne 0.
message i003 with p_vbeln.
stop.
endif.
ENDFORM. " get_invoice
*&---------------------------------------------------------------------*
*& Form cancel_invoice
*&---------------------------------------------------------------------*
* Cancel the Invoice
*----------------------------------------------------------------------*
FORM cancel_invoice.
if sy-subrc ne 0.
message i007 with v_deliv.
endif.
ENDFORM. " reverse_goodsissue
*&---------------------------------------------------------------------*
*& Form get_sales_deliv
*&---------------------------------------------------------------------*
* Get the Sales order and Deliv Items
*----------------------------------------------------------------------*
FORM get_sales_deliv.
* Local Variables
data : lv_kwmeng like vbap-kwmeng.
clear : i_lips,
i_vbap.
refresh : i_lips,
i_vbap.
* Select the data from LIPS
select * from lips into table i_lips
where vbeln = v_deliv.
if sy-subrc ne 0.
message i008 with v_deliv.
stop.
endif.
sort i_lips by vbeln posnr.
* Get the Sales order Item Data.
select * from vbap into table i_vbap
where vbeln = p_vbeln.
if sy-subrc ne 0.
message i006 with p_vbeln.
stop.
endif.
sort i_vbap by vbeln posnr.
* Compare delivery Item and Order Items
loop at i_lips.
clear lv_kwmeng.
read table i_vbap with key posnr = i_lips-posnr.
if sy-subrc eq 0.
lv_kwmeng = i_vbap-kwmeng * 2.
if lv_kwmeng >= i_lips-lfimg.
i_lips-lfimg = i_vbap-kwmeng.
modify i_lips.
endif.
endif.
endloop.
ENDFORM. " get_sales_deliv
*&---------------------------------------------------------------------*
*& Form Delivery_change
*&---------------------------------------------------------------------*
* Delivery Update
*----------------------------------------------------------------------*
FORM Delivery_change.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.