01-27-2009 1:12 PM
Hi
Im pretty new to SAP and RFC so please excuse me if I seem noob.
I have an external application that must use the rfc library to access some data in SAP.
At this moment I use RFCOpen to get a connection to the server (this seem to work correctly).
But now I have to use RFC_READ_TABLE.
to read 3 differents table
MAKT
MARD
MSLB
and idealy I have to read only part of the table (with where clause in sql)
Im using VS2005 c++ with the RFCSDK, and I have no real idea how to use RFC_READ_TABLE
the only thing I know is that I have to set export parameter to something that match what I want, and call callreceive()..
Can someone put me on the right path
Thanks
01-27-2009 3:32 PM
Hello Julien
A minimal call to RFC_READ_TABLE needs to include:
QUERY_TABLE - the table name to read
OPTIONS - an ABAP internal table. each line will be a line of the sql where.
FIELDS - an ABAP internal table containing the names of the fields to retrieve data for.
DATA - the data returned by the function.
eg QUERY_TABLE --- PA0001
OPTIONS --- PERNR = 999999 ( any valid value for PERNR)
FIELDS --- PERNR (return PERNR)
Not sure of the details from the external side .
Hope this helps a bit
Regards
Greg Kern
01-27-2009 2:44 PM
I did try to search forum but nothing found
tables[0].ithandle = ItCreate("MAKT", 200, 1, 0);
exporting[0].name = "MAKT";
exporting[1].name = " ";
exporting[2].name = " ";
exporting[3].name = "0";
exporting[4].name = "0";
exporting[5].name = "";
then call callreceive?
Then how can I see value returned in table?
01-27-2009 3:42 PM
This may not help since you're working outside SAP, but here is an example of calling RFC_READ_TABLE from one SAP system to read data from another - on this occasion querying table LFA1 using LIFNR vendor reference (passed into this macro as &1) and sending back KTOKK account group (passed back as &2). The WHERE clause here is LIFNR = "0000190211" and is passed in via the OPTIONS table; the query results are sent back in the DATA table.
DATA: lt_options TYPE TABLE OF rfc_db_opt,
lv_options TYPE rfc_db_opt,
lt_fields TYPE TABLE OF rfc_db_fld,
ls_fields TYPE rfc_db_fld,
lt_data TYPE TABLE OF tab512,
lv_data TYPE tab512.
CLEAR: lt_options,lt_fields, lt_data, lv_options.
CONCATENATE 'LIFNR = ''' &1 '''' INTO lv_options.
APPEND lv_options TO lt_options.
ls_fields-fieldname = 'KTOKK'.
APPEND ls_fields TO lt_fields.
CALL FUNCTION 'RFC_READ_TABLE' DESTINATION lv_rfc_dest
EXPORTING
query_table = 'LFA1'
TABLES
options = lt_options
fields = lt_fields
data = lt_data
EXCEPTIONS
table_not_available = 1
table_without_data = 2
option_not_valid = 3
field_not_valid = 4
not_authorized = 5
data_buffer_exceeded = 6
OTHERS = 7.
CLEAR: lv_data.
READ TABLE lt_data INTO lv_data
INDEX 1.
&2 = lv_data.
01-27-2009 3:50 PM
Hello Julien
Looks like you would specify the fields to be returned somewhere in your 'tables' data structure.
In the ABAP FM interface the table is called FIELDS
If you want you can leave it blank and you will get back all the fields of the table.
The other table that you need to fill is called OPTIONS. This is where you must build your where clause.
Unfortunately I beleive that you can only read one table at a time using this FM.
Regards
Greg Kern
01-27-2009 3:55 PM
What you mean by one table? like MAKT table but many rows right?
I dont have any fields or options table..
I have to create new indexes of rfc_tables and give them FIELDS name? like I did with exporting(which im not sure is the right way)?
thanks again
01-27-2009 4:16 PM
Hello Julien,
Yes, one table many rows.
What does the variable/structure 'tables' look like from your side?
I do not know how you defined exporting but you may need to do something similar for tables.
Regards
Greg Kern
01-27-2009 4:52 PM
I know the two fields i need they are MATNR and MAKTX but I dont know the max size of them
in Options tables I created how do I put where clause? I do ItAppLine(tablehandler)
then write to this like something like MATNR = 'EU-0339B'??
01-27-2009 5:24 PM
Hello Julien,
MATNR is defined as an 18 character string
MAKTX is defined as a 40 character string.
I am sorry but I cannot help with the where clause.
Christine's example shows how to pass the where clause in ABAP. That's about all I know.
Regards
Greg Kern
01-27-2009 7:26 PM
Thank you Greg
Now im able to reproduce the same result each time.
tables[0].name = "OPTIONS";
tables[0].nlen = 7;
tables[0].type = TYPC;
tables[0].leng = 100;
tables[0].itmode = RFC_ITMODE_BYREFERENCE;
tables[0].ithandle = ItCreate("OPTIONS", 100, 0, 0);
tables[1].name = "FIELDS";
tables[1].nlen = 6;
tables[1].type = TYPC;
tables[1].leng = 100;
tables[1].itmode = RFC_ITMODE_BYREFERENCE;
tables[1].ithandle = ItCreate("FIELDS", 100, 0, 0);
tables[2].name = "DATA";
tables[2].nlen = 4;
tables[2].type = TYPC;
tables[2].leng = 58;
tables[2].itmode = RFC_ITMODE_BYREFERENCE;
tables[2].ithandle = ItCreate("DATA", 10000, 0, 0);
exporting[0].name = "QUERY_TABLE";
exporting[0].nlen = strlen("QUERY_TABLE");
exporting[0].addr = "MAKT";
exporting[0].leng = strlen("MAKT");
exporting[0].type = RFCTYPE_CHAR;
exporting[1].name = "DELIMITER";
exporting[1].nlen = strlen("DELIMITER");
exporting[1].addr = " ";
exporting[1].leng = strlen(" ");
exporting[1].type = RFCTYPE_CHAR;
exporting[2].name = "NO_DATA";
exporting[2].nlen = strlen("NO_DATA");
exporting[2].addr = " ";
exporting[2].leng = strlen(" ");
exporting[2].type = RFCTYPE_CHAR;
exporting[3].name = "ROWSKIPS";
exporting[3].nlen = strlen("ROWSKIPS");
exporting[3].addr = " ";
exporting[3].leng = strlen(" ");
exporting[3].type = RFCTYPE_CHAR;
exporting[4].name = "ROWCOUNT";
exporting[4].nlen = strlen("ROWCOUNT");
exporting[4].addr = " ";
exporting[4].leng = strlen(" ");
exporting[4].type = RFCTYPE_CHAR;
exporting[5].name = NULL;
RfcCallReceive(RFC_Handle, "RFC_READ_TABLE", exporting, importing, tables, &ex);
if(rfc_rc != RFC_OK)
RFC_ERROR_INFO error_info;
char * ptr;
RfcLastError(&error_info);
with this I get System Failure each time in error_info
and the message say something about fields lenght is invalid.
i got the table and a handle created with 100 of size
but no row created (same as options)
01-27-2009 8:48 PM
Incorrect field length for 'Remote Function Call'.
this is the message I get when i call it
what is the correct field lenght? I dont want to specify any fields so I get them all
thanks
01-27-2009 9:09 PM
Fields has the following structure
FIELDNAME CHAR 30 0 Field Name
OFFSET NUMC 6 0 Offset of a field
LENGTH NUMC 6 0 Length (No. of Characters)
TYPE CHAR 1 0 ABAP data type (C,D,N,...)
FIELDTEXT CHAR 60 0 Short Description of Repository Objects
Options: ( must be filled with the where cllause)
TEXT CHAR 72 0 Text line of a message
Data: ( the returned data)
WA CHAR 512 0 Character field length 512
Regards
Greg Kern
01-27-2009 10:33 PM
great
must I specify the offset and length of each field i want?
and you know how you define a NUMC type variable in the code(48bit?)? with this I could make a fields struct for each field I need.
And thanks again each time im more close to something functional 😛
01-27-2009 11:35 PM
Don't think you need to specify offset. When I test from within an SAP system
I just leave blank.
Not sure about delcaring NUMC externally. NUMC is really just a character string that can
only contain numerics.
Regards
Greg Kern
08-11-2009 9:38 AM
Hello all,
did I understand the following correctly:
For the parameter transfer tables are used, especial for the sql statement. If I let it free, will RFC_READ_TABLE do a "select *" on the chosen table?
During my searches I found some hints, that RFC_READ_TABLE is not compatible with unicode C requests, is this correct?
Is there any other, maybe easier way, to read simple table data by RFC C programm?
01-27-2009 3:32 PM
Hello Julien
A minimal call to RFC_READ_TABLE needs to include:
QUERY_TABLE - the table name to read
OPTIONS - an ABAP internal table. each line will be a line of the sql where.
FIELDS - an ABAP internal table containing the names of the fields to retrieve data for.
DATA - the data returned by the function.
eg QUERY_TABLE --- PA0001
OPTIONS --- PERNR = 999999 ( any valid value for PERNR)
FIELDS --- PERNR (return PERNR)
Not sure of the details from the external side .
Hope this helps a bit
Regards
Greg Kern
01-27-2009 3:42 PM
Thanks but for this i have to use more than 1 RFC_TABLE??
at this moment I got this now
tables[0].itmode = RFC_ITMODE_BYREFERENCE;
tables[0].ithandle = ItCreate("MAKT", 100, 1, 0);
exporting[0].name = "QUERY_TABLE";
exporting[0].nlen = strlen("QUERY_TABLE");
exporting[0].addr = "MAKT";
exporting[0].leng = strlen("MAKT");
exporting[0].type = RFCTYPE_CHAR;
exporting[1].name = "DELIMITER";
exporting[1].nlen = strlen("DELIMITER");
exporting[1].addr = " ";
exporting[1].leng = strlen(" ");
exporting[1].type = RFCTYPE_CHAR;
exporting[2].name = "NO_DATA";
exporting[2].nlen = strlen("NO_DATA");
exporting[2].addr = " ";
exporting[2].leng = strlen(" ");
exporting[2].type = RFCTYPE_CHAR;
exporting[3].name = "ROWSKIPS";
exporting[3].nlen = strlen("ROWSKIPS");
exporting[3].addr = " ";
exporting[3].leng = strlen(" ");
exporting[3].type = RFCTYPE_CHAR;
exporting[4].name = "ROWCOUNT";
exporting[4].nlen = strlen("ROWCOUNT");
exporting[4].addr = " ";
exporting[4].leng = strlen(" ");
exporting[4].type = RFCTYPE_CHAR;
exporting[5].name = NULL;
RfcCallReceive(RFC_Handle, "RFC_READ_TABLE", exporting, &importing, tables, &ex);
But I get memory violation error at the call,
In where do i put the field option in table?
Thanks alot for helping
05-10-2010 10:03 PM
Hi Julien. I'm trying to do something fairly similar i.e. connect to a SAP system with C+. I have more knowledge on the SAP side than with C+. If you're still struggling with this then let me know and I'm sure we can work a solution out together. John