cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

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
Sandra_Rossi
Active Contributor

If you want to create an index on a table, but you can't because this input table is typed generically, and you know the component names on which you want to define the key (you are sure that these components will exist forever), and you know that this table is standard or sorted, I'd suggest that you define statically a temporary internal table with a component being the table index corresponding to the line in the input table, initialize it from the input table, and use the order of this temporary table to access the lines of the input table.

Example:

TYPES : BEGIN OF ty_temp_table,
          0FISCPER  TYPE ...
          0CURRENCY TYPE ...
          ZSCOPE    TYPE ...
          ZVERSION  TYPE ...
          TABIX     TYPE sytabix,
        END OF ty_temp_table,
        tt_temp_table TYPE SORTED TABLE OF ty_temp_table
             WITH NON-UNIQUE KEY 0FISCPER, 0CURRENCY, ZSCOPE, ZVERSION.

temp_table = VALUE #( 
    FOR <i_th_line> IN <i_th_data> INDEX INTO i_th_line_tabix
    ( VALUE #( BASE CORRESPONDING #( <i_th_line> ) tabix = i_th_line_tabix ) ).

LOOP AT temp_table REFERENCE INTO DATA(temp_line) 
      WHERE 0FISCPER  = ...
        AND 0CURRENCY = ...
        AND ZSCOPE    = ...
        AND ZVERSION  = ...
  <i_th_line> = <i_th_data>[ temp_line->tabix ].
  ...
0 Likes

Hello Sandra,

I am not sure I follow this:

LOOP AT temp_table REFERENCE INTO DATA(temp_line) 
      WHERE 0FISCPER  = ...
        AND 0CURRENCY = ...
        AND ZSCOPE    = ...
        AND ZVERSION  = ...

Because I don't know the values of these characteristics beforehand. I just want to loop at source table of hashed type for all combinations of these four fields. Maybe I'm missing something in what you suggest here.

Thank you,

Val

Sandra_Rossi
Active Contributor
0 Likes

Could you write a pseudo algorithm so that we can understand what you want to do?

0 Likes

Sandra,

Actually I described the algorithm that I need a bit earlier in the previous thread of this topic. mateuszadamus and michael.piesche, in turn, suggested solutions which I am going to explore in more details and (maybe) apply to my task.

Can we get back and talk the algorithm in more details after I'm done with the abovementioned research?

Thank you and best regards,

Val

Sandra_Rossi
Active Contributor
0 Likes

My answer fits your algorithm, I don't understand what you don't understand. Can you clarify?

  1. Input parameter: The hashed table I_TH_REF_DATA is defined by planning engine in accord with the structure of my aggregation level. It includes fields 0FISCPER, 0CURRENCY, ZSCOPE, ZVERSION, and more characteristics and keyfigures. The primary key for this table is also defined by planning engine and contains all characteristics. My custom planning function type accepts multiple single values for parameters 'Period' (0FISCPER), 'Currency' (0CURRENCY), 'Consolidation Scope' (ZSCOPE) and 'Version' (ZVERSION). So, my reference data (I_TH_REF_DATA) may contain multiple values for any of this characteristics.
  2. define all unique combinations of 'Period', 'Currency', 'Consolidation Scope' and 'Version' (this is done already);
  3. for every unique combination of 'Period', 'Currency', 'Consolidation Scope' and 'Version' loop at I_TH_REF_DATA, selecting only lines that belong to this combination. I have a custom logic implemented as a class method that accepts only single values of 'Period', 'Currency', 'Consolidation Scope' and 'Version'. I need to extract lines that belong to any unique combination of these characteristics from I_TH_REF_DATA, copy it to another dynamic table and pass this dynamic table to the custom logic as 'importing' parameter.

For part 3:

LOOP AT unique_combinations REFERENCE INTO DATA(combination).
LOOP AT temp_table REFERENCE INTO DATA(temp_line) WHERE 0FISCPER = combination->0fiscper AND 0CURRENCY = combination->0currency AND ZSCOPE = ... AND ZVERSION = ...
<i_th_line> = <i_th_data>[ temp_line->tabix ].

Thank you, Sandra, I'll take a note of that. This one definitely fits the scanario:

LOOP AT unique_combinations REFERENCE INTO DATA(combination).
  LOOP AT temp_table REFERENCE INTO DATA(temp_line) 
      WHERE 0FISCPER  = combination->0fiscper
        AND 0CURRENCY = combination->0currency

Best regards,

Val