Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
z_brandon
Active Participant
As many of you know, a technical ABAP interview can be quite a daunting prospect. Today I wanted to help with that and highlight a technical ABAP interview question you might have not prepared for or even heard of. A lot of good interviewers out there will want to get a feel for not only your technical ABAP coding skills but also how you approach relatively abstract problems that may not easily translate directly into code.

 

One such example is the game of FizzBuzz. If you've come from other programming languages you might've already heard of this but essentially the interviewer would ask you to do the following.

  • Output a table list that runs through a number range e.g. from 1 - 100.

  • Every time a number is exactly divisible by 3 (no remainders) then replace that number with the word "FIZZ".

  • Every time a number is exactly divisible by 5 (no remainders) then replace that number with the word "BUZZ".

  • And finally if divisible by both 3 and 5 - replace that number with the word "FIZZBUZZ".


 

The interviewer will be looking at 3 things:

  • How do you approach a simple problem like this.

    • Do you just quickly slap together something that works in a more or less functional way OR

    • Do you structure things in a more OO fashion with the view of keeping things as readable and maintainable as possible.



  • How familiar you are with both old and new ABAP syntax

  • The complexity of your finished code i.e. is it simple and easy to read or is it quite complex and hard to make out at first glance.


 

There are many ways to approach a problem like this but you can find my attempt in the GitHub repository here:

https://github.com/brandoncaulfield/youtube-abap/blob/master/z_fizzbuzz.abap

 

And also a video demostrating how I put the solution together explaining each step im my logic.



 

If you guys have a different solution please feel free to leave it in the comments below for us all to see 🙂

 

Thanks for reading!

 
10 Comments
jbungay
Participant
Hi Brandon,

We have a monthly code challenge and one of the earlier challenges was FizzBuzz.

Simple, but very interesting to see how people come up with different implementations.

Below is an example of one of our team members solutions.

I personally agree that code challenges to assess/evaluate potential developers is a great approach.

Nice blog!

Cheers,

James
class YL_CC_FIZZ_BUZZ_BCUSER definition
public
final
create public .

public section.
interfaces zif_cc_fizz_buzz.
aliases fizzbuzz for ZIF_CC_FIZZ_BUZZ~FIZZBUZZ.

interfaces if_oo_adt_classrun.
aliases main for IF_OO_ADT_CLASSRUN~MAIN.
protected section.
private section.
ENDCLASS.



CLASS YL_CC_FIZZ_BUZZ_BCUSER IMPLEMENTATION.
METHOD ZIF_CC_FIZZ_BUZZ~FIZZBUZZ.
fizzbuzz = cond #( let result = |{ cond #( when number mod 3 = 0 then |Fizz| ) }{ cond #( when number mod 5 = 0 then |Buzz| ) }|
in when result ne space then result else number ).
ENDMETHOD.

METHOD IF_OO_ADT_CLASSRUN~MAIN.
out->write( reduce #( init text type string
for index = 1 until index > 100
next text = |{ text }{ fizzbuzz( index ) }\n| ) ).
ENDMETHOD.
ENDCLASS.

 
mmcisme1
Active Contributor
0 Kudos

Nice thanks for sharing the code.  Another great way to do this.

mmcisme1
Active Contributor
Very nice.  You shared the code and the "why" behind it.  I've not had that question asked to me yet.
z_brandon
Active Participant

I really like this solution being a big fan of the REDUCE operator ? Thanks for sharing!

z_brandon
Active Participant
Thanks c436ae948d684935a91fce8b976e5aa7, I've also only seen it come up recently so perhaps we might see a bit more in the future. Always best to be prepared!
mmcisme1
Active Contributor
I totally agree.
nomssi
Active Contributor
FizzBuzz is a Rosetta Code's task with existing ABAP solutions.

Fun fact: you can use the Scheme solution in ABAP Scheme.

JNN
z_brandon
Active Participant
0 Kudos
That’s incredibly interesting, thank you for sharing!
Jelena
Active Contributor
Interviewer: So, how would you implement FizzBuzz in ABAP?

Me: Google-> FizzBuzz site:blogs.sap.com -> jackpot

That's pretty much my typical approach to ABAP development. 🙂
Abinathsiva
Active Contributor
0 Kudos
Interesting
Labels in this area