Application Development and Automation 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 only

read statement

Former Member
0 Likes
830

i am having errors with the following statement.

READ TABLE IT_A901 WITH KEY BZIRK = IT_KNVV-BZIRK

VKORG = IT_KNVV-VKORG

KDGRP = IT_KNVV-KDGRP

DATBI GE IT_BSID-BUDAT

DATAB LE IT_BSID-BUDAT.

Any suggestions.

madhu.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
803

Hi,

Yes..If the record is found then the EXIT statement will come out of the LOOP in the first iteration itself..If there is no record found..Then it will directly come out of the LOOP.

Thanks,

Naren

7 REPLIES 7
Read only

Former Member
0 Likes
803

Hi,

You cannot use GE operator in the READ statement..

Instead use LOOP AT..EXIT..ENDLOOP.

LOOP AT IT_A901 WHERE BZIRK = IT_KNVV-BZIRK

AND VKORG = IT_KNVV-VKORG

AND KDGRP = IT_KNVV-KDGRP

AND DATBI GE IT_BSID-BUDAT

AND DATAB LE IT_BSID-BUDAT.

EXIT.

ENDLOOP.

IF SY-SUBRC <> 0.

      • RECORD NOT FOUND.

ELSE.

      • RECORD FOUND.

ENDIF.

Thanks,

Naren

Read only

0 Likes
803

Thanks Naren. However i am assuming that the Exit command would loop the Internal table only once and would exit even if multiple entries found for the same condition.

Madhu.

Read only

0 Likes
803

Hi Madhu,

Istead of using 'EXIT' inside loop, U can perform the action whichever u want

in that loop. It will work only for the matching records.

Thanks,

Sreenu

Read only

0 Likes
803

That is right, but you were trying to use the READ statement which tells us that you only want to get one record, which is why Narren has added the EXIT statement. If you want all record that satisfy the condition, simply remove the EXIT statement.

Narren's solution is to get around the limitation of using GE or LE in a READ statement, this is the reason for the LOOP and the EXIT statements.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
804

Hi,

Yes..If the record is found then the EXIT statement will come out of the LOOP in the first iteration itself..If there is no record found..Then it will directly come out of the LOOP.

Thanks,

Naren

Read only

Former Member
0 Likes
803

Sort the table and then do a binary search. If an entry is found, continue with indexed reads.

Rob

Read only

Former Member
0 Likes
803

Hi,

In Read statement we should not use 'GE' or 'LE'. And why your are using Exit statement.

try like this

LOOP AT IT_KNVV-VKORG

READ TABLE IT_A901 WITH KEY BZIRK = IT_KNVV-BZIRK

VKORG = IT_KNVV-VKORG

KDGRP = IT_KNVV-KDGRP

DATBI > IT_BSID-BUDAT

DATAB < IT_BSID-BUDAT.

IF SY-SUBRC = 0. (RECORD FOUND)

WRITE YOUR CODE.

ELSE (RECORD NOT FOUND)

WRITE YOUR CODE.

ENDLOOP.

Thnak you

Gopal