forked from brandoncaulfield/youtube-abap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z_fizzbuzz.abap
51 lines (33 loc) · 1.12 KB
/
z_fizzbuzz.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
*&---------------------------------------------------------------------*
*& Report z_fizzbuzz
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_fizzbuzz.
CLASS lcl_fizzbuzz DEFINITION CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS: create
RETURNING
VALUE(ro_fizzbuzz) TYPE REF TO lcl_fizzbuzz.
METHODS: run.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS lcl_fizzbuzz IMPLEMENTATION.
METHOD create.
ro_fizzbuzz = NEW lcl_fizzbuzz( ).
ENDMETHOD.
METHOD run.
DATA(lt_fizzbuzz) = VALUE stringtab(
FOR i = 1 WHILE i <= 100 (
COND string( LET lv_3 = i MOD 3
lv_5 = i MOD 5 IN
WHEN lv_3 = 0 AND lv_5 = 0 THEN |FIZZBUZZ|
WHEN lv_3 = 0 THEN |FIZZ|
WHEN lv_5 = 0 THEN |BUZZ|
ELSE i ) ) ).
cl_demo_output=>display( lt_fizzbuzz ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
lcl_fizzbuzz=>create( )->run( ).