Rene,
Here is some example logic from the suggestions stated above, and more complex, also stated above, computations get interesting. Good luck.
Regards,
Terry
REPORT Y_CALCULATE_STRING_RESULT . DATA: MYSTRING(30), VALUE1(10), VALUE2(10), RESULT(10), CALC_ADD VALUE '+', CALC_SUBTRACT VALUE '-', CALC_MULTIPLY VALUE '*', CALC_DIVIDE VALUE '/'. MYSTRING = '5 * 7'. *MYSTRING = '5 + 7'. *MYSTRING = '5 - 7'. *MYSTRING = '5 / 7'. SPLIT MYSTRING AT CALC_ADD INTO VALUE1 VALUE2. IF NOT VALUE2 IS INITIAL. CONDENSE: VALUE1, VALUE2. RESULT = VALUE1 + VALUE2. CONDENSE RESULT. ENDIF. SPLIT MYSTRING AT CALC_SUBTRACT INTO VALUE1 VALUE2. IF NOT VALUE2 IS INITIAL. CONDENSE: VALUE1, VALUE2. RESULT = VALUE1 - VALUE2. CONDENSE RESULT. ENDIF. SPLIT MYSTRING AT CALC_MULTIPLY INTO VALUE1 VALUE2. IF NOT VALUE2 IS INITIAL. CONDENSE: VALUE1, VALUE2. RESULT = VALUE1 * VALUE2. CONDENSE RESULT. ENDIF. SPLIT MYSTRING AT CALC_DIVIDE INTO VALUE1 VALUE2. IF NOT VALUE2 IS INITIAL. CONDENSE: VALUE1, VALUE2. RESULT = VALUE1 / VALUE2. CONDENSE RESULT. ENDIF. WRITE:/ 'The result of', MYSTRING, / 'is', RESULT.
try this
data : w_result type i, w_string1 type string, w_string2 type string, w_string3 type string. w_string1 = '5*7'. split w_string1 at '*' into w_string2 w_string3. w_result = w_string2 * w_string3.
Regards,
Suresh Datti
If you know that the * character is the seperating character you can use this..
DATA str(12) VALUE '1 * 3'. DATA str1(10). DATA str2(10). SPLIT str AT '*' into str1 str2. DATA i_1 TYPE i. DATA i_2 TYPE i. i_1 = str1. i_2 = str2. WRITE: i_1, i_2.
HI rene,
1. There is no direct way
to do such computations
which are available as a string.
2. by doing some hard coding,
we can manage to calculatge 5 * 7.
3. But if the formula is a little more
complex
eg. 2 *5 + (6 / 3 ) * 5.5 - 9
then, things go for a toss !
regards,
amit m.
Add a comment