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: 

Conditional statement - evaluate a condition stored in a string

matteo_montalto
Contributor
0 Kudos
814

Hi gurus,

I have a dynamically build structure which is a table that has just a field (type WHERETXT).

As example of run leads to the following result (numbers on the left represents the row of the table)

1 (

2 PARAMETER = '10'

3 OR

4 PARAMETER = '30'

5 )

Such a table, call it wherecond[], could be used successfully in a SELECT statement in this way:

SELECT foo INTO bar

FROM DBtab

WHERE (wherecond).

Now; i'd like to use the SAME wherecond[] to buid a dynamic IF statement.

But:

IF (wherecond)

leads to a syntactical error: "Incorrect logical expression: "(wherecond)" : After "(" a white space was expected.

Then spacing as suggested::

IF ( wherecond )

I get the following error: "Relational operator ")" is not supported.

Tried then to "unroll" the itab into a flat string variable, but I get the same syntax error. Sound really strange; could this be related to the fact this is an old system (SAP_APPL 470 ) ? How can I workaround this?

Thanks in advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
177

You should be able to do this with a CASE statement.

On second thought, probably not.

Rob

Edited by: Rob Burbank on Apr 16, 2010 12:18 PM

9 REPLIES 9

Former Member
0 Kudos
177

Hi Matteo,

I'm pretty sure dynamic programming is not allowed for IF-ELSE-ENDIF statements, which is why you are getting the syntax error. But I could be wrong here... :-S

Cheers,

Shailesh.

0 Kudos
177

Thanks Shailesh,

that's a bad news, I'll need then to workaround on this topic... What do you think could be an efficient solution? Note that the condition will always in disjunctive form, and always referring to the same parameter (e.g. "PARAM EQ '1' OR PARAM EQ '5' OR... ..OR PARAM EQ 'n'). I was thinking in writing a conversion routine for the condition in a selopt structure, so that the IF statement could be stated as follows:

IF myparam IN <seloptname>

Is this an effective way? Or you think there's something easier/faster?

Thanks again

0 Kudos
177

This seems to be the best solution based on the circumstances.

If you just want confirmation, then go for it.

Unless some "guru" comes up with yet something more elegant.

Thomas

0 Kudos
177

This seems to be the best solution based on the circumstances (chained OR conditions for the same field).

If you just want confirmation, then go for it.

Unless some "guru" comes up with something more elegant.

Thomas

0 Kudos
177

Hey Guys,

Looks like the OP needs to migrate to SAPNW7.0 EhP2

Read on: [http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/18115] [original link is broken] [original link is broken] [original link is broken];

Anyways i think the best & only feasible solution would be create a range table with individual values & check ...

Cheers,

Suhas

0 Kudos
177

>

> Anyways i think the best & only feasible solution would be create a range table with individual values & check ...

> Suhas

Hello Suhas,

could you please provide me an example about the suggested solution? Thanks a lot

EDIT:

I'm evaluating the idea of a range table and I'm getting curious about Regular Expression processing in ABAP...

Considering that:

- I will loop on a table done as described in the first post;

- every assignment is a simple '=' sign

is there a way to write in abap a code that simply takes the value between ' (single quote mark) after an "equal" (=) sign?

Sounds like a pattern matching issue, something like "when string contains a pattern which is " = 'XY' ", no matter what XY are, take XY and fill the range table.

This sounds to me as the clearer way to accomplish the task; can anyone help me providing an example or documentation about that? I'm not so sure that's feasible in ABAP/4...

Edited by: Matteo Montalto on Apr 19, 2010 11:24 AM

0 Kudos
177

May be you should check the OPTIONS field of the range table. To match patterns to have to use OPTIONS = 'CP' (Contains Pattern) & pass the pattern '* pattern *' (SAP interprets * as a wild character while searching against the pattern)

Range table is similar to SELECT-OPTIONS, read this documentation on the possible values of OPTION & its impact: [http://help.sap.com/abapdocu_70/en/ABAPSELECT-OPTIONS.htm]

BR,

Suhas

Edited by: Suhas Saha on Apr 19, 2010 3:38 PM

0 Kudos
177

Thanks Suhas, probably I was not that clear before, anyway... I'll try to explain the idea:

1) define a range table for the value I'd like to check for (AUSP1):

DATA: range_ausp1 TYPE RANGE OF clobjdat-ausp1.

2) define a workarea of the above table;

DATA: BEGIN OF wa_ausp1 ,
          sign(1),
          option(2),
          low  TYPE  clobjdat-ausp1,
          END   OF wa_ausp1.

3) now process the iTab and look for conditions (tipically, for any ' = 'XY' ' pattern, take XY 😞

LOOP at wheretab.
IF "conditional statement based on the above assertions
      wa_ausp1-sign = 'I'.
      wa_ausp1-option = 'EQ'. "no need of CP here, since I'm checking on exact values
      wa_ausp1-low = XY.
      APPEND wa_ausp1 TO range_ausp1.
...

4) I can finally check if the value AUSP1 on my table respects the condition:

IF my_doc_itab_specs-AUSP1 IN range_ausp1.
  "ok
ELSE
 "ko.
ENDIF.

Well, my problem is how to formulate the conditional statement at point 3). I will always be something as:

param = 'XY'

where XY are two numbers and apostrophes are part of the string.

Edited by: Matteo Montalto on Apr 19, 2010 12:20 PM

Former Member
0 Kudos
178

You should be able to do this with a CASE statement.

On second thought, probably not.

Rob

Edited by: Rob Burbank on Apr 16, 2010 12:18 PM