Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Michael_Keller
Active Contributor
2,163
Today, no business topic but it's play time 🙂 A couple of days ago, I stumbled upon the free book "10 PRINT CHR$(205.5+RND(1)); : GOTO 10". No joke, that's the title of the book. It's about an one-line Commodore 64 BASIC program that prints a maze to the screen. Because I'm a big fan of Retrocomputing, I browsed the book a little bit.

Afterwards I asked myself what ABAP report I could write in one line of 40 characters with a nice output. The answer was sobering: Nothing interesting. Even with 80 characters I just printed vertical lines to the screen 🙂 Here is my approach.
REPORT z.DO 10 TIMES.DO 80 TIMES.WRITE AT sy-index(1) '|'.ENDDO.NEW-LINE.ENDDO.

Finally I decided to give up the length restriction and wrote my own random maze generator as a homage to the original BASIC program. It uses the WRITE instruction and the characters "-" and "|" to build frames. You will find it on GitHub, too.
REPORT z_random_maze.

DATA: lr_random_int TYPE REF TO cl_abap_random_int,
lv_random_int TYPE i,
lv_position_x TYPE i,
lv_position_y TYPE i,
lv_maze_part TYPE char2.

lr_random_int = cl_abap_random_int=>create( seed = CONV i( sy-uzeit ) min = 1 max = 9 ).

DO 20 TIMES.
lv_position_y = sy-index.
lv_position_x = 1.
DO 30 TIMES.
CLEAR lv_maze_part.
IF lv_position_y = 20.
lv_maze_part = '--'.
ELSE.
lv_random_int = lr_random_int->get_next( ).
IF lv_random_int < 5.
lv_maze_part = '|'.
ELSEIF lv_random_int > 7.
lv_maze_part = '--'.
ENDIF.
ENDIF.
WRITE AT lv_position_x(2) lv_maze_part.
lv_position_x = lv_position_x + 2.
ENDDO.
NEW-LINE.
ENDDO.

Relax your eyes, try to find your way through the maze and have fun 🙂 Here is a little example of the report output. And if you have a good idea for an interesting one-liner in ABAP, let me know.

23 Comments
Labels in this area