Skip to Content

What

Of late I have been doing lot’s of debugging and during such time I have come across some, how shall I put it, interesting code.

Why

On a couple of occasions I posted screen shots of the offending code on Twitter. One of my fellow Twitterers, who is a legend in his own right, Thorsten Franz (https://wiki.sdn.sap.com/wiki/display/profile/Thorsten+Franz), Tweeted back and said I should Blog about this so that is exactly what I am doing.

I expect that this blog will stir some memories in others and get them to share their experiences with interesting code.

I suspect I will end up moving this Blog to a Wiki to allow others to update it and add their stories

Findings

From what I have found so far it’s clear that most of the developers have neither had any formal training in ABAP programming or have either read books or spoken to other developers who are living in the past and don’t give a damn about a programs performance. They just make it work regardless of how it looks under the bonnet.

My Rules

For me there are some rules that I stick to when writting a program, these are:

1) It works, well Duh!

2) Perfomance is optimal.

3) The code is easy to read and the logic is easy to follow.

4) Use the latest methodologies where applicable.

The “Interesting” Code

Right, here are a few of the clangers that I have discovered so far.  

Here the developer is clearly paranoid about making sure the data is passed to l_ekko.

image

Here, it appears that no one other than the mentioned users are allowed to execute this code. This is SAP standard BTW.

image

Ok, here the developer has an issue with clearing the work area and internal table. I love the fact that he clears the table even though the table and work area are declared just prior to them being cleared.

image

And just in case they weren’t cleared in the previous two attempts the developer clears them another couple of times for good luck! Good on ya Mr Developer.  

image

Here we have a developer who hasn’t quite understood the user of move-correspnding.  

This is the type declaration for the internal table.  

image

This is the data select into the internal table.

image

For this next piece of code I don’t actually have words to describe my thoughts on it. It makes me want to cry. 

 image

again, the same developer from above example.

image

Closing Statement

Well, that’s just a few examples of what I have come across so far.

I think it would be a good idea to create a WIKI of horror code depending on the feedback I get from this blog. Hopefully I won’t have offended to many people. My intention was just to share some interesting code.

To report this post you need to login first.

54 Comments

