Import and export of CSV files in SAP

CSV files are still a popular and easy way to import data into or export from SAP.

We have developed a framework with which it is possible to import any type of CSV file into an 'internal table'. The only requirement is to create the table structure of the 'Internal Table' in the ABAP Dictionary.

In the first step, the data is read into a string table either locally from the PC or from the application server. In the second step, the data is converted into the 'internal table'.

Due to the field definition in the ABAP Dictionary, a syntactical check for the respective data type takes place automatically. For example, integer values ​​and floating-point numbers (amount fields) can be checked for content and their minimum and maximum length and scope. Likewise date/time fields, language and currency, CHAR fields and their defined length.
Special attention is paid to the date. When importing CSV files, a wide variety of date formats are used, which need to be converted into the SAP internal format. If a date format is used which is not defined in SAP or on the executing user (table USR01), you can specify your own date format globally or via the field definition (see below) for each field. For example, the date 15/16/1 in the form DD/YY/MM can be recognized as 15.01.2016.

In addition, it is possible to transfer a list of field definitions from the calling program. This allows customer-specific checks to be triggered for individual data fields in the 'internal table'.
It is possible to extend the structure of the field definitions using a customer include (CI_) with customer fields. Here you have additional options for data checking with your own programming.

Errors occurring during the conversion are logged and returned in the form of a BAPIRET2 table including line number and field name.

designation Description
Field name Name of a field from the 'internal table' for which the check takes place
Must/Can Defines the field as a mandatory or optional field. A mandatory field must not be initial (empty).
Initial Allowed Makes it possible to also read in a mandatory field initially. This is necessary, for example, for a checkbox where an empty value is also to be read.
Mandatory field if reference field is not empty Field name of a reference field from the 'internal table'. If the reference field is filled with a value, the current field becomes a mandatory field.
Eg Amount and Currency... If the reference field 'Amount' contains a value, the current field 'Currency' becomes mandatory.
default value If a field is initial, it will be filled with the specified default value.
replace values A read value can be replaced by another. For example, the word 'ja' or 'yes' can be replaced with a '1'. Substitutions can be specified multiple times.
valid values The read value can be checked with the valid values ​​specified here.
For example, only certain wage types can be defined as valid when importing 'additional payments' (infotype 0015).
Format Date fields only.
Definition of a date format to identify the correct date.
The form DD/YY/MM shows the date 15/16/1 to be imported as 15.01.2016/XNUMX/XNUMX.

Conversely, you can also export data from SAP. To do this, the data in an 'internal table' is converted into a string table and stored locally on the PC or on the application server as a CSV file.

When converting, as when importing, there is a syntactical check, which can also be set via the field definition, by the customer. Here, too, a date is converted into the appropriate target format according to the field definition.

In addition, the framework includes other helper methods with which it is possible to carry out various directory and file operations.

  • Selection of directories and files
  • Existence check of directories and files
  • Reading customer directories on the application server

Do you have any futher questions on this topic Import and export of CSV files in SAP?

Feel free to contact us via the below Contact.

We will use all information provided here solely in accordance with the Privacy policy use.

Thank you for your message, it has been sent.
There was an error, please try again.
Share this post