cancel
Showing results for 
Search instead for 
Did you mean: 

How to set up formula in inspection characteristic with IF, THEN, ELSE function

Former Member
0 Kudos

  Dear Expert,

I need to setup the calculated characteristics for beloe scenario

The first MIC contains the measured temperature.

The second MIC shoud calculate, based on the temperature of the first MIC,

SAP Standard accepts IF, THEN, ELSE functions in formulas.

My problem is: How can I calculate in one forumla the desribed problem (how has the formula to be set up in detail):

If the temperature is between 12.5°C to 16.5°C then give back the value 8.05

If the temperature is between 16.6°C to 19.5°C then give back the value 8.03

If the temperature is between 19.6°C to 21.0°C then give back the value 8.02

If the temperature is between 21.1°C to 23.5°C then give back the value 8.01

If the temperature is between 23.6°C to 27.5°C then give back the value 8.00

If the temperature is between 27.6°C to 32.5°C then give back the value 7.98

Please help to suggest the ways.

Regards,

Sandeep

Accepted Solutions (1)

Accepted Solutions (1)

former_member235613
Participant
0 Kudos

It can be done. The question is will it fit in the two 60 character fields that SAP gives you for the formula. it might!

Here is the full help text which clearly states this works with standard SAP. You will just have to get in your development system and try it out. Will probably need to nest your if/then statements.

Check syntax of a formula

Functionality

The function module CHECK_FORMULA checks the syntax of a Literal or Variable formula. It accepts:

  • arithmetic formulas (with floating point result of type FLOAT)
  • logical formulas (with result TRUE or FALSE)
  • conditions of the form:
    IF <logical expression> THEN
    <arithmethic formula>
    ELSE
    <arithmetic formula>
  • Expressions with fields of the structure SY

Example:

    FORMULA = COS(A**2+B**2)
    FORMULA = IF X>0 THEN SIN(X) ELSE SIN(-X)
    FORMULA = SY-TZONE / 2.324

Operands

The following operands are allowed:

  • numeric constants, e.g. -5, 3.1416, 1.3E12
  • variables
  • TRUE
  • FALSE
  • PI (= 3.14159 ...)
  • SY-UZEIT
  • SY-DATUM
  • formal parameters, e.g. #1, #2

Functions

The FM supports the following functions:

ABSabsolute value
Example: FORMULA = ABS(-2)
result: 2
NOTnegation
Example: FORMULA = IF NOT(2<3) THEN (5*6) ELSE (5-7)
result: -2
SINsine function
Example: FORMULA = SIN(PI/2)
result: 1
COScosine function
Example: FORMULA = COS(0)
result: 1
TANtangent function
Example: FORMULA = TAN(2*PI)
result: 0
LOGlogarithm to base e (natural logarithm)
Example: FORMULA = LOG(2.7182746352)
result: 1
EXPexponential function to base e
Example: FORMULA = EXP(1)
result: 2.7182746352
SQRTsquare root function
Example: FORMULA = SQRT(144)
result: 12
ROUNDround to a whole number
Example: FORMULA = ROUND(3.14159)
result: 3
TRUNCtruncate; the whole number part of a real number
Example: FORMULA = TRUNC(5/3)
result: 1
MODmodulus function
Example: FORMULA = 10 MOD 3
result: 1
DIVwhole number part of a division
Example: FORMULA = 10 DIV 3
result: 3

Operators

The operators are classified in 6 priority groups. The operators in group 0 have the lowest priority and those in group 6 the highest.

The operators are:

group 0:

ANDlogical AND
ORlogical OR

group 1:

=equals
<>, ><not equals
<less than
>greater than
<=, =<less than or equal to
>greater than
=>, >=greater than or equal to

group 2:

+plus value (of an expression)
-minus value (of an expression)
+addition
-subtraction

group 3:

*multiplication
/division

group 4:

**exponent

group 5:

ABSabsolute value
NOTnegation (of a logical expression)

group 6: all other functions.

user-defined FORMULAs

You can define functions in a table like TFKT and use them as well as standard functions. The function name is the table key. The table and function names (separated by a colon) are specified in calls.

Example

The FORMULA PI*R**2 is in the table TFKT under the function name circlearea. It is called with FORMULA = TFKT:circlearea(...)

