cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Loop over dynamic hashed table with a key

5,136

Hello,

I'm working on custom planning function type that implements IF_RSPLFA_SRVTYPE_IMP_EXEC_REF (planning on reference data).

The EXECUTE method of the implementing class has I_TH_REF_DATA TYPE HASHED TABLE as an 'importing' parameter. This table actually includes my reference data. The structure of the table is defined dynamically at runtime in accord with the structure of an aggregation level. It includes all characteristics and keyfigures that the aggregation level is comprised from.

To avoid full scan of the table I want to loop over it using some kind of 'partial' key that includes only limited set of characteristics. Product assistance suggests something like that:

DATA spfli_tab TYPE HASHED TABLE
OF spfli
WITH UNIQUE KEY primary_key
COMPONENTS carrid connid
WITH NON-UNIQUE SORTED KEY city_from_to
COMPONENTS cityfrom cityto
WITH NON-UNIQUE SORTED KEY city_to_from
COMPONENTS cityto cityfrom.

LOOP AT spfli_tab ASSIGNING <spfli> USING KEY city_from_to.

This, however. does not apply to my task, as the table I_TH_REF_DATA is defined somewhere inside planning engine and I have no control over its structure, keys included.

I know beforehand the structure of the aggregation level, and want to loop using a key that includes, let's say, characteristics 0FISCPER, 0CURRENCY, ZSCOPE and ZVERSION. I need something like

LOOP AT I_TH_REF_DATA ASSIGNING <fs_line> USING KEY COMPONENTS '0FISCPER' '0CURRENCY' 'ZSCOPE' 'ZVERSION'

However, it seems that ABAP syntax does not provide for that.

Please advise, how can I loop over a dynamic hashed table avoiding full table scan?

Thank you,

Val

View Entire Topic
gregor_dieckmann
Product and Topic Expert
Product and Topic Expert

Hi Val,

the parameter I_TH_REF_DATA is passed by value, so just do a dynamic sort (yes, hashed tables can be sorted) and do the usual group change logic. So in the loop at I_TH_REF_DATA you just fill a local table and at any new combination you just call your method with the collected records from the previous combination. You don't need the unique combination table here.

This also works without sorting but then you have to collect the records contained in one group first, e.g. in the non-key part of your unique combination table. This has the disadvantage that you have to copy the records (or use a reference).

I don't understand why you are afraid of the full table scan, the logic you explained anyway needs a full table scan.

I think the first option is simple and efficient; observe that SORT ... is one statement in the ABAP kernel, so it fast.

Regards,

Gregor

MateuszAdamus
Active Contributor

Heh, it never occurred to me, that a hash table can be sorted. I guess it's because I got burned on trying to sort a sorted table...

But indeed, it is possible and clearly stated in the documentation, too.

Kind regards,
Mateusz
0 Likes

Hi Gregor,

Thank you for your suggestion. I'll definitely try it, and see how it affects performace.

Best regards,

Val