Exercise 21 - Pass Variables to a Subroutine

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, Z16830 1 document.doc ã 2005 Accenture. All Rights Reserved.

description

Pass Variables to a Subroutine

Transcript of Exercise 21 - Pass Variables to a Subroutine

Page 1: Exercise 21 -  Pass Variables to a Subroutine

ATS APP. PROG. – ABAP PROGRAMMING UNIT: ABAP REPORT DEVELOPMENTMODULE: SUBROUTINES

Exercise 21: Pass Variables to a Subroutine

Estimated Completion Time: 90 minutes

OverviewThis 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.

InstructionsThe 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.

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

Z16830 1 document.docã 2005 Accenture. All Rights Reserved.

Page 2: Exercise 21 -  Pass Variables to a Subroutine

ATS APP. PROG. – ABAP PROGRAMMING UNIT: ABAP REPORT DEVELOPMENTMODULE: SUBROUTINES

Cumulative percentage = (percentage of sales + cumulative percentage).

Output the report.

Hints1. 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 2 document.docã 2005 Accenture. All Rights Reserved.