Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

WHERE condition in RFC_READ_TABLE FM - field length problem

matteo_montalto
Contributor
0 Kudos

Hi all gurus,

for my requirement I need to convert a selection from a select-option into a WHERE condition, in order to make a remote query using RFC_READ_TABLE fm.

Here's the relevant sketch of the code:


FORM cerca_pos_rda USING   selopt TYPE tbl_ext_so
                           logsys TYPE logsys
                CHANGING   tab_pos TYPE ty_pos_rda.
* selopt is a copy of the select-option structure into an itab
* w.r.t F4_CONV_SELOPT_TO_WHERECLAUSE parameters

  DATA: t_where TYPE TABLE OF rfc_db_opt WITH HEADER LINE,
        t_fields TYPE TABLE OF rfc_db_fld WITH HEADER LINE,
        t_data TYPE ty_pos_rda,
        wa_data TYPE t_pos_rda,
        lv_where TYPE string.

  CLEAR t_fields.
  t_fields-fieldname = 'BANFN'.
  t_fields-length = 5.
  APPEND t_fields.
  t_fields-fieldname = 'BNFPO'.
  t_fields-length = 10.
  APPEND t_fields.

* Convert selopt into string               *
  CALL FUNCTION 'F4_CONV_SELOPT_TO_WHERECLAUSE'
*   EXPORTING
*     GEN_ALIAS_NAMES       = ' '
*     ESCAPE_ALLOWED        = ' '
    IMPORTING
      where_clause          = lv_where
    TABLES
      selopt_tab            = selopt.
  t_where-text = lv_where.
  APPEND t_where.

  CALL FUNCTION 'RFC_READ_TABLE' DESTINATION logsys
  EXPORTING
  query_table = 'EBAN'
* DELIMITER = ' '
* NO_DATA = ' '
* ROWSKIPS = 0
* ROWCOUNT = 0
  TABLES
  OPTIONS = t_where
  fields = t_fields
  data = t_data.
  CLEAR: wa_data.

Here's the problem: lv_where could be a very long string, while t_where-text is a CHAR72. That means that if the "unrolled" WHERE condition is more than 72 char long, it will result truncated. I'd need an example on how to split the condition into T_WHERE rows, in particular, assuming lines are in conjunction (AND) between each other, how can I split, say, conditions like 'BANFN EQ x1 OR BANFN EQ x2 OR BANFN EQ x3' ?

Thanks in advance for your help

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

Just a remark about RFC_READ_TABLE (excerpt from [Note 382318|https://service.sap.com/sap/support/notes/382318]) :

"However, all this is quite immaterial, because the function is not meant to be publicly used anyway. It was only created to be used as a sample in various training courses, and is clearly flagged as "not released for customer"."

4 REPLIES 4

Former Member
0 Kudos

Hi

U need to split the logical exprension in several records of T_WHERE table

Max

0 Kudos

Thanks max,

I thought that the split should follow a logical sense, e.g. each line must represent a condition clause, but verified after your hint that's not the case. Simply I had to split every 72 char the WHERE string into t_where rows.

Thanks again

0 Kudos

Hi

I didn't thought to split the condition by ABAP, but only to translate every single select-option separatly by fm F4_CONV_SELOPT_TO_WHERECLAUSE.

DATA: T_WHERE  TYPE TABLE OF   RFC_DB_OPT WITH HEADER LINE,
      T_FIELDS TYPE TABLE OF  DDSHSELOPT WITH HEADER LINE,
      LV_WHERE TYPE STRING.

CLEAR T_FIELDS.
T_FIELDS-SHLPFIELD = 'BANFN'.
T_FIELDS-SIGN      = 'I'.
T_FIELDS-OPTION    = 'BT'.
T_FIELDS-LOW       = '0000000001'.
T_FIELDS-HIGH      = '0000000100'.
APPEND T_FIELDS.

* Convert selopt into string               *
CALL FUNCTION 'F4_CONV_SELOPT_TO_WHERECLAUSE'
*   EXPORTING
*     GEN_ALIAS_NAMES       = ' '
*     ESCAPE_ALLOWED        = ' '
  IMPORTING
    WHERE_CLAUSE          = LV_WHERE
  TABLES
    SELOPT_TAB            = T_FIELDS.

T_WHERE-TEXT = LV_WHERE.
APPEND T_WHERE.

REFRESH T_FIELDS.
CLEAR T_FIELDS.
T_FIELDS-SHLPFIELD = 'BNFPO'.
T_FIELDS-SIGN      = 'I'.
T_FIELDS-OPTION    = 'BT'.
T_FIELDS-LOW       = '00010'.
T_FIELDS-HIGH      = '00100'.
APPEND T_FIELDS.

CLEAR LV_WHERE.
* Convert selopt into string               *
CALL FUNCTION 'F4_CONV_SELOPT_TO_WHERECLAUSE'
*   EXPORTING
*     GEN_ALIAS_NAMES       = ' '
*     ESCAPE_ALLOWED        = ' '
  IMPORTING
    WHERE_CLAUSE          = LV_WHERE
  TABLES
    SELOPT_TAB            = T_FIELDS.

CLEAR T_WHERE.
T_WHERE-TEXT(3) = 'AND'.
T_WHERE-TEXT+4  = LV_WHERE.
APPEND T_WHERE.

LOOP AT T_WHERE.
  WRITE: / T_WHERE-TEXT.
ENDLOOP.

Max

Sandra_Rossi
Active Contributor
0 Kudos

Just a remark about RFC_READ_TABLE (excerpt from [Note 382318|https://service.sap.com/sap/support/notes/382318]) :

"However, all this is quite immaterial, because the function is not meant to be publicly used anyway. It was only created to be used as a sample in various training courses, and is clearly flagged as "not released for customer"."