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

Filling dynamic table with dynamic structure en fields!

Former Member
0 Likes
777

Hello All,

I have written the following code. Which is okay according the syntax check. But when I run the abap code it will give a syntax error. I want to insert data from database table into internal table. Because the tables that have to read are so many I decided to make a dynamic statement which can be used for all tables. Except it won't work as I wish.

(LT_FIELDS) content is the dynamic fields which are defined earlier in the code and will change each loop.

(TAB_X) content is the dynamic internal table which is defined earlier in the code and will change each loop.

= structure of PA0002.

(TAB_N) = T_PA0002.

The code:

SELECT (LT_FIELDS) FROM (TAB_X) INTO CORRESPONDING FIELDS OF .

ENDSELECT.

Can someone give me some advice how to solve this issue?

During the run at the line "INSERT (TAB_N) FROM . " SAP creates an error like below.

K. tekst

Ein in einem SQL-Befehl genannter Tabellenname ist unbekannt.

Wat is er gebeurd?

Error in ABAP application program.

The current ABAP program "ZPF_R_MUTATIEOVERZICHT_MAIA" had to be terminated

because one of the

statements could not be executed.

This is probably due to an error in the ABAP program.

Foutenanalyse

Es ist eine Ausnahme aufgetreten, die weiter unten näher erläutert wird.

Die Ausnahme, der die Klasse 'CX_SY_DYNAMIC_OSQL_SEMANTICS' zugeordnet ist,

wurde nicht abgefangen und führte deshalb zu einem Laufzeitfehler.

Der Grund für die Ausnahme ist:

In einem SELECT-, UPDATE- oder DELETE-Befehl wurde ein ungültiger

Tabellenname "T_PA0002" angegeben.

Aus einem der folgenden Gründe tritt der Fehler erst zur Laufzeit auf:

- der Tabellenname wurde dynamisch angegeben, oder

- die SELECT-Klausel, WHERE-Klausel, GROUP-BY-Klausel, HAVING-Klausel

oder ORDER-BY-Klausel wurde dynamisch angegeben.

4 REPLIES 4
Read only

Former Member
0 Likes
571

Hi,

Use fields symbols to achieve this.

regards

shibu

Read only

0 Likes
571

I use fieldsymbols.

See my code here:

DATA: TAB_N(12) TYPE C,

TAB_X(12) TYPE C,

L_TABREF TYPE REF TO DATA,

L_STRUCREF TYPE REF TO DATA.

FIELD-SYMBOLS: <T1_TAB> TYPE STANDARD TABLE,

<W1_TAB> TYPE ANY.

CREATE DATA L_TABREF TYPE TABLE OF (TAB_X).

CREATE DATA L_STRUCREF TYPE (TAB_X).

ASSIGN L_TABREF->* TO <T1_TAB>.

ASSIGN L_STRUCREF->* TO <W1_TAB>.

Read only

Sm1tje
Active Contributor
0 Likes
571

When I look at the short dump text it states that table T_PA0002 is unknown. I guess that you do not want to update a table called T_PA0002, but probably the actual transparant table PA0002. Correct me if I'm wrong.

One more thing though. If indeed, you want to update PA0002, I don't 'think' it would be wise to do a direct update on a Standard SAP database table. There are other ways, which I would strongly advice you to look into.

Read only

Former Member
0 Likes
571

I Just want to insert data into internal table T_PA0002 from database table PA0002.

The internal table and database table can change during the runtime of the program. But Its always filling the internal table with data from database table.

I made it this way because the data I need to extract from data base tables can change depending on the procedures in table T9VS2.

So I can't know the structure or the table which has to be selected each procedure. Or I have to make a big program with a lot of if or Case statements in it. I want to avoid that! Dynamic table is much quicker to write and understand when it works.

It wil reduce a lot of code! I hope someone can give me a hint to solve the problem.