cancel
Showing results for 
Search instead for 
Did you mean: 

Case with operator and operand1 and operand2 in ABAP.

0 Kudos

hello to everyone

could someone help me to correct this code. it seams not to be correct.

Parameter: operand1 TYPE i, operand2 TYPE i, operator TYPE c LENGTH 1.

DATA: result1 TYPE i, ....., ergebnis5 TYPE i.

ergebnis1 = operand1 + operand2. ...., result5 = operand1 % operand2.

CASE operator.

WHEN '+'.

WRITE: / operand1, operator, operand2, 'Is Equal to', result1.

WHEN '-'.

WRITE: / operand1, operator, operand2, 'Is Equal to', result2.

WHEN '*'.

WRITE: / operand1, operator, operand2, 'Is Equal to', result3.

WHEN '/'.

WRITE: / operand1, operator, operand2, 'Is Equal to', result4.

WHEN '%'.

WRITE: / operand1, operator, operand2, 'Is Equal to', result5.

WHEN OTHERS.

WRITE: / 'Give a Operator!!!'.

ENDCASE.

Please what is wrong in this code.

it some other way to write the code.

View Entire Topic
former_member186445
Active Contributor
0 Kudos

the calculation of the result must be done each time after the when statement and before the write statement. there is no need to define more than one result.

the first when would be:

when '+'. result = operand1 + operand2.
write: / operand1, operator, operand2, 'equal to', result.