Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language ABAP

(object-oriented version)

Date:04/20/05
Author:Dominik Ritter
URL:n/a
Comments:0
Info:n/a
Score: (2.90 in 10 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

VersionAuthorDateCommentsRate
standard versionDominik Ritter04/20/050
Use of Forms and MacrosDavid Lacorre11/19/081

Comments

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!

Name:

eMail:

URL:

Security Code:
  
Comment: