SAP: how to use RFBIBL00 (with sample code)

RFBIBL00 is an SAP standard program used for importing accounting data into an SAP system. It processes a text file in a specific format. Unfortunately, documentation for this program is scarce, and as far as I know, SAP does not provide any sample program for handling RFBIBL00.

The main purpose of the program is to generate batch input sessions. Alternatively, it is also offered to post the data directly. However, this can lead to problems if errors occur during processing. The call of RFBIBL00 must be designed to be restartable in such cases.

Since RFBIBL00 is already not trivial to use, direct posting of data makes it even more challenging to handle the import correctly. Therefore, the standard batch input approach should be preferred.

The program name RFBIBL00

What is the meaning of the program name RFBIBL00?

  • RF stands for “remote function”. So this is a progam that is called from outside of SAP
  • BI stands for “bank interface”
  • BL stands for “bank ledger”

The documentation for RFBIBL00

SAP provides documentation for RFBIBL00: Go to transaction SE38 and click on “Documentation” there.

However, this documentation does not go much beyond generalities. I hope that my explanations will help you make sense of this documentation.

The file format of RFBIBL00

RFBIBL00 expects an input file consisting of lines of these datatytes:

The structures are:

  • BGR00 record type 0 session prefix
  • BBKPF record type 1 header data
  • BBSEG record type 2 document segment data
  • BBTAX record type 2 document taxes
  • BWITH record type 2 document withholding tax data
  • BSELK record type 2 selection header data (FB05 only)
  • BSELP record type 2 selection items (FB05 only)

Each line begins with a field that identifies the record type, allowing rfbibl00 to assign the lines of the input file correctly. The fields need to be written in the full width of their respective field types. The format thus resembles the internal IDOC format (line by line, not the XML variant). You can create these lines by generating variables of the respective types and writing them to a text file (see below).

You can look up the meaning of the fields in the Data Dictionary (transaction SE11) for BBKPF und BBSEG. These structures are long, containing dozens of fields, not all of which are required. Many of these fields may not need to be set. Therefore, in the input file, they need to be marked as “do not process this field”. It is not sufficient to leave them empty (blank). Leaving them blank would mean that the field would be set as blank in the input dialogs during posting. Instead, the fields to be ignored must be specifically marked.

How to mark unused fields

For these purposes, a special character is used. The default setting is “/”. So, an unused field with a width of 5 characters should be filled with “/////”. During the program call of rfbibl00, it is also possible to specify any other character in the parameters, but the default “/” is a good choice.

There is a simple way to set all fields of a structure to this value. A variant of the ABAP clear command allows pre-filling a structure in full width:

constants:
  co_nodata         type char1       value '/'.

data: ls_bbseg      type bbseg.

clear ls_bbseg with co_nodata.

After that, all fields within ls_bbseg are filled with ‘/////////’ in full width.

Basic structure of an import program using rfbibl00

Our goal is to use RFBIBL00 to automatically upload a certain amount of booking data into the SAP system. I am not aware of your specific case, but the basic structure of this task should be the same. You need to solve the following sub-tasks:

  • Open the input data in an external format: The data you want to import will originate from some external program. The output format is likely to be some kind of proprietary program that the other company is not willing to change. Otherwise, you could have asked the other company to provide the data in a standard format like IDoc. So here we assume that you have to process a proprietary CSV format.
  • Process a CSV file: Ensure that you receive the data in CSV format. Do not accept Excel files in XLS format, as these are much more complicated to process. In principle, you can also process Excel files in SAP, but CSV is much simpler. Allow the user to upload the file via the SAP GUI from their local machine. Read the file line by line and split each line into its cells. Be mindful of escape sequences (if you use a semicolon as a delimiter, a text cell can also contain a semicolon if its content is enclosed in quotation marks). For this purpose, you can use the SAP standard function ‘RSDS_CONVERT_CSV’, with parameters such as the delimiter (e.g., semicolon), escape character (e.g., double quotation marks), and the text line. The return value can be a table of strings (lt_columns) for extracting the payload data correctly and populating the input structures of rfbibl00. You can find a detailed guide on how to read a CSV file here.Opens in a new tab.
  • Create a temporary file on the Application Server from the input data:
open dataset pa_fname for output in text mode encoding default.
data: ls_bgr00 type bgr00, " session header
" todo: session header füllen
transfer ls_bgr00 to pa_fname
data: ls_bbkpf type bbkpf
" todo: fill header data
transfer ls_bbkpf to pa_fname.
data: ls_bbseg type bbseg
" todo: fill segment data
transfer ls_bbseg to pa_fname
" repeat this for all segments of current dodument
" maybe: fill more header and segment records
close dataset pa_fname
" call rfbibl00

Details might vary, depending on which kind of data your CVS file contains. For this, I can only give you a general guideline.

Marking the record types

