Application Development and Automation 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: 
Read only

Calling a R/3 Database Table from a local variable

Former Member
0 Likes
857

Hey experts,

I cannot call a r/3 table out of a local variable.


DATA:      lv_test LIKE smoftables-r3tabname.

SELECT r3tabname FROM smoftables INTO lv_test WHERE objname = 'DNL_CUST_BASIS'.
  WRITE /. Write /. Write /. Write lv_test.
ENDSELECT.

So I loop the r/3 table name into lv_test, but here comes my problem : I'd like to display the content of the original database table whose name was saved in lv_test. Is there any way to do so?

Thanks in advance!

8 REPLIES 8
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
822

Hi,

This can be done and some coding has to be done. Please search in SCN for creating dynamic internal table based on a dbtable name and retrieving the contents . You may find lot of threads. You can also check my reply here for a similar kind of question

Read only

Former Member
0 Likes
822

Paul,

I am not sure that I follow your needs. Can you explain further?

Read only

0 Likes
822

If multiple records exist where objname = 'DNL...:" then you could use a simple Flag b/c you are using a SELECT... ENDSELECT. Bear in mind that Select... endselect is not a recommended code technique.

Something like below:

data: lv_First(1) value 'Y'.

Select ....

if lv_First = 'Y'.

  • write out the tab name

lv_First = 'N'.

endif.

EndSelect

Also - bear in mind that without an ORDER BY clause - that your OpenSQL could produce different results.

Read only

matt
Active Contributor
0 Likes
822

Funny how the same kinds of question pop up in clusters. See this thread, started today.

Read only

0 Likes
822

Hm I think you didnt quite get me.

lv_test is of the type r3table, there exist 8 of them (r3 database tables) within the adapter object "dnl_cust_basis".

For each loop of the select..endselect-statement I want to display one of them.

This is just a testing program because I need that functionality somewhere else.

Read only

0 Likes
822

Paul,

In that case, go with code like this:

DATA: lv_test LIKE smoftables-r3tabname.

data: lt_test type table of smoftables-r3tabname.

SELECT r3tabname INTO table lt_test

FROM smoftables

WHERE objname = 'DNL_CUST_BASIS'.

loop at lt_test into lv_test.

skip 3.

write: / lv_test.

endloop.

Read only

0 Likes
822

Again though - if order IS important - then an ORDER BY will be required.

A RDBMS does not gaurantee any ordering of the returned results. You must tell the RDBMS using an ORDER BY clause if that is necessary to meet your requirements.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
822

Hi Paul,

Did you check th link which I referred ?

Your question was

I'd like to display the content of the original database table whose name was saved in lv_test.

You have the solution in the link i referred.

Keshav