Exercise Basic ABAP Statements
Exercise Basic ABAP Statements
Exercise Objectives
After completing this exercise, you will be able to:
Business Example
You are to create a simple ABAP program for the four basic calculation types. You must be able to
enter the values and the arithmetic operator on a selection screen. Display the result in a list.
Task 1:
Create program
Task 2:
Define input parameters (implicit definition of the selection screen). 1. Define the input parameters
for two integer values (name suggestion: pa_int1,
pa_int2) and an arithmetic operator (name suggestion: pa_op).
Task 3:
Task 4:
Catch errors.
1. Display an error message on the list if the user has specified an invalid arithmetic operator.
Use the IF statement for checking.
2. Display an error message on the list if the user tries to divide by zero.
Solution 13: Basic ABAP Statements
REPORT sapbc400tss_compute.
PARAMETERS: pa_int1 TYPE i, pa_op(1) TYPE c, pa_int2 TYPE i.
DATA result TYPE p DECIMALS 2.
IF NOT ( pa_op = ’+’ OR
pa_op = ’’ OR
pa_op = ’*’ OR
pa_op = ’/’ ).
WRITE: ’Invalid operator!’(iop).
ELSEIF pa_op = ’/’ AND pa_int2 = 0.
WRITE: ’No division by zero!’(dbz).
ELSE.
CASE pa_op.
WHEN ’+’.
result = pa_int1 + pa_int2.
WHEN ’’.
result = pa_int1 pa_int2.
WHEN ’*’.
result = pa_int1 * pa_int2.
WHEN ’/’.
result = pa_int1 / pa_int2.
ENDCASE.
WRITE: ’Result:’(res), result.
ENDIF.
Exercise 15: Working with Internal Tables
Exercise Objectives
After completing this exercise, you will be able to:
Business Example
You are to output pedido dates stored in database table ekko in a list by using an internal table (as
temporary storage).
Task 1:
Define internal table
1. Create the executable program ZBC400_##_ITAB_LOOP without a TOP include.
2. Buffer the data from the database table ekko in an internal table. You should define an internal
table with a line type that is compatible with the line structure of ekko.
In the ABAP Dictionary, search for all table types that match this condition.
3. Define an internal table (name suggestion: it_ekko) based on one of the found global table
types.
4. Define awork area for the internal table (name suggestion: wa_ekko).
Task 2:
Fill and output the internal table
Program an array fetch access to all data records in the database table ekko as follows:
SELECT * FROM ekko INTO TABLE it_ekko.
Use the LOOP statement to output the buffered data in the internal table in a list.
SOLUCION
DATA it_ekko type standard table of ekko.
break wcontreras.
IF sy-subrc = 0.
WRITE: / wa_spfli-ebeln,
wa_spfli-bedat.
ENDLOOP.
ENDIF.