Skip to Content
Technical Articles
Author's profile photo Nabheet Madan

Advent of code – Let’s do it using ABAP

Advent of code..what is it?

Advent of code is an annual online programming event which usually happens in December every year. Each day you get set of two programming puzzles which you try to solve using any programming language of your choice, for more details you can read here. The important question is not what it is but important focus of this post is why doing it in ABAP? Read on!

Why doing it in ABAP…

Off late ABAP has gone so many changes it is very difficult to stay up to date.  When I saw a tweet from Christian about this my initial reaction was to do it in ABAP why…read on?

Get comfortable with using eclipse.

Eclipse is everywhere and I believe this is the best chance to learn both the basic and advanced level. You can already see my theme is all set for Eclipse dark one and I plan to use maximum eclipse to accommodate all tasks.

Is it that easy working with eclipse for an ABAPer,  I will say it takes some time to get habitual with multiple views but its great. After completing day 1 I am trying to find how do maintain text elements. Is it possible or not.. does not matter how basic the question is important is we all are trying to learn. This is one of the many questions which I hope to resolve during this journey. Just FYI I liked the bookmarks and outline feature?

Get comfortable with new ABAP features

This is another important reason to do AOC as we will try to use as much latest features of ABAP to arrive at the solution. For example for day1 part 1 puzzle I was able to use Reduce but for part2 used a old + new approach.  Are my approaches the best of course not, they must be the worst, that is why I am writing here to learn from you guys how to do the things right new, short and concise way . 

Puzzle link

 

Part 1 solution

    DATA(output) = REDUCE i(
    INIT sum = 0
    FOR wa IN me->input_data NEXT
    sum = sum + ( floor( wa / 3 ) - 2 )
     ).
    cl_demo_output=>display( output ).

Part 2 Solution

DATA(sum2) = 0.
    LOOP AT input_data ASSIGNING FIELD-SYMBOL(<fs>).
      DATA(sum3) = ( floor( <fs> / 3 ) - 2 ).
      sum2 += sum3.
      WHILE sum3 > 0.
        sum3 = ( floor( sum3 / 3 ) - 2 ).
        IF sum3 > 0.
          sum2 += sum3.
        ENDIF.
      ENDWHILE.

    ENDLOOP.
    cl_demo_output=>display( sum2 ).

Some how utilize the power of abapGit

Another important thing which I wanted to work on was abapGit. So I think no better way than this. My system has it now plus I am able to make my first push to remote repo here. I must say a great work done by Lars and other contributors?

What is next?

The plan is very simple try to solve these puzzles with ABAP. Share the solutions with the community for a feedback for a better solution. If few of you can join us in this journey it will be fun.  As now I am aware Hendrik is doing this in ABAP and I am waiting for his solutions to get posted so as to learn how can things be better. Another side benefit of doing this is you get to know what else also exist for example we have similar kind of challenges which exist for serverless thanks to Gregor Wolf for letting us know.

PS: I plan to do few of the parts in Javascript also:)

 

 

 

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo DJ Adams
      DJ Adams

      Nice one Nabheet! Looking forward to seeing more of this!

       

      For those folks wanting to join the discussion, you can head on over to the #adventofcode channel on the "SAP Mentors & Friends" Slack workspace:

      https://sapmentors.slack.com/archives/CQSBXFTD0/p1575215360002300

      You'll find links to code solution repos and more there too.

      Happy hacking!

      Author's profile photo Thiago Silva
      Thiago Silva

      Hi,

       

      The channel still alive on Slack?

       

       

      Author's profile photo Michael Keller
      Michael Keller

      Nice idea. I like to use ABAP for tasks other than typical business requirements 🙂 To make the entry into Eclipse easier, I made a little information collection on GitHub. This fits in a bit to the topic abapGit (GitHub). Happy hacking and exploring!

      Author's profile photo Frederik Hudak
      Frederik Hudak

      Hi Nabheet,

      Maintaining text elements is not directly supported, but there is a shortcut to get to the right place in sapgui:

       

      Author's profile photo Nabheet Madan
      Nabheet Madan
      Blog Post Author

      Great thanks:)

      Author's profile photo Enno Wulff
      Enno Wulff

      I also started with #abap:

      https://github.com/tricktresor/AdventOfCode2019

       

      two specialties:

      1. I created a package creator: the report will create local packages
        1. one main package
        2. 24 sub packages; one for each day to have a perfect structure for abapGit
      2. I used ZCL_TURTLE of Frederik Hudak to visualize the wire routing of day 3

      Author's profile photo Hendrik Neumann
      Hendrik Neumann

      hi Nabheet Madan,

      nice work. You can find my solutions on Github now: https://github.com/hendrik77/Advent_of_Code_2019

      Looking forward to see what Enno Wulff did there 😉 Graphic output already looks awesome!

      Cheers

      Hendrik

       

      Author's profile photo Nabheet Madan
      Nabheet Madan
      Blog Post Author

      Yes i am trying to learn from Enno Wulff and Hendrik Neumann solution they are Ubercool. Its a great way to end the year 2019 i must say:)

      Thanks

      Nabheet

      Author's profile photo Enno Wulff
      Enno Wulff

      sorry, to disappoint you, Nabheet. I didn't understand yesterdays task... 🙁

      I am not sure if I am ready to understand todays orbit calculation...

      Author's profile photo Nabheet Madan
      Nabheet Madan
      Blog Post Author

      No hurries i m on day3 trying to learn  from around new ABAP stuff:)