You are on page 1of 9

Working With Macros In HR-ABAP

Skip to end of metadata

Added by Venkat Appikonda, last edited by Manish Kumar on Jan 06, 2014 (view
change)

Go to start of metadata
Using macros in HRABAP
Macro means presenting programs in modular form.
Customer-specific RMAC modules should begin with a special character.
The macros defined in table TRMAC can be used by all reports.
When you change a RMAC macro in the table TRMAC, the reports that use this macro are not
regenerated automatically. You must regenerate them manually.
Macros in personnel administration
RP_PROVIDE_FROM_LAST Pnnnn SPACE PN-BEGDA PN-ENDDA.
or
RP_PROVIDE_FROM_FIRST Pnnnn SPACE PN-BEGDA PN-ENDDA.
These statements make the most recent or earliest record in the PN/BEGDA to PN/ENDDA data
selection period available in the structure Pnnnn for info type nnnn.
If the infotype has subtypes, replace the SPACE parameter by the appropriate subtype number.
When a record has been successfully read, the return code PNP-SW-FOUND = 1 is returned.
Use PNP logical database in the attributes of the program
1 REPORT zmacro01 .
2 TABLES: pernr.
INFOTYPES: 0008.
3
4 GET pernr.
5 *---get the first record for
rp_provide_from_frst p0008
6
IF pnp-sw-found EQ 1.
7
WRITE: / pernr-pernr,
8
pn-begda,
9
pn-endda,
10
p0008-ansal,
p0008-lga01,
11
p0008-bet01.
12
ENDIF.
13*---get the last record for
14 rp_provide_from_last p0008
15 IF pnp-sw-found EQ 1.
WRITE: / pernr-pernr,
16
pn-begda,
17
pn-endda,
18
p0008-ansal,
19
p0008-lga01,
p0008-bet01.
20
21 ENDIF.

the pernr from the infotype


space pn-begda pn-endda .

the pernr from the infotype


space pn-begda pn-endda.

22
23
24
25
Macros in applicant data.
Use PAP logical database in the attributes of the program
PAP_PROVIDE_FROM_LAST Pnnnn SPACE PA$BEGDA PA$ENDDA.
or
PAP_PROVIDE_FROM_FIRST Pnnnn SPACE PA$BEGDA PA$ENDDA.
If the infotype has subtypes, replace the SPACE parameter by the appropriate subtype number.
When a record has been successfully read, the return code PNP-SW-FOUND = 1 is returned.
1
2
REPORT zmacro02.
3
TABLES: applicant.
4
INFOTYPES: 0001.
5
6 GET applicant.
7
pap_provide_from_first p0001 space pa$begda pa$endda.
IF pap_sw_found EQ 1.
8
WRITE: / applicant-aplno,
9
p0001-bukrs,
10
p0001-werks,
11
p0001-persg,
pa$begda,
12
pa$endda.
13
ENDIF.
14
pap_provide_from_last p0001 space pa$begda pa$endda.
15 IF pap_sw_found EQ 1.
16
WRITE: / applicant-aplno,
p0001-bukrs,
17
p0001-werks,
18
p0001-persg,
19
pa$begda,
20
pa$endda.
21 ENDIF.
22
23
Macros in time management
You should not load all time infotype records from the earliest to most recent system dates into
the main memory. This would quickly lead to a memory overload, especially if a front-end time
recording system is connected to your HR system.
Use the infotype declaration supplement MODE N to define that the internal time infotype
tables

should be declared but not filled at the GET PERNR event.


