Skip to Content
Author's profile photo Former Member

Some Tips to avoid potential/hidden bugs in programs.

Hello All,

Most of the times, bugs, small issues become very critical issues leading to big impact to the business once when a project is gone live or when some change requests are moved to production, once the user starts using the new system. Identifying these hidden bugs,potential bugs sometimes becomes very difficult since some scenarios which needs to be tested are not there in other non-production environment(cannot be replicated) due to various reasons like configurations, necessary test data not available, sometimes all possible testing done in non-production environment and working fine, but when same functionality moved to production and used by user, it results in short-dump, functionality not working as expected, etc. Hence it is very important as an ABAPer, to think on various approaches while coding or implementing the logic using appropriate ABAP statements, understanding the working of different ABAP statements and how the program flow happens or execution flow.

  Hence , I would like to share my knowledge on various things which we need to analyze while implementing the logic in new programs, or any changes to the existing custom and standard programs. This will avoid potential/hidden bugs found in the program at a later stage.Some of them are as follows:

1. Use the language key in WHERE clause in Select Query while picking data from Text tables: When picking up the data from Text tables, for example, while picking up data from database table MAKT for material description, the language key(SPRAS) should be passed in where clause.Most of the times, it is missed when this query is used in many places of a big program. Not passing the language key, results in picking up first entry from table,which is the correct material description,but not in the required language as required by the user.

2. Using of READ TABLE ITAB INTO …INDEX 1 in a user exit or a generated program or custom include used in the standard program.

This is one of the big mistake done in using the READ statement. The user exit or include where you have written the READ statement with INDEX 1 might be called multiple times and ITAB will have more than one entry getting populated or values getting deleted every time the include is called.Using the INDEX 1, might result in reading the same first record of the table every time and might lead to an issue and logic being not implemented properly. Thus it is very important to analyze and understand how this table is getting populated. Instead of using INDEX 1, try to pass required key field in the READ statement,

i.e. READ TABLE ITAB INTO .. WITH KEY matnr = head-matnr.

3. Usage of correct BAPI in programs: The functionality of a BAPI is similar to a transaction. While using a BAPI in the program, proper analysis should be done to understand the complete functionality of it. Once when the BAPI does the functionality of what is required is achieved, we start using it, which is a big mistake. Some BAPIs will internally call different BAPIs for additional functionalities. These functionalities might be add-ons and need not be required for the user. It can be also the vice-versa, the subset of parent BAPI will alone implement our requirements. Hence, it is not needed to use the parent BAPi instead of using the subset of BAPI. So, analyze and test the functionality in standalone and understand before actually using the BAPI in your program.

4. Use of FMs for date calculations:  Most of the times, date calculations and conversions in programs are done using normal ABAP statements instead of using FMs which are available ready made for date calculations, date conversions, etc. with exception handling. This results in short dump or functionality not working. It might a silly mistake 🙁 , but would cost a lot when such changes are moved to production. Hence FMs should be used instead of using statements like CONCATENATE etc.

For example, for calculating the date 2 months before current date, direct subtraction was done using normal ABAP statement:

            Say the current date is 04/02/2013 (sy-datum – 20130204)

          month = sy-datum+4(2) – 0002.                                           ” result —-month = 0                                                

          CONCATENATE sy-datum+6(2) ‘/’ month ‘/’ sy-datum+0(4) INTO pdate. 

          Result:  pdate = 04/00/2013 – which is an invalid date.

– will result in date becoming 04/00/2013 – which is invalid date, which when used in next step or later might result in functionality not working, or even run-time error will occur if the date is used in the where clause of Select query.

Instead use FM BKK_ADD_MONTH_TO_DATE for the same, which will give proper result.



       months  = c_2      “-2

       olddate = sy-datum


                               newdate = p_date.          ————–result —- pdate = 04/12/2012 – which is Valid date.

This is a very simple example, but there might be very complex calculations required for date, day,month,year calculations in some cases,hence it is best to use Function Modules.

5. Use of FMs Conversion alpha exits/ conversions of key fields like material number,sales order number before using in select queries:

Sometimes in module pool programs, when input is provided without preceding zeros, when conversion to internal format is not done before querying to the table, it might result in record not found for fields like material number or sales order number or maybe any field. Hence using the FM Conversion Alpha exit input, the input needs to be converted to internal format, i.e. populate preceding zeros in them and then pass it to select query.

Note : This blog is only for beginners. Most of the sometimes, the beginners forget or don’t bother to go through the code inspector or the consistency checks,once the development or code changes are done. Hence  thought of sharing the same.


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Nicely put. Yes these are the common mistakes made by new programmers in ABAP. There are few more like:

      1. Reading internal table using BINARY SEARCH without first sorting the table which can then give wrong outputs.

      2. Not using sy-subrc checks after Queries or FMs.

      3. I see lots of posts on SDN when their queries are not working after they use FOR ALL ENTRIES without checking whether the previous table has any entries.



      Author's profile photo Former Member
      Former Member

      In release SAP_ABA 702, New ABAP Debugger has an option that checks sorting of internal table if binary search is used.

      Author's profile photo Former Member
      Former Member

      Hi Manish,

      How to check it from the new debugger.Please share it.

      Author's profile photo Matthew Billingham
      Matthew Billingham

      Please start a new discussion. Subsequent comments removed.

      Author's profile photo Kesavadas Thekkillath
      Kesavadas Thekkillath


      We have received a report about the redundant contents in this blog.

      I do not see anything new here. Such topics/tips/ideas are discussed many many times in the forums before. I am not degrading your effort though.Nowadays, most of the checks are easily highlighted by the code inspector itself.

      From the beginners point of view,  I feel this post is a bit useful to them.Hence, leaving it as it is.



      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Hello Kesavadas,

      This blog is only for beginners. Most of the sometimes, the beginners forget or don't bother to go through the code inspector or the consistency checks,once the development or code changes are done. Hence  thought of sharing the same.


      Author's profile photo Former Member
      Former Member

      I have checked the lost check box but it is not update the error in ITAB_ILLEGAL_ORDER can you please guide me..

      Author's profile photo Former Member
      Former Member

      Are you doing read table binary search on unsorted table right after checking that option?

      Try running this code, put breakpoint at read table, check debugger option and continue.

      BEGIN OF ty,
        num TYPE i,
      END OF ty.
      DATA lt TYPE TABLE OF ty.
      DATA ls TYPE ty.

      DO 20 TIMES.
        ls-num = sy-index.
        APPEND ls TO lt.
      SORT lt BY num DESCENDING.
      DO 20 TIMES.
        ls-num = sy-index.
            WITH KEY num = ls-num
            BINARY SEARCH.
        WRITE:/ sy-subrc.

      Author's profile photo Hai Wang
      Hai Wang

      date calculation is the Mathes work, the FM is just design for people who not very good at Mathes.  If you not very good at Mathes, then you certainly need to know the build in funcation for doing the job for you.