Вы находитесь на странице: 1из 2

ATS APP. PROG.

ABAP PROGRAMMING

UNIT: ABAP REPORT DEVELOPMENT


MODULE: SUBROUTINES

Exercise 21: Pass Variables to a Subroutine


Estimated Completion Time: 90 minutes

Overview
This exercise requires participants to define subroutines with FORM and ENDFORM
statements and call subroutines using the PERFORM statement. Participants also
pass parameters and use the STATICS statement instead of DATA.

Instructions
The program name is ZSER21## where ## is the last 2 digits of your User Id.
1. Write a program to compute sales percentage information as shown in the
sample output. Use tables SFLIGHT and SCARR.
2. Create a selection screen with a parameter for the carrier code and default
it to AA for the American Airlines.
3. Use AT SELECTION-SCREEN to validate the carrier Id parameter entered on
the selection screen. If the carrier Id entered is invalid, output a message
using the MESSAGE statement.
4. Compute the total sales for the carrier using the SELECT SUM (SALES) from
the table SFLIGHT where the carrier Id is the parameter entered in the
selection screen and store it in a variable total sales.
5. Code another SELECT statement to retrieve the carrier id, connection Id,
flight date and payment sum into a standard internal table.
6. Sort the internal table by payment sum field in descending order.
7. Loop through the internal table and for each row of the internal table call a
subroutine to calculate the percentage of payment sum in respect to total
sales, and to print a report as shown below.
8. To print the carrier name, the first time the subroutine executes use a
SELECT SINGLE statement to access the SCARR table. This can be
achieved by declaring a static flag variable within the subroutine. If the
flag has initial value, obtain the carrier name, and print the line, then set
the flag to X.
9. To calculate the percentage of sales within the subroutine:
Pass the record read from internal table using a structure (work
area), and the total sales to the subroutine. (In reality this is not
necessary, since the table row, and the variable are global, and
accessible to the subroutine.)

Declare a variable to hold the cumulative percentage as STATIC.


The static variable will maintain the cumulative value after exiting the
subroutine.

Calculate the sales percentage and compute the cumulative


percentage.

Z16830
2005 Accenture. All Rights Reserved.

Percentage of sales = (sales / total sales) * 100.

273098520.doc

ATS APP. PROG. ABAP PROGRAMMING

UNIT: ABAP REPORT DEVELOPMENT


MODULE: SUBROUTINES

Cumulative percentage = (percentage of sales + cumulative


percentage).

Output the report.

Hints
1. To obtain valid program results, the carrier code used in the execution of
the program must exist with sales data in the SFLIGHT table. (Use the SAP
Data Browser, SE16, to find valid examples, if needed).
2. For more information on subroutines, aggregate functions, and internal
tables refer to the online help.

Z16830
2005 Accenture. All Rights Reserved.

273098520.doc

Вам также может понравиться