ABAP Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 

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:

  1. Create the RAW structures for the interface
  2. Develop the interface
  3. Configure the file adapter settings for your interface
  4. Upload File
  5. 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.

pratik_shah9_25-1755709358100.png

pratik_shah9_26-1755709358101.png

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

pratik_shah9_27-1755709358103.png

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

pratik_shah9_28-1755709358104.png

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

 pratik_shah9_29-1755709358106.png

📦 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

pratik_shah9_30-1755709358108.png

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

pratik_shah9_31-1755709358109.png

 2. Develop the interface

🚀 Step 4: Configure AIF Interface

4.1 Define Namespace

  • Use transaction /AIF/CUST

pratik_shah9_32-1755709358114.png

Click->Define namespace (e.g. YSALE)

pratik_shah9_33-1755709358116.png

4.2 Define Interfaces

Click->Define Interface

 pratik_shah9_34-1755709358121.png

4.3 Specify Interface Engines    

pratik_shah9_35-1755709358125.png

  • Assign the SAP Application Engine

Click->Additional Interface Properties->Specify Interface Engines

pratik_shah9_36-1755709358128.png

4.4 Assign Source Structure Line

pratik_shah9_0-1755711217761.png

Click->Define Structure Mappings

pratik_shah9_37-1755709358130.png

4.4.2 Assign Destination Structure

Select source structure line->Click->Assign Destination Sturcture

pratik_shah9_50-1755710068080.png

4.4.3 Assign Actions

  • Create an action (e.g. SALE_CREATE)

Click->Assign Action

pratik_shah9_38-1755709358135.png

Click Enter on Action to create the action is action is not created

pratik_shah9_39-1755709358140.png

pratik_shah9_40-1755709358144.png

Click->Define Function ( To assign Function Module )

Double-click to create the Function Module that processes the data if not created

pratik_shah9_41-1755709358147.png

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

pratik_shah9_42-1755709358152.png

  • 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)

pratik_shah9_43-1755709358156.png

Leading Type (If we mark the record type as 'true', it means a new record will start from the file)

pratik_shah9_44-1755709358160.png

pratik_shah9_45-1755709358164.png

pratik_shah9_46-1755709358167.png

pratik_shah9_47-1755709358169.png

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.

pratik_shah9_48-1755709358173.png

pratik_shah9_49-1755709358177.png

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
6 Comments
Labels in this area