Vous êtes sur la page 1sur 10

Creating Sales Scheduling Agreement with Extensions using BAPI

By Arun Warrier, IBM India

Introduction:

A Scheduling Agreement is an outline agreement created between a Vendor and a Customer. A Sales
Scheduling Agreement (not to be confused with the Purchasing Scheduling Agreement) is a long term
Sales Agreement which contains the details of the delivery schedule and the deliveries are made to the
customer as per the schedule entered in the document.

The Transaction code for Creating a Sales Scheduling Agreement is VA31.

The objective of this document is to illustrate creation of Sales Scheduling Agreements with Extensions (Z
fields) using BAPI. In this scenario, a Z field (ZZMTLIFNR) that exist in VBAP (Sales order Line Item
Table) needs to be mapped using the BAPI for creation of Scheduling Agreement.

BAPI:

The BAPI used for Creation of Scheduling Agreements is SD_SALESDOCUMENT_CREATE.

The following parameters/tables need to be populated before the BAPI is called:

1. SALES_HEADER_IN

This structure needs to be populated with header level data of the scheduling agreement that needs
to be created.

Some of the parameters that are passed to this structure are:

1. DOC_DATE – Document date VBAK-AUDAT


2. DOC_TYPE – Document Type VBAK-AUART
3. SALES_ORG – Sales Organization VBAK-VKORG
4. DISTR_CHAN – Distribution Channel VBAK-VTWEG
5. DIVISION – Division VBAK-SPART
6. PURCH_DATE - Purchase Date VBAK-BSTDK
7. CT_VALID_F – Valid from date VBAK-GUEBG
8. CT_VALID_T – Valid to date VBAK-GUEEN
9. PRICE_DATE – Pricing Date VBAK-PRSDT

2. SALES_HEADER_INX

The fields in this structure needs to be populated with ‘X’, if they are being populated in the structure
SALES_HEADER_IN.

For e.g. if SALES_HEADER_IN-DOC_DATE is getting populated with a value say 11/01/2010, then
SALES_HEADER_INX-DOC_DATE should be set to ‘X’.

Code snippet for populating these two structures is given below:


Also the field SALES_HEADER_INX-UPDATEFLAG needs to be set to ‘I’.

3. SALES_ITEMS_IN

This table needs to be populated with item level data of the scheduling agreement that needs to be
created.

The parameters that are passed to this table are:

1. ITM_NUMBER - Item Number VBAP-POSNR


2. MATERIAL - Material Number VBAP-MATNR
3. PLANT - Plant VBAP-WERKS
4. ITEM_CAT - Item Category VBAP-PSTYV
5. TARGET_QTY - Target Quantity VBAP-ZMENG
6. CUST_MAT35 - Customer Material VBAP-KDMAT
7. REASON_REJ - Reason for Rejection VBAP-ABGRU

4. SALES_ITEMS_INX
The fields in this structure needs to be populated with ‘X’, if they are being populated in the structure
SALES_ITEMS_IN.

Code snippet for populating these two structures is given below:

The UPDATEFLAG in SALES_ITEMS_INX table needs to be set to ‘I’ (for insert).

The workareas are appended to the internal table.

5. SALES_PARTNER

This table should be populated with Partner Level Information (Sold to Party, Ship to Party Etc) of the
document. The parameters that need to be passed are:

1. PARTN_ROLE - Partner Role - VBPA-PARVW

2. PARTN_NUMBER – Partner Number – VBPA-KUNNR


3. ITM_NUMBER - Item Number - VBPA-POSNR – This field needs to be populated with ‘000000’ for
Header Level Partner and VBAP-POSNR for Item Level Partner.

6. SALES_SCHEDULES_IN

This table is populated with Schedule Line Level Data of the Document.

The following parameters need to be populated:

1. ITM_NUMBER - Item Number - VBEP-POSNR


2. SCHED_LINE - Schedule Line - VBEP-ETENR
3. REQ_DATE - Required Quantity VBEP-WMENG
4. REQ_DATE - Required Date VBEP-EDATU

7. SALES_SCHEDULES_INX

The fields in this structure needs to be populated with ‘X’, if they are being populated in the structure
SALES_SCHEDULES_IN.
Work area is appended to the Internal Table

8. SALES_TEXT

The parameters in this table are populated with header level and item level texts which need to be
populated for the Scheduling Agreement.

The parameters of this table which need to be filled are:

1. ITM_NUMBER Item Number - VBAP-POSNR for Item Level Text and ‘000000’ for Header
Level Text
2. TEXT_ID Text Id
3. TEXT_LINE Text Line -The actual text which needs to be populated
4. FUNCTION Function - needs to be populated with ‘009’ (Insert)
9. EXTENSIONIN

This table needs to be populated for populating the Z fields at Header or Item Level of the Schedule Line
agreement.

In this scenario, we will see how a Z field at the item level (VBAP-ZZMTLIFNR) is populated using the
BAPI.

The following procedure needs to be followed:

 The field ZZMTLIFNR already exists in VBAP table through customer append of structure
ZMOTC_LIFNR.

 Enhance Structure BAPE_VBAP by appending a structure (ZMSOTC_LIFNR) which contains the


two fields – ZZMTLIFNR and ZZMTIDNEX.
 Enhance BAPE_VBAPX by appending structure (ZMSOTC_LIFNRX) containing two flag fields –
ZZMTLIFNR (single character) and ZZMTIDNEX (single character). This structure has to be
enhanced because the BAPIs work with checkboxes.
 Enhance Structure VBAPKOZ by appending a structure (ZMSOTC_LIFNR_COM) which contains
the two fields – ZZMTLIFNR and ZZMTIDNEX.
 Enhance VBAPKOZX by appending structure (ZMSOTC_LIFNR_COMX) containing two flag
fields – ZZMTLIFNR (single character) and ZZMTIDNEX (single character). This structure has to
be enhanced because the BAPIs work with checkboxes.

 Adjust the following structures for customer enhancements to table VBAK:


a) VBAKKOZ
b) VBAKKOZX
c) BAPE_VBAK
d) BAPE_VBAKX
 Adjust the following structures for customer enhancements to table VBEK:
a) VBEPKOZ
b) VBEPKOZX
c) BAPE_VBEP
d) BAPE_VBEPX
 Now the structural enhancements have been done and the coding part has to be done in this
manner :
Populate EXTENSIONIN-STRUCTURE with ‘BAPE_VBAP’.
Populate 11th to 26th character EXTENSIONIN-VALUEPART1 with string which is a
concatenation of fields VBAP-POSNR and VBAP-ZZMTLIFNR.
The first 10 characters of EXTENSION-VALUEPART1 are reserved for VBAP-VBELN and the Z
fields to be populated are passed to VALUEPART1 as subsequent characters of this field.
Append this record to table EXTENSIONIN.
Populate EXTENSION-STRUCTURE with BAPE_VBAPX.
Populate 11th to 17th characters of EXTENSIONIN-VALUEPART1 with a string which is a
concatenation of fields VBAP-POSNR and ‘X’.
The first 10 characters of EXTENSION-VALUEPART1 are reserved for VBAP-VBELN and the Z
fields to be populated are passed to VALUEPART1 as subsequent characters of this field.
Append this record also to table EXTENSIONIN.

Now all the parameters that need to be passed to the BAPI have been populated. The BAPI will be
called now:

The scheduling agreement that is created is returned in the importing parameter SALESDOCUMENT_EX
and if the RETURN table does not have any error messages or abort messages then
BAPI_TRANSACTION_COMMIT is called.

In this manner a Sales Scheduling Agreement with Extensions is created using BAPI.