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: 

'loop where' on dynamic hashed table

Former Member
0 Kudos

hi everybody,

im having a problem reading selectively out of a dynamic hashed table.

i_th_ref_data is a hashed table delivered by a SAP UExit filled with data. i wish to loop over it (several entries required) selectively (i.e. WHERE) for performance reasons.

i've treid:

...

assign component '0COMPANY' of

structure <f_ref_data>

to <f_company>.

...

loop at i_th_ref_data assigning <f_ref_data>

where <f_company> = '4711'.

...

endloop.

but get the error "the row type of the table must be statically defined"

does anybody have an idea how to do a dynamic loop on a hashed table like this?

performance is critical: hence solutions with if-statements in the loop are not acceptable.

greetings,

martin

12 REPLIES 12

kesavadas_thekkillath
Active Contributor
0 Kudos

loop at i_th_ref_data assigning <f_ref_data>.
if <f_company> = '4711'.
...
endif.
endloop.

This will work

0 Kudos

performance is critical: hence solutions with if-statements in the loop are not acceptable

0 Kudos

>

>


> loop at i_th_ref_data assigning <f_ref_data>.
> if <f_company> = '4711'.
> ...
> endif.
> endloop.
> 

>

> This will work

Just a quick note about this. It won't work. Why? Because the <f_ref_data> (and it's component) are assigned before the loop. When you're in the loop, the <f_ref_data> points to a different area of memory. In these situations you must either put the ASSIGN COMPONENT inside the loop, or (more efficiently) use LOOP AT i_th_ref_data INTO <f_ref_data>.

To the original question:

Dynamically create a STANDARD table of the same line type as i_th_ref_data with a key of 'COMPANY' (double check the name of the key - in my experience infoobject 0COMPANY relates to field COMPANY).

DATA: lr_data TYPE REF TO data.
CREATE DATA lr_data LIKE LINE OF i_th_ref_data.
ASSIGN lr_data->* TO <ls_ref_data>.

CREATE DATA lr_data LIKE STANDARD TABLE OF <ls_ref_data>.
ASSIGN lr_data->* TO <lt_ref_data>.

<lt_ref_data> = i_th_ref_data.

SORT <lt_ref_data> BY ('COMPANY').

READ TABLE <lt_ref_data> WITH KEY ('COMPANY') eq '4711' TRANSPORTING NO FIELDS BINARY SEARCH.
l_index = sy-tabix.
ASSIGN COMPONENT 'COMPANY' OF STRUCTURE <ls_ref_data> TO <l_company>.
LOOP AT <lt_ref_data> INTO <ls_ref_data> FROM l_index.
  IF <l_company> NE '4711'.
    EXIT.
  ENDIF.
* Do stuff
ENDLOOP.

You might be able to dynamically create a SORTED table, which would be better. But I can't remember how to dynamically define the key. You probably can do it via RTTS.

matt

MarcinPciak
Active Contributor
0 Kudos

For me this loop is not ok. Does <f_company> hold component name or its value? It should be the former:


loop at i_th_ref_data assigning <f_ref_data>
where ('COMPONENT_NAME') = '4711'.
...
endloop.

"not as in your case
loop at i_th_ref_data assigning <f_ref_data>
where some_value = '4711'. "<f_company> holds SOME_VALUE
...
endloop.

Regards

Marcin

0 Kudos

hello marcin,

<f_company> hold the component name (not the value).

unfortunately if i hardcode it with '0COMPANY' the result is the same.

thanx for ur answer though.

martin

kesavadas_thekkillath
Active Contributor
0 Kudos

Loop statement supports dynamic clauses in higher versions only but read statement supports.

May be you have to do something like this


read table i_th_ref_data assigning <f_ref_data> with table key ('0COMPANY') = '4711'.

You can also dynamically pass the fields to the read statement instead of harcoding it , but the problem is you can only get one line per read statement . So the possibility is go for if .. endif conditions

0 Kudos

keshav,

what do you mean "Loop statement supports dynamic clauses in higher versions"?

which versions r u refering to?

u r read proposal does not work since i need several entries.

Moderator message - Please do not use textspeak

Edited by: Rob Burbank on Sep 21, 2010 1:51 PM

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi,

I mean the syntax of loop with dynamic where clause is supported in higher releases of SAP. In your code the field seems to be dynamic in nature.

In the link:[http://www.adfahrer.com/workplace/sem/2006-11-28-adsig-sbn-walldorfabap/horstkeller-cd200-sent-in.pdf] . Available after SAP NetWeaver 2004s under section preview of next release. I think so its available from SAP NetWeaver 7.0

0 Kudos

Keshav,

this presentation is from 2006 and we are using 2004S so I cant imagine that it would not be possible for us to use conditional/dynamic where's

Our system profile:

SAP_ABA 700 0019 SAPKA70019 Cross-Application Component

SAP_BASIS 700 0019 SAPKB70019 SAP Basis Component

PI_BASIS 2006_1_700 0009 SAPKIPYM09 Basis Plug-In (PI_BASIS) 2006_1_700

ST-PI 2008_1_700 0002 SAPKITLRD2 SAP Solution Tools Plug-In

SAP_BW 700 0021 SAPKW70021 SAP NetWeaver BI 7.0

FINBASIS 602 0005 SAPK-60205INFINBASIS FINBASIS

BI_CONT 703 0014 SAPKIBIIQ4 Business Intelligence Content

SEM-BW 602 0005 SAPK-60205INSEMBW SEM-BW 600 : Add-On Installation

ST-A/PI 01M_BCO700 0000 - Servicetools for other App./Netweaver 04

any other suggestions?

0 Kudos

Hi Martin,

IF..ENDIF will do , but as you said performance will be the issue. I dont see any other solutions , also im not sure if there is any work around for this.

Or moving to a temp table and deleting the entries which are not equal to the condition ( Delete statements supports dynamic where clauses i Guess in lower versions ), But if .. endif will be better than a delete.

0 Kudos

Keshav,

are you saying that our system does not support dynamic where's ???

If yes: what system requirements are required?

Martin

SAP_ABA 700 0019 SAPKA70019 Cross-Application Component

SAP_BASIS 700 0019 SAPKB70019 SAP Basis Component

PI_BASIS 2006_1_700 0009 SAPKIPYM09 Basis Plug-In (PI_BASIS) 2006_1_700

ST-PI 2008_1_700 0002 SAPKITLRD2 SAP Solution Tools Plug-In

SAP_BW 700 0021 SAPKW70021 SAP NetWeaver BI 7.0

FINBASIS 602 0005 SAPK-60205INFINBASIS FINBASIS

BI_CONT 703 0014 SAPKIBIIQ4 Business Intelligence Content

SEM-BW 602 0005 SAPK-60205INSEMBW SEM-BW 600 : Add-On Installation

0 Kudos

SAP NetWeaver 7.0 or higher.