Sie sind auf Seite 1von 7

ABAP Basics

Modularizing ABAP programs


Exercise 02.04 - Modularizing ABAP programs

Note: All the following objects to be created should follow a naming convention YEMPID_##$$
%%. ##$$ indicates the exercise number whereas %% indicates the question number in the
exercise.

Exercise on Subroutines:

1) Write a subroutine to print the user name, run date, and run time and invoke the
subroutine.

2) Write a program to accept two numbers and an arithmetic operator. Perform the specified
arithmetic operation on the number inputs, in a subroutine by passing the accepted inputs
by value. Print the numbers, the operator and the result in the main program. If the
accepted values are invalid, display that information on the list. (Use another subroutine to
validate the inputs).

3) Accept a number N from the user and print the first N numbers of the fibonacci series
using a subroutine. Implement this using recursion technique.

4) Do the necessary modularization for the following requirement:


Create internal tables to populate the following data:
Contents of the first internal table.

Plant Description
0100 YASH plant1
0110 YASH plant2
0200 Test plant

Contents of the second internal table.

Material Material type Plant Quantit


y in CA
MAT001 Raw material 0100 20
MAT002 Trading goods 0300 10
MAT001 Raw material 0110 15
MAT001 Raw material 0400 10
MAT002 Trading goods 0110 5
MAT003 Finished goods 0100 12
MAT002 Trading goods 0100 5
MAT001 Raw material 0100 10
MAT002 Trading goods 0110 6

Display the contents of the second internal table, only when there are corresponding
entries in the first internal table.
Exercise 02.04 - Modularizing ABAP programs
Exercise 02.04 - Modularizing ABAP programs
Plant: 0100 YASH plant1
Material Material type Quantity
MAT001 Raw material 30
MAT002 Trading goods 5
MAT003 Finished goods 12

Total Qty for plant 0100 47

Plant: 0110 YASH plant2


Material Material type Quantity
MAT001 Raw material 15
MAT002 Trading goods 11

Total Qty for plant 0110 26

Gross total quantity 73

5) Write two include programs to perform the following:

a) Create an internal table with the structure as specified below:


Field Name Data Type Length
Airline_Carrier_id C 2
Flight_Connection_id N 4
Flight_Date D

b) Write a subroutine to populate the internal table with the data as specified below:

Airline Carrier id Flight Connection id Flight Date


AA 0017 12.12.1999
DL 1984 06.05.2000
AA 0026 04.08.1999
UA 0941 11.11.2000
LH 1699 01.02.2000

6) Create a program to output the contents of the internal table created in the previous
question as specified below. Print user details like the user name, run date and run time
using the subroutine, which is created in question 1.

<User details should be displayed here>


Flight Connection Details

Airline Carrier id Flight Connection id Flight Date


AA 0017 12.12.1999
AA 0026 04.08.1999
DL 1984 06.05.2000
LH 1699 01.02.2000
UA 0941 11.11.2000
Exercise 02.04 - Modularizing ABAP programs
Exercise 02.04 - Modularizing ABAP programs
Exercise on Function Modules:
Note: All the following function modules need to be called from within a program and
the programs should be as generic as possible.

7) Write a function module to determine whether a given year is a leap year or not.

8) Write a function module to generate a random number. (You are at your liberty to use any
logic to generate a random number).

9) Write a function module to accept a date and display the date in the following format.
Ex: Wednesday September 18, 2002

10) Write a program to populate the internal table with the following data and calculate the
loss/gain and display the contents of the internal table. Use a function module to calculate
the loss or gain by passing the internal table by value to the function module.

Airline Carrid Connection Id Payment sum Seats Occupied Price


LH 0400 10000 10 900
AI 0009 3000 9 1000
LH 0404 7000 10 700
UA 0007 1000 10 500
SQ 0786 2000 10 100
AI 0987 1000 10 100

Output:
Airline Carrid Connection Id Loss/Gain
LH 0400 Gain
LH 0404 Gain
SQ 0786 Gain
AI 0987 Gain
AI 0009 Loss
UA 0007 Loss

11) Write a program to populate an internal table with the following data:

Name Age Over time in Hours


Employee1 30 7
Employee2 10 3
Employee3 25 15
Employee4 45 10
Employee5 15 4
Employee6 32 8
Employee7 25 16
Employee8 32 5
Exercise 02.04 - Modularizing ABAP programs
Use a function module to calculate the amount considering the pay per hour as 150/-, by
accepting the Age and over time.
Handle the following exceptions in the function module:
a. If employee age is less than 18 Child labor
b. If the employee works for more than 10 hours as over-time Over strain

Display the contents of the internal table as follows:

Name Age Over time Amount Comments


Employee1 30 7 1050
Employee2 10 3 Child labor
Employee3 25 15 Over strain
Employee4 45 10 1500
Employee5 15 4 Child labor
Employee6 32 7 1200
Employee7 25 16 Over strain
Employee8 32 5 750

Exercise on Macros:

12) Write a program to accept two numbers and an arithmetic operator. Write a macro to
perform the arithmetic operation on the number inputs and invoke another macro from it to
print the numbers, the operator and the result.

13) Write a program to print a given character string, for the user specified offset and length
using a macro. Validate the user input using another macro.

14) Write a program to calculate the factorials of first 5 numbers using a macro. Display the
output in the following format using another macro.

Factorial of 1 is 1.
Factorial of 2 is 2.
Factorial of 3 is 6.
Factorial of 4 is 24.
Factorial of 5 is 120.

Das könnte Ihnen auch gefallen