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: 

Exception in dynamic where clause in inner join

0 Kudos

Hi

Can I use dynamic where clause in inner join. I am getting exception  cx_sy_dynamic_osql_semantics .

Thanks

Madhu

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Madhumati,

Sure, dynamical sql should works for inner join, 

SELECT mara~matnr INTO TABLE it_mara

     FROM mara

     INNER JOIN marc

     ON mara~matnr = marc~matnr

     WHERE (' mara~matnr = ''000000000000000023''').

You`d better paste your code here.

regards,

Archer

8 REPLIES 8

Former Member
0 Kudos

Hi Madhumati,

Sure, dynamical sql should works for inner join, 

SELECT mara~matnr INTO TABLE it_mara

     FROM mara

     INNER JOIN marc

     ON mara~matnr = marc~matnr

     WHERE (' mara~matnr = ''000000000000000023''').

You`d better paste your code here.

regards,

Archer

0 Kudos

Below is my code

IF lv_object_id is NOT INITIAL .

       CONCATENATE lv_whr

                   'a~OBJECT_ID EQ '

                   lv_object_id

              into lv_whr

              SEPARATED BY space.

     ENDIF.

     IF iv_prog_start_date IS NOT INITIAL  .

       if lv_whr IS INITIAL.

       CONCATENATE lv_whr

                   'a~PROG_START_DATE GE '

                   iv_prog_start_date

              into lv_whr

              SEPARATED BY space.

       else.

         CONCATENATE lv_whr

                     'AND'

                     'a~PROG_START_DATE GE '

                     iv_prog_start_date

              into lv_whr

              SEPARATED BY space.

       endif.

     ENDIF.

     IF iv_prog_finish_date IS NOT INITIAL.

       IF lv_whr IS INITIAL.

         CONCATENATE lv_whr

                   'a~PROG_FINISH_DATE LE '

                   iv_prog_finish_date

              into lv_whr

              SEPARATED BY space.

        else.

          CONCATENATE lv_whr

                     'AND'

                     'a~PROG_FINISH_DATE LE '

                     iv_prog_finish_date

              into lv_whr

              SEPARATED BY space.

       ENDIF.

     ENDIF.

     IF iv_status is INITIAL.

       lv_status = PRG_STATUS_RELEASED . "release status

     else.

       lv_status = iv_status.

     ENDIF.

IF lv_whr IS INITIAL.

   CONCATENATE lv_whr

             'b~STAT EQ '

             lv_status

           INTO lv_whr

           SEPARATED BY space .

else.

     CONCATENATE lv_whr

             'AND'

             'b~STAT EQ '

             lv_status

           INTO lv_whr

           SEPARATED BY space .

ENDIF.


select a~guid a~OBJECT_ID a~PROG_TYPE a~BUAG_CLASS a~AUTH_GROUP

        a~SERV_ORG a~PROG_MGMT_AREA a~CURRENCY a~PROFILE_ID

        a~PROG_START_DATE a~PROG_FINISH_DATE a~PREMISE_REQUIRED

        a~PROG_DESC_TEXT a~AP_SUB_FROM_DATE a~AP_SUB_TO_DATE

        a~AG_SUB_FROM_DATE a~AG_SUB_TO_DATE a~AG_SUB_PER_TYPE

        a~AP_SUB_PER_TYPE a~BRF_FUNCTION_ID

        b~STAT

   from CRMD_IUDSM_PHEAD as a

   INNER JOIN CRM_JEST as b

   on   b~OBJNR = a~guid

   into CORRESPONDING FIELDS OF TABLE RT_header

   WHERE (lv_whr).

0 Kudos

Can you paste the WHERE clause that is built up?

Rob

0 Kudos

this is the where clause and now i see the issue

a~OBJECT_ID EQ ZDSM_SAVINGSBYDESIGN AND b~STAT EQ I1004

how do i put ' ' for values for example instead of I1004 it shoud be 'I1004'

0 Kudos

When concatenating, you have to use two single quotes:

CONCATENATE something ''1004'' INTO SOMETHING.

Rob

0 Kudos

value 1004 is coming from a variable. If I use two single quotes for variable in concatenate i get syntax error.

If i use 3 , i dont get syntax error but where clause is wrong

a~OBJECT_ID EQ 'lv_object_id' AND b~STAT EQ 'lv_status'

0 Kudos

I have put  ''' ''' on variable name and it solved issue.

VenkatRamesh_V
Active Contributor
0 Kudos

Hi,

View this link.

Dynamic where clause - ABAP Development - SCN Wiki

REPORT ytest1.

tables: mara.

DATA:gt_params TYPE TABLE OF rsparams,

       gt_ranges TYPE rs_t_rscedst,

       gs_ranges TYPE rscedst,

       gs_params LIKE LINE OF gt_params,

       gv_where  TYPE string,

       itab type table of mara.

select-options: matnr for mara-matnr,

                 mtart for mara-mtart.

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

    EXPORTING

      curr_report     = sy-repid

    TABLES

      selection_table = gt_params.

LOOP AT gt_params INTO gs_params.

    IF gs_params-sign IS INITIAL AND

       gs_params-option IS INITIAL AND

       gs_params-low IS INITIAL AND

       gs_params-high IS INITIAL.

      CONTINUE.

    ENDIF.

    gs_ranges-fnam = gs_params-selname.

    gs_ranges-sign = gs_params-sign.

    gs_ranges-option = gs_params-option.

    gs_ranges-low = gs_params-low.

    gs_ranges-high = gs_params-high.

    APPEND gs_ranges TO gt_ranges.

ENDLOOP.

CALL FUNCTION 'RSDS_RANGE_TO_WHERE'

   EXPORTING

     i_t_range            = gt_ranges

   IMPORTING

     e_where              = gv_where.

start-of-selection.

select * from mara into table itab where (gv_where).

Hope it helpful,

Regards,

Venkat.V