10-09-2008 6:01 PM
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).
10-09-2008 6:07 PM
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
10-09-2008 6:11 PM
10-09-2008 6:13 PM
You need to chain these together with ' AND ', just like in "normal" WHERE-conditions.
Thomas
10-09-2008 6:13 PM
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.