As mentioned above, there are various types of data lines. All rows need to fill a field called “stype.” This field must be set to 0 for the session header, 1 for bbkpf, and 2 for the segments.

Additionally, in bbseg, the column tbnam must be set to ‘BBSEG’. This is because multiple segment types (as mentioned above) share the line type 2.

Based on these entries, rfbibl00 can detect the record type of each input line and process them accordingly.

It is also essential to set ls_bbkpf-tcode = ‘FB01’. Each BKPF block (along with its subsequent segments) specifies the transaction to be used to book the data. If the transaction is not set, the import will fail abruptly.

How to fill the data fields

So, how can you determine which fields need to be filled and how?

First, examine the data structures for BBKPF and BBSEG in SE11 (or use SE16 on table dd03l). These data structures are extensive, and most of these fields may not require filling.

Next, analyze your input data (your CSV file). Discuss it with the customer: what do these fields mean? Have them demonstrate the manual posting that you are automating. The better you understand what happens during the manual process, the more likely you’ll correctly assign the fields during the import.

Then, try to perform the posting (likely FB01) yourself. In the input screens of FB01, use F1 to display the technical help for each field. Note the technical names of the individual elements. Then, try to find these fields in BBKPF and BBSEG.

Caution: The successfully posted documents are stored in BKPF (header data) and BSEG (line item data). However, the import data structures are named BBKPF and BBSEG, and they may differ in their columns. You can see this clearly in SE16 on table DD03L (enter both table names BSEG and BBSEG, then sort the shared field list alphabetically).

You might need to search or experiment for a while to find some fields. Take your time. The better you understand the manual booking, the better you can automate it.

How to fill the header data in BBKPF

Here are the fields that I fill in my import:

" => Incremental document id. These lines belong together.
ls_bbkpf-idxsp = lf_curdoc.
" Company code
ls_bbkpf-bukrs = ...
" Document type
ls_bbkpf-blart = 'KR'.
" External document number
ls_bbkpf-xblnr = ...
" Document date
ls_bbkpf-bldat = ...
" Posting date
ls_bbkpf-budat = ... 
" Currency
ls_bbkpf-waers = ...
" Document text
ls_bbkpf-bktxt = ...
" Transaction code
ls_bbkpf-tcode = 'FB01'.
" End of record, it's necessary
s_bbkpf-sende = 'X'.

How to fill the segment data in BBSEG

For the line item data, you will need more than one segment. Together, they must balance according to the principles of double-entry bookkeeping. Otherwise, SAP will not post the document, and the document will remain in SM35 as an erroneous batch input session.

" Incremental document ID, same value as in BBKPF
ls_bbseg1-idxsp = lf_curdoc.
" Account number
ls_bbseg1-newko = ...
" Amount
ls_bbseg1-wrbtr = ...
" Posting key
ls_bbseg1-newbs = ...
" External reference (my customer also wanted to have a reference at the segment level)
ls_bbseg1-xref3 = ...
" Reference to order in SAP
ls_bbseg1-aufnr = ...
" End of record, This field is important!
ls_bbseg1-sende = 'X'.

In places where I have written “…” you should use your data source, for example,
= lt_columns[ xy ]
if the corresponding field in your CSV file is in column xy after processing an input file line into an array of string.

The fields “sende” (German: “Satzende” for “end of record”) are important. If they are not set, a “forground posting” may result in additional pop-ups for which I have not set corresponding data. This can cause the posting process to get stuck. A “background posting” posting in SM35 will then not produce any results.

Calling rfbibl00

You must first write your data (as mentioned above) into a temporary file on the application server, which will then be fed into rfbibl00. The call could look like this:

    SUBMIT rfbibl00 WITH ds_name  = uf_dsout   " File name
                    WITH fl_check = abap_false " Only check file
                    WITH os_xon   = abap_false " Old structures?
                    WITH xnonunic = abap_false " Non unicode
                    WITH callmode = 'B'        " Batch-Input mode
                    WITH max_comm = '1000'     " Max documents per COMMIT
                    WITH pa_xprot = uf_btclog  " extended protocol
                    WITH xpop     = abap_false " Messages as window
                    WITH xlog     = abap_false " Messages as list
                    WITH xinf     = abap_true  " No messages
                    AND RETURN.


If you have an input file on the test system, call rfbibl00 with the parameter xlog=abap_true and review the error messages. It will take some time to resolve these errors. Eventually, the import should run without errors, and it will generate a batch input session that can be posted correctly.

Final remarks


The documentation provided by SAP for RFBIBL00 is scarce. Specifically, the individual fields of BBKPF and BBSEG are not explained in this documentation. Given the significance of this program, this lack of detailed information is concerning.

This means: the task of parsing any CSV file in a way that it can be processed with rfbibl00 will always involve a certain amount of research and exploration.

Getting rfbibl00 to work definitely is more than an afternoon project.

You can find more articles about SAP here.

Recent Posts