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: 

Sorted Table - tabix issue

former_member194669
Active Contributor
0 Kudos
639

All,

I have the following code While executing system is pointing to sy-tabix, but the data I am getting in the READ statement is from last record in the internal table

report  z_9699_30.
tables : eket.
types : begin of ty_eket.
        include structure eket.
types:  end of ty_eket.
data: wa_eket                 type ty_eket.
data: it_eket                 like sorted table of wa_eket
                              with unique key primary_key
                              components ebeln ebelp etenr
                              with non-unique sorted key secondary_key
                              components ebeln ebelp.
parameters: p_ebeln like eket-ebeln.
parameters: p_ebelp like eket-ebelp.
select * from eket into table it_eket
      where ebeln eq p_ebeln.
      read table it_eket into wa_eket with table key secondary_key
               components ebeln  = p_ebeln
                          ebelp  = p_ebelp.

Please copy and execute this by giving EBELN and EBELP from EKET

Please make sure while selecting from EKET please select data of multiple records available for same EBELP ie llike

Here below PO # 4500000003 and for Item # 00030 is have multiple records

Here in selection screen by giving PO # as 4500000003 (EBELN) Item # as 00030 (EBELP) , then in the above READ statement system giving SY-TABIX as 3 but if you see the WA_EKET-ETENR is showing 2 instead of 1. This is where is the issue is

EBELNEBELPETENRHeader 4
4500000003000101
4500000003000201
4500000003000301
4500000003000302
8 REPLIES 8

FredericGirod
Active Contributor
0 Kudos
407

Hi,

I have the same issue with an IDES.

Maybe the reason is the secondary index have only one entry, the last one, and the TABIX is the line readed by the secondary index.

Regards

Fred

0 Kudos
407

Hi,

The SAP documentation clearly saying it will read the first records if it having more than 1 record

SwadhinGhatuary
Active Contributor
0 Kudos
407

Hello Abaper,

Its unexpected  behaviour as regular ,

i also test in ides have out put,, i expect as it is sorted table system might found record in sy-tabix 3 but it search record having same key so we gat 4th row data in  work area.

0 Kudos
407

Hi,

I like to have experts in this forum, like to give their opinion whether it is SAP bug or its my code Bug.?

Thanks

aRs.

former_member194669
Active Contributor
0 Kudos
407

Any response to this please

aRs

0 Kudos
407

You'll have to wait more than 90 minutes before you get a response. Maybe even a few days.

raymond_giuseppi
Active Contributor
0 Kudos
407

Now execute some

MOVE sy_tabix TO lv_index.
READ TABLE it_eket INTO wa_eket
      INDEX lv_index USING KEY secondary_key.
BREAK-POINT.
READ TABLE it_eket INTO wa_eket
      INDEX lv_index USING KEY primary_key.
BREAK-POINT.

and conclude yourself on the meaning of life index with two different keys defined...


Regards,

Raymond


PS: Reference in online help for sy-tabix now

Note that the sy-tabix system field is populated by the assigned secondary index, if sorted secondary keys are used. If this value is used for the subsequent index access to the internal table, the same table index must be explicitly used here. If used implicitly, the value would be interpreted as a primary index. 

0 Kudos
407

Hi,

I am not fully understood your comment

that means we should not use declaration like the following


data: wa_eket                 type ty_eket.
data: it_eket                 like sorted table of wa_eket
                              with unique key primary_key
                              components ebeln ebelp etenr
                              with non-unique sorted key secondary_key
                              components ebeln ebelp.

Please correct if i wrongly understood.

Thanks

aRs