Language ABAP
(object-oriented version)
Date: | 04/20/05 |
Author: | Dominik Ritter |
URL: | n/a |
Comments: | 0 |
Info: | n/a |
Score: | (2.92 in 13 votes) |
REPORT z_99_bottles_of_beer. *&---------------------------------------------------------------------* *& Author: Dominik Ritter * *& Sprache: ABAP-Objects * *& Version: SAP R/3 4.6c *&---------------------------------------------------------------------* CLASS shelf DEFINITION. PUBLIC SECTION. METHODS: constructor IMPORTING value(bottles) TYPE i, take_bottles IMPORTING value(n) TYPE i, bottles_left EXPORTING value(bottles) TYPE i. PROTECTED SECTION. DATA: no_bottles TYPE i. ENDCLASS. CLASS shelf IMPLEMENTATION. METHOD constructor. no_bottles = bottles. ENDMETHOD. METHOD take_bottles. no_bottles = no_bottles - n. ENDMETHOD. METHOD bottles_left. bottles = no_bottles. ENDMETHOD. ENDCLASS. DATA: beer TYPE REF TO shelf. DATA: bottlesonshelf TYPE i. START-OF-SELECTION. CREATE OBJECT: beer EXPORTING bottles = 99. CALL METHOD beer->bottles_left IMPORTING bottles = bottlesonshelf. WHILE bottlesonshelf GT 1. WRITE:/(2) bottlesonshelf, ' bottles of beer on the wall, '. WRITE:/(2) bottlesonshelf, ' bottles of beer.'. WRITE:/ 'Take one down, pass it around, '. CALL METHOD beer->take_bottles EXPORTING n = 1. CALL METHOD beer->bottles_left IMPORTING bottles = bottlesonshelf. WRITE:/(2) bottlesonshelf, ' bottles of beer on the wall.'. SKIP. ENDWHILE. WRITE:/ '1 bottle of beer on the wall,'. WRITE:/ '1 bottle of beer.'. WRITE:/ 'Take one down, pass it around, '. WRITE:/ 'no more bottles of beer on the wall.'.
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
standard version | Dominik Ritter | 04/20/05 | 0 | |
Use of Forms and Macros | David Lacorre | 11/19/08 | 1 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments