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

BAPI_DELIVERYPROCESSING_EXEC



 
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: 1640

PostPosted: Fri Sep 21, 2007 9:54 am    Post subject: BAPI_DELIVERYPROCESSING_EXEC Reply with quote

BAPI_DELIVERYPROCESSING_EXEC - Delivery Processing: Deliver Preceding Document, Expand Delivery

Functionality
Delivery Processing

This Business Application Interface (BAPI) is for internal communication between Advanced Planner and Optimizer (APO) and the SAP Logistics Execution System (LES). It has not been released for external use. We reserve the right to change the interface and the functions in the interface without prior notification.

Only the items from the preceding document of a shipment for delivery are specified when this interface is called up.

Combining two preceding-document items from two different shipments in a delivery (which would be an error) is therefore ruled out by the calling program.

You can use this function module to carry out the following functions within the context of delivery processing:

Deliver preceding objects
- Deliver sales-order items with specification of date/time and quantity
- Deliver purchase-order items with specification of date/time and quantity
Add to a delivery
- Add packaging items to a delivery

Here is a little program that I wrote to test out this BAPI. This program asks for a Sales Order Number and Line Item, then creates a Delivery for 1 unit referencing that Sales Order.

TBL_REQUEST is a denormalised table holding the delivery data for each line item. This means that each record in this table contains both header and line item data.

Code:

*--------------------------------------------------------
REPORT ypat_create_delivery LINE-SIZE 256.

*--------------------------------------------------------
* Internal Tables
*--------------------------------------------------------
* Table to Hold Delivery Request
DATA: BEGIN OF tbl_request OCCURS 0.
INCLUDE STRUCTURE bapideliciousrequest.
DATA: END OF tbl_request.

* Table to hold Line Items Created
DATA: BEGIN OF tbl_items OCCURS 0.
INCLUDE STRUCTURE bapideliciouscreateditems.
DATA: END OF tbl_items.

* Table to hold BAPI Return Messages
DATA: BEGIN OF tbl_return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF tbl_return.

*--------------------------------------------------------
* Structures
*--------------------------------------------------------
DATA: st_vbak LIKE vbak,
st_vbap LIKE vbap.

*--------------------------------------------------------
* Selection Screen
*--------------------------------------------------------
PARAMETERS: p_vbeln LIKE vbak-vbeln,
p_posnr LIKE vbap-posnr DEFAULT '000010'.

*--------------------------------------------------------
* Start of Selection
*--------------------------------------------------------
START-OF-SELECTION.

SELECT SINGLE *
INTO st_vbak
FROM vbak
WHERE vbeln = p_vbeln.

CHECK sy-subrc EQ 0.

SELECT SINGLE *
INTO st_vbap
FROM vbap
WHERE vbeln = p_vbeln AND
posnr = p_posnr.


*--------------------------------------------------------* End of Selection
*--------------------------------------------------------
END-OF-SELECTION.

IF st_vbak IS INITIAL.
WRITE:/ 'Invalid Sales Order'.
EXIT.
ENDIF.

tbl_request-document_numb = st_vbap-vbeln.
tbl_request-document_item = st_vbap-posnr.
tbl_request-ship_to = st_vbak-kunnr.
tbl_request-sold_to = st_vbak-kunnr.
tbl_request-sales_organisation = st_vbak-vkorg.
tbl_request-distribution_channel = st_vbak-vtweg.
tbl_request-division = st_vbak-spart.
tbl_request-plant = st_vbap-werks.
tbl_request-quantity_sales_uom = '1'.

tbl_request-sales_unit = st_vbap-vrkme.
tbl_request-base_uom = st_vbap-meins.
tbl_request-material = st_vbap-matnr.
tbl_request-delivery_date = st_vbak-bstdk.
tbl_request-delivery_time = '160000'.
tbl_request-transp_plan_date = st_vbak-bstdk.
tbl_request-loading_date = st_vbak-bstdk.
tbl_request-goods_issue_date = st_vbak-bstdk.

tbl_request-extdelv_no = '98765'.
tbl_request-document_type = 'A'. "Delivery
tbl_request-document_type_predecessor = 'A'. "Sales Ord

tbl_request-document_type_delivery = 'LF'.


