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: 

how do i use dynamic where condition in abap

former_member592880
Participant
0 Kudos

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

11 REPLIES 11

ArthurParisius
Contributor
0 Kudos

Instead of using an internal table, try using a string with the complete condition.

matt
Active Contributor
0 Kudos

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.

0 Kudos

Thanks for the correction.

matt
Active Contributor

"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.

matt
Active Contributor

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.

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.

Sandra_Rossi
Active Contributor

Arthur Parisius Why not posting it as an answer?

0 Kudos

Sandra Rossi mistake on my side. Was commenting on something else and did the same here.

srikanthnalluri
Active Participant

Keep the rhs variables in the quotes('). Something like this - 'im_material' while performing the concatenate.

Sandra_Rossi
Active Contributor

S Nalluri Why not posting it as an answer?

former_member607412
Participant
0 Kudos

Thanks for the correction matthew.billingham .