Skip to Content
Event Information

SAP Community Coding Challenge Series

It is with great pleasure that we announce a new community activity – the SAP Community Coding Challenge Series. The idea is that periodically SAP will post a coding challenge or puzzle for the community to solve. It will be something fun yet hopefully will teach something as well. It should be simple enough that most people could work on it over a lunch break but if you really want to solve the problem optimally might require some thoughtful research and experimentation.

For this first challenge, we will go to our technology roots in the SAP community and open with an ABAP coding challenge.  This challenge can be performed in the SAP Cloud Platform ABAP Environment Trial (this is where our sample solution was tested).

Voting is now LIVE!

To vote on the winner, simply go to this Community question. The finalist are all listed as answers.  Upvote the answer you believe is best.

Also you can watch the replay of the Live steam where we unveiled the finalist and the special awards:

And if you want more details on the Special Award winners, Rich Heilman posted a blog about them here:

Midpoint Challenge Update:

Now that we are 1/2 way through the first challenge, we did a live stream to discuss the progress, judging and how to get started coding in the SAP Cloud Platform ABAP Environment Trial.  This is the recording of that live stream:

Challenge Directions:

Start with this line of code as the first line in your application. Requirement: make sure to cut and paste this line of code and NOT type it.

    DATA(sentence) = `ABАP  is excellent `.

Using the value in the variable sentence, programmatically determine the number of words in this variable and then count the number of UNIQUE letters in each word.

Your output should look like this:

The goal is to accomplish the task with as few lines of code as possible. Our sample implementation uses 9 lines including the data(sentence) and out->write lines. Can you do it in less?

Consider processing efficiency and ABAP best practices as well.  How clean is your code?  Usage of Hungarian notation will be severely ridiculed. ?

Finally you must also explain why ABАP correctly has 4 unique letters.

Submission and Judging

Once you have a solution you are happy with, please email your submissions along with a link to your public SAP Community Profile to the inbox.  Everyone has until March 15th, 23:59 Pacific Daylight Time (PDT) / UTC-7 to submit your coding solution.  The community and developer advocates team at SAP will then do the first round of judging, narrowing down to 5 finalist that have the cleanest, most elegant, or most creative solutions. We will then post these 5 finalist in a community Q&A entry so that everyone will have a chance to vote on the best overall solution.

In the spirit of the immortal Stan Lee, the fabulous prize for the winner of the Coding Challenge will be a No-Prize. The coveted No-Prize also comes with the unending adulation and admiration of the community of fellow developers.



