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: 
ennowulff
Active Contributor
Inspired by this diagram I found some day, we tried to implement a suitable ABAP-Version.



credtis: http://loveallthis.tumblr.com/search/jude

 

Songtext


The diagram shows the lyrics of Hey Jude by The Beatles but does not cover the complete songtext; only the refrain.

Hey Jude (© Sony/ATV Music Publishing LLC):
Hey Jude, don't make it bad
Take a sad song and make it better
Remember to let her into your heart
Then you can start to make it better

Hey Jude, don't be afraid
You were made to go out and get her
The minute you let her under your skin
Then you begin to make it better

And anytime you feel the pain, hey Jude, refrain
Don't carry the world upon your shoulders
For well you know that it's a fool who plays it cool
By making his world a little colder

Nah nah nah nah nah nah nah nah nah

Hey Jude, don't let me down
You have found her, now go and get her
Remember to let her into your heart
Then you can start to make it better

So let it out and let it in, hey Jude, begin
You're waiting for someone to perform with
And don't you know that it's just you, hey Jude, you'll do
The movement you need is on your shoulder

Nah nah nah nah nah nah nah nah nah yeah

Hey Jude, don't make it bad
Take a sad song and make it better
Remember to let her under your skin
Then you'll begin to make it
Better better better better better better, oh

Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude
Nah nah nah nah nah nah, nah nah nah, hey Jude

Coding


Whilst 90 minutes of coding time we developed different variations of course.

I tried to play around with some method chaining and different classes, Text fragments and importing parameters.

After having finished the dojo we found out that there is a challenge at codegolf.stackexchange.com.

Your task is to write a program which prints following four verses extracted from the lyrics from The Beatles' song "Hey Jude" (© Sony/ATV Music Publishing LLC):
Hey Jude, don't make it bad\n
Take a sad song and make it better\n
Remember to let her into your heart\n
Then you can start to make it better\n
\n
Hey Jude, don't be afraid\n
You were made to go out and get her\n
The minute you let her under your skin\n
Then you begin to make it better\n
\n
Hey Jude, don't let me down\n
You have found her, now go and get her\n
Remember to let her into your heart\n
Then you can start to make it better\n
\n
Hey Jude, don't make it bad\n
Take a sad song and make it better\n
Remember to let her under your skin\n
Then you'll begin to make it\n
\n

BUT

The only input you are allowed to use to construct these four verses is this list of tokens:
"Hey Jude, don't"
" make it bad"
" be afraid"
" let me down"
"Take a sad song and make it better"
"You"
" were made to go out"
" and get her"
" have found her, now go"
"Remember to"
"The minute you"
" let her"
" into your heart"
" under your skin"
"Then"
" you"
" can start"
"'ll"
" begin"
" to make it"
" better"

There are some really short solutions in some programming languages (Jelly: ;⁷“Ṙç€ṘḋḷŒø|Ṁ2kḤ⁽⁼SƁẒVṿẎj]ð⁵ṀƒƤ)÷Ƒ¦Ẋ½Iɠ⁻’ṃ) ... 😉

ABAP


So I also tried to build a one-liner for this in ABAP.

I didn't manage to do so because I did not find a function to get the index of a given character (like A = 1, B = 2 and so on). So I had to build a helper function which requires a separate class and destroys the wish to handle everything in one line.

This is my solution:
CLASS hey_jude DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ts_element,
word TYPE string,
END OF ts_element,
tt_elements TYPE STANDARD TABLE OF ts_element WITH DEFAULT KEY.

DATA elements TYPE tt_elements.
METHODS get_element IMPORTING letter TYPE char01 RETURNING VALUE(text) TYPE string.
METHODS constructor.
DATA sequence TYPE c LENGTH 100.
METHODS play.
ENDCLASS.

CLASS hey_jude IMPLEMENTATION.
METHOD constructor.
sequence = 'AB@E@JLM@OPQTU@@AC@FGH@KLN@OPSTU@@AD@FIH@JLM@OPQTU@@AB@E@JLN@OPRST@@'.
elements = VALUE #(
( word = `Hey Jude, don't` )
( word = ` make it bad`)
( word = ` be afraid` )
( word = ` let me down` )
( word = `Take a sad song and make it better` )
( word = `You` )
( word = ` were made to go out` )
( word = ` and get her` )
( word = ` have found her, now go` )
( word = `Remember to` )
( word = `The minute you` )
( word = ` let her` )
( word = ` into your heart` )
( word = ` under your skin` )
( word = `Then` )
( word = ` you` )
( word = ` can start` )
( word = `'ll` )
( word = ` begin` )
( word = ` to make it` )
( word = ` better` ) ).
ENDMETHOD.

METHOD get_element.

IF letter = '@'.
text = '</br>'.
ELSE.
FIND FIRST OCCURRENCE OF letter IN sy-abcde MATCH OFFSET DATA(offset).
IF sy-subrc = 0.
offset = offset + 1.
text = elements[ offset ]-word.
ENDIF.
ENDIF.

ENDMETHOD.

METHOD play.

cl_demo_output=>display_html(
REDUCE string(
INIT songtext = ``
FOR element IN VALUE tt_elements(
FOR index = 0 THEN index + 1 WHILE index < strlen( sequence )
( word = get_element( sequence+index(1) ) ) )
NEXT songtext = songtext && element-word ) ).

ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

NEW hey_jude( )->play( ).

Improvements


Maybe you find a way to improve the code?
8 Comments