Use PNP logical database in the attributes of the program
1
REPORT zmacros3.
2TABLES: pernr.
3INFOTYPES: 2001 MODE n.
4
5GET pernr.
6 rp_read_all_time_ity pn-begda pn-endda.
7 LOOP AT p2001.
WRITE: / p2001-abwtg.
8 ENDLOOP.
9
Macros in payroll
For repetitive structures
When evaluating repeat structures, you must ensure that all fields are entered. In the case of the
Basic Pay infotype, 20 * 5 = 100 fields are queried.
A loop offers a more streamlined method of evaluation. Here, one line of the repeat structure is
evaluated each time the loop is executed.To use this method of evaluation, define a field string
whose structure corresponds to the fields inone line of the repetitive structure.In this field string,
one line of the basic pay wage types is evaluated each time the loop is executed.
Use PNP logical database in the attributes of the program
1
2
3 REPORT zmacros05.
TABLES:pernr.
4 INFOTYPES: 0008.
5 DATA: BEGIN OF wagetypes,
6 lga LIKE p0008-lga01,
7 bet LIKE p0008-bet01,
LIKE p0008-anz01,
8 anz
ein LIKE p0008-ein01,
9 opk LIKE p0008-opk01,
10END OF wagetypes.
11
12GET pernr.
13 rp_provide_from_last p0008 space pn-begda pn-endda.
DO 20 TIMES VARYING wagetypes
14 FROM p0008-lga01
15 NEXT p0008-lga02.
IF wagetypes-lga IS INITIAL.
16
EXIT.
17
ELSE.
18
WRITE: / wagetypes-lga, wagetypes-bet.
19
ENDIF.
20 ENDDO.
21
22

In Payroll these macros are used to import and export the data from/to the cluster tables
RP-aaa-Cn-xy
where aaa = IMP / EXP,
n=1 for PCL1, 2 for PCL2, 3 for PCL3, 4 or PCL4
and xy = cluster name.
Export Using the Data Buffer
When macros are used for exporting, records are written to a main memory buffer and not
directly to the database. When the program run has been completed, the records in the buffer are
stored in the appropriate PCLn database.
Import Using the Data Buffer
When the macros are used to import data, the data records are not read directly from file PCLn.
Instead, the system checks the buffer directory to see whether the main memory already
contains a record with the same key. If this is not the case, the record is read from PCLn to the
buffer and then retrieved from the buffer for the report.
If the import is successful, the return code RP-IMP-xy-SUBRC = 0 is set. When data is read
from the buffer, the system carries out a check for cluster authorization. Standard import
programs follow the naming convention RPCLSTxy (xy = cluster name).
here is the program how to use the macros RP-aaa-Cn-xy in the payroll
Use PNP logical database in the attributes of the program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

REPORT zhrpayroll
NO STANDARD PAGE HEADING
LINE-SIZE 255
LINE-COUNT 65
MESSAGE-ID zz.
************************************************************************
*
T A B L E S D E C L A R A T I O N
*
************************************************************************
TABLES: pernr,
" STUCTURE PERNR DECLARATION
pcl1,
" CLUSTER DECLARATION
pcl2.
" CLUSTER DECLARATION
************************************************************************
*
I N F O T Y P E S
D E C L A R A T I O N
*
************************************************************************
INFOTYPES: 0001,
"INFOTYPE 0001 DECLARATION
0002.
"INFOTYPE 0002 DECLARATION
***********************************************************************
*
I N C L U D E
S T R U C T U R E S
*
***********************************************************************
INCLUDE rpc2cd09.
"Cluster CD Data-Definition
INCLUDE rpc2ca00.
"Cluster CA Data-Definition "XUJP30K079863
INCLUDE rpc2ruu0.
"Cluster RU Data-Definition
INCLUDE rpc2rx09.
"Cluster RU Data-Definition internat. part
INCLUDE rpppxd00.
"Data Definition buffer PCL1/PCL2
INCLUDE rpppxd10.
"Common part buffer PCL1/PCL2
INCLUDE rpppxm00.
"Buffer handling routine
************************************************************************
*
I N T E R N A L T A B L E S D E C L A R A T I O N
*
************************************************************************
*....internal table to store final data
DATA: BEGIN OF it_final OCCURS 0,

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

pernr LIKE pa0001-pernr,


