ABAP Performance Test: Hashed Tables vs Database Buffers

There are two significant techniques to avoid repetitive access to database records: Hashed internal tables and database buffers. We ignore other internal table types because hashed tables are proven to be the fastest approach when reading single records.

If we decide to use the former method, we need to get the database record into a hashed internal table. Whenever we need to access the record, we read the internal table instead of the database table.

If we decide to use the latter method, all we need to do is to activate the table buffer in SE11. If we do that, the accessed data is cached on the application server, and the cache is used whenever possible. Thus, database access is reduced. There are exceptional cases where the buffer is bypassed, but that’s beyond the scope of this article.

Wondering how they compare in terms of performance, I created a fully buffered database table with example data.

Screen Shot 2017-10-20 at 19.12.24

I also wrote a program, which accesses the data using both techniques and compares the runtime.

It turns out that hashed access is 3-4 times faster than database buffering.

Screen Shot 2017-10-20 at 19.14.15

You can use the attached source code yourself and repeat the test; I would like to hear about any disproving results.

REPORT zdummy01.

CLASS main DEFINITION.
 PUBLIC SECTION.
   CLASS-METHODS execute.
 PROTECTED SECTION.
 PRIVATE SECTION.

CONSTANTS:
 c_do_times TYPE i VALUE 100,
 c_matnr TYPE matnr VALUE 'M1'.

CLASS-DATA:
 go_text TYPE REF TO cl_demo_text,
 gv_begin TYPE i.

CLASS-METHODS:
 hash,
 select,
 start_chrono,
 stop_chrono.

ENDCLASS. "main DEFINITION

*----------------------------------------------------------------------*
* CLASS main IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS main IMPLEMENTATION.

METHOD execute.

  go_text = cl_demo_text=>get_handle( ).

  start_chrono( ).
  hash( ).
  stop_chrono( ).

  start_chrono( ).
  select( ).
  stop_chrono( ).

  go_text->display( ).

ENDMETHOD. "execute

METHOD hash.

 DATA:
   lt_dummy
   TYPE HASHED TABLE OF zdummy01
   WITH UNIQUE KEY primary_key COMPONENTS matnr.

  FIELD-SYMBOLS:
   <ls_dummy> LIKE LINE OF lt_dummy.

  go_text->add_line( 'Starting hash read' ).

  SELECT * INTO TABLE lt_dummy FROM zdummy01.

  DO c_do_times TIMES.

    READ TABLE lt_dummy
      ASSIGNING <ls_dummy>
      WITH TABLE KEY primary_key
      COMPONENTS matnr = c_matnr.

  ENDDO.

ENDMETHOD. "hash

METHOD select.

  DATA ls_dummy TYPE zdummy01.

  go_text->add_line( 'Starting select' ).

  DO c_do_times TIMES.

    SELECT SINGLE *
      INTO ls_dummy
      FROM zdummy01
      WHERE matnr EQ c_matnr.

  ENDDO.

ENDMETHOD. "select

METHOD start_chrono.
 GET RUN TIME FIELD gv_begin.
ENDMETHOD. "start_chrono

METHOD stop_chrono.

  DATA:
    lv_diff TYPE i,
    lv_difft TYPE cl_demo_text=>t_line,
    lv_end TYPE i.

  GET RUN TIME FIELD lv_end.
  lv_diff = lv_end - gv_begin.
  WRITE lv_diff TO lv_difft LEFT-JUSTIFIED.

  go_text->add_line(:
    'Runtime result:' ),
   lv_difft ).

ENDMETHOD. "stop_chrono

ENDCLASS. "main IMPLEMENTATION

START-OF-SELECTION.
 main=>execute( ).

 

Advertisements

Tecrübesiz Yeni Mezun Danışman Adayları

Bugün; yeni mezun bir arkadaşımız bana CV’sini göndererek, SAP danışmanlığına adım atmak istediğini ve tavsiyelerimi merak ettiğimi söyledi. CV’yi incelediğimde, üniversite hayatı boyunca herhangi bir SAP tecrübesi kazanmadığını gördüm. Kendisine verdiğim tavsiyeleri; başkalarına da faydalı olabileceğini düşünerek herkesle paylaşmak istiyorum.

Selam, CV’ni inceledim. Gördüğüm kadarıyla SAP tecrüben yok. Şahsen tanışmadığımız için, seni kişilik özelliklerini baz alarak da uygun bir yere öneremem.

Ara sıra SAP danışmanlık firmalarının Junior alımları veya danışman yetiştirme programları oluyor. LinkedIn üzerinden Türk danışmanlık firmalarını takibe alarak bu dönemleri kollamanı tavsiye ederim.

Bunun yanı sıra; kişisel Web sitemin FAQ bölümünde SAP kariyeri ile ilgili oldukça faydalı olacağını tahmin ettiğim bazı kaynaklar var, bunları da incelemeni tavsiye ediyorum.

Yapıcı bir karşılaştırma yapmak gerekirse; CV’si elimden geçen pek çok yeni mezunun, okuldan iş tecrübesiyle mezun olduğunu görüyorum. Ya yazları, ya da okula paralel yarı zamanlı olarak gelecekteki mesleğine istinaden tecrübe kazanmış kişiler daha çok tercih ediliyor.

Dolayısıyla; “ilk işe atılan herkes gibi tecrübesizim” ifadesi pek geçerli değil. Hobilerin ve yurtdışı tecrübesinin insanı çok geliştirdiğini savunan biri olmakla birlikte; işe alım kararı veren kişilerin CV’de aradığı şey hobi değil sıcak iş tecrübesidir. Bir modülün başında hemen iş yapabilir hale gelmiş biri tercih edilecektir.

Bu moralini bozmasın, bu tecrübelerin karşılığını daha uzun vadede alacağından şüphem yok. Ancak, sıcak tecrübe konusundaki açığını kabul edip onu kapatacak çalışmalar yapmanı öneririm. Eğer maddi açıdan karşılayabilirsen, SAP’nin veya yetkili bir kurumun eğitimlerine katılıp sertifika alabilirsin mesela. Bu tarz bir sertifika, istediğin gibi bir pozisyon bulmanı kolaylaştırır.

Seni şahsen tanıyan ve kişilik özelliklerine kefil olabilecek birinin sektöre tavsiye etmesi de etkili olur. O zaman sertifikaya belki de gerek kalmadan, en azından birkaç aylık bir deneme süresinde mutabık kalarak kendine bir pozisyon bulabilirsin. O pozisyonda kendini ispatlamak da sana kalmış.

Architect vs Developer Responsibilities

Responsibilities of an architect and a developer don’t solely depend on the employees role; it also depends on the project and company type. Let me give you an overview based on my personal experience in Turkey.

Support Agreements

A support agreement is the situation where a SAP client makes a deal with a consultancy company to resolve their daily issues over tickets. In that case, the consultant is responsible of understanding the issue, solving it, making the users test it and eventually transporting the solution to the live system. One of the significant responsibilities is to resolve the tickets quickly if the matter in hand is urgent. This sometimes involves working late or at weekends.

Usually; companies agree on response time for priorities. For example; urgent tickets might expected to be replied within an hour & resolved within 24 hours, while low level tickets might expected to be replied within 24 hours & resolved within a day. In that case, this scheme would also act as the KPI of the support consultants. At the performance evaluation at the end of the year, their actual response & resolution rates are compared against the targets. This can run on team and/or personal level. FTR (first time right) is another typical KPI, which indicates the percentage of tickets where the first technical reply got accepted by the client.

In typical support deals, we rarely see architects get involved. Support issues are basically small corrections or enhancements on an existing system, so no architects are full time present. In case a correction needs modification on the fundamental level or some supervisory advice is needed, that’s where they step in. Knowing and understanding the bowels, standards and deep infrastructure of the system much better than developers, the architect can make those fundamental modifications accurately and risk free. Alternatively, the architect can guide the developer on how to proceed – that’s also possible. Whenever a developer without architectural knowledge attempts to do a fundamental change, we usually see anti-patterns emerge.

You can imagine it like this: You can hire a worker to paint your walls, no architect needed. But in case you want to expand your swimming pool, you ask your architect first.

Implementation Projects

This is the deal where a consulting company implements a new functionality to a SAP client. It can be a huge fresh SAP implementation, or a mid-sized implementation of a new functionality over an existing system; or even an upgrade. That’s where ideally developers work under the supervision of an architect.

Each project has a number of tasks to complete. On shallow tasks, the developers would be allowed to directly start with the development. However, the architect walks in for bigger developments, frameworks, integrations and similar comprehensive tasks. The architect usually designs the framework, does the low level coding, does a few demo implementations, and leaves the rest to developers. Other developers build on top of what the architect has prepared.

If I had to list some typical responsibilities on top of my head; an architect would be resposible of:

  • Defining the development standards, naming conventions and document formats
  • Technical supervision to functional consultants during the analysis phase
  • Supporting time estimations
  • Acting as an objective technical authority in meetings
  • Communication and agreement with non-SAP architects on integration points
  • Supervision to project management for task distribution
  • Architectural design & development of complex applications
  • Framework design & development for applications sharing a common ground
  • Supervising developers so they don’t re-invent the wheel
  • Review & validation of code from developers
  • Prevention of code duplication
  • Pursuing and evaluating test results
  • Pursuing architectural, technical, performance and usability excellence
  • Early recognition & proactive measures of architectural risks; such as contradicting or overlapping requirements
  • General responsibility of the big picture

