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: 

Function Module to retrieve data

Former Member
0 Kudos

Hi Friends,

I created one FM to retrieve data from a database table.

It is working fine.In that FM i hard coded import parameter for table name.And in export parameter i created one internal table type in SE11 t-code.That table type is refered to one specific database table.So after getting data in the itab, i will update one more table usng insert statement.This FM i will set as remote enabled and i will call from other server.ie.retriving data from one server and updating data for same table in another server.It is working fine.But like this i have to update more than 50 tables.

Can any body tell me the logic for that? Can it be done using the same and single FM?

Your help is highly appreciated.I am sure of reward points.

Thanks in Advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Use the std SAP FM "RFC_READ_TABLE". This FM could be used to fetch any tables data across the system.

You dont have to build any complex logic. Used the above FM and you can get data from one system and update on other system. You might want to do a where used list to check how its being used.

Hope this helps.

Cheers

VJ

14 REPLIES 14

Former Member
0 Kudos

Hi,

Use the std SAP FM "RFC_READ_TABLE". This FM could be used to fetch any tables data across the system.

You dont have to build any complex logic. Used the above FM and you can get data from one system and update on other system. You might want to do a where used list to check how its being used.

Hope this helps.

Cheers

VJ

0 Kudos

HI Thanks.

But it reads data from only 1 table at a time.

i have to retrieve data from one server and i will create

same table in another server and i have to update data that is retrieved data from the first server from work area.

naimesh_patel
Active Contributor
0 Kudos

Hello,

Below attached code is for dynamic table into dynamic internal table.

Take all 50 tables in one internal table.

And modify below given program to update the tables.

Hope this will help you.

Regards,

Naimesh

Reward if it is helpful..!

**************

REPORT ZTEST_NP.

PARAMETERS: p_tab TYPE dd02l-tabname,

compon TYPE i.

DATA: field1 TYPE c VALUE '5',

field2(2) TYPE c VALUE '10',

field3(6) TYPE c ,

ref_tab TYPE REF TO data.

FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.

create DATA ref_tab TYPE standard TABLE of (P_TAB).

ASSIGN ref_tab->* TO <fs>.

PERFORM test TABLES <fs> USING field1 .

*&----


*

*& Form test

*&----


FORM test TABLES p_field1 USING p_field3.

FIELD-SYMBOLS <fs_wa> TYPE ANY.

FIELD-SYMBOLS <fs_comp> TYPE ANY.

CREATE DATA ref_tab TYPE (p_tab).

ASSIGN ref_tab->* TO <fs_wa>.

SELECT * FROM (p_tab) INTO TABLE <fs> .

LOOP AT <fs> INTO <fs_wa>.

ASSIGN COMPONENT compon OF STRUCTURE <fs_wa> TO <fs_comp>.

WRITE:/ <fs_comp>.

ENDLOOP.

ENDFORM. " test

former_member181962
Active Contributor
0 Kudos

Hi Kumar,

1) Create a FM with two tables parameters One to hold a table of names of the tables (say t_tables)

2) Another table with the data(say t_data).(Lets have two fields in Name of the table, Data).

3) IN the source code.

loop at t_tables.

call function 'RFC_READ_TABLE'

exporting QUERY_TABLE = t_tables-table_name.

tables DATA = t_data_temp.

loop at t_data_temp.

t_data-table_name = t_tables-table_name.

t_data-data = t_data_temp-data.

append t_data.

clear t_data.

endloop.

refresh t_data_temp.

endloop.

4) Now your table will have t_data with the table name and the corresponding data.

REgards,

Ravi

0 Kudos

Hi Thanks.pints are given.

You meant to say that first i have to create a new FM with two tables parameters in that source code of FM i have to call the FM RFC_READ_TABLE ??But while creating first FM what and how to give the import and export paramaters?.If i create a table parameter for that i have to create a table type in SE11..am i right?

