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 can I use a READ statement for the checking date <=sydatum?

Former Member
0 Kudos
4,568

Hello,

I need use a READ statement on an internal table ITAB (with feild var1) and check whether feild var1<= sydatum(i.e. var1 greater than or equal to sy-datum)....how can I implement this??

Regards,

Shashank.

1 ACCEPTED SOLUTION

former_member533584
Contributor
0 Kudos
343

Hi ,

use

loop at itab where var1 le sy-datum.

endloop.

regrds,

ananth

8 REPLIES 8

former_member533584
Contributor
0 Kudos
344

Hi ,

use

loop at itab where var1 le sy-datum.

endloop.

regrds,

ananth

0 Kudos
343

Hi Ananth,

Cant I use a READ statement??

Regards,

Shashank.

0 Kudos
343

<u>SORT ITAB.

READ TABLE ITAB WITH KEY VAR1 <= SYDATUM BINARY SEARCH.</u>

OR

<u>READ ITAB WITH KEY VAR1 <= SYDATUM</u>

YOU CAN USE ANY ONE READ STATEMENT

1ST ONE IS BINARY SEARCH IT IS BETTER IN PERFORMANCE

YOU HAVE TO SORT THAT ITAB BEFORE THIS STATEMENT

2ND ONE IS NORMAL SEARCHIN TECH IT IS NOT GOOD IN THE PERFORMANCE POINT OF VIEW

REGARDS

NARESH

0 Kudos
343

Hi Shashank,

If you use READ statement, you would get only the first record that has the date less than sy-datum.

<= will result in more than one record and hence it is not advisable to use read statement with such conditions.

Ideally you should have only = for reading data.

if you want ALL the records which have date <= sy-datum, then use LOOP

loop at itab where datum <= sy-datum.

  • all the records which pass the condition willl come through.

endloop.

Regards,

Ravi

Former Member
0 Kudos
343

SORT ITAB.

READ TABLE ITAB WITH KEY VAR1 <= SYDATUM BINARY SEARCH.

OR

READ ITAB WITH KEY VAR1 <= SYDATUM

YOU CAN USE ANY ONE READ STATEMENT

1ST ONE IS BINARY SEARCH IT IS BETTER IN PERFORMANCE

YOU HAVE TO SORT THAT ITAB BEFORE THIS STATEMENT

2ND ONE IS NORMAL SEARCHIN TECH IT IS NOT GOOD IN THE PERFORMANCE POINT OF VIEW

REGARDS

NARESH

0 Kudos
343

Hi Naresh,

We cannot use any of this read statement.I tried prior to posting this query.

Regards,

Shashank.

Former Member
0 Kudos
343

Hi,

try this short example.

DATA: BEGIN OF ITAB OCCURS 0,

DATE LIKE SY-DATUM,

END OF ITAB.

*

ITAB-DATE = '20000101'. APPEND ITAB.

ITAB-DATE = '20010101'. APPEND ITAB.

ITAB-DATE = '20020101'. APPEND ITAB.

ITAB-DATE = '20030101'. APPEND ITAB.

ITAB-DATE = '20040101'. APPEND ITAB.

ITAB-DATE = '20050101'. APPEND ITAB.

ITAB-DATE = '20060101'. APPEND ITAB.

ITAB-DATE = '20070101'. APPEND ITAB.

ITAB-DATE = SY-DATUM. APPEND ITAB.

ITAB-DATE = '20080101'. APPEND ITAB.

*

LOOP AT ITAB WHERE DATE < SY-DATUM.

WRITE: / 'before', ITAB-DATE.

ENDLOOP.

LOOP AT ITAB WHERE DATE = SY-DATUM.

WRITE: / 'equal ', ITAB-DATE.

ENDLOOP.

LOOP AT ITAB WHERE DATE > SY-DATUM.

WRITE: / 'after ', ITAB-DATE.

ENDLOOP.

Regards, Dieter

Former Member
0 Kudos
343

read statement is used to get value from the internal table based on key, therefore u cannot give <= or >= in read statement except =.

But you can still get the values using loop statement with where date LE sy-datum.