Question
SAP - ABAP: I need to rework the following program to abide by the following rules. Rewrite the program so that the appropriate actual parameters
SAP - ABAP:
I need to rework the following program to abide by the following rules.
Rewrite the program so that the appropriate actual parameters are passed to subroutines within which the mathematical calculations take place. No write statements are allowed inside your subroutines. After being rewritten, it should look and function exactly the same as the original from the user's perspective.
*-------------- parameters -------------------------------------------*
PARAMETERS par_num1(2) TYPE p. PARAMETERS par_num2(2) TYPE p. PARAMETERS par_code(1) TYPE c.
*-------------- variables --------------------------------------------*
DATA calc_result(6) TYPE p decimals 2.
*-------------- constants --------------------------------------------*
CONSTANTS con_num1(12) TYPE c VALUE 'Number One: '. CONSTANTS con_num2(12) TYPE c VALUE 'Number Two: '.
CONSTANTS con_result(8) TYPE c VALUE 'Result: '.
CONSTANTS con_add(1) TYPE c VALUE 'A'. CONSTANTS con_sub(1) TYPE c VALUE 'S'. CONSTANTS con_mult(1) TYPE c VALUE 'M'. CONSTANTS con_div(1) TYPE c VALUE 'D'.
CONSTANTS con_error(17) TYPE c VALUE 'Invalid Operation'.
* ------------- main program -----------------------------------------*
* performing the calculation using a case
CASE par_code.
* perform the add
WHEN con_add. COMPUTE calc_result = par_num1 + par_num2.
FORMAT COLOR 1 INVERSE.
WRITE: /, con_num1, par_num1. WRITE: /, con_num2, par_num2. WRITE: /, con_result, calc_result.
FORMAT COLOR OFF INVERSE OFF.
* perform the subtract
WHEN con_sub. COMPUTE calc_result = par_num1 - par_num2.
FORMAT COLOR 2 INVERSE.
WRITE: /, con_num1, par_num1. WRITE: /, con_num2, par_num2. WRITE: /, con_result, calc_result.
FORMAT COLOR OFF INVERSE OFF.
* perform the multiply
WHEN con_mult. COMPUTE calc_result = par_num1 * par_num2. FORMAT COLOR 3 INVERSE.
WRITE: /, con_num1, par_num1. WRITE: /, con_num2, par_num2. WRITE: /, con_result, calc_result.
FORMAT COLOR OFF INVERSE OFF.
* perform the divide
WHEN con_div. COMPUTE calc_result = par_num1 / par_num2.
FORMAT COLOR 4 INVERSE.
WRITE: /, con_num1, par_num1. WRITE: /, con_num2, par_num2. WRITE: /, con_result, calc_result.
FORMAT COLOR OFF INVERSE OFF.
* invalid operation code
WHEN OTHERS. WRITE / con_error. FORMAT COLOR 5 INVERSE.
WRITE: /, con_num1, par_num1. WRITE: /, con_num2, par_num2. WRITE: /, con_result, calc_result.
FORMAT COLOR OFF INVERSE OFF.
ENDCASE.
* end of program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started