You must be Logged on to comment or reply to a post.
  • /
  • Dear Thomas,

    as I love automated unit testing some questions to your requirement:

    1. Do we only talk about alphabetic letters (A-Za-z) which can make up a word or also numbers (0-9) and other letters (!"§...) but not separated by any space like characters?
    2. Shall it also work for other languages as like chinese, arabic, etc.?
    3. Do we talk about case-sensitive or case-insensitive?
    4. are we allowed to use helper classes like cl_demo_output or only out->write?

    Love the challenge!

    Cheers Klaus

    • Characters not letters


      upper/lower would be different characters

      Your choice.  We didn’t specify how to produce the output.  The calculation itself is what we are after

      • Awesome challenge. Learned something new and would say it is possible in 6 statements. The ABAP case with 4 chars nice trick 🙂 Looking forward to your judgement.

  • I love a challenge but am wondering: is it solvable (without using brute force) on a NW 750 EHP 8 system or are newer ABAP syntax options needed to get it done in as few lines of code as possible?



    • Yes. It’s fine to break a single line of code over multiple lines in the editor. That improves readability which is also an important factor here.

  • /
    • As Thomas said on Twitter "Until you hit the period it’s one line of code even if spread across multiple lines in the editor" I got 4 lines of super modern, dirty, expression-style nightmare code I made just as an exercise 😀 [as opposite to my elegant solution].

  • Hi Thomas,

    I have a doubt, in the challenge they say nothing about the use of classes that attend to solve the problem, but if I use a method that has 20 lines of code that solve the problem, 1 line of code is counted by the method call or 20 lines of code for the implementation of the method?


    • Well did you write the class or your reusing something supplied by the platform? But in the end I hope people aren't getting too tied up in the lines of code. I called that out mostly to challenge people to think of more inventive ways of solving the problem than just brute force approaches. Hopefully this gives you an opportunity to research some syntax that is new to you.  Elegance, readability, maintainability are all factors as well. We will only use these criteria to narrow down to the finalist. Ultimately the community will vote on the winner.

      • I think the sentence

        The goal is to accomplish the task with as few lines of code as possible

        make the chalenge based on the number of lines.


        Maybe next time, we could have "Clean Code Challenge".

        • The next paragraph does add to that:

          Consider processing efficiency and ABAP best practices as well.  How clean is your code?  Usage of Hungarian notation will be severely ridiculed.

          But point taken that people have taken to the lines of code aspect a bit more than I had personally intended. I was hoping that aspect would push people to explore some new ABAP syntax (which seeing the submissions it certainly has).  Its one of several interesting aspects for people I hope. But we will be sure to balance or rotate the challenge modifiers in the future.

          • I'll add that I've been really impressed by how many unique and creative approaches there have been in the submissions. I think the community is going to have lots of fun looking at them once the submission period is over.

          • Done !

            It was easier in Clean Code / more readable

            So if I don't count the class/method/.. lines, I am now with 7 lines.

            It is interesting to see, with the same number of lines, but with Class & methods, the code is simpler.


          • Exactly, if there was no mention of no of lines, I sure would have not taken it as a challenge 😉

            Just because of that criteria, I tried different ways and used many new functions and syntax. It sure was a fun learning experience for me 😀 ,

            one of my colleague saw me doing this today and she started to learn about constructor expressions, reduce, for,  e.t.c, to do this challenge.

            With normal abap, surely we cannot do it in less lines, we have to use some new features to do this. maybe 2 categories would be nice, one with Clean ABAP and one with less lines. So people can push both ways.


          • Yes i think that the idea of ​​Master Thomas is that we look 
            for new ways to do it, not only using the old sentences 
            that we are used to using. I personally have had to 
            investigate many sentences that I did not know and 
            I think that is the objective of the challenge, 
            to challenge the knowledge we already have in order 
            to be better. Thanks to Master Thomas and team.
  • I did it with 2 lines of code including the initial line, but one line for everything is just madness, especially the logic to count unique characters… The choice of auxiliary variable names is essential to make the code understandable. And if you do it “right” by using translatable texts, that’s even more madness ?

    • ? I wouldn’t say it is madness,  It’s more like an art :P, I’ve sent the code both with 1 line(included data declaration inside) and 2 lines with separate data declaration.

      but have you done that using regex?

    • Frederic Girod Mahesh Kumar Palavalli The answer is simple: what solution other than SPLIT can you use? Of course, the issue with doing it in one statement is that fellow developers who will maintain the code need to master many aspects of the ABAP language, including the regular expressions which are widely adopted in many languages, understand very well the constructor expressions. It's often not the case, so my code fits "shortest" but doesn't fit "Elegance, readability, maintainability".

  • One "line" of code.

                      LET s
                      FOR w
                      IN RE
                      FOR i
                      FOR p

    now working a bit on clean code... 😀

    • thanks for the discussion, I have it now in one line as well. I thought it might be overkill to replace the split by reduce expression. but its okay. We should compare results next time.

  • Hi guys,

    Below is my simplified version for anyone interested.  A little Reduce and some regex.

    Neat challenge, can't wait for the next one.



    CLASS ycl_sap_cc_20200228_dirty DEFINITION
        interfaces if_oo_adt_classrun.
    CLASS ycl_sap_cc_20200228_dirty IMPLEMENTATION.
      METHOD if_oo_adt_classrun~main.
        DATA(sentence) = `ABАP  is excellent `.
        data(number_of_words) = count( val = condense( sentence ) regex = `(\b[^\s]+\b)` ).
        out->write( reduce stringtab(
                    init output = value #( ( |Number of words: { conv string( number_of_words ) }| ) )
                         word type string
                         number_of_unique_characters type i
                    for index = 1 until index > number_of_words
                    next word = segment( val = sentence index = index space = ` ` )
                         number_of_unique_characters = count( val = word regex = `(\S)(?!.*\1.*)` )
                         output = value #( BASE output ( |Number of unique characters in the word: { word } - { conv string( number_of_unique_characters ) }| ) ) ) ).




  • I’ve made a simple solution, using two REDUCE operations, no more than that. I believe most people went for that, or using LOOP, FOR, DO, etc., the result is the same. I thought about doing sorted tables, select, char/number calculation, or even Regex. But favored the REDUCE one. Nice to see different approaches for the same problem.

  • Hi,

    I just found this challenge blog. Love the announcement video stream where you two comment on the submitted code! Funny reactions and comments on regex etc. Relatable 🙂

    I will try get up to date with blogs and hopefully join some of the upcoming challenges.

  • One more solution

      METHOD if_oo_adt_classrun~main.
        DATA(sentence) = `ABАP  is excellent `.
        SPLIT condense( sentence ) AT space INTO TABLE DATA(words).
        out->write( |Number of words: { lines( words ) }\n| && REDUCE #( INIT s = `` FOR <word> IN words NEXT s = s &&
        |Number of unique characters in the word:  { <word> } - { REDUCE #( INIT c = 0 r = <word> FOR i = 0 WHILE i < strlen( <word> )
        NEXT c = c + COND #( WHEN count( val = r regex = <word>+i(1) ) > 0 THEN 1 ) r = replace( val = r sub = <word>+i(1) with = `` occ = 0 ) ) }\n| ) ).