Skip to Content
Technical Articles
Author's profile photo Enno Wulff

Hey Jude

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?

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matthew Billingham
      Matthew Billingham

      Is this a way to improve the song: https://www.youtube.com/watch?v=u5sQGyRK9pw (Hugh Laurie and Stephen Fry from way back).

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      Should have renamed the song to "Hey Duck"... 😀

      Author's profile photo Mahesh Palavalli
      Mahesh Palavalli

      I think Enno Wulff should add the voice parameter and decision to the program ?

      Author's profile photo Richard Harper
      Richard Harper

      I wonder what it would look like in Piet.....

      Author's profile photo RAJJAN KHAN
      RAJJAN KHAN

      always astounding

      Author's profile photo Timo John
      Timo John

      Hey Enno Wulff ... #TooMuchFreeTime?

      Really nice challenge, took me quite a while to figure out the procedure of the code using

      sy-abcde

       

      Unfortunately I guess due to this the code is not #ABAPCloudReady

      Peter Langner can you prove?

       

      Anyway we could flag this idea with #ABAPLearning challenge!

      Tanks for sharing!

       

      Author's profile photo Enno Wulff
      Enno Wulff
      Blog Post Author

      It was hard to code, so it should be hard to read! 🙂

      Good hint about SY-ABCDE. Feel free to replace by 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'. 😉

      That might be the place where the additional function could be replaced by another while-shift-do loop to find out the index of the character.

      btw: There is no free time - there is only time. 😀

      Author's profile photo Jacques Nomssi Nzali
      Jacques Nomssi Nzali

      is it cheating if I extend the token list?

      CLASS hey_jude DEFINITION.
        PUBLIC SECTION.
          METHODS play RETURNING VALUE(song) TYPE string.
      ENDCLASS.
      
      CLASS hey_jude IMPLEMENTATION.
      
        METHOD play.
          CONSTANTS c_abcde TYPE c LENGTH 22 VALUE 'ABCDEFGHIJKLMNOPQRSTU@'.
      
          DATA(sequence) = 'AB@E@JLM@OPQTU@@AC@FGH@KLN@OPSTU@@AD@FIH@JLM@OPQTU@@AB@E@JLN@OPRST@@'.
      
          DATA(elements) = VALUE string_table(
                            ( `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` )
                            (  |\n| ) ).
      
          song = concat_lines_of( VALUE string_table( FOR index = 0 UNTIL index = strlen( sequence )
                                           ( elements[ find( val = c_abcde
                                                             sub = sequence+index(1) ) + 1 ] ) ) ).
        ENDMETHOD.
      
      ENDCLASS.