cancel
Showing results for 
Search instead for 
Did you mean: 

RFC_READ_TABLE Options causes System Failure

Former Member
0 Kudos

In VBA, I want to use the options parameter like:

Set OPTIONS = MyFunc.Tables("OPTIONS")

OPTIONS.Rows.Add

OPTIONS.Value(1, "TEXT") = "OBJECT = 'S_TCODE'"

however when I then run the module it produces a system failure. If I comment out the two options lines then it runs with no problem with no filter on the data of course.

Any ideas how to correct this?

Accepted Solutions (0)

Answers (1)

Answers (1)

krzysztof_konitz4
Contributor
0 Kudos

Hi,

First check if you can call this function using the same parameters from ABAP without errors.

Some time ago I used this FM but not in VB but in Delphi. I think that code should be similar so i post it below.

This code reads table KNA1 for specific customer name:

 var Funct, RFC_Read_table: Variant;
     SelectWhere, Fields, TableContent: TStringList;
 
 try
  Funct := CreateOleObject('SAP.Functions');
 except
(...)
 end;
 try
  RFC_Read_table := Funct.Add('RFC_READ_TABLE');
 except
(...) 
 end; 
 
 SelectWhere  := TStringList.Create;
 Fields       := TStringList.Create;
 TableContent := TStringList.Create;

 SelectWhere.Add('NAME1 = KOWALSKI');
 Fields.Add('KUNNR');
 Fields.Add('ORT01');
 if not ReadDataFromSAPTable('KNA1', SelectWhere, Fields, TableContent) then
  ShowMessage(RFC_Read_table.Exception)
 end;

 SelectWhere.Free; Fields.Free; TableContent.Free;
 
function ReadDataFromSAPTable(TableName: String; SelectWhere, Fields,
                              TableContent: TStringList): Boolean;
var Row, iQueryTable, tOptions, tFields, tData: Variant;
    i: Integer;
begin
 iQueryTable := RFC_Read_table.exports('QUERY_TABLE');
 iQueryTable.Value := TableName;

 tOptions := RFC_Read_table.Tables.Item('OPTIONS');
 for i := 0 to SelectWhere.Count - 1 do
  begin
   Row := tOptions.Rows.Add;
   Row.Value('TEXT') := SelectWhere<i>;
  end;

 tFields := RFC_Read_table.Tables.Item('FIELDS');
 for i := 0 to Fields.Count - 1 do
  begin
   Row := tFields.Rows.Add;
   Row.Value('FIELDNAME') := Fields<i>;
  end;

 tData := RFC_Read_table.Tables.Item('DATA');

 Result := RFC_Read_table.Call;

 if Result = True then
  for i := 1 to tData.Rowcount do TableContent.Add(tData.Value(i, 1));
end;

Krzys