SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Tool to fix Overweight in delivery line item



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 29, 2007 4:10 pm    Post subject: Tool to fix Overweight in delivery line item Reply with quote

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 *******************
************************************************************************

* Tables

Tables : vbak,
vbap,
vbfa,
likp,
lips,
vbrk,
vbrp.

* Internal Tables

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.

clear : i_ret2,
i_cret,
i_csucess.

refresh : i_cret,
i_csucess.

CALL FUNCTION 'BAPI_BILLINGDOC_CANCEL1'
EXPORTING
BILLINGDOCUMENT = v_invoic
* TESTRUN =
* NO_COMMIT =
* BILLINGDATE =
TABLES
RETURN = i_cret
SUCCESS = i_csucess
.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = space
IMPORTING
RETURN = i_ret2.


* read table i_cret with key type = 'E'.

if sy-subrc ne 0.

message i005 with v_invoic.
stop.

endif.


ENDFORM. " cancel_invoice
*&---------------------------------------------------------------------*
*& Form reverse_goodsissue
*&---------------------------------------------------------------------*
* Reverse the goods Issue
*----------------------------------------------------------------------*
FORM reverse_goodsissue.

* Local Variable

data : lv_vbtyp like likp-vbtyp.

clear : i_mesg,
lv_vbtyp.

refresh : i_mesg.

select single vbtyp from likp into lv_vbtyp
where vbeln = v_deliv.

CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
EXPORTING
I_VBELN = v_deliv
I_BUDAT = sy-datum
* I_COUNT =
* I_MBLNR =
* I_TCODE =
I_VBTYP = lv_vbtyp
TABLES
T_MESG = i_mesg
EXCEPTIONS
ERROR_REVERSE_GOODS_ISSUE = 1
OTHERS = 2
.

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.

Clear : i_prot.
refresh : i_prot.

* Delivery Update
CALL FUNCTION 'LE_MOB_DELIVERY_UPDATE'
EXPORTING
do_commit = 'X'
TABLES
t_delivery_items = i_lips
prot = i_prot
EXCEPTIONS
conversion_overflow = 1
essential_data_missing = 2
error = 3
nothing_to_update = 4
lock_after_update_failed = 5
error_in_delivery_update = 6
OTHERS = 7.

COMMIT WORK.

IF sy-subrc <> 0.

MESSAGE i009 with v_deliv.

endif.



* Post Goods Issue
CLEAR: d_return,
i_prot,
l_vbeln,
l_vbkok.

REFRESH i_prot.

CLEAR: ef_error_in_item_deletion_0 ,
ef_error_in_pod_update_0 ,
ef_error_in_interface_0 ,
ef_error_in_goods_issue_0 ,
ef_error_in_final_check_0 .

* carry out goods issue
l_vbeln = v_deliv.
l_vbkok-vbeln_vl = l_vbeln.
l_vbkok-wabuc = 'X'.



* carry out goods issue
l_vbeln = v_deliv.
l_vbkok-vbeln_vl = l_vbeln.
l_vbkok-wabuc = 'X'.

* SET UPDATE TASK LOCAL.
CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
vbkok_wa = l_vbkok
synchron = 'X'
no_messages_update = ' '
update_picking = 'X'
commit = 'X'
delivery = l_vbeln
nicht_sperren = 'X'
if_error_messages_send_0 = space
IMPORTING
ef_error_any_0 = ef_error_any_0
ef_error_in_item_deletion_0 = ef_error_in_item_deletion_0
ef_error_in_pod_update_0 = ef_error_in_pod_update_0
ef_error_in_interface_0 = ef_error_in_interface_0
ef_error_in_goods_issue_0 = ef_error_in_goods_issue_0
ef_error_in_final_check_0 = ef_error_in_final_check_0
TABLES
prot = i_prot
EXCEPTIONS
error_message = 1
OTHERS = 2.

if sy-subrc ne 0.
message i010 with v_deliv.

else.
COMMIT WORK .
endif.

ENDFORM. " Delivery_change
*&---------------------------------------------------------------------*
*& Form invoice_create
*&---------------------------------------------------------------------*
* Invoice Creation
*----------------------------------------------------------------------*
FORM invoice_create.

refresh: XKOMFK, XKOMV,
XTHEAD, XVBFS,
XVBPA, XVBRK,
XVBRP, XVBSS.

clear : XKOMFK, XKOMV,
XTHEAD, XVBFS,
XVBPA, XVBRK,
XVBRP, XVBSS,
VBSK_I.



VBSK_I-SMART = 'F'.
XKOMFK-VBELN = v_deliv.
XKOMFK-VBTYP = 'J'.
APPEND XKOMFK.

CALL FUNCTION 'RV_INVOICE_CREATE'
EXPORTING
VBSK_I = VBSK_I
WITH_POSTING = 'C'
TABLES
XKOMFK = XKOMFK
XKOMV = XKOMV
XTHEAD = XTHEAD
XVBFS = XVBFS
XVBPA = XVBPA
XVBRK = XVBRK
XVBRP = XVBRP
XVBSS = XVBSS.

if sy-subrc eq 0.
COMMIT WORK.
flag = 'X'.

else.
message i011 with p_vbeln.
endif.

ENDFORM. " invoice_create
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.