I am not clear..can elobarate your logic?

Thanks in Advance

0 Kudos

Hi Kumar,

Yes.

1) say your Function module name is ZRFC_READ_TABLES.

2) In the tables tab, declare a table t_tables type z_tables.This z_tables should be defined as a structure in se11.

Goto se11 create a z_tables structure with only one field which is of type DD02L-TABNAME.

3) In the tables tab, declare one more table t_data type z_data. This z_data should be defined as a structure in se11.

Goto se11 create z_data structure with two fields one is of type DD02L-TABNAME and the other is of type TAB512.

4) IN source code, you can paste my last post code.

In that, t_data_temp can be declared as a local variable.

REgards,

Ravi

0 Kudos

Hi Ravi,

Thank You Very much. Reward points are given. I will try this and let you know.

Regards

0 Kudos

Hi Ravi Kanth,

in the 2nd point i created z_tables structure(not table type) in se11.it is working fine. But

in the 3rd ppoint.

i created structure(not table type) in se11 with two fields.

the structuire name is zdata in this 2 fields:

1.tab_name like tabname(component type)

2.data like like tab512(componet type)

But when i give this in tables parameter in ZRFC_READ_TABLES,i given like this.

t_data like zdata..but it is giving error like:"Tables using LIKE may only reference flat structures"

Even if i create a table type for t_data it is not allowing..

Can you look into this and give any suggesion?

Thanks in Advance

0 Kudos

Hi Ravi Kanth,

i created FM ZRFC_READ_TABLES. it is active.

But there is no import paramaters for ths.

How will we call this FM in another ABAP pgm and how to give paramaters...Can you pls give solution for this?

Thanks in Advance.

0 Kudos

Jak,

Please look at my reply to Radhika's same question.

Regards,

Ravi

Note : Please mark the helpful answers

0 Kudos

Hi Ravi Kumar,

Thank you for response.I need some clarification in this:

1.Declare as many paramters as the no. of tables you want to retrieve in one SHOT. This parameter can refer to DD02L-TABNAME: means is it a import parameter to FM while creating?if so shall we have to declare like p1 like DD02l-TABNAME..p2 like DD02l-TABNAME..etc...

2.Now, also declare as many TABLE paramters by referring to TYPE REF TO DATA so that you are not tied to a specific table: means like itab1,itab2...like this..?

These we have to create in se11?..as a structure or table type?..i did't get this second point...

Can you elobarate the 2nd point?

Thanks in Advance

0 Kudos

Jak,

1. Yes declare like P1, P2 ... P10 for table names.

2. Similarly ITAB1 .... ITAB10. TYPE REF TO DATA.

As these are not pointing to any table, you don't have to create anything in SE11.

Look at the way we use REUSE_ALV_GRID_DISPLAY.

Inside the function what you will have to do is

CREATE DATA ITAB1 type (P1).

field-symbols : <FT_TABLE> type any table.

Assign ITAB1->* to <FT_TABLE>

SELECT * from (p1) into corresponding fields of table <FT_TABLE>.

This should return you the data.

Regards,

Ravi

Note : please mark the helpful answers

0 Kudos

Hi Ravi Kumar,

Thank you.

You mean to say:

in the imort parametrs:

pi like DD02L-TABNAME,

p2 like DD02L-TABNAME,

..etc.

and in Tables parameters:

ITAB1 TYPE REF TO DATA.HERE WAHT IS DATA? THIS WE HAVE TO DECLARE IN SE11?...PLEASE GIVE CLARIFY THIS..

THANKS IN ADVANCE

0 Kudos

Jak,

P1, P2 yes, what you have written is right.

TYPE REF TO DATA, is to tell the system that I want to use this variable but as of now I don't know the data type.

So, later while CREATE DATA statement I refer it to a table using which it will get a structure. You don't have to declare in SE11.

Which version of SAP you are working on?

Regards,

Ravi

Note : please mark the helpful answers