"PERSONNEL NUMBER
gbdat LIKE pa0002-gbdat,
"DATE OF BIRTH
vorna LIKE pa0002-vorna,
"FIRST NAME
nachn LIKE pa0002-nachn,
"LAST NAME
betrg LIKE rt-betrg,
"BASIC PAY
betrg1 LIKE tcrt-betrg,
"TOTAL GROSS CUMMULATIVE TAX
END OF it_final.
*....internal table used to get sequence number
DATA: it_rgdir LIKE pc261 OCCURS 0 WITH HEADER LINE.
************************************************************************
*
D A T A
D E C L A R A T I O N
*
************************************************************************
DATA: v_permo LIKE t549a-permo,
"VARIABLE TO GET PERIOD PARAMETERS
v_pabrj LIKE t569v-pabrj,
"VARIABLE TO GET YEAR
v_pabrp LIKE t569v-pabrp,
"VARIABLE TO GET PERIOD
v_endda LIKE t549q-endda,
"VARIABLE TO GET END DATE
v_begda LIKE t549q-begda,
"VARIABLE TO GET BEGIN DATE
v_seqnr LIKE rgdir-seqnr,
"VARIABLE TO GET SEQUENCE NUMBER
v_abkrs LIKE pa0001-abkrs,
"PAY ROLL AREA
v_atext LIKE t549t-atext,
"PAY ROLL AREA TEXT
v_name(35).
"VARAIABLE TO STORE EMPLOYEE NAME
************************************************************************
*
S T A R T
O F
S E L E C T I O N
*
************************************************************************
START-OF-SELECTION.
*....form to get payroll area text
PERFORM get_payrollareatext.
*....form to get Period parameter into v_permo from table t549a
PERFORM getpermo.
*....from to get begda and endda
PERFORM getdates.
***********************************************************************
* G E T
P E R N R
E V E N T
*
***********************************************************************
GET pernr.
*.....form for getting latest org. info and personal info.
PERFORM get-data.
************************************************************************
*
E N D
O F
S E L E C T I O N
*
************************************************************************
END-OF-SELECTION.
*.....form to display data as report
PERFORM display-para.
************************************************************************
*
Form GET_PAYROLLAREATEXT
*
************************************************************************
FORM get_payrollareatext.
v_abkrs = pnpxabkr.
SELECT SINGLE
atext
INTO v_atext
FROM t549t WHERE abkrs = v_abkrs
AND sprsl = sy-langu.
ENDFORM.
" GET_PAYROLLAREATEXT
************************************************************************
*
Form GETPERMO
*
************************************************************************

71 FORM getpermo.
72 *.....get Period parameter into v_permo from table t549a
SELECT SINGLE permo
73
FROM t549a
74
INTO v_permo
WHERE abkrs = v_abkrs.
75
ENDFORM.
" GETPERMO
76
************************************************************************
77 *
Form GETDATES
*
78 ************************************************************************
79 FORM getdates.
80 *.....Time period indicator: Current period is initial
IF pnptimr9 = 'X'.
81
PERFORM getdates1.
82 *.....Time period indicator: Other period is initial
83
ELSEIF pnptimra = 'X'.
PERFORM getdates2.
84
ENDIF.
85
" GETDATES
86 ENDFORM.
************************************************************************
87 *
Form GETDATES1
*
88 ************************************************************************
89 FORM getdates1.
90 *.....get Payroll year and period from table t569v
SELECT SINGLE pabrj
91
pabrp
92
FROM t569v
93
INTO (v_pabrj , v_pabrp)
WHERE abkrs = v_abkrs.
94
*.....get
Start Date and End Date from table t549q
95
SELECT SINGLE endda
96
begda
97
FROM t549q
INTO (v_endda , v_begda)
98
WHERE pabrj = v_pabrj
99
pabrp = v_pabrp
100 AND
AND permo = v_permo.
101ENDFORM.
" GETDATES1
102************************************************************************
Form GETDATES2
*
103*
************************************************************************
104
FORM getdates2.
105*.....get Start Date and End Date from table t549q
106 SELECT SINGLE endda
107 begda
108 FROM t549q
109 INTO (v_endda , v_begda)
WHERE pabrj = pnppabrj
110 AND pabrp = pnppabrp
111 AND permo = v_permo.
" GETDATES2
112 ENDFORM.
************************************************************************
113
Form GET-DATA
*
114 *************************************************************************
115 FORM get-data.
116 *.....HR macro to get Latest Personnel Org. Info by Start and End dates
rp-provide-from-frst p0001 space v_begda

