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

Dynamic data declaration - need help

Former Member
0 Likes
476

Hi,

I have a following issue - I am not sure whether this is possible - so I need your feedback/expertise.

I have a custom table (example ZABC) with several fields in it - one of them being TABNAME . Content of that table ZABC is

MANDT TABNAME ZCHECK

800 KNA1 X

800 KNVV X

800 KNVP

etc.

There is no rule how many entries will be in this ZABC table - I guess it will be less than 20 - but this is not business rule.

MANDT and ZCHECK fields are not important at this stage.

The challenge I have is to fetch all data from all those physical tables (KNA1, KNVV, KNVP) in their matching internal tables.

I need to keep those "internal" table with content throughout the entire program for certain validation.

I know that I should dynamically define those internal tables but I have issues not knowing how many tables will be defined in ZABC table and I personally do not want to declare "<fs_itab> TYPE ANY TABLE" 20 or so times as fs_itab1 - fs_itab20.

Is there any way I can dynamically create as many internal tables as needed and keep their content throughout program run-time.

Regards

Goran

3 REPLIES 3
Read only

Former Member
0 Likes
451

Using <b>CREATE DATA</b> statement you can create as many internal tables you want as shown below. But you have to assign that to a field symbol to process

DATA: dref TYPE REF TO data.

FIELD-SYMBOLS: <FS_TABLE> TYPE ANY TABLE.

CREATE DATA dref TYPE TABLE OF (table name).

ASSIGN dref->* TO <FS_TABLE>.

SELECT * FROM (table name) INTO TABLE <FS_TABLE>.

Regards

Kathirvel

Read only

Former Member
0 Likes
451

See the examples in the following blogs

/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

Former Member
0 Likes
451

All those examples you'all posted are great BUT it does not answer my question nor help me to solve my issue. Maybe I was not clear enough ... or something is wrong with me

Once again.

I have no problem to get a dynamically defined table and fill its content from ONE physicall table. That is pretty straight forward. The issue I have is that I do not know how many dynamically tables I will have to define and later asign to field symbol. Look at my custom table above and you will understand what I am trying to say.

What makes this issue more complex is that, once data fetch from those physicall SAP tables, I have to keep the content for all those internal tables during the entire program run . Second the most, I do not want to limit the program by defining FS "n" times in data declaration section. That is really important since I have no idea how many tables will be accessed.

If I follow the logic from your examples, I will end up overwritting the FS content every time I assign new internal table to FS.

In order to solve this issue, I was thinking that whenever I get the data from SAP table into internal table (field symbol) i export the content of internal table / FS to memory and then retrieve them when needed. This sounds like waky /fuzzy process and I am not aware of anything better. I am old fashion ABAP guy who got certified 1995 and have not seen ABAP for at least 5 years.

I would like that someone either tells me whether I am OK going forard with my "memory" solution or ... in few words gives me hint how to handle multiple dynamicall defined tables AT THE SAME TIME with its content using some OO code.

Thanks

G