cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read this "standard" table in my Function Module?

former_member210148
Participant
0 Kudos

I have a remote-enable Function Module (RFC). I am receiving two tables as part of the parameters. Table "A" is header information, and Table "B" is detail information. So for every 1 "A" header record, I may have 1 to many "B" detail records. I have a field we'll call "vendor_number" that is the common link between the two tables.

Here's what I want to do: I want to loop through table "A", and for each record, I want to do a READ on table "B", using the "ref_doc_no" from "A" as my key, to get the position of the first matching record. I hold onto the value of the table index and then start looping table "B", adding 1 to the saved table index each time to process all of the detail records.

Here's the problem: This worked great as an ABAP program. I had my "B" table declared with "ref_doc_no" as a non-unique key. But when I ported my code over to the RFC, it told me that the RFC could only deal with standard tables. I had to remove the "ref_doc_no" key declaration. So now when I try to activate, I get an error similar to this:

The declaration for the key field "another_field" is incomplete; however, "another_field" is contained in the key of table "B" and must be filled.

I don't understand that. I've not declared any keys for table "B". I don't understand why it's thinking I need to populate "another_field" (I don't even know what the value would be). My code to read the table (i.e. the line getting the error) is this:

  • Priming read on table (sets the initial sy-tabix index value)

READ TABLE it_incoming_invoice_line_item "table 'B'

WITH TABLE KEY ref_doc_no =

wa_incoming_invoice_header-ref_doc_no

INTO wa_incoming_invoice_line_item.

Is it possible for me to do some sort of direct read on a table in an RFC? The only alternative I can think of would be to have to loop through table "B" until I find the first occurrence of a match. Is that what I need to do?

Thanks everyone. Points, as always, awarded for helpful answers.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dave,

In this case have you thought about using LOOP with WHERE clause.

Loop at TABLEB where ref_doc_no = TABLEA-ref_doc_no.

Endloop.

This will loop only through so many entries which satisfy the condition.

Regards,

Ravi

Answers (4)

Answers (4)

former_member210148
Participant
0 Kudos

Wow, thanks everyone! It sounds like the LOOP WHERE is the way to go. I've learned quite a bit about Function Modules today.

Thanks again! Points assigned.

Former Member
0 Kudos

Looping through the table "where something" will read all of the values of the table but only return the ones you want. So it's not very efficient. It would be better to find a way to do the 'read'.

Rob

Former Member
0 Kudos

You could pass a sorted table to the RFC and declare it as standard in the RFC (I think you can do that). Then do a binary read of the table in the RFC.

Rob

Former Member
0 Kudos

Dave,

1. You can fire SELECTS in an RFC as well, but in your case the data exists in SYSTEM A and the RFC is in System B, so you can't do that. You can fire SELECTS on tables in the same system.

2. Quick example of two table loops - EKKO (HEADER) EKPO (ITEM).

LOOP AT EKKO.

LOOP AT EKPO WHERE EBELN = EKKO-EBELN.

ENDLOOP.

ENDLOOP.

I hope this is clear now.

Regards,

Ravi

naimesh_patel
Active Contributor
0 Kudos

Hello,

loop at tablea.

Loop at tableb where vendor = tablea-vendor

  • put your code

endloop.

endloop.

Regards,

Naimesh