Introduction:
In modern enterprise integration scenarios, organizations often exchange file-based data that includes multiple layers of structured information—typically comprising header records and their associated item records. Accurately processing these complex file formats is vital to ensure seamless and reliable data exchange between systems.
SAP’s Application Integration Framework (AIF) offers a comprehensive solution for managing such integrations. It supports the definition and handling of complex data structures, including nested models where each header can be linked to multiple item records. This capability enables flexible interface design and robust data validation, making AIF an ideal choice for processing structured file content in SAP environments.
By utilizing AIF’s features, organizations can streamline file-based integrations and enhance data consistency across systems.
Problem Description
In enterprise integrations, companies often receive files from external systems that contain structured data—like sales orders with headers and related item details. These files can be complex, with multiple layers of information that need to be grouped and processed correctly.
Standard file processing in SAP can struggle with this kind of nested data. Common issues include:
- Difficulty linking items to the correct headers
- Risk of data mismatches
- Complicated custom code for parsing and validation
- Limited tools for tracking and fixing errors
SAP Application Integration Framework (AIF) helps solve these problems by supporting complex data structures. It allows headers to be connected to multiple items and provides tools for parsing, validating, and monitoring the data. However, setting up AIF for this requires careful planning and configuration to ensure everything works smoothly.
How does it work?
You need to perform the following steps to create an inbound file interface:
- Create the RAW structures for the interface
- Develop the interface
- Configure the file adapter settings for your interface
- Upload File
- Check Monitoring and Error Handling transaction
The following example will describe step-by-step how to Configure AIF for Complex File Data with Multiple Header-Item in Flat File
Simple example of a Sales Order creation in SAP, showing how the Header, Item, and Schedule Line levels are organized
Prepare the Flat File (CSV Format)
Create a .csv file using a pipe (|) as the delimiter. Here's a simple structure:
In order to execute this example, we require a file containing some test data and corresponding structures.
Explanation:
- HEAD = Header line (Sales Order Number, Date, Customer, Sales Org, Currency)
- ITEM = Item line (Item Number, Material, Material Description, Quantity, Price)
- SCHD = Schedule line (Item Number, Schedule Line Item, Delivery Date, Quantity)
1. Create Raw Structures for the interface
🔧 Step 1: Create DDIC Structures
1.1 Header Structure – YAIF_ORDER_HDR
Field Name | Data Element | Description |
ORDER_NO | VBELN | Sales Order Number |
ORDER_DATE | AUDAT | Document Date |
CUSTOMER_ID | KUNNR | Customer Number |
VKORG | VKORG | Sales Organization |
CURRENCY | WAERS | Currency |
1.2 Item Structure – YAIF_ORDER_ITEM
Field Name | Data Element | Description |
ITEM_NO | POSNR | Item Number |
MATNR | MATNR | Material Number |
MAKTX | MAKTX | Material Description |
MENGE | MENGE_D | Quantity |
AMOUNT | NETPR | Price |
1.3 Schedule Line Structure – YAIF_ORDER_SCHEDULE_LINE
Field Name | Data Element | Description |
POSNR | POSNR | Item Number |
ETENR | ETENR | Schedule Line Number |
DELIVERY_DATE | EDATU | Delivery Date |
BMENG | BMENG | Delivery Quantity |
📦 Step 2: Create Table Types
2.1 Item Table Type – YAIF_ORDER_ITEM_TT
- Line Type: YAIF_ORDER_ITEM
2.2 Schedule Line Table Type – YAIF_ORDER_SCHEDULE_LINE_TT
- Line Type: YAIF_ORDER_SCHEDULE_LINE
🧩 Step 3: Create Composite Structure
3.1 Detail Structure – YAIF_ORDER_DTL
Field Name | Type | Description |
HEADER | YAIF_ORDER_HDR | Header Structure |
ITEM | YAIF_ORDER_ITEM_TT | Table of Items |
SCHEDULE_LINE | YAIF_ORDER_SCHEDULE_LINE_TT | Table of Schedule Lines |
3.2 Table Type – YAIF_ORDER_DTL_TT
- Line Type: YAIF_ORDER_DTL
3.3 RAW Structure – YAIF_ORDER_DTL_S
Create the RAW structure for the interface. The structure contains only one component named
- Component Name: ORDER
- Component Type: YAIF_ORDER_DTL_TT
2. Develop the interface
🚀 Step 4: Configure AIF Interface
4.1 Define Namespace
- Use transaction /AIF/CUST
Click->Define namespace (e.g. YSALE)
4.2 Define Interfaces
Click->Define Interface
4.3 Specify Interface Engines
- Assign the SAP Application Engine
Click->Additional Interface Properties->Specify Interface Engines
4.4 Assign Source Structure Line
Click->Define Structure Mappings
4.4.2 Assign Destination Structure
Select source structure line->Click->Assign Destination Sturcture
4.4.3 Assign Actions
- Create an action (e.g. SALE_CREATE)
Click->Assign Action
Click Enter on Action to create the action is action is not created
Click->Define Function ( To assign Function Module )
Double-click to create the Function Module that processes the data if not created
Navigate into the new function module by double clicking the name. In the function module call the follow up processing by inserting the coding displayed below:
*// Sample Logic
CALL FUNCTION 'BAPI_CUSTOMER_CREATE
EXPORTING
customer_data = CURR-HEADER
customer_item = CURR-ITEM
schedule_line = CURR-SCHEDULE_LINE
TABLES
return = return_tab.
Save and activate the function module.
3. Configure the file adapter settings for your interface
Click-> System Configuration->Configure File Adapter
- File Type (ASC or BINARY)
- File Content (Flat Structure, Complex Structure, XML, USER, XSLX )
- Text Type (Fix char, Special Character Separator)
- Offset Type Det Val (To Identify the record type from where it will start i.e HEAD, ITEM, SCHD line Details to prepare the data structure dynamically)
- Length Type Det Val (Length of identity record type in i.e in our case first 4 character of new line)
- Del Deter Val (True means ignore 1st Field separator immediately after the Det Value)
Leading Type (If we mark the record type as 'true', it means a new record will start from the file)
4. Upload File
The final step is to select and upload the file. The AIF File Upload can be found in the SAP Menu under SAP Menu -> Cross-Application Components --> SAP Application Interface Framework --> File Upload (or directly via transaction /AIF/LFA_UPLOAD_FILE).
Select your File Adapter Configuration (Config. Namespace and Config ID created in step 3). In section Upload from select the path where your file is stored.
Press executes.
5. Check Monitoring and Error Handling transaction
You will be forwarded to a log view where the log messages which have occurred during upload through below T-Code.
- T-Code : /AIF/ERR , /AIF/IFMON