Monday, June 15, 2015

ABAP - Using Macros In HR ABAP Report Program.

ABAP - Using Macros In HR ABAP Report Program.

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

REPORT ZMACRO01 .

TABLES: PERNR.
INFOTYPES: 0008.
GET PERNR.

*---get the first record for the pernr from the infotype
RP_PROVIDE_FROM_FRST P0008 SPACE PN-BEGDA PN-ENDDA .

IF PNP-SW-FOUND eq 1.
WRITE: / PERNR-PERNR,
PN-BEGDA,
PN-ENDDA,
P0008-ansal,
P0008-lga01,
P0008-bet01.
ENDIF.

*---get the last record for the pernr from the infotype
RP_PROVIDE_FROM_LAST P0008 SPACE PN-BEGDA PN-ENDDA.

IF PNP-SW-FOUND eq 1.
WRITE: / PERNR-PERNR,
PN-BEGDA,
PN-ENDDA,
P0008-ansal,
P0008-lga01,
P0008-bet01.
ENDIF.


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

REPORT ZMARCO02.
TABLES: APPLICANT.

INFOTYPES: 0001.

GET APPLICANT.

*--get the first application record
PAP_PROVIDE_FROM_FIRST P0001 SPACE PA$BEGDA PA$ENDDA.

IF PAP_SW_FOUND eq 1.
WRITE: / APPLICANT-APLNO,
P0001-BUKRS,
P0001-WERKS,
P0001-PERSG,
PA$BEGDA,
PA$ENDDA.
ENDIF.

PAP_PROVIDE_FROM_LAST P0001 SPACE PA$BEGDA PA$ENDDA.

IF PAP_SW_FOUND eq 1.
WRITE: / APPLICANT-APLNO,
P0001-BUKRS,
P0001-WERKS,
P0001-PERSG,
PA$BEGDA,
PA$ENDDA.
ENDIF.

Marcos 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

REPORT zmacros3.

TABLES: PERNR.

INFOTYPES: 2001 MODE N.

GET PERNR.
RP_READ_ALL_TIME_ITY PN-BEGDA PN-ENDDA.

LOOP AT P2001.
WRITE: / P2001-ABWTG.
ENDLOOP.

Marcos in payroll.
For repetitive structures( do varying)
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

REPORT zmacros04.
TABLES: PERNR.
INFOTYPES: 0008.
DATA: BEGIN OF WAGETYPES,
LGA LIKE P0008-LGA01,
BET LIKE P0008-BET01,
ANZ LIKE P0008-ANZ01,
EIN LIKE P0008-EIN01,
OPK LIKE P0008-OPK01,
END OF WAGETYPES.
GET PERNR.
RP_PROVIDE_FROM_LAST P0008 SPACE PN-BEGDA PN-ENDDA.
DO 20 TIMES VARYING WAGETYPES
FROM P0008-LGA01
NEXT P0008-LGA02.
IF WAGETYPES-LGA IS INITIAL.
EXIT.
ELSE.
WRITE: / WAGETYPES-LGA, WAGETYPES-BET.
ENDIF.
ENDDO.

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).
Program On how to use the macros RP-aaa-Cn-xy in the payroll
Use PNP logical database in the attributes of the program


REPORT zmacro05 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,
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 *
************************************************************************
FORM getpermo.
*.....get Period parameter into v_permo from table t549a
SELECT SINGLE permo
FROM t549a
INTO v_permo
WHERE abkrs = v_abkrs.
ENDFORM. " GETPERMO
************************************************************************
* Form GETDATES *
************************************************************************
FORM getdates.
*.....Time period indicator: Current period is initial
IF pnptimr9 = 'X'.
PERFORM getdates1.
*.....Time period indicator: Other period is initial
ELSEIF pnptimra = 'X'.
PERFORM getdates2.
ENDIF.
ENDFORM. " GETDATES
************************************************************************
* Form GETDATES1 *
************************************************************************
FORM getdates1.
*.....get Payroll year and period from table t569v
SELECT SINGLE pabrj
pabrp
FROM t569v
INTO (v_pabrj , v_pabrp)
WHERE abkrs = v_abkrs.
*.....get Start Date and End Date from table t549q
SELECT SINGLE endda
begda
FROM t549q
INTO (v_endda , v_begda)
WHERE pabrj = v_pabrj
AND pabrp = v_pabrp
AND permo = v_permo.
ENDFORM. " GETDATES1
************************************************************************
* Form GETDATES2 *
************************************************************************
FORM getdates2.
*.....get Start Date and End Date from table t549q
SELECT SINGLE endda
begda
FROM t549q
INTO (v_endda , v_begda)
WHERE pabrj = pnppabrj
AND pabrp = pnppabrp
AND permo = v_permo.
ENDFORM. " GETDATES2
************************************************************************
* Form GET-DATA *
************************************************************************
FORM get-data.

