How to import CSV with dynamic file names into SAP BW


Written By: Sebastian - 21 September 2020
(updated on: 23 January 2023)

For larger companies with a broad system landscape, it is sometimes necessary to import data into BW via the flat file interface. The file names have a timestamp and change daily. In this article I will show you how to load these files automatically.

When coordinating data flows, we often face the challenge of connecting certain systems to SAP BW. For example, missing interfaces are often a problem. In this case, information is exported to a CSV file, which is then imported into BW. This process is repeated daily. In order to distinguish the files from each other, the creation date is appended to the file name. Thus the file name changes daily, which creates another challenge when automating the loading process. This can be solved using a couple of lines of ABAP.

For a better understanding I will use a concrete example. A flat file with the data of a legacy system is stored daily in the /tmp/ directory of the SAP server. You can view the directory using transaction AL11. The stored files are differentiated by the current date in the file name. For example, actuals_20190918.csv.

Folder Overview

So, the complete file path is /tmp/actuals_20190918.csv. It consists of a fixed (folder and file name) and a variable part (the current date). To determine the file path automatically, we have to program a routine.

SAP BW, HANA Native and SAP Datawarehouse Cloud - Download the comparison

New call-to-action

To do this, switch to your InfoPackage or DTP (for extraction without PSA) and select the option Load Text-Type File from Application Server under Adapter 1. Then click on Create Routine for File Name under File Name 2.

DataSource Parameter

Now enter the name for the routine and click on Editor.

Enter name for the routine

The file name is determined via the parameter p_filename. If you want to load the file with the current date, you can do this with only one line of code. We use the system variable sy-datum, which outputs the current date.

p_filename = |/tmp/actuals_{ sy-datum }.csv|.

If you want to load the file of the previous day, use the following code.

  DATA: lv_vortag TYPE sy-datum.

  lv_vortag = sy-datum - 1.

p_filename = |/tmp/actuals_{ lv_vortag }.csv|.

Save the changes and activate the DTP or InfoPackage.

The load process can now be executed automatically. The name of the file to be loaded is updated each time. This ensures that the latest file is always loaded.

Learn more about SAP BW

Image Source: Alex Knight from Pexels

Topics: SAP BW/4HANA, Master Data & Data Import in SAP BW

Share article