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

Replacement for select single in a user exit

Former Member
0 Likes
417

Hi Experts,

I am changing the below code in user exit,because select single always fetch the first record from database and in my ZTABLE there can be more than 1 entry:

IF I_KNA1-VBUND <>.
  DATA L_VAR  LIKE ZTAB.
    SELECT SINGLE * FROM ZTAB INTO                                   
    L_VAR   WHERE RCOMP = I_KNA1-VBUND.  (RCOMP  and EFF_TO are key field)
IF SY-SUBRC = 0.


IF SY-DATUM LT L_VAR-EFF_FROM OR SY-DATUM > L_VAR-EFF_TO.
Error message

ENDIF.
  ENDIF.
ENDIF.

Since there can be more than 1 entry in ZTAB the above logic wont work, my logic:

(If you guys can advice on a better logic than the below ?)

IF i_kna1-vbund <>.

select * from ZTAB  into itabwhere RCOMP = Ikna1-vbund.

if sy-subrc = 0.

loop at itab where EFF_FROM LE SY-DATUM and EFF_TO GE SY-DATUM.

endloop.

if sy-subrc <> 0.

error message.

endif.

endif.

endif.

Please advice if there is a better logic to do this?

Hi Experts,

I am changing the below code in user exit,because select single always fetch the first record from database and in my ZTABLE there can be more than 1 entry:

IF I_KNA1-VBUND <>.
  DATA L_VAR  LIKE ZTAB.
    SELECT SINGLE * FROM ZTAB INTO                                   
    L_VAR   WHERE RCOMP = I_KNA1-VBUND.  (RCOMP  and EFF_TO are key field)
IF SY-SUBRC = 0.


IF SY-DATUM LT L_VAR-EFF_FROM OR SY-DATUM > L_VAR-EFF_TO.
Error message

ENDIF.
  ENDIF.
ENDIF.

Since there can be more than 1 entry in ZTAB the above logic wont work, my logic:

(If you guys can advice on a better logic than the below ?)

IF i_kna1-vbund <>.

select * from ZTAB  into itabwhere RCOMP = Ikna1-vbund.

if sy-subrc = 0.

loop at itab where EFF_FROM LE SY-DATUM and EFF_TO GE SY-DATUM.

endloop.

if sy-subrc <> 0.

error message.

endif.

endif.

endif.

Please advice if there is a better logic to do this?

1 REPLY 1
Read only

Former Member
0 Likes
371

Moderator message - this has been discussed many times before. Please search before asking.

Press F1 on SELECT UP TO N ROWS ... ORDER BY

Locked.

Rob