Skip to Content
1

Reduce operator with Secondary key

Feb 28, 2017 at 04:22 AM

107

avatar image
Former Member

Hi,

I am trying to use secondary key with the reduce constructor operator. Below are the code lines.

data: lt_index TYPE STANDARD TABLE OF cmm_d_idx
               WITH NON-UNIQUE SORTED KEY ik_obj_id COMPONENTS obj_id.

lt_index = VALUE cmm_t_idx(
           FOR ls_root_extract IN lt_risk_root_extract 
           LET lv_obj_id  = |{ ls_root_extract-fbuda DATE = USER }| & |{ '-                ' && ls_root_extract-locid && '-' && ls_root_extract-ro_type+               7(3) }|
            IN  ( key = ls_root_extract-key
                  obj_id   = lv_obj_id
                  obj_item = REDUCE cmm_idx_obj_item( 
                             INIT lv_itm = 1 FOR ls_idx IN lt_index 
                             USING KEY ik_obj_id 
                             WHERE ( obj_id = lv_obj_id ) 
                             NEXT lv_itm = ls_idx-obj_item + 1 ) 
                  obj_type = ls_root_extract-ro_type ) ).

These line are giving me syntax error as:-

However skipping the where condition giving me error free code. I have tried using the same logic with the old style and that is working fine, so I'm not sure what is missing here.

LOOP AT lt_index ASSIGNING FIELD-SYMBOL(<fs_idx>) 
                  USING KEY ik_obj_id WHERE obj_id is INITIAL.
* <<Rest of the logic>>
ENDLOOP.
error.png (4.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Horst Keller
Feb 28, 2017 at 07:30 AM
1

The error message for your expression is correct.

There is a type mismatch in the WHERE condition

Your

LET lv_obj_id = |{ ls ... 

is of type string.

Put a CONV around the RHS, to make lv_obj_id the same type as obj_id.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

My bad.. Thanks it has resolved the issue.

0
Horst Keller
Feb 28, 2017 at 07:15 AM
1

In a simplified example both either give syntax errors or not:

TYPES itab TYPE STANDARD TABLE OF spfli
      WITH EMPTY KEY
      WITH NON-UNIQUE SORTED KEY mkey COMPONENTS cityfrom cityto.
DATA itab TYPE itab.
LOOP AT itab INTO DATA(wb) USING KEY mkey WHERE carrid  = '...'. "Syntax error
ENDLOOP.
DATA(jtab) = VALUE itab( FOR wa IN itab USING KEY mkey           "Syntax error
                                        WHERE ( carrid = '...' )
                         ( wa ) ).
TYPES itab TYPE STANDARD TABLE OF spfli
      WITH EMPTY KEY
      WITH NON-UNIQUE SORTED KEY mkey COMPONENTS cityfrom cityto.
DATA itab TYPE itab.
LOOP AT itab INTO DATA(wb) USING KEY mkey WHERE cityfrom  = '...'. "No Syntax error
ENDLOOP.
DATA(jtab) = VALUE itab( FOR wa IN itab USING KEY mkey             "No Syntax error
                                        WHERE ( cityfrom = '...' )
                         ( wa ) ).

Back to 7.40, SP08, Kernel Patch Level 14. And that is as documented.

Share
10 |10000 characters needed characters left characters exceeded