You must be Logged on to comment or reply to a post.

  1. Susan Keohan
    Neil,
    Thanks for pointing these out.  I’m looking forward to new entries from the Little SE80 of Horrors.  Also hope you never see some of my code 😉
    Cheers,
    Sue
    (0) 
  2. Michelle Crapo
    I’ve run across some others.  It would be great to have a WIKI.  I think we all would use it. There easily could be some things that I do routinely that I’m not thinking about.  ** Clearing the table after it is declared.  I know I do that one 🙂 **
    (0) 
    1. Neil Gardiner Post author
      Hi Michelle,

      I am glad you liked the Blog. I am pretty sure at some stage I will create a WIKI of a similar nature. At the moment though WIKI has been semi closed so it’s not possible.

      Cheers,
      Neil.

      (0) 
  3. Uwe Schieferstein
    Dear Neil

    Your blog is really entertaining (at least from a developer’s point of view). Actually I had a draft blog with the title “Software Quality? No, thanks! I’m an ABAP developer.” in mind but I drop this now.

    I would like to add two remarks:
    a. My rules are slightly different:
    1) It works, Yep!
    3) The code is easy to read and the logic is easy to follow.
    4) Use the latest methodologies where applicable.
    2) Perfomance is optimal. (In 10 years of ABAP development I had only once a serious performance problem).

    b. In general the quality of internal and in particular external developers outside SAP (i.e. at customers) appears to be similarly low.

    Customers face a big dilemma: since they usually cannot judge the quality of the coding they are happy if it works. They may pay less than half for such a low-level developer as compared to a brilliant one (see blog 14901 by Thorsten Franz). However, they will pay ten times or more when it comes to maintenance.

    Regards
      Uwe

    (0) 
    1. Neil Gardiner Post author
      Hi Uwe,

      Firstly, don’t drop your blog, the more the merrier.

      Secondly you are right that customers judge the quality of the code and happy just as long as it works.

      One thing I have learnt from my years in SAP is that if I am ever in a position where I get to choose to all the developers then I will chose the more expensive as they are worth 4 or more of the cheaper ones and in the long run this will reduce ongoing maintenance.

      Cheers,
      Neil.

      (0) 
      1. Matthew Billingham
        I totally agree with Uwe’s criteria.  I was going to post the same.

        I’ve said many times – in terms of Total Cost of Ownership and good programmer (programs work and are easy to maintain), is 20x cheaper (assuming same daily rate) as an average programmer.  And 50x cheaper then a poor programmer.

        I did have the good fortune to manage a project where I could hire the developers.  I think I’ll write a blog about it…

        (0) 
  4. Thorsten Franz
    Hi Neil,
    What a lovely blog! And I’m very flattered to be mentioned here. Anyway, it was fun reading it and I want to share the impression I got from the first example where the developer repeatedly clears the table and work area: I think he (or she) is programmatically clearing his (or her) throat – just like somebody who has to harrumph several times before actually speaking. LOL! What would life be without our little tics.
    Cheers,
    Thorsten
    (0) 
    1. Ram Manohar Tiwari
      Guilty as charged :). I also use refresh and clear after declaring the variables. But then sometime there is a reason for that and I would consider it a safety measure.

      Try this code ( once with refresh and then without ) and let me know what do you think?

      REPORT  Z_TEST_RAM.

      Do 2 times.

      DATA: gt_ddlb type bsp_wd_dropdown_table,
            wa_ddlb like line of gt_ddlb.
      * try without refreshing
        refresh gt_ddlb.
        wa_ddlb-key = 'E0001'.
        wa_ddlb-value = 'Open'.
        append wa_ddlb to gt_ddlb.

      LOOP AT gt_ddlb into wa_ddlb.
          write : wa_ddlb-value.
        ENDLOOP.

      ENDDO.

      (0) 
      1. Dushyant Shetty
        I don’t think it was intentional, but you just contributed one more horror snippet to the one’s already on the blog…
        Old jungle saying… “Irrespective of where you place declarations in ABAP Code, unless they’re in a subroutine, they’re processed only once at the top of the generated program…”
        I suggest you relook at your own example with this new perspective and I’m sure you’ll see the behaviour is no longer as strange as you thought earlier…

        You might now want to stop refreshing your data objects right after declaring them 🙂

        Regards,

        Dushyant

        (0) 
        1. Ram Manohar Tiwari
          saw that coming 🙂 But that’s why the rule that, you don’t have to refresh the variables after declaration is not valid in this case.
          Just been discussing this with @thorstenster and @TonkaPome http://twitter.com/#search?q=thorstenster%20+%20rmtiwari%20+%20TonkaPome

          The rules of maintaing production code and writing from scratch are slightly different.
          I don’t see anything wrong with these kind of declaration if it makes the code more readable. ( consider when original program was not written by you and that do loop or any other loop is not so clearly visible ).

          It’s easier to provide a small patch at one place. debatable but I won’t put that as “horror code”.

          (0) 
        2. Ajay Das
          I would draw a totally different conclusion and think that the refresh might indeed be needed in this ‘special’ case.
          (0) 
  5. Vijay Vijayasankar
    Loved it, and rekindled some old memories.

    1. I had one project in India where they used CIN, SAP’s Country India version for managing tax and Excise duties etc. This was more than 10 years ago or so. There was a table control in a standard program where if you select one line and hit delete – the whole table (data and the screen control) will get deleted persistently. We (developers from the project) fixed the code and sent the code as reply to OSS note to fix the problem – just to show where the issue lies. A week later, we get a reply that it is all fixed with a note, and guess what – it was just our own code !!

    2. A friend who always used variable names and comments in tamil (a language from south india). This was part fun and part job secrity for the guy 🙂

    3. A big Z table that had to be updated real time with very little tolerance for mistkes. The code read something like

    Do 5 times.
    update zblahblah from itab_blahblah.
    commit work.
    enddo.

    select count(*) from
    zblahblah for all entries in itab_blahblah…..

    if sy-subrc ne 0 OR sy-dbcnt ne itab_lines.
    Do 5 times.
    update zblahblah from itab_blahblah.
    COMMIT WORK.
    enddo.

    The guy who wrote it later quit programming and is now a HR manager in a big company. He hasn’t heard the end of it yet though – we tease him every time we run into him:)

    (0) 
    1. Neil Gardiner Post author
      Thanks for the comments Vijay and sharing some code.  I hope you never cease to tease the guy as his code is classic.

      Cheers,
      Neil.

      (0) 
  6. Bala Prabahar

    Hi Neal,        /* No SQL return code check  /<br/>  <table_name>.<one of the fields> = sy-datum.      <br/> <table_name>.<Second field>     = sy-uname.      <br/> <table_name>.<third field>      = <value of a variable>. <br/>  MODIFY <TABLE_NAME>.  / No sql return code check */<br/>  COMMIT WORK.<br/><br/>    Note: This code is in Production system<br/><br/>Thanks,<br/>Bala Prabahar<br/>

    (0) 
  7. Alvaro Tejada Galindo
    Neil:

    Great blog dude -:) I think we all had made similar error when we were beginners in the ABAP world…I think that’s why we find those even funnier -;)

    Greetings,
    Blag.

    (0) 
    1. Neil Gardiner Post author
      Cheers Dude,

      I, like others, made damn silly mistakes when starting out but the scariest thing of all is that a good percentage of this code was written by alleged senior consultants. :o)

      Cheers,
      Neil.

      (0) 
  8. Suresh Datti
    There should be a process in place to review the code before the Program moves out of Development & the entire team should be guilty. Most of what you have stated could have been easily corrected had there been a process in place.
    (0) 
    1. Paul Hardy
      I quite agree. As most of the examples here come from standard SAP you would think they would have some sort of quality assurance process.
      SAP must regret letting us see their code. This is why they won’t let us run an extended program check on a standard SAP program.
      At my company we are paranoid about code quality, and performance, and have a strong peer review process.
      When we find an error (or badly performing piec of code) in standard SAP, whilst debugging for example, we let OSS know, with a suggested fix, but never get beyond first level support. No-one at that end appears interested, or even to understand what we are trying to do i.e. make the standard SAP product better. I have one such OSS note in progress, if I get nowhere as before, I will publish the (clearly wrong) piece of standard SAP code and either this blog or any succedding WIKI.
      (0) 
      1. Neil Gardiner Post author
        Matter of factly Paul most of this code is from client side rather than SAP.

        As much as I agree that there should be controls in place to review and ensure the quality of code being delivered this is not always possible on projects who’s deadlines are up against a wall.

        As for publishing the SAP standard piece of code, I sincerely hope you do. It would be good to share others experiences in this area.

        Cheers,
        Neil.

        (0) 
  9. Pablo Casamayor
    WHAT?
    Awful code.
    WHY?
    Someone (Thorsten Franz) told you.

    “I expect that this blog will stir some memories in others and get them to share their experiences with interesting code.”
    “I suspect I will end up moving this Blog to a Wiki to allow others to update it and add their stories”

    Ok, just imagine all of us adding our “findings” and laughing at others mistakes while having a beer al the local pub.
    How funny!. But, what is the purpose of all this? I do not understand.

    FINDINGS
    No formal training in ABAP programming
    No books read
    Not talked to other developers
    Living in the past
    Don`t give a damn about a programms performance

    This is somehow a “weak” explanation. It remains in the surface and does not go to the root.
    I expected more deepness in this findings.
    Pinpointing others mistakes for the sake of it it´s very easy.
    We can spend hours watching “interesting” pieces of code.
    But in a blog i would expect something more. I´m really disappointed.

    What can make an abap developer do that apart from poor training?
    i´m sure there might be several reasons e.g.

    1.- accepting a project with very low fees and tight deadlines and hiring people without filtering.
    Are those hired people to blame for that?

    2.- Lack of knowledge and experience from the functional side.
    Some time ago i read something from Dan Macweeny and he said something like this:
    “if i explain something related to my job to my mom and she doesn´t understand what i´m talking about maybe
    it´s because i do not understand it too”. How many times do developers receive poor functional specifications?

    3.- Pure desperation.
    If you´re offered a job and you lack the skills for it, would you blame someone for trying to feed his family?
    Hasn´t the hiring firm something to do with it?

    4.- The code has been “redone” several times by several developers and always in a hurry.

    5.- Sub-Sub-Sub-contracting.
    Yes this does happen.

    6.- Lack of sleep.

    7.- Poor educational system (language skills …etc)

    …. etc

    With the “food for points” program we´re trying to help communities in difficult situations.
    Maybe we are now laughing at the code of someone who is in a difficult situation like any of these communities. Is that fair?
    Personally when i find some “interesting” piece of code i just fix it and blame nobody.

    Some titles for your next blogs:
    The littte SPRO of Horrors
    The little BASIS of Horrors

    Best regards.

    (0) 
    1. Neil Gardiner Post author
      Pablo,

      You do have some valid points but you misunderstand the point of this Blog.

      It was not point to blame or name and shame anyone. It was purely just to share some bad coding techniques.

      I could list of whole bunch of reasons as to why the code is bad but that is not my intention.

      Cheers,
      Neil.

      (0) 
    2. Thorsten Franz
      Hi Pablo,
      for the record, I don’t go around telling Neil which code is good and which is bad. He found these pieces, posted them on twitter, and I suggested that he might blog about them.
      I think you misunderstood the intentions of the blog. I’m pretty sure Neil is not ridiculing or judging the people who wrote that code, only the code itself. I do stupid things all the time, and I intend no offense when I say that I expect so do you, because it’s normal. Making fun of these blunders from developer to developer is the most natural thing in the world.
      (Unless one is the kind of person who goes down into the cellar when they want to have a laugh.)
      With SY-SUBRC-agnostic regards,
      Thorsten
      (0) 
  10. John Patterson
    Hey Neil,
    Catch22 – ABAP is easy to learn but takes a long time to master. I think you have only scratched the sufface and without a reference to bad or ineffective practice how do we learn.

    How about you start a wiki of ABAP Anti Patterns. –

    Cheers
    JSP

    (0) 
    1. Neil Gardiner Post author
      JSP,

      Long time no hear!

      Thanks for the comment. It is a catch 22 indeed but I have tried to limit my code examples where I know the developer was in fact billed as a Snr Consultant.

      As for the WIKI, that is a good idea. I assume by anti-patterns you mean how NOT to program?

      I am going to create a WIKI on the back of this Blog to others can share their experiences.

      Cheers,
      Neil.

      (0) 
  11. Shailesh Naik
    The author has given some of the errors developers made, apreciated. But I was expecting something more. It would have been great if he has listed do’s and don’ts OR errors Vs solution OR a link where common errors are listed. In modules like BI it is expected the person should know BI, functional module and ABAP. It is very difficult in such cases to go and learn ABAP in detail. Not all who write ABAP are hard core programmers, there are people who are primarily functional and can write ABAP a bit.
    (0) 
    1. Neil Gardiner Post author
      Hi Shailesh,

      The point of the Blog as such wasn’t too put wrongs right. More so just to just share them.

      Time allowing I am going to create a WIKI that will cover right versus wrong.

      You have to understand I am not a hardcore programmer. I am just a bloody good programmer who expects better from people. Especially if they are going to sell themselves as programmers.

      There is right and wrong and I just want to share, in my opinion, the difference between the two.

      P.S. I was joking about being a bloody good programmer! :o)

      (0) 
    2. Bala Prabahar
      Hello Shailesh,

      I don’t have any issues with people who write bad code. ABAP as we all know, is not science. However in general most of ABAP programmers(by ABAP programmers, I mean everyone who writes ABAP programs) have a poor listening skills.
      I know BI developers who know a little bit of BI but not a lot about programming as you mentioned. Recently one of them wrote ABAP program which was reading the same record few thousand times(I showed him st05 output) from the database. This could have been handled easily by storing the record in a program variable. Instead he suggested building an additional index on table because of poorly written program. He refused to change the program when better solution was pointed out. And his lead was interested in some solution not necessarily a better solution. I built an additional index.

      Why ABAP’ers refuse to listen? I can’t explain.

      Regards,
      Bala Prabahar

      (0) 
      1. Jhon G
        Hello Bala,

        I dont know what kind of ABAPer’s you are working with?

        ‘Why ABAP’ers refuse to listen? I can’t explain.’..
        this point is not true with every ABAPer..

        i can put this in other words..
        ‘You Failed in explaining the consequences of this kind of code to the specific developer..’

        Might be you got ABAPer who are not trained well..

        Thjanks,
        Krishna.

        (0) 
  12. Kiran Kumar
    Hello,

    According to my view this blog again helps many of guys who are reluctant of using the ABAP properly and one will really learn from this.

    Regards,

    Kiran Kumar

    (0) 
  13. Tony Shearsby
    Standards and Quality of code are vital to ensure that an ERP runs consistently smoothly and efficiently.  But this blog only serves to insult code written by others when it is clear that education is required not criticism.

    If SDN is going to highlight these worthless blogs I despair.

    Can we please have something that will help drive improvements, rather than rants like this which are a waste of our time.

    (0) 
    1. Neil Gardiner Post author
      Tony,

      For your information a Wiki is being created as we speak to show right versus wrong to help others out there improve their development skills.

      And for the record this Blog was no intended to insult anyone.

      Neil.

      (0) 
  14. Paul Levey
    Anyone can go find faults with code, but what about being constructive instead. You could point the out the nature of the problem and how it should have been done properly. That would actually help newcomers to ABAP instead of poking fun.
    (0) 
    1. Neil Gardiner Post author
      Paul,

      The plan is to follow up this Blog with a Wiki, which I am working on now, which will cover the nature of the issue how it should be done better.

      Neil.

      (0) 
  15. Raja Thangamani
    Good one & funny :)… My take is, it’s not because of lack of training or reading documents, etc. for basic mistakes such as two consecutive move-corresponding to l_ekko or clearing variable after declaring, etc.

    Developer should use their common sense while developing the code. Because no document says that don’t clear the variable after declaration 🙂

    (0) 
  16. Eric Hernandez Pardo
    Hi Neil,

    This is a very interesting blog, I don’t undertant why many people got upset about it. I think that there is no ABAP developer that hasn’t develop a horrible program at the beginning of it’s professional life.

    Sometimes when I look at my first developed programms, I laught at myself when I see the mistakes (horror code) that I made on some programs.

    It will be nice to see the comments that you can find on several programs too. One time I read on a standard SAP Function something like this:

    if sy-subrc ne 0.
    * PANIC!!!
    else.
    …. some code
    endif.

    Regards,
    Eric

    (0) 
    1. Neil Gardiner Post author
      Hi Eric,

      Thanks for the positive comment.

      I am in the midst of creating a wiki. Once this is completed please feel free to add the amusing comments you have come across in your travels.

      Cheers,
      Neil.

      (0) 
  17. Krishna Kumar
    Sorry to say this, I was looking to use SDN to learn some tips and enhance skills. If i am looking for timepass, I can even look at other sites.

    Neil replied for almost all the comments that he will be creating a wiki. I am wondering how it will be really usefull.

    In the first code, MOVE was used twice and will the wiki say as one MOVE is correct. Most of the code mistakes are with confusion or may be lack of time or lazy coders.

    I strongly believe that they need to be attentive and debug the code properly. Please use a different title, saying that it is for FUN or a separate category for these type of blogs.

    (0) 
  18. Raf Boudewijns
    Love it!
    I moved from ABAP developer to BI consultant about 9 years ago. Especially in a BI environment your points 2 & 3 are crucial. I have seen my share of horror (a load taking 1.5 days… which a “junior” colleague and I reduced to 1 hour, just by optimizing the code in the transformation). Back in the days I though there were quite a lot of “cowboys” out there and that they would eventually disappear… however, I find that there are even more of them out there now?! The good thing is, it keeps me “busy” 😉
    Cheers!
    (0) 
    1. Matthew Billingham
      I work 2 days a week for a BI client as a dedicated ABAP resource.  Although the BI guys can write ABAP to an extent, it’s been recognised that for anything above the run of the mill, it’s better to get an expert in.  They do the authorisations and (shudder) STS.  I do the complicated ABAP.  The rest, we share.
      (0) 
    2. Neil Gardiner Post author
      Hi Raf,

      I am glad you enjoyed the Blog. I am just applying some finishing touched to a Wiki page. Once this is complete please feel free to add your own horror stories.

      Cheers,
      Neil.

      (0) 
  19. Amey Divekar
    Awesome post Neil.

    Very first thing I did after seeing this blog was forward this to all my ABAP teammates. Most of them if not all admitted to committing such silly mistakes.

    Cheers!!

    (0) 
  20. Michael Arter
    I fail to see how useful this post is in terms of SDN being a repository from where developers can find information.  If it had pointed out the pitfalls in each of the examples and a better coding solution then I wouldn’t have an issue. The impression it leaves me with however is it is simply serving as an opportunity to ridicule people where their coding experience may not be as extensive as the author.
    (0) 
    1. Abraham Bukit
      I do believe that in this Blog there are lots of valuable information.
      For senior abap consultant, some might realized the needs of code review in their organizations to ensure the problematic codes in this blog will not exist in their system.

      I disagree with this statement :
      “The impression it leaves me with however is it is simply serving as an opportunity to ridicule people where their coding experience may not be as extensive as the author.”

      My opinion is, being less experience ABAP-er does not justify you in writing poorly written ABAP program. I remember in my previous organization how we have the same standard in reviewing code of 3 years experienced ABAP programmer and entry level ABAP programmer. That’s the purpose of having quality control for ABAP program, something that more often ignored.

      (0) 

Leave a Reply