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: 

How to binary search ITAB without structure

Former Member
0 Kudos

Hi everybody,

I defined an ITAB with

lt_rlm_pods TYPE TABLE OF int_ui.

where int_ui is a data-element not a structure!

So, the following is not possible:

READ TABLE lt_rlm_pods  WITH KEY int_ui = ls_anlage-int_ui
                BINARY SEARCH
                TRANSPORTING NO FIELDS.

Does anbody know how to performe the binary search?

Thanks

Regards

Mario

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
0 Kudos

Use pseudo component TABLE_LINE in the READ TABLE statement (press F1 or google help.sap.com)


Regards,

Raymond

12 REPLIES 12

Former Member
0 Kudos

Hi Mario,


Try this:


TYPES: BEGIN OF ty_int_ui,

             int_ui TYPE int_ui,

             END OF ty_int_ui.

DATA: lt_rlm_pods TYPE TABLE OF ty_int_ui.

READ TABLE lt_rlm_pods  WITH KEY int_ui = ls_anlage-int_ui

                                        BINARY SEARCH

                                        TRANSPORTING NO FIELDS.    

Regards,

Viswa.                                                      

0 Kudos

Hi Viswa,

yes, I tried this already. But I wanted to know, how it works with:

lt_rlm_pods TYPE TABLE OF int_ui.

🙂

Regards

Mario

0 Kudos

Try to check the structure of the Table created in Debug mode. You might understand.

0 Kudos

Hi Mario,

for key access WITH KEY you need one or several fields, and for BINARY SEARCH the table must be sorted by this field(s). Without fields you can't use this READ TABLE itab WITH KEY option.

Regards,

Klaus

raymond_giuseppi
Active Contributor
0 Kudos

Use pseudo component TABLE_LINE in the READ TABLE statement (press F1 or google help.sap.com)


Regards,

Raymond

0 Kudos

Hi,

thank you all!

As it is not possible I mark the question as answered.

Regards Mario

0 Kudos

Wrong, did you try my solution ?

REPORT ztableline.
DATA: itab TYPE TABLE OF i.
APPEND 1 TO itab.
APPEND 10 TO itab.
APPEND 2 TO itab.
SORT itab.
READ TABLE itab TRANSPORTING NO FIELDS WITH KEY table_line = 2 BINARY SEARCH.
WRITE: / '2', sy-subrc.
READ TABLE itab TRANSPORTING NO FIELDS WITH KEY table_line = 3 BINARY SEARCH.
WRITE: / '3', sy-subrc.

Regards,

Raymond

0 Kudos

The READ statement is possible on your Table. But if you check it in debug mode you will see that the structure of your table is as follows

LINE |  TABLE_LINE |

Hence the WITH KEY condition in your READ statement must be on the column TABLE_LINE.

Regards,

Mayur Priyan. S

0 Kudos

Hi Mario,

Raimond wants you to have a look at this:

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb35f8358411d1829f0000e829fbfe/content.htm

There the option

READ TABLE itab WITH TABLE KEY table_line = f result.

might be of interest.

Regards,

Klaus

0 Kudos

Hi Mario,

It is possible.

Regards,

Viswa.

0 Kudos

is correct. You are just "fabulous".....

0 Kudos

Hi Raymond,


sorry. In deed you are right. Unfortunately I cannot give a perfect 10, because I marked it already as soled.


Sorry, Regards

Mario