Photo by Goran Ivos on Unsplash

SAP ABAP General and HR Macros

Ahmet Acar
4 min readDec 13, 2019

What is Macro for SAP ABAP?

As programs grow larger and larger, it becomes more difficult for programmers to enhance and debug source code. Luckily, computer languages make developers’ lives easier by offering various modularization methods, making program code meaningful and easily understandable.

ABAP, SAP’s programming language, is no exception. It leverages various modularization options, each having its own strengths and weaknesses. These options may have local access from a particular program (such as form routines and macros) or they may have global access, such as function modules or include programs.

Although a comprehensive discussion of all the modularization techniques available in ABAP is beyond the scope of this article, we can look at one option(macros) and consider some situations where they work better than other options.

How Can We Use Macros in Non-HR Developments?

Macro contains some part of source code which it will be useful for number of applications.

You can get the list of macros in the table TRMAC.

TRMAC Table

Whenever you are using the macros ,check whether you have included the relevant logical database in program attributes.

Macros can also be defined as TRMAC macros. The source code of these modules is stored in the function section of the control table TRMAC. This code is grouped under a specific name in the table key. According to conventions, the first two letters of the name must stand for the application. The rest of the name is freely definable.

Customer-specific macro modules should begin with a special character. The macros defined in the control table TRMAC can be used by all reports.

Macro is a statements block created to call multiple times within the same program and to reduce the code redundancy. If same statements blocks are repeated more than once in various places of the program, it causes code redundancy. One of statements block can be placed in the macro from the repeated statements block and the macro call replaces the statements block where ever the statements block existed. The macro only used in the program where it is defined.

The macro should be defined before the macro called. All the statements in the macro should be coded in between DEFINE and END-OF-DEFINITION. MACROS are not operational statements. MACRO cannot call itself. Macros are nested, another MACRO can be called within a MACRO. Below program explains how the using MACRO implementation.

Macro

As you can see, disp_macro_info is the macro coded to reduce the redundant code.

How Can We Use Macros in HR Developments?

HR Macros are working as a function module and more convenient to use and it saves the efforts of writing a long source code by using the macro. using macro e.g. RP_PROVIDE_FROM_FIRST gives the first record for the given begda and endda ,RP_PROVIDE_FROM_LAST gives the last record for the given begda and endda, the result coming out of it as reliable and need not be checked by debugging.

Below example displays how can you use macros in hr abap and RP_PROVIDE_FROM_LAST gives the last record for the given begda and endda in p0001 p0008… infotypes.

*
rp-provide-from-last p0001 space sy-datum sy-datum.
rp-provide-from-last p0008 space sy-datum sy-datum.
rp-provide-from-last p0009 space sy-datum sy-datum.
rp-provide-from-last p0015 space sy-datum sy-datum.
rp-provide-from-last p0770 space sy-datum sy-datum.
*

If you want to know more about HR Macros you should check this include “DBPNPCOM” and DBPNPMAC.

DBPNPCOM
DBPNPMAC

Moreover, we want to create payroll report, we must use payroll includes.

Payroll Macros

So, we are ready to read payroll informations using by personel number (pernr). Below example displays how can you use macros in SAP for HR payroll development.

If you want to know more about HR Payroll Macros you should check this include RPC2CD09.

Thank you for reading. Stay tuned!

What do you guys think? I love to know your thoughts. Kindly like, share or comment below.

Ahmet Acar.

--

--

Ahmet Acar

SAP ABAP Developer, Computer Engineer, Amateur Basketball Player.