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: 

Read Internal Table based on Multiple Values for Key Field

Former Member
0 Kudos

Hi Gurus,

i have one query can you tell me how read an internal table it_kna1 for multiple values of land1 DE US IND etc.

i had tried as below but i could not can you try and let me knwo at the earliest.

here i want read the values with DE or US and want further prosess them.

REPORT YC001.

tables kna1.

select-options: cust for kna1-kunnr.

data: begin of it_kna1 occurs 0,

kunnr like kna1-kunnr,

name1 like kna1-name1,

land1 like kna1-land1,

end of it_kna1.

select kunnr name1 land1 into table it_kna1 from kna1 where kunnr in cust.

read table it_kna1 with key land1 = ( 'DE' OR 'US' ) .

can anybody suggest me some solution.

Thanks,

Jeevi.

8 REPLIES 8

Former Member
0 Kudos

hi Jeevi,

You cannot use Or with READ, you have to loop,

loop at itab where land1 eq 'DE' Or
                           land1 eq 'US'.

endloop.

Former Member
0 Kudos

Hi,

Use

read table it_kna1 with key land1 = 'DE'

land1 = 'US' .

<b>Reward if helpful.</b>

Former Member
0 Kudos

Hi Jeevi,

By using the <b>Read</b> statement you are trying to select only one record, so you can try doing that in the below mentioned way too..

read table............ land1 = 'DE'.

if sy-subrc ne 0.

read table........... land1 = 'US'.

if sy-subrc ne 0.

read table........... land1 = 'IND'.

if sy-subrc eq 0.

< process your code>

endif.

endif.

endif.

<b>

Reward points if this helps,</b>

Kiran

Former Member
0 Kudos

hi jeevi,

when ur using list of values use OPERATORS as LIKE, IN, BETWEEN ..........

and change ur code as

read table it_kna1 with key land1 in ( 'DE' ,'US' ) .

or

read table it_kna1 with key land1 like 'DE%' OR 'US%' .

if helpful reward some points.

with regards,

Suresh Aluri.

Former Member
0 Kudos

read table itab with kunnr = itab2-kunnr.

if itab1-land1 eq IN or itab1-land1 eq US .

do any thing

endif.

Regards

Peram

Former Member
0 Kudos

Hi,

try this:

TABLES KNA1.

SELECT-OPTIONS: CUST FOR KNA1-KUNNR.

DATA: BEGIN OF IT_KNA1 OCCURS 0,

KUNNR LIKE KNA1-KUNNR,

NAME1 LIKE KNA1-NAME1,

LAND1 LIKE KNA1-LAND1,

END OF IT_KNA1.

SELECT KUNNR NAME1 LAND1 INTO TABLE IT_KNA1 FROM KNA1 WHERE KUNNR IN CUST.

  • read table it_kna1 with key land1 = ( 'DE' OR 'US' ) .

LOOP AT IT_KNA1 WHERE LAND1 = 'DE'

OR LAND1 = 'US'.

WRITE: / IT_KNA1-KUNNR, IT_KNA1-NAME1, IT_KNA1-LAND1.

ENDLOOP.

Regards, Dieter

Former Member
0 Kudos

This should be what you need:


REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 80 MESSAGE-ID 00.

TABLES kna1.

SELECT-OPTIONS: cust FOR kna1-kunnr.

DATA: BEGIN OF it_kna1 OCCURS 0,
        kunnr LIKE kna1-kunnr,
        name1 LIKE kna1-name1,
        land1 LIKE kna1-land1,
      END OF it_kna1.

DATA: itab_index LIKE sy-tabix.

SELECT kunnr name1 land1
  INTO TABLE it_kna1
  FROM kna1
  WHERE kunnr IN cust.

SORT it_kna1 BY land1.
READ TABLE it_kna1 WITH KEY
  land1 = 'DE'
  BINARY SEARCH.

itab_index = sy-tabix.
WHILE sy-subrc = 0.
  itab_index = itab_index + 1.
  WRITE: /001 it_kna1-kunnr, it_kna1-land1, it_kna1-name1.
  READ TABLE it_kna1 INDEX itab_index.
  IF it_kna1-land1 <> 'DE'.
    sy-subrc = 99.
  ENDIF.
ENDWHILE.

SKIP 1.

READ TABLE it_kna1 WITH KEY
  land1 = 'US'
  BINARY SEARCH.

itab_index = sy-tabix.
WHILE sy-subrc = 0.
  itab_index = itab_index + 1.
  WRITE: /001 it_kna1-kunnr, it_kna1-land1, it_kna1-name1.
  READ TABLE it_kna1 INDEX itab_index.
  IF it_kna1-land1 <> 'US'.
    sy-subrc = 99.
  ENDIF.
ENDWHILE.

Rob

Former Member
0 Kudos

Hi All,

My query has been answered, thanks for your quick response and the precious time spent by the contributors.

thanks,

Jeevi.