Application Development and Automation 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: 
Read only

Dynamic IF statement...like dynamic where clause...

Former Member
0 Likes
1,752

Hi,

I know how to do a dynamic where clause by putting (varname) like shown below -

select * from cust_mstr where (varname).

Can I do it something like this in IF statement.

if (varname).

endif.

The varname will have different conditions.

Your help will be greately appreciated.

Regards,

Sume

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
722

Hi Sume,

You can use field-symbols for defining IF statements. We can not write it like dynamic where cls but v can write like


if <FLD> = <VAL>.
endif.

Thanks,

Anmol.

Hi Sume,

You can use field-symbols for defining IF statements. We can not write it like dynamic where cls but v can write like


if <FLD> = <VAL>.
endif.

Thanks,

Anmol.

4 REPLIES 4
Read only

ThomasZloch
Active Contributor
0 Likes
722

Have you tried? No, it's not possible (yet), as far as I know, you might have to use dynamically created code, see GENERATE SUBROUTINE POOL, or maybe there is a simpler solution (like using ranges with IN operator), depending on what (varname) might contain.

Thomas

Read only

Former Member
0 Likes
723

Hi Sume,

You can use field-symbols for defining IF statements. We can not write it like dynamic where cls but v can write like


if <FLD> = <VAL>.
endif.

Thanks,

Anmol.

Read only

0 Likes
722

Thank you for the replies.

Field symbol also do not work as the values are tread like variable values and not dynamic if stament.

Regards.

Read only

722

Hello Sume,

I would try to use an approach using ranges:

DATA:
  gv_material TYPE matnr.

gv_material = '292-392-392-202'.

IF gv_material = '292-392-392-202'.
  WRITE: / `Static check:`, gv_material, `matches!`.
ELSE.
  WRITE: / `Static check:`, gv_material, `doesn't match!`.
ENDIF.

PERFORM dynamic_check
            USING
               gv_material
               'I'
               'EQ'
               '292-392-392-202'
               space.

PERFORM dynamic_check
            USING
               gv_material
               'I'
               'CP'
               '*292*'
               space.

PERFORM dynamic_check
            USING
               gv_material
               'I'
               'CP'
               '*ABC*'
               space.

*&---------------------------------------------------------------------*
*&      Form  dynamic_check
*&---------------------------------------------------------------------*
FORM dynamic_check USING pv_value    TYPE clike
                         pv_sign     TYPE ddsign
                         pv_option   TYPE ddoption
                         pv_low      TYPE string
                         pv_high     TYPE string.

  DATA lr_range TYPE RANGE OF string.
  DATA ls_range LIKE LINE  OF lr_range.

  ls_range-sign   = pv_sign.
  ls_range-option = pv_option.
  ls_range-low    = pv_low.
  ls_range-high   = pv_high.
  APPEND ls_range TO lr_range.

  IF pv_value IN lr_range.
    WRITE: / `Dynamic check matches: `, pv_value, ls_range-sign, ls_range-option, ls_range-low, ls_range-high.
  ELSE.
    WRITE: / `Dynamic check doesn't match:`, pv_value, ls_range-sign, ls_range-option, ls_range-low, ls_range-high.
  ENDIF.

ENDFORM.                    "dynamic_check

For values of SIGN and OPTION check the values of the domains used in the data elements of the parameters of form dynamic_check.

Output is like:

Static check:                292-392-392-202    matches!
Dynamic check matches:       292-392-392-202    I EQ 292-392-392-202
Dynamic check matches:       292-392-392-202    I CP *292*
Dynamic check doesn't match: 292-392-392-202    I CP *ABC*

Edited by: Alejiandro Sensejl on Aug 11, 2010 8:23 PM:

Unfortunately I don't know why the code-tag isn't working, I sent a mail to SCN tech-team about this... Sorry, but you have to copy the code somehow to have a look at it