This is a test message to test the length of the message box.
Login
ABAP Quick read table with rfc
Created by Software-Heroes

ABAP Quick - Read table with RFC

Reading in a table via RFC function module is very easy, if you create a specific module for it. Reading any table can be just as easy.

Advertising

It can sometimes be necessary to read data from another system via distributed landscapes or you want to distribute data from production to the other systems (test, development, etc.). There are several scenarios in which you can save your own function modules, as there are already generic variants for reading tables.

 

Advantages

The advantages of using a generic function modules are obvious:

  • Time and cost savings through no own programming
  • A standard check against the table permissions that protects sensitive data in the system
  • Limitation of data and quantities in Select

 

RFC_READ_TABLE

The classic RFC function module is the RFC_READ_TABLE, since it covers most scenarios in most cases. It has an authorization check, the output fields can be changed in number and sequence. The amount of data returned is 512 characters, minus the column separators needed.

There are many examples of the use of this function module on the Internet, so we will only give a rough idea of its use here. We would like to share with you a qucik tip for creating the Where-Clause table.


DATA:
  lt_opt   TYPE STANDARD TABLE OF rfc_db_opt,
  ls_where TYPE rsds_where.

" Create selection
IF mt_sel IS NOT INITIAL.
  CALL FUNCTION 'AIBZ_FILL_WHERE_CLAUSE'
    EXPORTING
      i_tabname       = md_table
      it_select       = mt_sel
    IMPORTING
      es_where_clause = ls_where.

  lt_opt = ls_where-where_tab.
ENDIF.

 

After filling the selection with the individual restrictions, you can use the table to generate the where condition for the RFC function module. Also very handy when using dynamic selections.

 

Problems

As long as the width of the record is sufficient (512 characters), this is not a problem. But imagine you want to read a table where a column already has 512 characters or more. This is not possible with the function module and only generates an error while reading the data.

In our example, we would like to read IDoc data and verify the content. But the data field SDATA is 1000 characters wide and can not be read with the normal RFC function module. Here we reach the limit of this function module.

 

TABLE_ENTRIES_GET_VIA_RFC

The function module also checks the authorizations when reading the table. The line width is 2048 characters and no separators are used to return the data. However, the complete structure is always returned and you can not restrict the columns.

In addition, the function module has a problem with the conversion of number fields, which ends in a program exception. Therefore, we can only recommend the block conditionally.

 

CRM_CODEX_GET_TABLE_VIA_RFC

It roughly looks like a copy of the function module TABLE_ENTRIES_GET_VIA_RFC, but has been extended with crucial functions. Thus, an offset conversion is performed before the data allocation, which numbers are no longer a problem in the transfer.

For the above example, we have therefore once created a sample code, which also includes the subsequent conversion of the data.


DATA:
  lt_sel    TYPE STANDARD TABLE OF bdsel_stat,
  lt_fields TYPE STANDARD TABLE OF bdi_mfgrp,
  lt_data   TYPE STANDARD TABLE OF bdi_entry,
  ld_subrc  TYPE sysubrc,
  ld_sdata  TYPE edi_sdata.
FIELD-SYMBOLS:
  <ls_data> TYPE edid4,
  <ls_head> TYPE e1fikpf.


" Create selection
APPEND VALUE #( zeile = |DOCNUM EQ '0000000009991234' AND SEGNAM EQ 'E1FIKPF'| ) TO lt_sel.

" Read entries from the table
CALL FUNCTION 'CRM_CODEX_GET_TABLE_VIA_RFC'
  EXPORTING
    tabname             = 'EDID4'
  IMPORTING
    rc                  = ld_subrc
  TABLES
    sel_tab             = lt_sel
    nametab             = lt_fields
    tabentry            = lt_data
  EXCEPTIONS
    internal_error      = 1
    table_has_no_fields = 2
    table_not_activ     = 3
    not_authorized      = 4
    OTHERS              = 5.
IF sy-subrc <> 0.
ENDIF.

" Map line
TRY.
    " Read the first line
    DATA(ld_line) = lt_data[ 1 ]-entry.
    DATA(ls_field) = lt_fields[ fieldname = 'SDATA' ].

    " Map field to structure
    ld_sdata = ld_line ls_field-offset.
    ASSIGN ld_sdata TO <ls_head> CASTING.

  CATCH cx_root.
ENDTRY.

 

We read the header for a FIDCC1 or FIDCC2 and map the line to the data structure. This allows us to check the content of the header and, for example, validate the company code. This works just as well for other data and tables.

 

Conclusion

Reading generic data across systems should not be a problem for you with our little tip. In most cases, use the function module RFC_READ_TABLE because it has the most flexibility. If the requested data line is too big, you can now switch to other function modules. If all else fails, individual development remains for you.


Included topics:
QuickRFCTableRFC_READ_TABLE
Comments (0)
Advertising

ABAP Quick - Wait for task

Category - ABAP

Today a tip for asynchronous processing or if you want to put processing in a separate task in special situations. What happens afterwards?

03/05/2021

ABAP Quick - Performance INSERT vs VALUE

Category - ABAP

In this article we take a look at the performance of the insert operations APPEND, INSERT and VALUE with regard to tables and evaluate the performance and stability during development.

02/26/2021

ABAP - BOPF Quick Guide (Update)

Category - ABAP

A little update to our book that we published. For all people who find the paperless office boring.

10/23/2020

ABAP - BOPF Quick Guide

Category - ABAP

You need a quick introduction to the SAP Business Object Processing Framework (BOPF), we have the right guide for you here.

09/11/2020

ABAP Quick - Search in source code

Category - ABAP

Sometimes it is necessary to search through different source codes in one system. We show you how it works in the SAP GUI and in Eclipse.

04/24/2020

We use cookies for our services and functions. More informations