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

Function Module Table problem

Former Member
0 Likes
990

Hi,

I have a FM with a changing parameter of type TABLE,

I want to use loop at on this table with WHERE Clause



FUNCTION Z_DATA_RECCOUNT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  CHANGING
*"     REFERENCE(T_SOURCE_PACKAGE) TYPE  TABLE

FIELD-SYMBOLS: <l_s_source_package> type ANY,
               <temp_buffer> type any.

LOOP AT t_source_package ASSIGNING <temp_buffer>
                                    WHERE /bic/tr = '2' AND
                                                /bic/res = '3'.

But the system is saying that:

Error:

"In "LOOP ... WHERE ..." the row type of the table must be statically defined statically defined"

Please advice

10 REPLIES 10
Read only

former_member156446
Active Contributor
0 Likes
964

declare :

<temp_buffer> like line of t_source_package.

Read only

0 Likes
964

Nopes, not working:

It is saying:

The field "T_SOURCE_PACKAGE" specified under LIKE has no type.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
964

Hello Merc,

This is because the Field Symbol <temp_buffer> is generic & its type is not determined till runtime.

So when you are trying to use LOOP ... WHERE & giving the fieldnames

WHERE /bic/tr = '2' AND /bic/res = '3'.

the compiler cannot determine that these fields are available in <temp_buffer>.

Hence you are getting this error.

I have a question, if you know the tables fields then why have you decalred the TABLES param as generic ?

BR,

Suhas

PS: LOOP ... WHERE does not support dynamic tokens. So you have to think of some workaround for this

Read only

Former Member
0 Likes
964

Ok, But if I do:



FUNCTION Z_DATA_RECCOUNT.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  CHANGING
*"     REFERENCE(T_SOURCE_PACKAGE) TYPE  TABLE
 
DATA: temp_buffer LIKE SORTED TABLE OF  l_s_source_package
                 WITH UNIQUE KEY /BIC/SETRADAT
                                   /BIC/SERESNAM.
 "There are 2000 records in t_source_package table.

READ TABLE t_source_package into temp_buffer 
                          WITH TABLE KEY /BIC/SETRADAT = '2'
                                         /BIC/SERESNAM = '3'.

Error:

The specified type has no structure and therefore no component called "/BIC/SETRADAT". component called "/BIC/SETRADAT".

Thats cuz t_source_package is of type table, how shall I get the type of it and assign to it it ?

Read only

Former Member
0 Likes
964

I think i resolved it like this





READ TABLE t_source_package into temp_buffer 
                          WITH TABLE KEY ('/BIC/SETRADAT') = <TRADE_DATE>
                                         ('/BIC/SERESNAM') = <RESOURCE_NAME>.


Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
964

Hello,

You can do this because READ TABLE supports dynamic tokens

But then you will read only 1 line of the table which contradicts the usage of LOOP ... WHERE

BR,

Suhas

Read only

0 Likes
964
<temp_buffer> type line of t_source_package.
Read only

Former Member
0 Likes
964

type line of t_source_package.

does not work.

Read only

Former Member
0 Likes
964

Saha,

What shall I do then, I need more records not just one, Please help !

Read only

markus_hofmann2
Explorer
0 Likes
964

Hi Merc

Try the following non performant workaround:


LOOP AT t_source_package ASSIGNING <temp_buffer>.
    IF <temp_buffer>-/bic/tr = '2' AND <temp_buffer>-/bic/res = '3'.
        " Do your coding
    ENDIF.
ENDLOOP.

Best regards

Markus

Edited by: Markus Hofmann on Dec 16, 2009 10:08 AM