If I had to do the same for developers;

  • Writing clean, understandable, optimized code with enough comments
  • Complying with technical standards of the project and global best practices
  • Re-using code whenever possible
  • Maximizing information flow with co-workers and the architect
  • Finishing tasks on time
  • Supporting tests and correcting bugs
  • Consult the architect on uncertain cases

Pre-Sales

This is the case where the consulting company wants to sell a product or service to a potential client.

In such cases, presence of the architect is more than welcome due to a lot of reasons; of which some are listed below:

  • Knowledge of the architect would positively influence the client
  • An architect can conclude technical discussions with the client’s employees rather quickly
  • In case a demo application is needed, an architect can understand, plan and implement it very well; demonstrating the technical muscle of the consulting company
  • An architect can inform the sales team of technical limitations and regulations; proactively stopping them from making unfulfillable promises
  • Accuracy of development time estimations would increase

Conclusion

The picture I painted in this article is far from complete; however, I think that it gave you the overall insight you needed. In summary; you can imagine the developers like construction workers, and the software architect like a, well, architect (doh).

Evernote Daily Progress Report

I manage my life plans and todo lists in Evernote; both personal and business. For every task I need to work on, I have a corresponding Evernote item.

A typical work day ends with a review of what I did on that day. A clever Evernote search query returns me just that:

tag:"#ecz" updated:day

#ecz is the tag I use on job related notes. updated:day covers the notes created or updated today. Combining them both, I get to list the job related notes I created or updated today. Cool, right?

Please note that Evernote search queries don’t return deleted notes at this time. So if you deleted a note, it won’t appear in the search results. Be mindful of that.

For more information on search capabilities of Evernote, you can check the following articles:

Bonus information: On a Mac, Evernote can also be automated via scripting; you can check my sample codes on GitHub.

Parsing JSON in ABAP

SAP ECC has two beautiful classes for JSON parsing operations.

/ui2/cl_json is useful in case you know the structure of the JSON file. Similar to the CALL TRANSFORMATION command; you can parse a JSON string directly if you have a corresponding nested structure. This class is very forgiving too; it doesn’t raise any exceptions if your structure has missing or excess fields. Turning a nested ABAP structure into a JSON string is also possible.

/ui5/cl_json_parser is useful in case you don’t know the exact structure of the JSON file. When you pass the JSON string to this class, it simply transforms the data into an internal table of key / value pairs. It is your responsibility to loop through this ITAB to fetch whatever you are looking for. It doesn’t transform your nested structure into JSON format at this time though – it parses JSON strings only.

Monospaced Coding Font Review

I have tried a bunch of monospaced fonts, and here is my little review.

Consolas was a long time favourite of mine, and it is still my number one.

Source Code Pro from Adobe turned out to be my second favourite at this time. It is clean and easy to read. It lacks ligatures, but that’s kind of the point – read further.

Hasklig is basically Source Code Pro with ligatures, but the ligatures simply don’t work in Eclipse. Therefore, I ruled that one out.

Fira Code seems to be a very popular choice of many programmers. It is a beautiful font with ligature support. The problem is; Fira Code works slow on my Eclipse, and I use it a lot. Whenever I do a simple text operation like selecting, hitting TAB, etc; it takes a little while for the application to process the command. My assumption is; ligatures are slowing down the calculation process. Therefore; I regrettable uninstalled Fira Code.

Pragmata pro seems to be an expensive but popular choice among many developers. Although it is a thoroughly calculated font; the characters are narrow. The squeezed characters simply don’t work for me. But it may work for others, of course – it is a matter of taste. I don’t know if its ligatures slow down Eclipse though, couldn’t use it that much, frankly.

Why I Refused To Become a Mentor with Everwise

I have been mentoring people for a long time. Hoping that I would find new people to mentor over the Internet, I have applied for mentorship at Everwise. However; after our initial meeting, I didn’t like their model and cancelled my application. Here is my final message to them.

I have evaluated our phone call, and I regret to say that I won’t be part of the Everwise ecosystem at this time.

Here is my feedback:

I have voluntarily mentored countless people so far, without charging them anything. Simply out of good will. That’s one way of mentoring. I also understand that mentoring can be a business. Involving compensation within the process can be fair enough in many cases.

However, your model is based on being an intermediary company charging the clients and paying the mentors nothing. Instead; you offer a social platform and mentoring experience.

If this would be a free service for all parties, I could join it as a mentor out of good will – I do mentoring all the time anyway. But when compensation is involved, I start evaluating the system as a business. And the non-monetary compensation you offer doesn’t appeal to me, frankly.

Best regards…