How to process and monitor a simple file with AIF
During my work in AIF development I sometimes get questions from customers asking how different functionalities are working or what the best way is to solve a specific requirement with SAP Application Interface Framework. From time-to-time I like to describe the solutions to the most common problems in How-To-Guides. If you have a specific topic where it would be nice to have a How-To-Guide drop me a message with the topic request.
You have a file containing data which needs to be processed and monitored. The file containing the data is a flat file (the data contained in the file has no structural relationship between the records).
AIF provides the possibility to process and monitor flat files. During the processing of the file in AIF you can use all available mapping functionalities like checks, fix values, value mappings,… Afterwards the result of the message processing can be viewed in the Monitoring and Error Handling.
How does it work?
You need to perform the following steps to create an inbound file interface:
- Create the DDIC 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 setup a simple file interface.
This example uses the SAP flight booking example.
In order to execute this example we require a file containing some test data and corresponding structures.
Create a CSV file and add some entries:
|9999||Fritz Maier||Hauptstrasse 291||Stuttgart||DE||4242424242424242|
|9998||Edeltraud Fischer||Berliner Str. 8||Hamburg||DE||4299424123456789|
Use ; to separate the data.
1. Develop the Interface
Create RAW Structure
Create the RAW structure for your interface.
Create a DDIC structure for the line type re-sampling the content of the file. In our example the structure should look like this:
The name used for the structure in this example was ZAIF_BM_FILE_CUSTOMER.
Create a table type for the newly created structure. The table type used in this example was named ZAIF_BM_FILE_CUSTOMER_TT. The table type uses ZAIF_BM_FILE_CUSTOMER as line type.
Create the RAW structure for the interface. The structure contains only one component named LINES with the newly created table type as component type. The DDIC structure should look like this:
In this example ZAIF_BM_RAW_CUSTOMER is used as name for the RAW structure.
Save and activate all structures.
Create SAP Structure
Create the DDIC SAP structure for your interface. The SAP structure re-samples the data in the way it is required by the follow up processing in the system. In order to create the SAP structure we have to check the function module we will use to process the flight customer. In this example we will use function module BAPI_FLCUST_CREATEFROMDATA. The function module requires the customer data in a structure from type BAPISCUNEW. As we have several customers in our file we require a structure as shown below.
The structure will be created bottom to top. Therefore we start to create a structure to contain the customer data (in the example the structure is named as ZAIF_BM_CUSTOMER_DETAIL):
As our file can contain the data of several customer we again require a table type for the newly created structure. Create a table type ZAIF_BM_CUSTOMER_DETAIL_TT and use the newly created structure ZAIF_BM_CUSTOMER_DETAIL as line type.
Create the SAP structure for the interface. The structure contains only one component named CUSTOMERS with the newly created table type as component type. The structure should look like this:
In this example ZAIF_BM_SAP_CUSTOMER is used as name for the SAP structure.
Save and activate all structures.
2. Develop Interface
After creating the required structures for the AIF interface it is time to develop the interface itself.
Go to AIF customizing and navigate to –> Interface Development –> Define Namespace. Enter a name and description. In this example namespace ZBM_03 is used.
Go to AIF customizing and navigate to –> Interface Development –> Define Interfaces. Select your namespace and create a new interface. Enter a description and maintain the structures created in the first step.
Specify Interface Engines
To ensure the data is processed correctly by AIF the interface engines have to be maintained. Go to AIF customizing –> Interface Development –> Additional Interface Properties –> Specify Interface Engines and select your interface.The AIF file adapter is using AIFs own XML persistence and runtime. Therefore we have to set the Application and Persistene Engine for the interface to XML.
Define Structure Mappings
Go to the AIF customizing and create the mappings for the interface. –> Interface Development –> Define Structure Mappings select your interface.
In the Select source structure dialog create a new entry and select the structure part that will contain the line items. In this example select LINES.
Select the line and nativate to Assign Destination Structure on the left hand side. Create a new entry. As destination structure select the structure part of your SAP structure that will contain the customers.
Navigate to Define Field Mappings. Map all fields of the RAW structure to the corresponding field of the SAP structure. Create the following field mappings:
Use the forward navigation to jump into the action. Doubleclick the action to navigate forward.
Change the Action definition. Enter a meaningful description for the action and set the commit mode and the commit level. Maintain the main component type. The main component type is the name of the structure which is used to store the details of a flight customer in the SAP structure.
Navigate to Define Functions in the menu on the left hand side and create a new entry. If the Function Module does not yet exist you will be asked if you want to create the function module.
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:
CALL FUNCTION 'BAPI_FLCUST_CREATEFROMDATA' EXPORTING customer_data = curr_line-CUSTOMER_DATA IMPORTING customernumber = curr_line-id TABLES return = return_tab.
In addition CURR_LINE does not have a type yet. Navigate to the changing parameters and enter the associated type for parameter CURR_LINE (Hint: it should be the same type like the Main Component Type used in the step before).
Save and activate the function module.
3. Configure File Adapter
To be finally be able to process the file in AIF the details have to be specified. The configuration is done in the AIF customizing under System Configuration –> Configure File Adapter.
Select your namespace and create a new fileadapter configuration.
In this example we use a CSV file. To process the file correctly we have to select text file as type. The content of the file is a flat structure. Enter ; as Field Separator. The file contains a specified header line, therefore we have to select “Header Line Exists”. The final step is to enter the RAW structure name in field structure name. Beside the RAW structure the field in the structure that will contain the imported lines need to be selected. In this example the value for Field Name is LINES.
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.
You will be forwarded to a log view where the log messages which have occurred during upload are displayed.
5. Check Monitoring and Error Handling
The final step: check the result in the monitoring and error handling. Go to transaction /AIF/ERR and select your interface (if you did assign a recipient to the interface you can also jump to the Monitoring and Error Handling via Interface Monitor).
Press execute. You are forwarded to the Monitoring and Error Handling View. Check the messages displayed in the data messages view by double clicking on the interface name.
This is one possibility to create an AIF interface for a simple file upload.
This blog post gave an introduction on how to use the AIF file upload to process a flat file. As the file is processed by AIF it is possible to use all mapping functionalities provided by AIF. This is a very simple interface and therefore not all possible functionalities that can be used during the processing of a file in AIF are described here.