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: 

Sort for VBELN and POSNR

Former Member
0 Kudos
623

Hello All,

I have a internal table with 3 fields in the following order:

VBELN (CHAR field), POSNR (NUMC field) and ETENR . I have sorted this table based on VBELN and POSNR; when I READ the TABLE with binary search WITH VBELN and POSNR as KEY fields, some times the read fails even if the entry is there.

If I READ TABLE without binary search it works good!

Anybody knows the reason and ideas to fix it.

Thanks

Kasee

8 REPLIES 8

Former Member
0 Kudos
162

I think your binary search works well only when you have one key. I am not sure though.

Regards,

Ravi

anversha_s
Active Contributor
0 Kudos
162

hi,

<i>when u read the table,

read it with key fields that are used for sorting.</i>

pls chk this link.

http://help.sap.com/saphelp_erp2005/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/frameset.htm

rgds

anver

Former Member
0 Kudos
162

binary search works better for key fields....if vbeln and posnr are the key fields it will work fine...there might be a mistake in the definition..

jayanthi_jayaraman
Active Contributor
0 Kudos
162

Hi,

If you are reading the table using vbeln and posnr,sort the table by both.Otherwise,whatever things are used in reading,just sort with those fields.

Former Member
0 Kudos
162

Hello All,

I have sorted on both the key fields (VBELN and POSNR)!

Actually if both the fields are of same type (for example CHAR OR NUMC or just NUM) it works well for me.

Thanks

Kasee

0 Kudos
162

hi,

in the read statement use both VBELN and POSNR.

rgds

Anver

Former Member
0 Kudos
162

hi,

check this..

vbeln posnr etenr

10 000001 12.13

10 000002 16.15

11 000001 112.13

11 000002 11.13

11 000003 18.30

index vbeln posnr etenr

0 10 000001 12.13

1 10 000002 16.15

2 11 000001 112.13 " index is set here

3 11 000002 11.13

4 11 000003 18.30

read table itab with key vbeln = 10

and posnr = 000002

binary search.

the index is set to 2 in here ..

now look for posnr here when im applying the binary search ..

there might be a possibility of posnr

10 < 11 (correct) and 000002 < 000001(false) so condition fails ..

this might be the case ..

i know that the binary search logic must read the index 0 and 1 that means the upper portion in the list leaving the index 3 and 4 ..

on the condition fail this is going down with sy-subrc <>0 as binary search is on

just check this ..

regards,

vijay.

0 Kudos
162

Hello All,

I guess as Vinay says, this works for me. Can any body suggest ways to come over this problem?