2019 Apr 26 11:54 AM
hii,
I want to use dynamic where condition in abap. this is the current code that I'm using:
DATA: lt_req_log TYPE STANDARD TABLE OF ts_req_log,
ls_req_log TYPE ts_req_log,
cond(72) TYPE c,
itab LIKE TABLE OF cond.
CONCATENATE 'b~req_date' 'BETWEEN' im_validfrom 'AND' im_validto INTO cond SEPARATED BY space.
APPEND cond TO itab.
CLEAR cond.
IF im_customer IS NOT INITIAL.
CONCATENATE 'AND' 'b~customer_code' 'eq' im_customer INTO cond SEPARATED BY space.
APPEND cond TO itab.
CLEAR cond.
ENDIF.
IF im_consignee IS NOT INITIAL.
CONCATENATE 'AND b~consignee_code eq' im_consignee INTO cond SEPARATED BY space.
APPEND cond TO itab.
CLEAR cond.
ENDIF.
IF im_material IS NOT INITIAL.
CONCATENATE 'AND b~material_code eq' im_material INTO cond SEPARATED BY space.
APPEND cond TO itab.
CLEAR cond.
ENDIF.
SELECT
a~request_no
a~item_no
b~customer_code
b~customer_name
b~consignee_code
b~consignee_name
b~material_code
b~material_desc
b~requestor
b~req_date
a~approvedby1
a~approvedon1
a~approvedby2
a~approvedon2
a~rejected
FROM /aag362/sd_apdet AS a JOIN /aag362/sd_spreq AS b ON a~request_no EQ b~request_no AND a~item_no EQ b~item_no
INTO TABLE lt_req_log
WHERE (itab).
* WHERE b~req_date BETWEEN im_validfrom AND im_validto AND b~customer_code eq im_customer.
LOOP AT lt_req_log INTO ls_req_log.
APPEND ls_req_log TO ex_req_log.
ENDLOOP.
i am not getting any errors but it is not retrieving any data either.
where am I going wrong??
regards
Siddharth
2019 Apr 26 12:00 PM
Instead of using an internal table, try using a string with the complete condition.
2019 Apr 26 1:08 PM
From the documentation
The data object cond_syntax can be a character-like data object or a standard table with a character-like row type.
There is nothing wrong with using an internal table.
2019 Apr 26 1:34 PM
2019 Apr 26 1:07 PM
"Dynamic queries expect a string such as "fld1 = val1 AND fld2 = val2 OR fld3 IN range3" etc." - Incorrect.
From the documentation
The data object cond_syntax can be a character-like data object or a standard table with a character-like row type.
2019 Apr 26 1:09 PM
Set a breakpoint just at the SELECT. Look at the contents of itab (which is a terrible name for an internal table. How about where_clause?).
Then you will probably get the reason why you see no data.
2019 Apr 26 1:38 PM
This is probably the best option.
But looking at the code again, it might be because in your concatenate the values are placed in the field. If you place those variabels between quotes as well the variabele names will be placed in your table instead of their values.
2019 Apr 26 6:37 PM
2019 Apr 29 8:12 AM
Sandra Rossi mistake on my side. Was commenting on something else and did the same here.
2019 Apr 26 2:05 PM
Keep the rhs variables in the quotes('). Something like this - 'im_material' while performing the concatenate.
2019 Apr 26 6:37 PM
2019 Apr 29 6:49 AM