APPEND tbl_request.

CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = tbl_request
createditems = tbl_items
return = tbl_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

LOOP AT tbl_return.
WRITE:/ tbl_return-type,
tbl_return-id,
tbl_return-number,
tbl_return-message.
ENDLOOP.


Example of creating a sales order and for creating delivery...

Code:
************SALES ORDER INPUT CREATION.

PARAMETERS: p_auart TYPE auart OBLIGATORY.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
PARAMETERS: p_spart TYPE vtweg OBLIGATORY.

PARAMETERS: p_sold TYPE kunnr OBLIGATORY.
PARAMETERS: p_ship TYPE kunnr OBLIGATORY.

*ITEM
PARAMETERS: p_matnr TYPE matnr OBLIGATORY.
PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.
PARAMETERS: p_plant TYPE werks_d OBLIGATORY.
PARAMETERS: p_itcat TYPE pstyv OBLIGATORY.

* DATA DECLARATIONS.
DATA: v_vbeln LIKE vbak-vbeln.
DATA: header LIKE bapisdhead1.
DATA: headerx LIKE bapisdhead1x.
DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx
WITH HEADER LINE.
DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl
WITH HEADER LINE.

* HEADER DATA
header-doc_type = p_auart.
headerx-doc_type = 'X'.

header-sales_org = p_vkorg.
headerx-sales_org = 'X'.

header-distr_chan = p_vtweg.
headerx-distr_chan = 'X'.

header-division = p_spart.
headerx-division = 'X'.

headerx-updateflag = 'I'.

* PARTNER DATA
partner-partn_role = 'AG'.
partner-partn_numb = p_sold.
APPEND partner.

partner-partn_role = 'WE'.
partner-partn_numb = p_ship.
APPEND partner.

* ITEM DATA
itemx-updateflag = 'I'.

item-itm_number = '000010'.
itemx-itm_number = 'X'.


item-material = p_matnr.
itemx-material = 'X'.

item-plant = p_plant.
itemx-plant = 'X'.

item-target_qty = p_menge.
itemx-target_qty = 'X'.

item-target_qu = 'EA'.
itemx-target_qu = 'X'.

item-item_categ = p_itcat.
itemx-item_categ = 'X'.

APPEND item.
APPEND itemx.

* Fill schedule lines
lt_schedules_in-itm_number = '000010'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.

* Fill schedule line flags
lt_schedules_inx-itm_number = '000010'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.

* Call the BAPI
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = header
sales_header_inx = headerx
IMPORTING
salesdocument_ex = v_vbeln
TABLES
return = return
sales_items_in = item
sales_items_inx = itemx
sales_schedules_in = lt_schedules_in
sales_schedules_inx = lt_schedules_inx
sales_partners = partner.

* Check the return table.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.

IF sy-subrc = 0.

WRITE: / 'Error in creating document'.

ELSE.

COMMIT WORK AND WAIT.

WRITE: / 'Document ', v_vbeln, ' created'.

ENDIF.


************DELIVERY CREATION.

DATA: BEGIN OF t_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
zmeng LIKE vbap-kwmeng,
matnr LIKE vbap-matnr,
werks LIKE vbap-werks,
END OF t_vbap.

DATA: t_request TYPE STANDARD TABLE OF bapideliciousrequest
WITH HEADER LINE.


DATA: t_created TYPE STANDARD TABLE OF bapideliciouscreateditems
WITH HEADER LINE.


DATA: t_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.

SELECT vbeln posnr zmeng matnr werks
INTO TABLE t_vbap
FROM vbap
WHERE vbeln = v_vbeln.


LOOP AT t_vbap.

t_request-document_numb = t_vbap-vbeln.
t_request-document_item = t_vbap-posnr.
t_request-quantity_sales_uom = t_vbap-zmeng.
t_request-quantity_base__uom = t_vbap-zmeng.
t_request-id = 1.
t_request-document_type = 'A'.
t_request-delivery_date = sy-datum.
t_request-material = t_vbap-matnr.
t_request-plant = t_vbap-werks.
t_request-date = sy-datum.
t_request-goods_issue_date = sy-datum.
t_request-goods_issue_time = sy-uzeit.
APPEND t_request.

ENDLOOP.

CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = t_request
createditems = t_created
return = t_return.


READ TABLE t_return WITH KEY type = 'E'.

IF sy-subrc = 0.
MESSAGE e208(00) WITH 'Delivery creation error'.
ENDIF.


COMMIT WORK.
*
************Post goods issue.
READ TABLE t_created INDEX 1.

DATA: vbkok_wa TYPE vbkok.

vbkok_wa-vbeln_vl = t_created-document_numb.
vbkok_wa-wabuc = 'X'.

DATA: v_error.

CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
vbkok_wa = vbkok_wa
delivery = t_created-document_numb
IMPORTING
ef_error_in_goods_issue_0 = v_error.

COMMIT WORK.



Here is a little program that to test out this BAPI. This program asks for a Sales Order Number and Line Item, then creates a Delivery for 1 unit referencing that Sales Order.

TBL_REQUEST is a denormalised table holding the delivery data for each line item. This means that each record in this table contains both header and line item data.
Code:

*--------------------------------------------------------
REPORT ypat_create_delivery LINE-SIZE 256.
 
*--------------------------------------------------------
* Internal Tables
*--------------------------------------------------------
* Table to Hold Delivery Request
DATA: BEGIN OF tbl_request OCCURS 0.
INCLUDE STRUCTURE bapideliciousrequest.
DATA: END OF tbl_request.
 
* Table to hold Line Items Created
DATA: BEGIN OF tbl_items OCCURS 0.
INCLUDE STRUCTURE bapideliciouscreateditems.
DATA: END OF tbl_items.
 
* Table to hold BAPI Return Messages
DATA: BEGIN OF tbl_return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF tbl_return.
 
*--------------------------------------------------------
* Structures
*--------------------------------------------------------
DATA: st_vbak LIKE vbak,
st_vbap LIKE vbap.
 
*--------------------------------------------------------
* Selection Screen
*--------------------------------------------------------
PARAMETERS: p_vbeln LIKE vbak-vbeln,
p_posnr LIKE vbap-posnr DEFAULT '000010'.
 
*--------------------------------------------------------
* Start of Selection
*--------------------------------------------------------
START-OF-SELECTION.
 
SELECT SINGLE *
INTO st_vbak
FROM vbak
WHERE vbeln = p_vbeln.
 
CHECK sy-subrc EQ 0.
 
SELECT SINGLE *
INTO st_vbap
FROM vbap
WHERE vbeln = p_vbeln AND
posnr = p_posnr.
 
 
*--------------------------------------------------------* End of Selection
*--------------------------------------------------------
END-OF-SELECTION.
 
IF st_vbak IS INITIAL.
WRITE:/ 'Invalid Sales Order'.
EXIT.
ENDIF.
 
tbl_request-document_numb = st_vbap-vbeln.
tbl_request-document_item = st_vbap-posnr.
tbl_request-ship_to = st_vbak-kunnr.
tbl_request-sold_to = st_vbak-kunnr.
tbl_request-sales_organisation = st_vbak-vkorg.
tbl_request-distribution_channel = st_vbak-vtweg.
tbl_request-division = st_vbak-spart.
tbl_request-plant = st_vbap-werks.
tbl_request-quantity_sales_uom = '1'.
 
tbl_request-sales_unit = st_vbap-vrkme.
tbl_request-base_uom = st_vbap-meins.
tbl_request-material = st_vbap-matnr.
tbl_request-delivery_date = st_vbak-bstdk.
tbl_request-delivery_time = '160000'.
tbl_request-transp_plan_date = st_vbak-bstdk.
tbl_request-loading_date = st_vbak-bstdk.
tbl_request-goods_issue_date = st_vbak-bstdk.
 
tbl_request-extdelv_no = '98765'.
tbl_request-document_type = 'A'. "Delivery
tbl_request-document_type_predecessor = 'A'. "Sales Ord
 
tbl_request-document_type_delivery = 'LF'.
 
 
APPEND tbl_request.
 
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = tbl_request
createditems = tbl_items
return = tbl_return.
 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
 
LOOP AT tbl_return.
WRITE:/ tbl_return-type,
tbl_return-id,
tbl_return-number,
tbl_return-message.
ENDLOOP.
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.