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: 

How to use dynamic internal table with FOR ALL ENTRIES

SuhaSaha
Advisor
Advisor
0 Kudos

Hello SDNers,

I am having a dynamic internal table & want to use FOR ALL ENTRIES(FAE) using this dyn. table.

This works fine for me:

IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
        SELECT field1 field2
          FROM TABLE ztable
          INTO TABLE itab "Itab is a static table
          FOR ALL ENTRIES IN <lt_tmp>
          WHERE (lv_dynwhere). "lv_dynwhere -> dynamic where clause
      ENDIF.

SAP documentation says:

"The logical expression sql_cond of the WHERE condition can be comprised of several logical expressions using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one comparison with a column of the internal table itab that can be specified statically or dynamically. "

How do we specify the column of the internal table dynamically ? Can we do something like this:

IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table
        SELECT field1 field2
          FROM TABLE
          INTO TABLE itab "Itab is a static table
          FOR ALL ENTRIES IN <lt_tmp>
          WHERE key_field1 = (dynamic token for column1 of <lt_tmp>)
                       key_field2 = (dynamic token for column2 of <lt_tmp>)
      ENDIF.

ENDIF.

Let me know if i am not clear about my requirement.

BR,

Suhas

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor

Hi Suhas,

I don't really see why you specifically need to write

WHERE key_field1 = (dynamic token for column1 of <lt_tmp>) AND
      key_field2 = (dynamic token for column2 of <lt_tmp>)

when you can build and use any dynamic where clause (including addressing the fields of the internal table used in FAE) via

WHERE (lv_dynwhere)

I think the second syntax is what the quoted help text is referring to.

Thomas

9 REPLIES 9

Former Member
0 Kudos

Hi Suhas,

Check this if it is of any help.

[;

0 Kudos

I have already read this message. Thanks anyways.

Any ideas guys ?

Edited by: Suhas Saha on Apr 5, 2010 7:51 PM

0 Kudos

What release are you on?

Rob

0 Kudos

Sorry for not mentioning it. I am on ECC 5.0 @ work & SAP NW 7.01 @ home

BR,

Suhas

0 Kudos

The help file also says:

> The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher).

Note the "Release 6.40 and higher".

Rob

Subhankar
Active Contributor
0 Kudos

Hi Suhas,

There is two solutions.

1. If you declare field symbol with static structure then you can do normally. like

IF <lt_tmp> IS NOT INITIAL. "<lt_tmp> is my dyn. internal table

SELECT field1 field2

FROM TABLE ztable

INTO TABLE itab "Itab is a static table

FOR ALL ENTRIES IN <lt_tmp>

WHERE field1 = <it_temp>-fld1.

ENDIF.

2. If the declare is dynamic(i.e type any table)You can generate one subroutine pool at runtime with the dynamic where clause. Then there will no syntax error.

Thanks,

Subhankar

ThomasZloch
Active Contributor

Hi Suhas,

I don't really see why you specifically need to write

WHERE key_field1 = (dynamic token for column1 of <lt_tmp>) AND
      key_field2 = (dynamic token for column2 of <lt_tmp>)

when you can build and use any dynamic where clause (including addressing the fields of the internal table used in FAE) via

WHERE (lv_dynwhere)

I think the second syntax is what the quoted help text is referring to.

Thomas

0 Kudos

Hello Thomas,

What i meant was something like this:

WHERE key_field1 = ('<LT_TMP-COL1>') AND 
      key_field2 = ('<LT_TMP-COL2>')

I am confused by what SAP means with "dynamic representation of internal table columns" in FAE ?

@Rob: I was referring to SAPNW 7.0 documentation & the phrase (release 6.40 & higher) is missing. Anyways fyi i am on ECC5.0 ABAP release 6.40.

@Subhankar: This is what Marcin had proposed in .

Thanks,

Suhas

Edited by: Suhas Saha on Apr 6, 2010 11:53 AM

SuhaSaha
Advisor
Advisor
0 Kudos

For future reference.

In ECC5.0 only way to achieve this would be create a dynamic WHERE clause with the internal table fields as mentioned in the post.

I don't think dynamic tokens are supported.