Saturday, October 26, 2013

calculator programs

hey folks, it's been a while since my last post. now i would like to share you about my calculator programs in abap editor. first i would like to show you the screenshots, then the code. here goes....
what above is the screenshot of the code, process calculating, and the result itself.
and now let the coding begin.

REPORT bc400_mos subroutine.

TYPE gty_result TYPE p LENGTH 16 DECIMALS 2.

PARAMETERS:
pa_int1 TYPE i,
pa_int2 TYPE i,
pa_op TYPE c LENGTH 1.

DATA gv_result TYPE gty_result.

IF ( pa_op = '+' OR
       pa_op = '-' OR
       pa_op = '*' OR
       pa_op = '/'  and pa_int2 <> 0 ) .

CASE pa_op.
WHEN '+'.
gv_result = pa_int1 + pa_int2.
WHEN '-'.
gv_result = pa_int1 - pa_int2.
WHEN '*'.
gv_result = pa_int1 * pa_int2.
WHEN '/'.
gv_result = pa_int1 / pa_int2.

WRITE: 'Result:'(res), gv_result.

ELSEIF pa_op = ' / ' AND pa_int2 = 0.
WRITE: 'No division by zero.!' (dbz).
ELSE.
WRITE: 'Invalid Operator.!'(iop).
ENDIF.

No comments:

Post a Comment