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).

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.

Batman Syndrome of Freelancers

At some point, many freelance consultants consider hiring a junior consultant. The idea is to train him/her, and send him/her to low priority clients. The assumption is; low priority clients would accept the junior (as Robin) just because the freelancer has a brand name (as Batman).

However, this assumption often fails.

Have you seen anyone calling Robin without Batman? No. Exceptions aside; people call Batman, and they could accept Robin as a sidekick only if Batman is present as well.

Batman may consider a client as “low priority”, but the client considers its own business as “high priority”. Therefore; if they call Batman, they want Batman. They often won’t accept an unaccompanied Robin. It is really hard to convince clients to accept Robin as a regular consultant just because Batman has a name.

This has a psychological aspect as well: They will continuously compare Robin to Batman, and assume Robin to be a character lesser than he/she really is.

Solution?

My initial suggestion is to make a schedule where Batman & Robin can go to projects mostly together. If both of them are present at the client site 3 days/week, the client might be willing to accept an unaccompanied Robin at the 4th day; assuming that Robin’s activities are transparent, rate is agreeable and he/she will add reasonable value to the project.

If you can find a position where one of your clients need a junior consultant, this would be a rare opportunity to market Robin! If the trust of the client is obtained, promising that Batman would jump in on critical occasions would increase the chance of a deal.

In any case, I would suggest premeditating on possible positions for Robin before taking any costly action.

Some big consultancy companies have the tendency to showcase “Batman”s during the sales process and send “Robin”s to the actual project.

This is a different case though. They are selling projects over the brand and image of a company, not a person. The client can request a change of certain consultants any time, and they can force the consultancy company to call-in “Batman”s in case a significant risk surfaces. Therefore, clients are relatively comfortable accepting mid-level team members of a big company.

Another important aspect is; decision makers feel more comfortable when they select a big brand for their SAP project (despite the mediocre CV’s). If the project fails, the manager can save his/her rear end by telling that they made the best decision they could by picking the biggest name on the market. Picking a boutique set of freelancers means that some manager takes full responsibility. Smart managers make a mixture of a big company + Batman-level freelancers though.

In any case; big players can market Robins due to such factors. It doesn’t mean that a singular Batman can pull off the same thing. It is possible, but not as easy & common.

SAP GUI For Java Connection Strings

A question I get often is about the way I connect to SAP ECC from my Mac.

Obviously, many users prefer to install Windows to their Macbooks and run SAP GUI For Windows over it.

However; SAP has an alternative less known GUI for Linux / Mac systems: SAP GUI For Java. You can download it from http://service.sap.com for free using an S-user, install it to your Mac like a regular application and connect to any SAP ECC system. No need to install Windows at all.

The way you define a new SAP Connection in SAP GUI For Java differs slightly from SAP GUI For Windows. Let’s assume that you have the following connection information:

  • Address: 10.1.3.40
  • System No: 02

In SAP GUI For Java, you need to get to the “Advanced” tab, click “Expert mode” and enter the following connection string:

conn=/H/10.1.3.40/S/3202

Obviously, the address goes between /H/ and /S/ and the system number goes to the end of the string. If your system ID is 00, you need to enter 3200. If your system ID is 07, you need to enter 3207. In our case, your system ID is 02 so you need to enter 3202.

That’s all there is! Using this connection string, you should be good to go.

Your connection string can contain additional parameters; such as your user name, client number, etc. Here are some sample connection strings:

conn=/H/sapsrv/S/3204&jenc=MacTurkish&jloc=tr&cpg=1607&clnt=100&user=kerem

Here are some sample connection strings going over routers (IP’s changed for security reasons):

conn=/H/88.249.244.45/H/10.0.0.5/S/3200

conn=/H/78.186.178.12/W/golive2013/H/192.168.2.10/S/3200
The only disadvantage of SAP GUI For Java is for ABAP programmers: Smartform designer, Workflow tools and graphical screen designer tools are Windows-only and won’t run under SAP GUI For Java. Personally, I have a casual Windows installation with SAP GUI for Windows living under VMWare Fusion. Whenever I need to use one of those tools (maybe once a month); I run Windows inside the virtual machine without leaving Mac OS, get my job done, shut down Windows and continue working on the Mac with SAP GUI For Java.

Quick SAP Tip: Get Rid of Stuck Truck Icon in STMS

In case SAP thinks that some transport requests in STMS are still imported and keeps displaying the truck icon next to them, you might get frustrated.

The solution is simple though: Just delete the corresponding entries in table TPSTAT, and you are good to go.

This is a risky approach, though. If the requests are actually being transported, removing them from TPSTAT might trigger some unpredictable behaviour. If you are 100% sure that TP is doing nothing about them, you might try this little hack.