are you an abap coder or a programmer?

8

Click here to load reader

Upload: sapyard

Post on 14-Feb-2017

240 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 1/8

Are you an ABAP coder or aprogrammer?TOPICS: ABAP Checklist Good Programming Practice

Guidelines

POSTED BY: SAP YARD OCTOBER 16, 2014

The difference between a normal programmer and agood programmer is, the latter keeps his/her basicsright. Good programmers are distinguished by thequality of their deliverables. They provide enoughdocumentation in their object so that the futurepractitioners supporting their product do not cursethem. One of my Team Lead once told me, “your codeshould not only meet the functionalities, it should also beasthetically pleasing if someone happens to peep into it“.

Today, in this post I do not want to bore you with the“Gyan” (Sanskrit word that roughly translates to

Enter email

Subscribe

RECENT POSTS

DELETING rows of theinternal table within theLOOP. Is it a Taboo? A bigNO NO?Quick Reference for VistexTechnicalOffshore DevelopmentModel in 10 Steps

SAP YARDYOUR BACKYARD FOR SAP TECHNICAL TIPS AND SOLUTIONS

HOME SEE ALL POSTS ASK YOUR QUESTIONS ABOUT ME CONTACT ME

You and 92 other friends like this

SAP Yard168 likes

Liked

SEARCH …

17

7

2

2

Page 2: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 2/8

“sermons/preachings”). But, I would like to provide alist of simple checks which every programmer shouldremember even in their sleep…

Note: Numbers are only for bullet marker. It does notrate one higher to next. Every point has differentweightage in different scenarios.

1) Define your variables with meaningful names (eg:instead of v_var1; v_material is more meaningful).Provide as much documentations/halfline commentsas possible. Align your code and demarcate yourblocks. Provide uniform spacing in between differentunits and remove dead codes. Clean code wouldreflect your personality..

2) In the AT SELECTION-SCREEN event, use UP TO 1ROWS (or count( * ) UP TO 1 ROWS) in the SELECTstatement used for validating the data since the ideais just to ensure that at least 1 row will be consideredfor processing in the main selection event.

3) Internal table is defined with “TYPESTANDARD/SORTED/HASHED TABLE OF”  “INITIALSIZE 0″ and work area is used instead of tables withHEADER LINES. If you have multiple internal tablesof same type, you need not always define as manywork areas. Same work area should be used acrossmultiple internal tables, if they are of same type.

4) Declare  global internal tables only if they areexpected to be used globally (across multiplesubroutines) in the program. This is to avoidunnecessary memory usage as local internal tables arecleared from the memory on exiting the subroutine.

5) Wild cards like ‘A%’  should be avoided as much aspossible.

6) Always SELECT INTO internal table, except when

Ready Reckoner for SAPDevelopersJust a key and two clicks forALV consistency check

Page 3: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 3/8

the table will be very large, use “UP TO N Rows” whenthe number of records needed is known.

7) Use “JIT”, Just In Time concept to select data whenneeded, use them and free them. Most programmershave the habit of selecting all the tables one by onefirst and then processing/massaging them later at theend. This practice burdens the system by unnecessarymemory consumption by holding the data when theyare not needed. SELECTs should be done whenneeded and FREE/REFRESH the tables as soon as it isused and not needed afterwards.

8) SORT fields and SORT Order on the SORTstatement should be mentioned explicitly (e.g. SORTITAB BY FLD1 ASCENDING FLD2 DESCENDING).

9) HASHED table is used for processing large amountof data (provided that you access single records only,and all with a fully specified key).

10) DELETE or SORT is not used on a HASHED tablesince it increases memory consumption.

11) Fields specified in the WHERE condition with thecritical operators NOT and <> (negative SQLstatements) cannot be used for a search usingdatabase indexes. Whenever possible formulate SQLstatements positively. Avoid negation statements.

12) When IF or CASE, testing conditions are nested sothat the most frequently true conditions areprocessed first. Also CASE is used instead of IF whentesting multiple fields “equal to” something.

13) READ TABLE INTO WORKAREA should be usedinstead of only READ TABLE. If INTO work area is notneeded then, use the addition TRANSPORTING NOFIELDS if the purpose of the read statement is only tocheck the existence of the record in that table.

Page 4: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 4/8

14) For copying internal tables use ‘=’ operatorinstead of LOOPing and appending. SORT inside aLOOP should be avoided.

15) Do not delete the records of internal table insidethe LOOP — ENDLOOP. Instead mark the rows to bedeleted by passing some identifier to the row field(s)and delete all those identified after the end of LOOP.Use Field Symbol, if you want to modify the fields of atable in the LOOP. Usage of field symbol would avoidmodify statement inside the LOOP.

16) Use CONTROL BREAKS in the LOOP — ENDLOOPsyntax to avoid repeated reading of other internaltables and for summarizing / updating the internaltables.

