This website is not affiliated with, sponsored by, or approved by SAP AG.

Dynamically Passing Database Table name

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Dynamically Passing Database Table name

Postby shaileshdube » Wed Feb 12, 2003 1:18 am

Hi friends ,

How to dynamically pass database table name through parameters .

e.g . Select * from (parameters name ) .

how to make internal table of that database table

e.g.

data itab like ( parameter name )

parameter name is database table name which v r passing through
parameter .

Thanks In Advance .
shaileshdube
 
Posts: 15
Joined: Wed Feb 12, 2003 1:08 am

Postby sgabaper » Wed Feb 12, 2003 2:30 am

Hi,

The following section in SAP Doc should help you.

Though I have created structure using the second section, I havent tried creating a int.table.



Specifying Database Tables Dynamically

To specify the name of a database table dynamically, use the following:

SELECT ... FROM (<name>) <options> ...

The field <name> must contain the name of a database table in the ABAP Dictionary. The table name must be written in uppercase. When you specify the name of a database table dynamically, you cannot use an empty INTO clause to read all of the columns into the work area <dbtab>. It is also not possible to use alternative table names.



Creating Data Objects Dynamically

All of the data objects that you define in the declaration part of a program using statements such as DATA are created statically, and already exist when you start the program. To create a data object dynamically during a program, you need a data reference variable and the following statement:

CREATE DATA <dref> TYPE <type>|LIKE <obj>.

This statement creates a data object in the internal session of the current ABAP program. After the statement, the data reference in the data reference variable <dref> points to the object. The data object that you create does not have its own name. You can only address it using a data reference variable. To access the contents of the data object, you must dereference the data reference.

You must specify the data type of the object using the TYPE or LIKE addition. In the TYPE addition, you can specify the data type dynamically as the contents of a field (this is not possible with other uses of TYPE).

CREATE DATA <dref> TYPE (<name>).

Here, <name> is the name of a field that contains the name of the required data type.
Cheers!
Sgabaper
sgabaper
 
Posts: 120
Joined: Sun Oct 20, 2002 11:42 pm
Location: Singapore

How to define Header line of Dynamic Table

Postby shaileshdube » Wed Feb 12, 2003 2:51 am

Hi ...

if i used this Statement to take data frm dynamically table ,
SELECT ... FROM (<name>) <options> ...
how to define its Header line .

thanks In Advancee .
shaileshdube
 
Posts: 15
Joined: Wed Feb 12, 2003 1:08 am

Postby sgabaper » Wed Feb 12, 2003 3:23 am

The second option tells you how to create a field symbol of the structure that u want, dynamically.
Cheers!
Sgabaper
sgabaper
 
Posts: 120
Joined: Sun Oct 20, 2002 11:42 pm
Location: Singapore

Postby sgabaper » Wed Feb 12, 2003 3:26 am

I hope the following will explain more....

create data dref type (REC_T6B2F-kotab).
assign dref->* to <fs1> .
select (tbl_fld)
into corresponding fields of <fs1>
from (REC_T6B2F-kotab)
where knuma = tbl_kona1-knuma and
DATBI >= sy-datlo and
DATAB <= sy-datlo.
Cheers!
Sgabaper
sgabaper
 
Posts: 120
Joined: Sun Oct 20, 2002 11:42 pm
Location: Singapore

Postby question_mark » Wed Feb 12, 2003 4:26 am

To make things less complicated, are you open to using call transaction?

Set parameter ID 'DTB' field table_name (of parameter).

call transaction 'SE16'.

:D
question_mark
 
Posts: 146
Joined: Wed Jan 29, 2003 7:12 pm

dynamically create internal table

Postby rachrach » Sun Feb 16, 2003 4:43 pm

sgabaper, I just tried to create an internal table dynamically. It turns out that 4.6 only support creating a line structure/type of work area using this 'CREATE ...' and field symbol method, but not internal table. am I right?

Code: Select all
DATA:  dref TYPE REF to data.
field-symbols: <fs_tname> type any.

PARAMETERS: tab_name(10).

START-OF-SELECTION.

CREATE DATA dref type (tab_name).
assign dref->* to <fs_tname> .

* the following not working:
* select * from (tab_name) into table <fs_tname>



what do you suggest to do such things w/o using data extract?
rachrach
 


Return to ABAP

Who is online

Users browsing this forum: No registered users and 4 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.