Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
Active Contributor


This is not going to be rocket-science, but after searching SCN for some time not finding the answer/code I needed, but realizing that many people have the same/similar requirement to mine, I decided to share this code via this blog.


* you have a report with select-options

* you need to collect data from remote systems and despite all the warnings that the RFC_READ_TABLE function module should not be used (although it is used in zillions of SAP standard programs as well as customer programs so it is zero chance SAP would ever change or remove this function module, I would say), you decided to go for RFC_READ_TABLE.

* you need to transfer the complex selection provided by the user to the remote system because downloading all the data to the local system and deleting the data based on the selection locally is just so inefficient and slow (try transferring huge tables via RFC once and you will understand why this blog...)

* ...which means you need to transfer the select-options to the remote system, because the selection is much smaller and faster to transfer than all the data in the table you need to download

Here is the code you need...

* first comes the part of the WHERE clause that you can easily specify manually/hardcode in the source code, because it never changes

* then comes the conversion of one select-option (so for more select-options you need to do this several times)

* ...and finally comes the code that puts the two together

cheers Otto

DATA lt_options TYPE tt_option.
   DATA lt_selopt TYPE TABLE OF ddshselopt.
   DATA ls_selopt LIKE LINE OF lt_selopt.
   DATA ls_option LIKE LINE OF et_options.
   DATA lv_where TYPE string.
   FIELD-SYMBOLS <so_fld> LIKE LINE OF so_fld.
CLEAR ls_option.
   CONCATENATE 'FROM_DAT <= ''' sy-datum ''' AND TO_DAT >= ''' sy-datum '''' INTO ls_option.
   APPEND ls_option TO et_options.
CLEAR: lt_selopt[].
   LOOP AT so_fld ASSIGNING <so_fld>.
     CLEAR: ls_selopt.
     MOVE-CORRESPONDING <so_fld> TO ls_selopt.
     ls_selopt-shlpfield = 'FIELD'.
     APPEND ls_selopt TO lt_selopt.
CLEAR lv_where.
       where_clause = lv_where
       selopt_tab   = lt_selopt.
   CLEAR: lt_options[].
   PERFORM convert_where_to_rfc_options USING lv_where CHANGING lt_options.
   IF lt_options IS NOT INITIAL.
     APPEND 'AND' TO et_options.
     APPEND LINES OF lt_options TO et_options.
     CLEAR lt_options[].
FORM convert_where_to_rfc_options USING iv_where TYPE rsstring CHANGING et_options TYPE tt_option.
   DATA lv_where LIKE iv_where.
   DATA lv_bit TYPE so_text.
   DATA lv_len TYPE int4.
   IF iv_where IS INITIAL.
   CLEAR lv_where.
   lv_where = iv_where.
     IF lv_where IS INITIAL.
     CLEAR lv_len.
     lv_len = strlen( lv_where ).
     IF lv_len <= 72.
       APPEND lv_where TO et_options.
       lv_bit = lv_where.
       lv_len = 71.
       DO 71 TIMES.
         IF lv_bit+lv_len(1) = ' '.
         lv_len = lv_len - 1.
*** Index of the last space is in LV_LEN now.
       APPEND lv_bit(lv_len) TO et_options.
       lv_where = lv_where+lv_len.
1 Comment
Labels in this area