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: 

building a dynamic where clause

Former Member
0 Kudos

Hi, I'm building a dynamic where clause, but I keep getting error messages.

This is what the code looks like, but apparently the condition is incorrectly parenthesized. Can someone tell me how it should be?

THX!!

IF s_type is not initial.

APPEND 'lgtyp IN s_type' to where_tab.

ENDIF.

IF s_emplac is not initial.

APPEND 'lgpla IN s_emplac' to where_tab.

ENDIF.

if s_emplty is not initial.

APPEND 'lptyp = s_emplty' to where_tab.

ENDIF.

SELECT lgnum FROM lagp

into i_item-lgnum

where lgnum = s_mag

AND (where_tab).

4 REPLIES 4

Former Member
0 Kudos

Hi,

For this scenario..I don't think you require a dynamic where clause...if there is no value in teh select-options/ranges...then it will pick up all the records..

Create range for the field LPTYP..

SELECT lgnum FROM lagp
into i_item-lgnum
where lgnum = s_mag
AND lgtyp IN s_type
AND lgpla IN s_emplac
AND lptyp IN r_emplty.

Thanks

Naren

Former Member
0 Kudos

You need to include the AND/OR.

Rob

ThomasZloch
Active Contributor
0 Kudos

You need to chain these together with ' AND ', just like in "normal" WHERE-conditions.

Thomas

former_member188685
Active Contributor
0 Kudos

check this sample code.

REPORT  ZDYNAMIC_WHERE.

TABLES: VBAK.
DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
        VBELN LIKE VBAK-VBELN,
        POSNR LIKE VBAP-POSNR,
     END OF ITAB.
DATA: IT_OPTIONS LIKE RFC_DB_OPT OCCURS 0 WITH HEADER LINE.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
CONCATENATE 'VBELN'  'IN'  'S_VBELN.' INTO CONDITION SEPARATED BY SPACE.

IT_OPTIONS-TEXT = CONDITION.
APPEND IT_OPTIONS.
CLEAR IT_OPTIONS.
SELECT VBELN
       POSNR
       FROM VBAP
       INTO TABLE ITAB
       WHERE (IT_OPTIONS).

LOOP AT ITAB.

  WRITE:/ itab.

ENDLOOP.