17) DELETE ADJACENT DUPLICATES entries frominternal table before selection from database tableusing “ FOR ALL ENTRIES” statement. Applicableonly in those cases where the table can possibly haveduplicate entries.

18) Nested SELECT should not be used instead,“INNER JOIN” and/or “FAE” should be used. “FAE” isto be used over “LOOP at ITAB / SELECT /ENDLOOP”.

19) In SELECT statement, only the required fieldsshould be selected  from the databasetable/structure/view. While using FOR ALL ENTRIES,make sure to SELECT all the primary keys even if youdo not need some of them later as FAE retrievesunique result set.  For selecting single row from adatabase table, “SELECT UP TO 1 ROWS” is used(when you do not have full primary key for yourWHERE clause). Always CHECK that the internal tableused in FOR ALL ENTRIES is NOT empty. “SELECTSINGLE” is used only when full primary keycombination is known.  Avoid SELECT * as much as

Page 5: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 5/8

possible.

20) When creating JOINs over database tables thereshould be an index at least on the inner table for thefields in the JOIN condition else use “ FOR ALLENTRIES” SELECT statement. Ensure that the innerjoin uses the correct indexes.

21) SORT internal table by fields in the correct order,which are used in a READ TABLE statement usingBINARY SEARCH. If the order of SORTING is invalid,the BINARY SEARCH will never work. And you wouldbe scratching your head for a long time to find theroot cause if you need to do dry run where issuescould be replicated..

22) Avoid MODIFY, use explicit INSERT or UPDATE;it is better for performance and support. MODIFYstatement is more attractive to programmers becauseof the ease of usage. But, believe me, splitting yourtable entries to INSERT and UPDATE is still better,even though it might need one more selectstatements. Tried and Tested in real projects.

23) For large internal tables where only some rows areto be processed, use SORT and then the READ TABLEcommand is used to set index to first relevant rowbefore LOOPing from that index. Use CHECK or IF…EXIT…ENDIF as appropriate to exit from the loop.Also called, Parallel Cursor technique.

24) SORTed table is used for range accesses involvingtable key or index accesses. SORTed tables areparticularly useful in nested loop processing. LOOPAT ITAB with a WHERE condition is preferred whereITAB is a SORTED table (instead of STANDARD orHASHED internal table) and the fields used in theWHERE condition are the non-unique key fields of thesorted table.

Page 6: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 6/8

25) Use indexed table like VAPMA instead of VBAP toidentify sales orders for a particular MATNR (i.e insituations when you have material and you do nothave VBELN (sales order number) in hand). SimilarlyVAKPA etc. VBFA is used for forward search i.e.preceding to subsequent. For subsequent to precedingwe should use alternate tables such as LIPS or VBRP(VBGEL, VGPOS). Try to use Views instead of joiningmultiple tables.

26) Run Code Inspector and Extended syntax checkswith character literals checkbox switched on to rectifyall relevant errors and warnings. SAP has providedthis cool feature, please use it. Proudly flaunt theresults with zero/ignorable warnings.

27) Use transaction code SCI/SCII to do the sanitycheck of your deliverables before passing it to thequality reviewers. Easy way to impress your reviewer.

28) Use transaction code ST05/ST12 to trace yourcode. Make sure to check what indices your databaseaccesses are using. Check these indices against your“WHERE” clause to assure they are significant. Checkother indices for this table and where you have tochange your “WHERE” clause to use it. Create newindices if necessary after consulting your Basis team.For client dependant tables, use MANDT as the firstfield in the secondary index since it is internallyconsidered by SAP when retrieving the data from thedatabase tables.

Please note, this article is not intended for PerformanceTuning. This is an effort to remind the programmersabout the simple checks which we should take care aspart of good programming practice. Please feel free tosuggest if you think something is missing. We would behappy to add them in this list.

Page 7: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 7/8

2 COMMENTS

ON "ARE YOU AN ABAP CODER OR A PROGRAMMER?"

 

Previous post Next post

Great staff, thanks a lot

Dear William – Thank youso much for your feedback.. Glad thatyou like it.

Regards,SAPYard.

Leave a commentYour email address will not be published.

Name *

Mutero william | July 30, 2015 at 12:50pm | Reply

SAP Yard | July 30, 2015 at 1:41pm | Reply

Page 8: Are you an abap coder or a programmer?

8/11/2015 Are you an ABAP coder or a programmer? | SAP Yard

http://www.sapyard.com/areyouanabapcoderoraprogrammer/ 8/8

Raju

Email *[email protected]

Website

Comment

Post Comment

COPYRIGHT 2015 | SAPYARD BY WWW.SAPYARD.COMALL PRODUCT NAMES ARE TRADEMARKS OF THEIR RESPECTIVE COMPANIES. SAPYARD.COM IS NOT AFFILIATED TO SAP AG.