Functional Specification Document
1. Document Control
Document Title: Implementation of BAPI_INCOMINGINVOICE_CREATE for Invoice
Posting
Version: 1.0
Prepared By: M. Waqas Kandawala
Date: 10.12.2024
Approved By: Kamil
Approval Date:
2. Purpose
The purpose of this document is to provide a detailed specification for implementing the BAPI
BAPI_INCOMINGINVOICE_CREATE in S/4HANA to handle invoice postings for incoming vendor
invoices.
3. Scope
The implementation will automate the posting of vendor invoices via the specified BAPI in
S/4HANA. This solution will:
Accept invoice data from an external system or file.
Validate the data against SAP master data and business rules.
Post the invoices into SAP S/4HANA and return results to the source system.
4. Requirements
4.1. Functional Requirements
1. Input Data Structure
o Invoice Header Information: Vendor, Document Date, Posting Date, Currency,
Reference, etc.
o Invoice Item Information: Purchase Order (PO) details, GL accounts, cost centers,
tax codes, and amounts.
o Payment Terms: Relevant payment terms linked to vendor or invoice.
o Attachments: Optional support for attaching documents to the invoice.
2. Process Workflow
o Validate incoming data for completeness and correctness.
o Map external fields to SAP structures for BAPI input.
o Call BAPI_INCOMINGINVOICE_CREATE to post the invoice.
o Handle BAPI response and update external system with success or error
messages.
3. Error Handling
o Log validation errors and BAPI execution errors.
o Provide detailed error feedback to the external system.
4. Audit and Reporting
o Maintain logs of all invoices posted.
o Provide reporting capabilities for posted invoices and errors.
1. Header Data (HEADERDATA)
Field Name Data Type Length Description Mandatory/Non-Mandatory
COMP_CODE CHAR 4 Company Code Mandatory
DOC_DATE DATE 8 Document Date Mandatory
PSTNG_DATE DATE 8 Posting Date Mandatory
REF_DOC_NO CHAR 16 Reference Document Number Mandatory
CURRENCY CUKY 5 Currency Mandatory
DOC_TYPE CHAR 2 Document Type Mandatory
HEADER_TXT CHAR 25 Header Text Non-Mandatory
GROSS_AMOUNT DEC 15 Gross Amount Mandatory
2. Item Data (ITEMDATA)
Data
Field Name Length Description Mandatory/Non-Mandatory
Type
Purchase Order
PO_NUMBER CHAR 10 Mandatory for PO-based invoices
Number
PO_ITEM NUMC 5 Purchase Order Item Mandatory for PO-based invoices
ITEM_AMOUNT DEC 15 Amount for the Item Mandatory
QUANTITY DEC 13 Quantity Non-Mandatory
Mandatory for non-PO-based
GL_ACCOUNT CHAR 10 GL Account
invoices
COSTCENTER CHAR 10 Cost Center Non-Mandatory
TAX_CODE CHAR 2 Tax Code Mandatory
ITEM_TEXT CHAR 50 Item Text Non-Mandatory
3. GL Account Data (GLACCOUNTDATA) (For non-PO based invoices)
Field Name Data Type Length Description Mandatory/Non-Mandatory
GL_ACCOUNT CHAR 10 GL Account Number Mandatory
Field Name Data Type Length Description Mandatory/Non-Mandatory
ITEM_AMOUNT DEC 15 Amount for the GL Account Mandatory
COSTCENTER CHAR 10 Cost Center Non-Mandatory
PROFIT_CENTER CHAR 10 Profit Center Non-Mandatory
TAX_CODE CHAR 2 Tax Code Mandatory
4. Withholding Tax Data (WITHHOLDTAXDATA)
Data Mandatory/Non-
Field Name Length Description
Type Mandatory
WI_TAX_TYPE CHAR 2 Withholding Tax Type Non-Mandatory
WI_TAX_CODE CHAR 2 Withholding Tax Code Non-Mandatory
Withholding Tax Base
WI_TAX_BASE DEC 15 Non-Mandatory
Amount
WI_TAX_AMOUNT DEC 15 Withholding Tax Amount Non-Mandatory
5. Currency Data (CURRENCYDATA)
Field Name Data Type Length Description Mandatory/Non-Mandatory
CURRENCY CUKY 5 Currency Code Mandatory
CURRENCY_ISO CHAR 3 ISO Currency Code Non-Mandatory
EXCH_RATE DEC 9 Exchange Rate Non-Mandatory
6. Return Parameter (RETURN)
Field Name Data Type Length Description Mandatory/Non-Mandatory
TYPE CHAR 1 Message Type (S/E/W) Output Only
CODE CHAR 5 Message Code Output Only
MESSAGE CHAR 220 Message Text Output Only
LOG_NO CHAR 20 Application Log Number Output Only
Notes:
5. Mandatory fields depend on the invoice type (PO-based or non-PO-based). For
example:
o PO_NUMBER and PO_ITEM are mandatory for PO-based invoices.
o GL_ACCOUNT is mandatory for non-PO-based invoices.
6. TAX_CODE is usually required for tax calculations.
7. All currency-related fields must be consistent, including CURRENCY and EXCH_RATE (if
multi-currency scenarios apply).
8. Some fields like HEADER_TXT, ITEM_TEXT, and COSTCENTER are optional but
recommended for better reporting and clarity.
5. Design
5.1. Technical Design
BAPI Name: BAPI_INCOMINGINVOICE_CREATE
1. Input Parameters
The BAPI requires the following structures:
o HEADERDATA: Invoice header data (e.g., COMP_CODE, DOC_DATE, REF_DOC_NO, etc.).
o ITEMDATA: Invoice line items (e.g., PO_NUMBER, PO_ITEM, ITEM_AMOUNT, etc.).
o GLACCOUNTDATA: GL Account details (optional for non-PO invoices).
o WITHHOLDTAXDATA: Withholding tax details (if applicable).
o RETURN: Structure to capture error/success messages.
2. Output
o INVOICEDOCNUMBER: Invoice document number generated by SAP upon
successful posting.
o RETURN: Detailed error/success messages.
3. Execution Flow
o Validate the input data using a custom ABAP program or middleware.
o Populate BAPI structures with the validated data.
o Execute BAPI_INCOMINGINVOICE_CREATE using an ABAP program or an
integration layer (e.g., SAP PI/PO, SAP Cloud Integration).
o Commit the work using BAPI_TRANSACTION_COMMIT or rollback using
BAPI_TRANSACTION_ROLLBACK based on the response.
o Return the results (invoice document number or error details) to the calling
system.
5.2. Data Validation
Validate the vendor is active and valid in the given company code.
Check the PO number exists and matches the vendor.
Validate GL accounts, cost centers, and tax codes against master data.
Ensure the invoice amount matches the PO or specified tolerance limits.
5.3. Custom Enhancements
Mapping Logic: Use custom mapping for field transformation from external systems to
SAP structures.
Logging: Implement logging for successful and failed postings.
Extensions: Allow additional fields if required by specific business processes.
6. Integration
External Systems: Receives data from [Specify Source System] in [Format, e.g., XML,
JSON, IDoc].
Middleware: [Specify Middleware, if applicable, e.g., SAP PI/PO or SAP Cloud
Integration].
7. Test Plan
7.1. Test Scenarios
1. Successful Invoice Posting
o Input: Valid invoice data for PO and non-PO-based invoices.
o Output: Invoice document created in SAP.
2. Validation Errors
o Input: Missing/incorrect vendor or PO details.
o Output: Error messages in RETURN table.
3. Duplicate Invoice
o Input: Duplicate invoice reference for the same vendor.
o Output: Duplicate invoice error.
4. Tolerance Exceedance
o Input: Invoice amount exceeding configured tolerance.
o Output: Tolerance error in RETURN.
7.2. Test Data
Prepare sample data for each test scenario, including edge cases (e.g., large invoice amounts,
multiple line items).
8. Security
Ensure user roles and authorizations for calling the BAPI are configured correctly.
Restrict access to sensitive fields (e.g., bank details, tax data).
9. Performance
Optimize the ABAP program to handle bulk processing of invoices.
Test the system for high-volume scenarios to ensure acceptable performance.
10. Deliverables
ABAP program to call BAPI_INCOMINGINVOICE_CREATE.
Test case documentation and test results.
User manual for the solution.
11. Approval
Name Rol Signature Date
e