Here our requirement is to Post New Invoice Document (with new document type- to get different number range) with all the other information (Vendor / GL / PO amount etc) from an existing parked invoice document. Park Document includes both categories of invoice document (PO invoice and Non-PO invoice). Though requirement is a bit specific this program will help you to get an idea of the parameters need to be fed to the above mentioned BAPIs.
BAPI_ACC_DOCUMENT_POST : For Non-PO invoice
BAPI_INCOMINGINVOICE_CREATE : For PO Invoice (The same BAPI can be used for Parking only)
Code:
*&---------------------------------------------------------------------*
*& Report name : ZFIAPCC0001_POST_DOCUMENT
*& Program name : ZFIAPCC0001_POST_DOCUMENT
*& Coded by : Achirangshu De)
*& Date : February 2009
*& Purpose : Post new FI document with new Document Type
*& from a previously Parked document
*&---------------------------------------------------------------------*
************************************************************************
REPORT zfiapcc0001_post_document
NO STANDARD PAGE HEADING
LINE-SIZE 255
LINE-COUNT 65
MESSAGE-ID zfi.
************************************************************************
* D A T A D E F I N I T I O N
************************************************************************
************************************************************************
* C O N S T A N T S
************************************************************************
CONSTANTS:
gc_blart LIKE vbkpf-blart VALUE 'KE'.
************************************************************************
* S E L E C T I O N S C R E E N
************************************************************************
SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-006.
PARAMETERS: p_bukrs LIKE vbkpf-bukrs,
p_belnr LIKE vbkpf-belnr,
p_gjahr LIKE vbkpf-gjahr.
SELECTION-SCREEN: END OF BLOCK blk1.
************************************************************************
* I N T E R N A L S T R U C T U R E S & T A B L E S
************************************************************************
DATA:
gs_vbkpf TYPE vbkpf ,
gt_vbsegs TYPE STANDARD TABLE OF vbsegs WITH HEADER LINE,
gt_vbsegk TYPE STANDARD TABLE OF vbsegk WITH HEADER LINE,
* gt_rseg TYPE STANDARD TABLE OF rseg WITH HEADER LINE,
gt_with_item TYPE STANDARD TABLE OF with_item WITH HEADER LINE,
gt_mwdat TYPE STANDARD TABLE OF rtax1u15 WITH HEADER LINE,
***---- Tables related to Non-PO Invoice Posting------------*
gs_header TYPE bapiache09,
gt_acctgl TYPE STANDARD TABLE OF bapiacgl09 WITH HEADER LINE,
gt_accpay TYPE STANDARD TABLE OF bapiacap09 WITH HEADER LINE,
gt_amnt TYPE STANDARD TABLE OF bapiaccr09 WITH HEADER LINE,
gt_tax_nonpo TYPE STANDARD TABLE OF bapiactx09 WITH HEADER LINE,
gt_extn TYPE STANDARD TABLE OF bapiparex WITH HEADER LINE,
gt_wtax TYPE STANDARD TABLE OF bapiacwt09 WITH HEADER LINE,
gt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE,
***---- Tables related to PO Invoice Posting----------------*
gs_inv_header_in TYPE bapi_incinv_detail_header,
gt_item_in TYPE STANDARD TABLE OF bapi_incinv_detail_item WITH HEADER LINE,
gt_tax_in TYPE STANDARD TABLE OF bapi_incinv_detail_tax WITH HEADER LINE,
gt_vsplit_in TYPE STANDARD TABLE OF bapi_incinv_detail_vendorsplit WITH HEADER LINE,
gt_withtax_in TYPE STANDARD TABLE OF bapi_incinv_detail_withtax WITH HEADER LINE,
gs_inv_header TYPE bapi_incinv_create_header,
gt_item TYPE STANDARD TABLE OF bapi_incinv_create_item WITH HEADER LINE,
gt_tax TYPE STANDARD TABLE OF bapi_incinv_create_tax WITH HEADER LINE,
gt_withtax TYPE STANDARD TABLE OF bapi_incinv_create_withtax WITH HEADER LINE,
gt_vsplit TYPE STANDARD TABLE OF bapi_incinv_create_vendorsplit WITH HEADER LINE.
************************************************************************
* V A R I A B L E S
************************************************************************
DATA: g_invoicedocnumber LIKE bapi_incinv_fld-inv_doc_no,
g_fiscalyear LIKE bapi_incinv_fld-fisc_year,
g_compcode LIKE bkpf-bukrs.
*----PO Invoice ---------------*
DATA: g_flag_po TYPE c, "Flag is set if its a PO invoice
g_belnr LIKE bapi_incinv_fld-inv_doc_no, "Incoming Invoice No.
g_gjahr LIKE bapi_incinv_fld-fisc_year. "Incoming Invoice - Fiscal Year
************************************************************************
* E V E N T P R O C E S S I N G
************************************************************************
INITIALIZATION.
************************************************************************
* S U B R O U T I N E S
************************************************************************
*&---------------------------------------------------------------------*
*& Form A100_GET_DATA_FROM_DB
*&---------------------------------------------------------------------*
* Get data from Database
*----------------------------------------------------------------------*
FORM a100_get_data_from_db .
***--- Select Header Information of Parked Document-----*
SELECT SINGLE * FROM vbkpf
INTO gs_vbkpf
WHERE bukrs EQ p_bukrs
AND belnr EQ p_belnr
AND gjahr EQ p_gjahr.
IF sy-subrc EQ 0.
***-----------------------------------------------------***
*** In case of PO Invoice , there will be no entries in ***
*** VBSEGS table as there is no line in that parked ***
*** document. To get the PO related information we need ***
*** to search through RSEG Table. ***
***-----------------------------------------------------***
***--- PO Invoice -------*
IF gs_vbkpf-awtyp EQ 'RMRP' AND
gs_vbkpf-awkey IS NOT INITIAL.
***--- Non-PO Invoice -------*
*---Vendor Line----------*
SELECT * FROM vbsegk
INTO TABLE gt_vbsegk
WHERE bukrs EQ p_bukrs
AND belnr EQ p_belnr
AND gjahr EQ p_gjahr.
*---GL Line----------*
SELECT * FROM vbsegs
INTO TABLE gt_vbsegs
WHERE bukrs EQ p_bukrs
AND belnr EQ p_belnr
AND gjahr EQ p_gjahr.
*---With Holding Tax ---------*
SELECT * FROM with_item
INTO TABLE gt_with_item
WHERE bukrs EQ p_bukrs
AND belnr EQ p_belnr
AND gjahr EQ p_gjahr.
ENDIF.
ELSE.
*-- Error Message--------*
MESSAGE s000 WITH 'Invalid Accounting Document !'(001) DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " A100_GET_DATA_FROM_DB
*&---------------------------------------------------------------------*
*& Form A150_PROCESS_DATA
*&---------------------------------------------------------------------*
* Process Data for BAPI
*----------------------------------------------------------------------*
FORM a150_process_data .
DATA: l_itemno(3) TYPE n,
l_itemno_hold(3) TYPE n,
l_wrbtr LIKE vbsegs-wrbtr.
IF g_flag_po EQ 'X'. "PO Invoice
**** PO INVOICE ***************************************
IF gt_return[] IS INITIAL.
MOVE-CORRESPONDING gs_inv_header_in TO gs_inv_header.
gs_inv_header-doc_type = gc_blart .
gs_inv_header-header_txt = p_belnr. "Storing Referrence of Old Doc
gs_inv_header-gross_amount = gs_inv_header_in-gross_amnt.
CLEAR gs_inv_header-inv_doc_no.
LOOP AT gt_item_in.
MOVE-CORRESPONDING gt_item_in TO gt_item.
APPEND gt_item.
ENDLOOP.
IF gs_inv_header-calc_tax_ind NE 'X'.
LOOP AT gt_tax_in.
MOVE-CORRESPONDING gt_tax_in TO gt_tax.
APPEND gt_tax.
ENDLOOP.
ENDIF.
LOOP AT gt_vsplit_in.
MOVE-CORRESPONDING gt_vsplit_in TO gt_vsplit.
APPEND gt_vsplit.
ENDLOOP.
LOOP AT gt_withtax_in.
MOVE-CORRESPONDING gt_withtax_in TO gt_withtax.
APPEND gt_withtax.
ENDLOOP.
***---- With Holding Tax----------------*
LOOP AT gt_with_item WHERE bukrs EQ gt_vbsegk-bukrs AND
belnr EQ gt_vbsegk-belnr AND
gjahr EQ gt_vbsegk-gjahr AND
buzei EQ gt_vbsegk-buzei.
ENDFORM. " A150_PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form A200_POST_DOCUMENT
*&---------------------------------------------------------------------*
* Post Park Document
*----------------------------------------------------------------------*
FORM a200_post_document .
DATA: l_obj_type LIKE bapiache09-obj_type ,
l_obj_key LIKE bapiache09-obj_key.
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.