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 table issue

former_member48736
Participant
0 Likes
1,388

Hi,

I want to read a record from a table with below condition

READ TABLE pp0001 WITH KEY PERNR = group_all_pernrs_wa-pernr and BEGDA <= PN-DBEDA ENDDA >= PN-ENDDA.

but encounter error, it said can't use <=, only =,  how can I get the record with above condition?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,124

Hi,

   The best way to do it is use a LOOP statement with all conditions in the where clause of the LOOP. This will make sure only that particular record enters inside the LOOP statement. Syntax would be like below,

LOOP AT pp0001 WHERE PERNR = group_all_pernrs_wa-pernr AND BEGDA <= PN-DBEDA AND ENDDA >= PN-ENDDA.

< your logic>

ENDLOOP.

Reagrds,

Praveenkumar T

8 REPLIES 8
Read only

Former Member
0 Likes
1,125

Hi,

   The best way to do it is use a LOOP statement with all conditions in the where clause of the LOOP. This will make sure only that particular record enters inside the LOOP statement. Syntax would be like below,

LOOP AT pp0001 WHERE PERNR = group_all_pernrs_wa-pernr AND BEGDA <= PN-DBEDA AND ENDDA >= PN-ENDDA.

< your logic>

ENDLOOP.

Reagrds,

Praveenkumar T

Read only

Former Member
0 Likes
1,124

Hi,

You could TRY this.

READ TABLE pp0001 WITH KEY PERNR = group_all_pernrs_wa-pernr.

IF sy-subrc EQ 0.

     IF BEGDA <= PN-DBEDA AND ENDDA >= PN-ENDDA.

          " put your action here

     ENDIF.
ENDIF.

Regards,

Jake

Read only

Former Member
0 Likes
1,124

Hi,

In read statement you cannot use the <= or >= signs.It allows only = sign in the with key condition.

For your requirement you can use loop statement as below:

Loop at pp0001 where PERNR = group_all_pernrs_wa-pernr

                          and BEGDA <= PN-DBEDA

                          and ENDDA >= PN-ENDDA.

"Your logic"

Endloop.

If sy-subrc ne 0.         "If the above condition is not satisfied that is the loop fails.

"Your logic

Endif.

Hope it serves your problem.

Read only

former_member209920
Active Participant
0 Likes
1,124

You can use this way...

READ TABLE pp0001 WITH KEY PERNR = group_all_pernrs_wa-pernr.

if BEGDA <= PN-DBEDA and ENDDA >= PN-ENDDA.

  ****** process your code***

endif.


Regards,

Manu

Read only

0 Likes
1,124

Hi

I thought you need to READ TABLE and do not required to Run a LOOP.

Rgds,

ManuB

Read only

0 Likes
1,124

Hi Manu,

     yes you could have used READ TABLE , But the problem would be if you had more than one data for PERNR = group_all_pernrs_wa-pernr. Then your read table will return only the first record and hence you will miss out the remaining records. Therefore READ TABLE will not workout for all the cases in this situation.

Hope i am clear.

Regards,

Praveenkumar T.

Read only

Former Member
0 Likes
1,124

Hi,

The table PP0001 looks like a HR infotype, so you should be using the LDB(Logical Database) statements like PROVIDE to acheive your requirement.

Also see ABAP HR macros like ;

RP_PROVIDE_FROM_LAST

RP_SET_DATA_INTERVAL

RP_READ_INFOTYPE

Read the F1 help for PROVIDE.

Regards,

Karthik D

Read only

Former Member
0 Likes
1,124

DO NOT USE 'AND' -- between two conditions of Read table command.

ur code:

READ TABLE pp0001 WITH KEY PERNR = group_all_pernrs_wa-pernr and BEGDA <= PN-DBEDA ENDDA >= PN-ENDDA.

instead u should Write:

READ TABLE pp0001 WITH KEY PERNR = group_all_pernrs_wa-pernr

BEGDA <= PN-DBEDA ENDDA >= PN-ENDDA.