117 v_endda.
118 *.....if infotype p0001 succussfully read
IF pnp-sw-found = '1'.
119
it_final-pernr = p0001-pernr.
120*.....HR macro to get Latest personal Info by Start and End dates
rp-provide-from-last p0002 space v_begda
121
v_endda.
122
*.....if infotype p0002 succussfully read
123
IF pnp-sw-found = '1'.
124
it_final-vorna = p0002-vorna.
125
it_final-nachn = p0002-nachn.
it_final-gbdat = p0002-gbdat.
126
*.....get
data into Resultant table using function module CU_READ_RGDIR
127
PERFORM read-rgdir.
128
ENDIF.
129 ENDIF.
" GET-DATA
130ENDFORM.
************************************************************************
131
Form READ-RGDIR
*
132*************************************************************************
133FORM read-rgdir.
134*.....fill it_rgdir Personnel Number
135 CALL FUNCTION 'CU_READ_RGDIR'
EXPORTING
136
persnr
= p0001-pernr
137
TABLES
138
in_rgdir
= it_rgdir
139
EXCEPTIONS
no_record_found = 1
140
OTHERS
= 2.
141
IF sy-subrc <> 0.
142
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
143
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
144 ENDIF.
145*.....check whether "Pay date for payroll result" with in Start Date and
End date, and "Reason for Off-Cycle Payroll" is initial
146* LOOP AT it_rgdir
WHERE paydt >= v_begda
147 AND paydt <= v_endda AND
148 void IS INITIAL
149 AND ocrsn IS INITIAL
150 AND srtza = 'A'.
v_seqnr = it_rgdir-seqnr.
151*.....Move pernr and seqnr to cluster RX
152
UNPACK p0001-pernr TO rx-key-pernr.
UNPACK v_seqnr TO rx-key-seqno.
153
*.....Macro
for getting US pernrs Info. in cluster PCL2
154
rp-imp-c2-ru.
155
*.....populate internal table RT where Wage Type is '1000'
156
LOOP AT rt WHERE lgart = '1000'.
157
it_final-betrg = rt-betrg.
158*.......populate internal table TCRT where Wage Type is '/100'
LOOP AT tcrt WHERE lgart = '/101' AND ctype = 'Y'.
159
it_final-betrg1 = tcrt-betrg.
160
APPEND it_final.
161
ENDLOOP.
162
ENDLOOP.
CLEAR it_final.

163 ENDLOOP.
164 REFRESH it_rgdir.
ENDFORM.
" READ-RGDIR
165************************************************************************
166*
Form DISPLAY-PARA
*
167************************************************************************
168FORM display-para.
IF it_final[] IS INITIAL.
169
MESSAGE i013 WITH 'No data matched selection criteria'.
170 ELSE.
171
WRITE:/ sy-uline(125).
WRITE:/5 'PAYROLL AREA ' ,
172
30 'PAYROLL TEXT'.
173
WRITE:/ sy-uline(125).
174
WRITE:/10 v_abkrs,
175
35 v_atext.
WRITE:/ sy-uline(125).
176
WRITE:/2 'EMP ID',
177
10 'FULL NAME',
178
46 'DATE OF BIRTH',
179
70 'BASIC PAY',
180
90'TOTAL GROSS CUMULATED TAX AMOUNT'.
WRITE:/ sy-uline(125).
181
LOOP AT it_final.
182
CONCATENATE it_final-vorna it_final-nachn INTO v_name
183
SEPARATED BY ' '.
184
WRITE: / it_final-pernr,
185
v_name,
it_final-gbdat,
186
it_final-betrg,
187
it_final-betrg1.
188
CLEAR v_name.
189
CLEAR it_final.
ENDLOOP.
190
WRITE:/ sy-uline(125).
191
ENDIF.
192ENDFORM.
" DISPLAY-PARA
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238