User-defined functions can be nested.

Example:

The expression PI*R**2 is defined as the function circlearea. The function cylinder can now be defined as cylinder = TFKT:circlearea*H.

If a user group needs another table than TFKT (e.g. to structure the key or include user fields), the reference table TFKT should be copied. User functions can be inserted from position 79.

Tables used to store FORMULAs must have a key length of 13 and a function length of 65.

Notes
  • In contrast to ABAP, spaces are ignored.
  • A FORMULA must not contain other Literals.
  • Character strings in quotation marks are interpreted as comments and are ignored.
former_member42743
Active Contributor
0 Kudos

Jim

If I remember correctly, (always a problem!), I tried to use an AND statement within the IF-THEN-ELSE statement and I didn't have any success with that.  Or it had a problem using nested IF-THEN's.  Can't remember which one.

I.e. you could do

IF CO0010 < 10 then 5.0 Else 6.0

But I don't think you can do

IF ((CO0010 <10) AND (CO0010 >= 5)) then 6.0 Else

  IF ((CO0010 <15) AND (CO0010 >= 10)) then 11.0 Else

     IF ((CO0010 <20) AND (CO0010 >= 15)) then 16.0 etc..etc..

I think Karen's answer to use the FM would be he best.

Craig

nitin_jinagal
Active Contributor
0 Kudos

Jim,

Help me out in understanding one thing. When I first saw this query, I couldn't think of a solution except using FM. Then Karen and You also seemed going for it, the FM. I didn't go through the whole content of yours (as I'm using cell phone currently). Did you also suggested a solution via FM ?? Or without it using standard SAP?

ntn

nitin_jinagal
Active Contributor
0 Kudos

Yes, you are correct. I have tried mapping it in several ways but couldn't get it. Possible in MS Excel but not in SAP with two fields or MIC. I guess FM is the only solution.

ntn

former_member235613
Participant
0 Kudos

I was suggesting standard SAP, but to be honest i've never tried nesting IF/THEN statements in the MIC. Maybe if i get some spare time one these days (if that exists anymore) i'll play around with it.

I would suggest Sandeep to give the standard a whirl, and if it doesn't pan out, get with an ABAP'er and make a Z formula.

nitin_jinagal
Active Contributor
0 Kudos

Yup. Developing a formula converter such as Z0 may help in mapping this.

ntn

former_member42743
Active Contributor
0 Kudos

I want to think is was more trying to use the AND within the IF-THEN.

Craig

nitin_jinagal
Active Contributor
0 Kudos

I tried.. The If(And.. Thing. It didn't work out. Or I might had put something wrong but it was fine in excel spreadsheet.

Former Member
0 Kudos

Dear All,

Thanks for your reply,

I tried through standard SAP but as per Craig suggestion it work for one line formula not all multiple option also i am not able to put range e.g between 12.5°C to 16.5°C in formula.it work for <.>= etc.

I will now check with developer but please let me know if any other way to get it done

   

I am open for other ideas then the IF, THEN, ELSE function. It only must be possible to get out the correct value by an automated process.

Regards,

Sandeep


Answers (4)

Answers (4)

former_member184536
Active Contributor
0 Kudos

Hi Sandeep

This is only possible for one line formula by making key in table TFKT and formula text there. There is limit so you cann't beyond that. So it better to use formula parameter DO. Change the logic of function module which is attached to this parameter according to your requirement.

Regards'

Manish

former_member42743
Active Contributor
0 Kudos

Please don't use DO.  Make a new parameter ZO and copy the FM over.  DO is  not in the customer name space and can be overwritten or modified by SAP in any hot pack or upgrade.

Craig

former_member211676
Contributor
0 Kudos

Hi Sandeep

As per my knowledge standard SAP won't allow us to write like this formulas. For this we can use User exits:  EXIT_SAPLQEEM_015 or EXIT_SAPLQEEM_011 to fulfill this requirements.

Regards

kesava

Former Member
0 Kudos

I don't think this can be done by standard SAP route. You may need to use a FM to get this requirement done. Consult your abap person for this.

KJ

former_member211618
Contributor
0 Kudos

Hi,

  Ru looking for formula or how to write the formula???