Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member186750
Contributor
0 Kudos
1,893

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.

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

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.

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.  

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

This is the type declaration for the internal table.  

This is the data select into the internal table.

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

 

again, the same developer from above example.

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.

54 Comments
keohanster
Active Contributor
0 Kudos
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
former_member186750
Contributor
0 Kudos
Hi Sue,

Thanks for the comment. Not to worry, I am sure your code is up to par. 🐵

Cheers,
Neil.
Former Member
0 Kudos
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 🙂 **
uwe_schieferstein
Active Contributor
0 Kudos
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

former_member186750
Contributor
0 Kudos
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.
former_member186750
Contributor
0 Kudos
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.
former_member182046
Contributor
0 Kudos
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
former_member186750
Contributor
0 Kudos
Hey Thorsten,

Glad you liked the blog. It was your idea after all. :o).

Cheers,
Neil.
valentin_catalin2
Active Participant
0 Kudos
The part with the hard coding by user name in standard programs is really nice :))))
Former Member
0 Kudos
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.
Former Member
0 Kudos
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:)
Former Member
0 Kudos
Great blog!

I'm looking forward to the Wiki version. You could create a section dedicated just for SAP standard code funny stuff.

Regards,
José Omar
Former Member
0 Kudos
The best part is when you said: It makes me want to cry.
Horror code indeed...!
dustyplanet
Active Participant
0 Kudos
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
former_member182313
Participant
0 Kudos

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/>

Former Member
0 Kudos
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.
suresh_datti
Active Contributor
0 Kudos
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.
Former Member
0 Kudos
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".
hardyp180
Active Contributor
0 Kudos
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.
former_member182371
Active Contributor
0 Kudos
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.
Former Member
0 Kudos
I would draw a totally different conclusion and think that the refresh might indeed be needed in this 'special' case.
Former Member
0 Kudos
Pretty good and resonable counter-view.
former_member186750
Contributor
0 Kudos
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.
former_member186750
Contributor
0 Kudos
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.
former_member186750
Contributor
0 Kudos
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. 🐵

Cheers,
Neil.
former_member186750
Contributor
0 Kudos
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.
former_member182048
Active Contributor
0 Kudos
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
former_member186750
Contributor
0 Kudos
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.
former_member182046
Contributor
0 Kudos
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
Former Member
0 Kudos
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.
former_member186750
Contributor
0 Kudos
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! 🐵
former_member182313
Participant
0 Kudos
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
Former Member
0 Kudos
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.
Former Member
0 Kudos
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
Former Member
0 Kudos
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.
former_member186750
Contributor
0 Kudos
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.
Former Member
0 Kudos
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.
raja_thangamani
Active Contributor
0 Kudos
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 🙂
former_member186750
Contributor
0 Kudos
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.
former_member186750
Contributor
0 Kudos
Raja,

Thanks for the comment. I totally agree that common sense should be used and shall mention that in the Wiki.

Cheers,
Neil.
Former Member
0 Kudos
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

former_member186750
Contributor
0 Kudos
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.
matt
Active Contributor
0 Kudos
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...
former_member186750
Contributor
0 Kudos
Hi Matthew,

I hope you do write a blog as I am sure it would be a good read.

Cheers,
Neil.
Former Member
0 Kudos
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.
Former Member
0 Kudos
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!
Former Member
0 Kudos
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!!
matt
Active Contributor
0 Kudos
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.
former_member186750
Contributor
0 Kudos
Hi Amey,

I am glad you enjoyed the blog.

Cheers,
Neil.
former_member186750
Contributor
0 Kudos
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.