How to define "where" clause for RFC_READ_TABLE ?

Hello,

I'm trying to define a where clause for the RFC_READ_TABLE function like so:

RFC_READ_TABLE("KNA1", "tblKNA1", "KUNNR,KTOKD,NAME1")

Where KUNNR = "260*" and KTOKD In ("9026","9017").

Could you tell me please where can i define this inside the code ?

Also, is it possible to export the table generated into a text file ? (not to overload the database.)

Thank you.

Duration: 
1 month

Comments

1
Jimbo's picture

This is a relatively simple step, but it took me a while to figure it out. In SE37 the RFC_READ_TABLE function has this line:

  SELECT * FROM (QUERY_TABLE) INTO <WA> WHERE (OPTIONS).

I had to experiment with it and finally came to the conclusion that adding a single OPTION value to the RFC before calling it would populate the WHERE in the query. It is important to leave out the "WHERE" and the period; include only the condition of the where clause like so in your VBA code:

 
    OPTIONS.Rows.Add
    OPTIONS.Value(1, 1) = "KUNNR eq '0000001010'"

Take note of the single quotes within the string encapsulating the customer number above. This "option" is effectively a short piece of ABAP code that is slipped into the SELECT statement when the RFC_READ_TABLE function is called.

The usage of or and and statements will require a little experimentation. It appears they can be included in the single value in the OPTIONS array or potentially added as additional OPTIONS values.

I include a screen shot of the code in the VBA debugger and the successful results. A simple copy-past from the VBA snippet above keeps it simple.