*.....HR macro to get Latest Personnel Org. Info by Start and End dates
rp-provide-from-frst p0001 space v_begda
v_endda.
*.....if infotype p0001 succussfully read
IF pnp-sw-found = '1'.
it_final-pernr = p0001-pernr.
*.....HR macro to get Latest personal Info by Start and End dates
rp-provide-from-last p0002 space v_begda
v_endda.
*.....if infotype p0002 succussfully read
IF pnp-sw-found = '1'.
it_final-vorna = p0002-vorna.
it_final-nachn = p0002-nachn.
it_final-gbdat = p0002-gbdat.
*.....get data into Resultant table using function module CU_READ_RGDIR
PERFORM read-rgdir.
ENDIF.
ENDIF.
ENDFORM. " GET-DATA

************************************************************************
* Form READ-RGDIR *
************************************************************************
FORM read-rgdir.
*.....fill it_rgdir Personnel Number
CALL FUNCTION 'CU_READ_RGDIR'
EXPORTING
persnr = p0001-pernr
TABLES
in_rgdir = it_rgdir
EXCEPTIONS
no_record_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

*.....check whether "Pay date for payroll result" with in Start Date and

* End date, and "Reason for Off-Cycle Payroll" is initial
LOOP AT it_rgdir WHERE paydt >= v_begda
AND paydt <= v_endda AND void IS INITIAL AND ocrsn IS INITIAL AND srtza = 'A'. v_seqnr = it_rgdir-seqnr.
*.....Move pernr and seqnr to cluster RX
UNPACK p0001-pernr TO rx-key-pernr.
UNPACK v_seqnr TO rx-key-seqno.

*.....Macro for getting US pernrs Info. in cluster PCL2
rp-imp-c2-ru.

*.....populate internal table RT where Wage Type is '1000'
LOOP AT rt WHERE lgart = '1000'.
it_final-betrg = rt-betrg.

*.......populate internal table TCRT where Wage Type is '/100'
LOOP AT tcrt WHERE lgart = '/101' AND ctype = 'Y'.
it_final-betrg1 = tcrt-betrg.
APPEND it_final.
ENDLOOP.
ENDLOOP.

CLEAR it_final.
ENDLOOP.

REFRESH it_rgdir.
ENDFORM. " READ-RGDIR

************************************************************************
* Form DISPLAY-PARA *
************************************************************************
FORM display-para.
IF it_final[] IS INITIAL.
MESSAGE i013 WITH 'No data matched selection criteria'.
ELSE.
WRITE:/ sy-uline(125).
WRITE:/5 'PAYROLL AREA ' ,
30 'PAYROLL TEXT'.
WRITE:/ sy-uline(125).

WRITE:/10 v_abkrs,
35 v_atext.
WRITE:/ sy-uline(125).

WRITE:/2 'EMP ID',
10 'FULL NAME',
46 'DATE OF BIRTH',
70 'BASIC PAY',
90'TOTAL GROSS CUMULATED TAX AMOUNT'.
WRITE:/ sy-uline(125).
LOOP AT it_final.
CONCATENATE it_final-vorna it_final-nachn INTO v_name
SEPARATED BY ' '.
WRITE: / it_final-pernr,
v_name,
it_final-gbdat,
it_final-betrg,
it_final-betrg1.
CLEAR v_name.
CLEAR it_final.
ENDLOOP.
WRITE:/ sy-uline(125).
ENDIF.
ENDFORM. " DISPLAY-PARA

No comments:

Post a Comment