|
Blogs
WhatOf 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. WhyOn 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 FindingsFrom 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 RulesFor 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" CodeRight, 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 StatementWell, 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.
Neil Gardiner
Wannabe Netweaver nerd.

Comment on this weblog
GoodOnes
2009-08-30 20:05:33 Naga Krishnamoorthy
Business Card
[Reply]
Thanks for pointing out, now people will start writing the code properly
ABAP Pearls...
2009-08-25 00:36:05 Ivan Femia
Business Card
[Reply]
Neil, take a look to this forum post
http://forums.sdn.sap.com/thread.jspa?threadID=1398380&tstart=60
Bye
Ivan
Useful?
2009-08-24 15:53:39 Michael Arter
Business Card
[Reply]
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.
Useful?
2009-08-24 23:07:39 Abraham Bukit
Business Card
[Reply]
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.
Awesome post!
2009-08-21 03:17:30 Amey Divekar
Business Card
[Reply]
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!!
Sweet :-)
2009-08-21 03:16:48 Raf Boudewijns
Business Card
[Reply]
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!
Sweet :-)
2009-08-24 04:24:05 Neil Gardiner
Business Card
[Reply]
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.
Sweet :-)
2009-08-21 05:51:17 Matthew Billingham
Business Card
[Reply]
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.
Not a Funny Blog
2009-08-20 12:18:37 Krishna Kumar
Business Card
[Reply]
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.
Interesting blog
2009-08-19 15:36:42 Eric Hernandez Pardo
Business Card
[Reply]
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
Interesting blog
2009-08-19 15:58:00 Neil Gardiner
Business Card
[Reply]
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.
Common sense!!!
2009-08-19 11:27:28 Raja Thangamani
Business Card
[Reply]
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 :)
Common sense!!!
2009-08-19 13:36:18 Neil Gardiner
Business Card
[Reply]
Raja,
Thanks for the comment. I totally agree that common sense should be used and shall mention that in the Wiki.
Cheers,
Neil.
Worthless blog
2009-08-19 06:42:48 Paul Levey
Business Card
[Reply]
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.
Worthless blog
2009-08-19 13:34:11 Neil Gardiner
Business Card
[Reply]
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.
Where's the point?
2009-08-18 06:04:12 Tony Shearsby
Business Card
[Reply]
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.
Where's the point?
2009-08-18 23:42:27 Neil Gardiner
Business Card
[Reply]
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.
Should have been in more detail
2009-08-15 00:16:03 Shailesh Naik
Business Card
[Reply]
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.
Should have been in more detail
2009-08-15 07:12:44 Bala Prabahar
Business Card
[Reply]
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
Should have been in more detail
2009-08-17 01:02:48 Ramakrishna Gelli
Business Card
[Reply]
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.
Should have been in more detail
2009-08-15 02:55:13 Neil Gardiner
Business Card
[Reply]
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)
ABAP anti-patterns
2009-08-11 17:30:06 John Patterson
Business Card
[Reply]
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
ABAP anti-patterns
2009-08-11 17:43:56 Neil Gardiner
Business Card
[Reply]
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.
disappointed
2009-08-11 07:59:28 Pablo Casamayor
Business Card
[Reply]
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.
disappointed
2009-08-12 00:37:42 Thorsten Franz
Business Card
[Reply]
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
disappointed
2009-08-11 16:46:35 Neil Gardiner
Business Card
[Reply]
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.
Don't blame the developer alone!
2009-08-11 07:51:14 Suresh Datti
Business Card
[Reply]
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.
Don't blame the developer alone!
2009-08-11 07:58:13 Paul Hardy
Business Card
[Reply]
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.
Don't blame the developer alone!
2009-08-11 16:41:04 Neil Gardiner
Business Card
[Reply]
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.
IF 0 EQ 0...
2009-08-11 07:47:38 Alvaro Tejada Galindo
Business Card
[Reply]
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.
IF 0 EQ 0...
2009-08-11 16:48:22 Neil Gardiner
Business Card
[Reply]
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.
Appropriate title!
2009-08-11 07:28:13 Bala Prabahar
Business Card
[Reply]
Hi Neal,
I loved reading you blog.
Your rules:
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.
Personally, I would be happy if developers can write code that works. (2),(3) and (4) are certainly critical; however (1), you might agree, is more critical than (2), (3) and (4).
What do you think about the developers who cares less(or doesn't care at all) about checking return code of DML statements?
I will explain two scenarios:
Developer's complaint:
Why the records are getting deleted.
Fact:
They originally intended to create records in table A and table B in addition to other changes within a transaction. However, without checking the status of insert statement against table B, they committed. I believe the insert statement against table B (or Table A) sometimes fails; simple SQL status check would have helped them to rollback the transaction thereby undoing the insert against table A(or table B). The rollback would have accomplished two things:
a) The insert against table (A) (or B) and all other changes would have been rolled back. and
b) The program would have thrown an error indicating why the user's transaction failed.
Instead they complain why the record against table B (or A)got deleted....
Another scenario:
Developer's Complaint:
The developers wonder why their code fails sometimes(Translation: Their code fails due to either DB bug and/or DBA issue).
Fact:
They simply ignored to check the return code of two DML statements. So the code works generally but sometimes fail with no error. Review this code:
SELECT SINGLE FOR UPDATE * FROM <Custom Table>
WHERE FieldA = VALUEA
AND FieldB = VALUEB.
/* No SQL return code check */
<table_name>.<one of the fields> = sy-datum.
<table_name>.<Second field> = sy-uname.
<table_name>.<third field> = <value of a variable>.
MODIFY <TABLE_NAME>. /* No sql return code check */
COMMIT WORK.
Note: This code is in Production system
Thanks,
Bala Prabahar
Great blog!
2009-08-11 07:13:56 José Omar Dutra Jr.
Business Card
[Reply]
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
down memory lane
2009-08-11 07:05:50 Vijay Vijayasankar
Business Card
[Reply]
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:)
down memory lane
2009-08-11 16:51:28 Neil Gardiner
Business Card
[Reply]
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.
Funny
2009-08-11 05:00:53 Valentin Catalin
Business Card
[Reply]
The part with the hard coding by user name in standard programs is really nice :))))
Lovely blog
2009-08-11 04:55:44 Thorsten Franz
Business Card
[Reply]
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
on my defence :)
2009-08-11 05:06:31 Ram Manohar Tiwari
Business Card
[Reply]
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.
the defence rests :-(
2009-08-11 07:25:28 Dushyant Shetty
Business Card
[Reply]
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
objection my lord :)
2009-08-11 07:55:53 Ram Manohar Tiwari
Business Card
[Reply]
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".
Really entertaining!
2009-08-11 04:12:47 Uwe Schieferstein
Business Card
[Reply]
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
Really entertaining!
2009-08-11 04:36:23 Neil Gardiner
Business Card
[Reply]
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.
Really entertaining!
2009-08-20 01:24:33 Matthew Billingham
Business Card
[Reply]
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...
Excellent!
2009-08-11 03:57:34 Michelle Crapo
Business Card
[Reply]
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 :) **
Excellent!
2009-08-11 04:39:34 Neil Gardiner
Business Card
[Reply]
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.
Good ones, Neil!
2009-08-11 03:30:36 Susan Keohan
Business Card
[Reply]
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
|
Showing messages 1 through 54 of 54.
|
|