Vous êtes sur la page 1sur 38

Naveesh Surapureddy BASICS OF

ABAP HR PROGRAMMING

BASICS OF
ABAP HR PROGRAMMING
In SAP
Author: Naveesh Surapureddy
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The HR module is a true demonstration of the strength of the SAP product in
Enterprise Resource Planning.
The Human Resource module is comprised of major areas of functionality known
as submodules.The HR system has ery strong integration points !where data is
passed back and forth without human data entry" with just about all of the other
SAP modules. #n addition$ there is ery tight integration amongst the HR
submodules.
The following pages in this presentation will
proide understanding of some basic SAP HR terms
highlight the business processes within Human Resources which are
supported by the SAP HR product.
The following screen shot is a iew of the SAP HR module with the arious
submodules that go along with it .
#n this discussion of ours $ we will focus mainly on the HR Programming aspect
rather than the functional areas .
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
INFOTYPES:
To begin with $ let me gie you a small oeriew on the HR #nfotypes .
#nfotypes are the units of information in the Human Resource %anagement
System .
Infotypes are used to group related data fields together. They proide
information with a structure$ facilitate data entry$ and enable you to store data for
specific periods.
USE :
Recording employee data for administratie$ time recording$ and payroll
purposes is of primary importance for master data administration in HR. #n the
SAP System$ the information units used to enter master data are called
infotypes.
Structure
Infotypes are characteri&ed by the following'
Infotype Structure
(ata Entry
Time)(ependent Storage of Infotype (ata
Infotype Structure
To the user$ infotypes appear as data entry screens. They contain whole series
of information !for e*ample$ last name$ first name$ date of birth" that you enter in
data fields. (ata fields concerning the same or similar subject matter are
combined into data groups or information units.
#n database terms$ infotypes represent a data structure or set of related data
records. +hen you update an infotype$ old data is not lost but is instead stored
in the system for historical ealuation purposes.
Time-Dependent Storage of Infotype Data
+hen you update an infotype$ the old data may not be lost. #nstead$ it must be
retained so that past data can be ealuated. +hen you update an employee,s
personal data$ the old data is automatically time)delimited. The system creates a
alidity period for each infotype record. As a result$ each employee infotype has
seeral data records that differ from each other by their alidity periods.
Time Constraints in ! "aster Data
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The concept of Time -onstraints is ery important in HR A.AP . This is due to
the fact that all the infotype records are Time (elimited which is to say that all
the records are alid only for a particular time frame .
+hen you update an infotype$ old data is not lost but archied for historical
ealuation. The system records a specific period of alidity for each infotype$ This
enables the system to store more than one infotype record at the same time$
een if their alidity periods oerlap. This means that the time relationships
between infotype records must be defined. The concept of time constraints
enables you to do this.
HR master data uses the following three time constraints'
Time Constraint #
/or the entire time that the employee works at the enterprise$ e*actly one
alid infotype record must e*ist. The alidity periods of the indiidual
records must not oerlap. #f a new record is created$ the system
automatically uses the start date of the new record as the delimitation date
of the old record. 0aps are only allowed between the employee1s entry
date and the start date of the first record.
Time constraint 2 must be used for all of the infotypes containing
information that must be aailable at all times. This is particularly true of
personal and organi&ational assignment data.
#f a record is delimited because of time constraint 2$ the system displays
an appropriate message.
Time Constraint $
3o more than one alid record can e*ist at any one time. Records with
constraint 4 must not oerlap. Their e*istence is not obligatory. #f a new
record is created$ the system automatically delimits the preious record$ if
one e*ists.
#f a record is delimited because of time constraint 4$ the system displays
an appropriate message.
Time Constraint %
Any number of alid records can e*ist at any one time. The indiidual
records do not conflict with each other.
&'SIC FO!" :
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
#3/5T6PES nnnn.
Each info type has a formal description in the A.AP (ictionary as structure
Pnnnn
nnnn between 7777 and 7888' HR master data info types
nnnn between 2777 and 2888' HR planning data info types
nnnn between 4777 and 4888' HR time data info types
nnnn between 9777 and :888' 3ot yet used
nnnn between 8777 and 8888' -ustomer)specific info types
Effect
(eclares the HR info type nnnn . -reates an internal table as follows'
(ATA .E0#3 5/ Pnnnn 5--;RS 27.
#3-<;(E STR;-T;RE Pnnnn.
(ATA E3( 5/ Pnnnn =A<#( .ET+EE3 .E0(A A3( E3((A.
E(amp)e
#3/5T6PES' 7777$ 7772$ 7774.
'ddition #
... 3A%E c
Effect
c is a name up to 47 characters long. -reates an internal table as follows'
(ATA .E0#3 5/ c 5--;RS 27.
#3-<;(E STR;-T;RE Pnnnn.
(ATA E3( 5/ c =A<#( .ET+EE3 .E0(A A3( E3((A.
E(amp)e
INFOTYPES: 0005 NAME VACATION, 0006 NAME ADDRESS.
Addition 2
... OCCURS occ
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Effect
occ is a num!" #o" $%! OCCURS &a'u!. C"!a$!s an in$!"na' $a'! as #o''o(s:
DATA )E*IN OF c OCCURS m.
INC+UDE STRUCTURE Pnnnn.
DATA END OF c VA+ID )ET,EEN )E*DA AND ENDDA.
E(amp)e
#3/5T6PES 7779 5--;RS 2.
All the Repository objects re>uired for the infotype hae been created. The
releant infotype specific table entries in tables T???T !#nfotype te*ts" and T??:T
!#nfotypes" hae been maintained by the infotype copier. The user has
maintained the releant entry in T???# !#nfotypes per object type".
Infotype *roups
Definition
An infotype group$ or info group$ is a se>uence of related infotypes that are
displayed one after the other for maintenance purposes when a personnel action
is performed.
Use
The infogroup guarantees that during the personnel action$ all information
needed for the business processes is stored.
Structure
An infogroup e*ists in the standard system for eery personnel action type in the
Personnel Actions section.
#n -ustomi&ing for Personnel Administration, you can modify the relationship
between indiidual infogroups and define the infogroups as user)dependent.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
#n the standard system$ different types of employee data are stored in indiidual
infotypes. Rather than accessing each infotype indiidually and entering data into
them$ the system can group together the most important infotypes into personnel
actions and lead you through processing the employee data.
Personne) actions
Personnel procedures$ such as hiring an employee$ organi&ational reassignment$
or an employee leaing the enterprise are represented by indiidual personne)
actions in Personnel Administration. Each personnel action contains the
infotypes that you must maintain to record the personnel action at hand. The
infotypes are retrieed in succession so that you can maintain them. /or
e*ample$ all the fields in which you need to make entries to hire an employee will
be offered to you for maintenance automatically by the system in the personnel
action Hiring.
This ensures that all the core data is entered into the system. This function also
facilitates entering data as you do not need to access each infotype within the
personnel action indiidually .
E(amp)e : O!*'NIS'TION INFOTYPE+,,,#-
The 5rganisational Assignment !7772" deals with the incorporation of the
employee into the organi&ational structure .
+e can display the infotypes from the transaction PA97!%aintain HR %aster
(ata" .
0oto PA97 .
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Enter the Personnel 3o . and the infotype no . in the places shown and then
-reate@-hange@(isplay .
5n pressing the (isplay button the following screen appears .
/or the particular person !247" the organi&ation structure can be displayed on
pressing the A5rg StructureB button .
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The Aboe screen gies us the 5rganisational Assignment for the particular
person . /or E*ample 247 belongs to the 5rg unit A(irection %arket Swit&erlandB
Holds the position of A Secretary Head 5ffice -HB and the position is described
by the Cob A SecretaryB .
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
.O*IC'. D'T'&'SES'
After this brief discussion on #3/5T6PES let us now concentrate on the HR
PR50RA%%#30 .AS#-S and in 0eneral and <ogical (atabases in Particular .
ierarc/y of a .ogica) Data0ase
<ogical databases are programs that read data from database tables and pass it
to other programs for processing. The order of reading the database tables is
determined by a hierarchy.
%any tables in the R@9 System are linked using foreign key relationships. Parts of
these relationships form tree)like hierarchical structures. <ogical databases allow
you to read data easily from database tables that form parts of these structures.
The logical database /2S has the following hierarchy'
Transaction SE9D .
+hen reading the tables$ the system first reads one element of table SP/<#.
Then$ it reads the first element of the subordinate table S/<#0HT that$ according
to the foreign key relationship$ belongs to the first element of table SP/<#. Then$
it reads all elements of table S.55E that belong to the first element read from
table S/<#0HT. 3e*t$ it reads the second element of table S/<#0HT and all
corresponding elements of table S.55E. This step is repeated until the system
has read all elements of table S/<#0HT that belong to the first element of table
SP/<#. Then the system reads the second element of table SP/<# and the entire
procedure starts again. This procedure is repeated until the entire hierarchy has
been processed.
.ogica) data0ases contain 5pen SF< statements that read data from the
database. 6ou do not therefore need to use SF< in your own programs. The
)ogica) data0ase reads the program$ stores them in the program if necessary$
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
and then passes them line by line to the application program or the function
module <(.GPR5-ESS using an interface work area.
Structure of .ogica) Data0ases
A logical database is made up of three components .They are'
Structure
The structure defines the data iew of the logical database. #t determines
the structure of the other components and the behaior of the logical
database at runtime. The order in which data is made aailable to the user
depends on the hierarchical structure of the logical database concerned.
Selections
The selections define a selection screen$ which forms the user interface of
the e*ecutable programs that use the logical database. #ts layout is usually
determined by the structure. 6ou can adapt the selections to your own
re>uirements and also add new ones. +hen you link a logical database to
an e*ecutable program$ the selections of the logical database become
part of the standard selection screen of the program !screen number
2777".
The database program contains the A.AP statements used to read the
data and pass it to the user of the logical database. The structure of the
database program is a collection of special subroutines. #t is determined
by the structure and the selections. 6ou can adapt the database program
to your own re>uirements and also e*tend it.
5ther components such as documentation$ language)specific te*ts$ and user)
defined selection screens e*tend the functions further.
Structure
The structure of a logical database is usually based on the foreign key
relationships between hierarchical tables in the R@9 System. <ogical databases
hae a tree)like structure$ which can be defined as follows'
H There is a single node at the highest leel. This is known as the root node.
H Each node can hae one or seeral branches.
H Each node is deried from one other node.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The nodes must be structures defined in the A.AP (ictionary or data types from
a type group. 3ormally$ these are the structures of database tables which the
logical database reads and passes to the user for further ealuation. Howeer$ it
is also possible$ and sometimes useful$ to use A.AP (ictionary structures
without an underlying database. /or technical reasons$ the ma*imum number of
nodes allowed in the structure of a logical database is 977.
Any e*ecutable A.AP program that has a logical database linked to it can
contain a 0ET statement for each node of the structure. +hen you run the
program$ the corresponding eent blocks are processed in the se>uence
prescribed by the hierarchical structure of the logical database. #f a program does
not contain a 0ET statement for eery node of a logical database$ the processing
passes through all the nodes that lie in the path from the root to the nodes
specified by 0ET statements.
.ogica) Data0ases - 1ie2s of Data
A )ogica) data0ase proides a particular iew of database tables in the R@9
System. #t is always worth using )ogica) data0ases if the structure of the data
that you want to read corresponds to a iew aailable through a )ogica)
data0ase.
The data structure in a )ogica) data0ase is hierarchical. %any tables in the R@9
System are linked to each other using foreign key relationships. Some of these
dependencies form tree)like hierarchical structures. .ogica) data0ases read
data from database tables that are part of these structures.
!etrie3ing Data Using a .ogica) Data0ase
After you hae specified the logical database in the report attributes$ you can
access the database in the program. #n the declaration part of your program$
declare the tables you want to access in the program using the TA.<ES
statement$ as described in the SE<E-T Statement section. This proides the
work areas for passing the data from the logical database to the program. The
system also configures the selection screen to include fields from the tables you
specified.
The program of the logical database places the data from the database tables
into the work areas created by the TA.<ES statement. The logical database then
triggers an eent. #n your program$ you catch this eent using the keyword 0ET
with the corresponding table name. #f$ for e*ample$ the logical database just filled
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
the work area of table S.55E$ it triggers the eent 0ET S.55E in your
program. The system then e*ecutes the statement block belonging to this eent.
A statement block starts directly after the eent keyword and ends at the ne*t
eent keyword or at the end of the program.
*ET E1ENT
This is the most important eent for e*ecutable programs that use a logical
database. #t occurs when the logical database has read a line from the node
ItableJ and made it aailable to the program in the work area declared using the
statement 35(ES ItableJ.
+hen you define the corresponding eent block in the program$ you can specify
a field list if the logical database supports field selection for this node'
0ET ItableJ K/#E<(S If
2
J If
4
J...L.
6ou can process the data in the work area in this eent block. /or e*ample$ you
can write it directly to a list$ or store it in a se>uential dataset !internal table or
e*tract" so that you can process it later.
The logical database reads a)) columns from a)) nodes that are not designated
for field selection in the logical database and which are superior to ItableJ on the
access path of the logical database. This works independently of whether you
hae defined *ET e3ent blocks for these nodes or not. Howeer$ you can only
access the data of the nodes for which you hae declared a work area in the
35(ES statement.
6ou can use the /#E<(S option to specify e*plicitly the columns of a node that
the logical database should read. +ith the /#E<(S option$ the logical database
program reads only the fields If
#
J If
$
J ... and the key fields from the database
table ItableJ. Howeer$ the node ItableJ must hae been designated for field
selection in the logical database.
;sing /#E<(S can result in much better response times than when the logical
database has to read all of the columns of the node.
All fields of the node ItableJ that are not key fields and are not listed after
/#E<(S$ are not read by the logical database. The contents of the corresponding
components of the table work area ItableJ are set to he*adecimal 77. This
means that they are also set to he* 77 during the *ET e3ents of the nodes
below ItableJ in the hierarchy. 6ou should therefore not use these fields in your
program or call subroutines that work with them .
The following program is connected to the logical database /2S.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
!EPO!T E1ENT4DE"O5
NODES: SPF.I6 SF.I*T6 S&OO75
ST'!T-OF-SE.ECTION5
8!ITE 9Test Program for *ET95
*ET SPF.I5
S7IP5
8!ITE: : 9From:96 SPF.I-CITYF!O"6
9TO :96 SPF.I-CITYTO5
*ET SF.I*T5
S7IP5
8!ITE: : 9Carrid:96 SF.I*T-C'!!ID6
9Connid:96 SF.I*T-CONNID5
U.INE5
*ET S&OO75
8!ITE: : 9F)date:96 SF.I*T-F.D'TE6
9&oo;id:96 S&OO7-&OO7ID6
9.ugg2eig/t96 S&OO7-.U**8EI*T5
U.INE5
The table work area S/<#0HT is also used in the eent block for 0ET
S.55E. (epending on what you enter on the selection screen$ the
beginning of the list display might look like this'
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
#n the logical database /2S$ the nodes S/<#0HT and S.55E are
designated for field selection. This means that you can specify a field list in
their *ET e3ent blocks'
!EPO!T E1ENT4DE"O5
35(ES' S/<#0HT$ S.55E.
0ET S/<#0HT /#E<(S -ARR#( -533#(.
...
0ET S.55E /#E<(S .55E#(.
...
0ET S/<#0HT <ATE /#E<(S P<A3ET6PE.
...
#n this case$ the logical database reads the following fields'
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
%A3(T$ -ARR#($ -533#($ /<(ATE$ and P<A3ET6PE from S/<#0HT
%A3(T$ -ARR#($ -533#($ /<(ATE$ and .55E#( from S.55E
The system reads the fields %A3(T and /<(ATE from S/<#0HT$ een
though they are not specified in the field list$ since they belong to the table
key.
5nly the key fields of S.55E are read.
PR5=#(E
PR5=#(E Synta( Diagram
&asic form
P!O1IDE f2 f4 ... /R5% itab2
g2 g4 ... /R5% itab4
...
/R5% itabn
...
.ET+EE3 f A3( g.
See P!O1IDE ) E3(PR5=#(E not allowed .
Effect
Retriees the contents of the specified fields from the internal tables !itab2$
itab4 $ ..." and places them in the table header lines within the re>uired range.
Also e*ecutes the processing block enclosed by the P!O1IDE and
E3(PR5=#(E statements for each range.
3ote
/or itab2$ itab4 ... only tables with header lines are allowed.
Effect
&asic princip)e:
The diagram below illustrates the functionality of the P!O1IDE statement for the
most simple case where just two tables A and . are to be processed'
#A2 #A4
M)))))))))))M M))))))))))))))M table A
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
' ' ' '
' #.2 ' #.4 ' '
' M)))))))))))M M)))))))))))))M ' table .
' ' ' ' ' ' ' '
' ' P!O1IDE area ' ' '
...M))))))))))))))))))))))))))))))))))))))))M...
' ' ' ' ' ' ' '
'T#2' T#4 'T#9' ' T#N ' T#O ' T#D '
...M)))M)))))))M)))M M)))))))M)))))M)))))M...
result ranges
The data structures which form the basis for the table lines must each contain
two components which can be interpreted as a range !e.g. start date and end
date". #n the diagram$ the ranges belonging to the entries in table A are marked
with #A2 or #A4 $ and those in table . with #.2 or #.4. #f you split the ranges of
both tables into oerlapping and non)oerlapping ranges and then form the
intersection with the P!O1IDE area$ this results in D sub)ranges T#2 to T#D. #n
these sub)ranges$ the alues of the tables A and . are constant. The P!O1IDE
statement makes the contents of the tables A and . aailable for the D sub)
ranges$ one after the other. #t thus acts as a kind of loop where the data of the
tables inoled can be processed with reference to each range.
Effect
*enera) princip)e
Each of the specified internal tables has two fields which contain the line)related
alidity range. 6ou can determine these in the
(ATA statement with the addition P=A<#( .ET+EE3 ... A3( ...P. #f this
addition is not used$ the first two sub)fields of the table determine these
range fields !corresponds to =A<#( .ET+EE3 first field A3( second field".
These fields can be date fields$ time fields or number fields. .oth these two
fields and also f and g should be the same type.
P!O1IDE splits the range f to g into sub)ranges so that each of the fields
!f2$ f4$ ..." specified for each table is constant in this range and so that each
sub)range is as large as possible !range limits are considered part of the
range".
Each time the processing passes through the loop$ the current range limits
and the specified sub)fields are placed in the header lines of the internal
tables. #f you want to make all sub)fields aailable$ enter QRQ instead of the
field list. The unspecified sub)fields are set to their initial alue !
-<EAR".
#t is a re>uirement that the ranges within a table are in ascending
order and not oerlapping. Howeer$ there can be gaps between one
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
upper range limit and the ne*t lower range limit.
/or each table itab2$ itab4 ... $ the automatically generated fields
itab2G=A<#($ itab4G=A<#( $ ... indicate !with QSQ or blank Q Q" whether a
suitable entry was found for the current sub)range.
E*ample
The entries in the table SE$ PR and SH contain time ranges and are
filled as follows'

(ATA' .E0#3 5/ SE 5--;RS 9$
/R5% T6PE ($
T5 T6PE ($
3A%E!2O" T6PE -$
A0E T6PE #$
E3( 5/ SE$
.E0#3 5/ PR 5--;RS N$
START T6PE ($
E3( T6PE ($
PR#-E T6PE #$
3A%E!27" T6PE -$
E3( 5/ PR$
.E0#3 5/ SH 5--;RS 4$
-<5SE( T6PE ($
STR!47" T6PE -$
5PE3E( T6PE ($
E3( 5/ SH =A<#( .ET+EE3 5PE3E( A3( -<5SE($
.E0#3 T6PE ( =A<;E Q28827?72Q$
E3( T6PE ( =A<;E Q28842772Q.
SE)/R5% T Q28827:72Q. SE)T5 T Q28827897Q.
SE)3A%E T QShortyQ. SE)A0E T 28. APPE3( SE.
SE)/R5% T Q2882277OQ. SE)T5 T Q2884792OQ.
SE)3A%E T QSnowmanQ. SE)A0E T 9O. APPE3( SE.
SE)/R5% T Q2884792:Q. SE)T5 T Q28842492Q.
SE)3A%E T QTomQ. SE)A0E T 4O. APPE3( SE.
PR)START T Q28827872Q. PR)E3( T Q28822297Q.
PR)3A%E T Q-arQ. PR)PR#-E T 97777. APPE3( PR.
PR)START T Q28822472Q. PR)E3( T Q2884792OQ.
PR)3A%E T Q+oodQ. PR)PR#-E T 27. APPE3( PR.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
PR)START T Q2884792:Q. PR)E3( T Q28847:72Q.
PR)3A%E T QT=Q. PR)PR#-E T 2777. APPE3( PR.
PR)START T Q28847:74Q. PR)E3( T Q28842792Q.
PR)3A%E T Q%edalQ. PR)PR#-E T O777. APPE3( PR.
SH)-<5SE( T Q2884792OQ. SH)STR T Q0old AenueQ.
SH)5PE3E( T Q28827:72Q. APPE3( SH.
SH)-<5SE( T Q28842792Q. SH)STR T Q+all StreetQ.
SH)5PE3E( T Q2884792:Q. APPE3( SH.
P!O1IDE 3A%E A0E /R5% SE
3A%E /R5% PR
R /R5% SH
.ET+EE3 .E0#3 A3( E3(.
...
E3(PR5=#(E.
The three tables are processed according to the following schema'
#SE2 #SE4 #SE9
M)))))))M M)))))))))))M M))))))))))))))))))))))))M
' ' ' ' ' '
' '#PR2 #PR4 ' ' #PR9 #PRN '
' M))))))))))M))))))M M))))))))))))))M))))))M '
' ' ' ' ' ' ' ' ' '
' ' #SH2 ' ' ' #SH4 ' ' '
M))))))))))))))))))))))M M)))))))))))))))))))))M '
' ' ' ' ' ' ' ' ' '
' ' ' ' P!O1IDE area ' ' '
M))))))))))))))))))))))))))))))))))))))))))))))))))M...
' ' ' ' ' ' ' ' '
' ' ' ' ' ' ' ' '
...M))))M))M))M))))M))))))M M))))))))))))))M))))))M...
result ranges
This P!O1IDE loop is e*ecuted ? times and produces the following
sub)ranges'
o 72.7:.2882 ) 92.7:.2882

o 72.78.2882 ) 97.78.2882

o 72.27.2882 ) 7N.27.2882

o 7O.27.2882 ) 97.22.2882

Naveesh Surapureddy BASICS OF


ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
o 72.24.2882 ) 2O.79.2884

o 2:.79.2884 ) 72.7:.2884

o 74.7:.2884 ) 72.27.2884
#n most of the loop passes$ the fields SEG=A<#($ PRG=A<#( and
SHG=A<#( contain QSQ . The e*ceptions to this are the 2st loop pass$
where PRG=A<#( contains Q Q$ and the 9rd loop pass$ where
SEG=A<#( contains Q Q.
/ield contents !header lines" during the third loop pass'
SE)/R5% T Q72272882Q
SE)T5 T Q7N272882Q
SE)3A%E T Q Q
SE)A0E T 7
PR)START T Q72272882Q
PR)E3( T Q7N272882Q
PR)PR#-E T 7
PR)3A%E T Q-arQ
SH)-<5SE( T Q7N272882Q
SH)STR T Q0old AenueQ
SH)5PE3E( T Q72272882Q
o 3otes
Strictly speaking$ if you imagine each range as a short way of writing
a set of single alues$ this is an Pouter joinP of the tables.
o After E3(PR5=#(E$ the contents of the system fields S6)
#3(ES$ S6)TA.#S and S6)S;.R- are undefined.

o 3either the header lines nor the actual table lines of the table
specified with P!O1IDE should be changed between
P!O1IDE and E3(PR5=#(E. 5therwise$ the P!O1IDE
results are undefined.
Pro3ide t/e .ast Entry in t/e Period
Use
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
;se the following programming utility to place the last entry in a re>uired period
!this can be a for a subtype" in the table header entry from an internal infotype
table.
%acro' RP_PROVIDE_FROM_LAST
6ou define the macro using the keyword #3/5T6PES.
6ou use macro RP_PROVIDE_FROM_LAST in programs for the logical
databases P3P and PAP where the last data record for a period !can be a
subtype" is read from an infotype table. The infotype table has been filled earlier
!for e*ample$ with 0ET PER3R or RP_READ_INFOTYPE". This macro is only
helpful if the infotype !or subtype" has time constraint 2 or 4.
Prere<uisites
The alidity begin date of the time period must be before or the same as
the alidity end date.
=alidity start and end dates are correct !preferably of the type (ATE".
The infotype table is sorted in ascending order. 5therwise$ you would
receie the last fitting table entry that might not necessarily correspond to
the last time entry.
Features
The macro RP_PROVIDE_FROM_LAST makes sure that the last entry for a
specified period is placed in the table header entry of the report output list.
Parameters
RPGP!O1IDEG/R5%G<AST inftytab subty beg end
#3 ' 2" 3ame of the internal table

4" Subtype re>uired or SP'CE if no subtype is being specified

9" =alidity begin date of the time interal

N" =alidity end date of the time interal
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
5;T' 2" P3P)S+)/5;3(' has the alue 7 if there is no matching entry in the
infotype table in the gien time period. 5therwise it has the alue 2.

4" The matching table header entry if P3P)S+)/5;3( T # or
the cleared table header entry if P3P)S+)/5;3( T ,
C/ec;
3one
E(amp)e
!RPGP!O1IDEG/R5%G<AST inftytab subty beg end"
RPGP!O1IDEG/R5%G<AST P7742 Q2Q P3).E0(A P3)E3((A.
#/ P3P)S+)/5;3( EF Q2Q.
...
or
RPGP!O1IDEG/R5%G<AST P7772 SPA-E P3).E0(A P3)
E3((A.
#/ P3P)S+)/5;3( EF Q7Q.
+R#TE' @ QError' 5rg. assignment is missingQ. RECE-T.
E3(#/.
The module P!O1IDE)/R5%)/#3A<$ which is not implemented$ is
a special case of P!O1IDE)/R5%)<AST'
P!O1IDE)/R5%)/#3A< inftytab subty beg end T
RPGP!O1IDEG/R5%G<AST inftytab subty end end


.ea3ing E3ent &)oc;s Using CEC7
#f you use the -HE-E Ie*prJ statement within an eent block but not 2it/in a
)oop$ and the condition Ie*prJ is not fulfilled$ the system e*its the processing
block immediately.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Ie*prJ can be any logical e*pression or the name of a selection table. #f you
specify a selection table and the contents of the corresponding table work are do
not fulfill the condition in the selection table$ it is the same as a false logical
e*pression.
The A.AP runtime enironment triggers the ne*t eent according to the following
diagram'
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The ne*t eent in the prescribed se>uence is always called.
#f the -HE-E statement occurs in a loop using (5$ +H#<E$ or <55P$ it is the
loop that terminates$ not the processing block.
+ithin a *ET e3ent block$ this means the ne*t *ET e3ent at the same
/ierarc/ica) )e3e). +hen it leaes the eent block$ the logical database reads
the ne*t line of the current node$ or the ne*t)highest node if it has already
reached the end of the hierarchy leel. 3odes that are lower down in the
hierarchical structure of the logical database are not processed.
The following program is connected to the logical database /2S.
REP5RT E=E3TG(E%5.
35(ES' SP/<#$ S/<#0HT$ S.55E.
START)5/)SE<E-T#53.
-HE-E -#T6G/R 3E Q Q.
+R#TE' @ QSelected -ity)/rom'Q$ -#T6G/R.
;<#3E.
-HE-E -#T6GT5 3E Q Q.
+R#TE' @ Q Selected -ity)To'Q$ -#T6GT5.
;<#3E.
0ET S/<#0HT.
+R#TE' @ Q-onnid'Q$ S/<#0HT)-533#($
Q-arrid'Q$ S/<#0HT)-ARR#($
Q/ldate'Q$ S/<#0HT)/<(ATE.
#f the user enters P/rankfurtP for -#T6G/R$ but nothing for -#T6GT5$ the
beginning of the list would look like this'
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
After the second -HE-E statement$ the system leaes the START)5/)
SE<E-T#53 block and triggers the eent 0ET S/<#0HT.
The following program is connected to the logical database /2S.
REP5RT E=E3TG(E%5.
35(ES' SP/<#$ S/<#0HT$ S.55E.
0ET S/<#0HT.
-HE-E S/<#0HT)-ARR#( EF Q<HQ.
+R#TE' @ Q-onnid'Q$ S/<#0HT)-533#($
Q-arrid'Q$ S/<#0HT)-ARR#($
Q/ldate'Q$ S/<#0HT)/<(ATE.
0ET S.55E.
-HE-E S.55E).55E#( <T 77777947.
+R#TE' @ Q.ookid'Q$ S.55E).55E#(.
0ET S/<#0HT <ATE.
;<#3E.
This produces the following output list'
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
#n the e*ample aboe$ all lines of the node S/<#0HT and$ if S/<#0HT)-ARR#( is
P<HP$ all lines of the node S.55E$ must be read. /or performance reasons$ you
should a3oid programming se)ections as a0o3e. #nstead$ use the selections of
the logical database.
*ET =ta0)ename> .'TE
The logical database triggers the eent 0ET ItablenameJ <ATE after processing
all tables below the table ItablenameJ in the hierarchy structure. This allows you
to output additional information or insert statements that change the list layout.
P;T d0ta0
P;T Synta( Diagram
=ariants'
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
2. PUT node.
4. PUT InodeJ.
Effect
6ou can only use this statement in the database access program of a logical
database whose structure contains the node node. 6ou use it to pass data read
by the logical database to its user. This is either an e*ecutable !type 2" program
with the logical database entered in its program attributes$ or a program that is
using the function module <(.GPR5-ESS .
#n the first case !e*ecutable programs"$ the PPUT node.P or PPUT InodeJ.P
statement triggers the P
0ET node. P eent in the program. #n the second case$ the corresponding
callback routine is called$ and the data from the work area node or InodeJ is
passed back to it. Then$ the PUT subroutines of the ne*t nodes in the structure
are called !if the user wants data from these subordinate nodes". /inally$ the P
0ET node <ATE. P eent is triggered$ if it is used in the e*ecutable program$ or
the corresponding callback routine is e*ecuted.
/5R% PUTGInodeJ
-alled in the se>uence defined in the structure. Reads the data from the
node InodeJ and uses the
PUT InodeJ.
statement to trigger a corresponding 0ET eent in the A.AP runtime
enironment. The PUT statement is the central statement in this
subroutine' #t can only be used within a subroutine of a logical database.
The logical database must contain the node InodeJ$ and the subroutine
name must begin with PUTGInodeJ. The PUT statement directs the
program flow according to the structure of the logical database. The depth
to which the logical database is read is determined by the 0ET statements
in the application program or the interface parameter -A<<.A-E of the
function module <(.GPR5-ESS.
/irst$ the subroutine PUTGIrootJ is e*ecuted for the root node. The PUT
statement then directs the program flow as follows'
i" #f the database program contains the subroutine
A;TH5R#T6G-HE-EGItableJ$ the first thing the PUTGInodeJ statement does
is to call it.
ii" 3e*t$ the PUT statement triggers a 0ET eent in the runtime enironment. #f
there is a corresponding 0ET InodeJ statement in the e*ecutable program to
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
which the logical database is linked$ the associated eent block is processed. #f
the -A<<.A-E parameter of the function module <(.GPR5-ESS is filled
accordingly$ the corresponding callback routine is called.
iii" The PUT statement then directs the program flow as follows'
!a" To the ne*t subroutine of a node that follows directly$ if a lower)leel node !not
necessarily the ery ne*t" in the same subtree is re>uested by 0ET in the
e*ecutable program or in the function module.
!b" To the subroutine of a node at the same leel$ if the preceding node branches
to such a node and if a 0ET statement e*ists for such a node in the e*ecutable
program or the function module.
The PUT statement in that subroutine starts again at step !i". #n the subroutine of
the lowest node in a subtree to be processed using 0ET$ the program control
does not branch further. #nstead$ the current subroutine is processed further.
+hen a subroutine PUTGInodeJ has been e*ecuted in its entirety$ the program
flow returns to the PUT statement from which it branched to the subroutine
PUTGInodeJ.
i" +hen control has returned from a lower)leel subroutine PUTGInodeJ$ the
PUT statement triggers the eent 0ET InodeJ <ATE in the runtime enironment.
/5R% A;TH5R#T6G-HE-EGInodeJ
-alled automatically by the PUT ItableJ statement. #n this subroutine$ you
can specify authori&ation checks for the appropriate node ItableJ from the
structure of the logical database
' C'SE STUDY 8IT .O*IC'. D'T'&'SE PNP
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The logical database P3P is proided for ealuation of HR master data and time
data. #t enables conenient$ high)performance ealuation of the transparent
tables PAnnnn !nnnn is the infotype number ) table PA4722 is an e*ception."
Data !etrie3a)
+hen you run your report$ the logical database loads the personnel data for each
employee into the main memory and makes it aailable for processing.
The entire history of each infotype is loaded into the main memory$ that is all
infotype records from the lowest to highest system date.
The data of the preious personnel number is deleted when you select another
personnel number.
'ut/ori?ation C/ec;
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
The logical database e*ecutes an authori&ation check for personnel data.
#t checks whether the master record of the user who starts the report contains the
authori&ations for the data that is to be read in the report.
A distinction is made between a person and a data authori&ation.
The system first checks whether the user has an authori&ation for the employee
in accordance with the criteria of organi&ational assignment. Employees for
which the user has no authori&ation are not ealuated.
The system then checks whether the user is authori&ed to process the infotypes
of the specified report. A list would be meaningless if the data were not ealuated
completely.
E(amp)e of an ! report
An HR report which uses the logical database has the following basic structure'
REPORT RPABAP01.
TABLES: PERNR.
INFOTYPES: 0001.
GET PERNR.
PROVIDE * FROM P0001 BETWEEN PN-BEGDA AND PN-ENDDA.
WRITE: / P0001-PERNR,
P0001-STELL,
P0001-BEGDA,
P0001-ENDDA.
ENDPROVIDE.
This report ealuates the Organizational Assignment infotype records in the
specified data selection period.
Infotype Dec)aration
All infotypes to be processed in the report are listed in the A.AP INFOTYPES
keyword.
The database usually contains seeral records with different alidity periods and
not just one record for each infotype and personnel number . #nfotypes are time)
dependent since their data changes oer time. /or this reason$ one structure or
work area would not suffice for the proision of infotype data in the main memory.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Therefore$ the INFOTYPES statement is used to create an internal table for each
of the listed infotypes. The structure of this table corresponds to that of the
releant infotype.
Data !etrie3a)
(ata is retrieed at the GET PERNR eent. The GET PERNR action is e*ecuted
for all personnel numbers that were selected on the basis of selection screen
entries. The eent should therefore be iewed as a loop using the selected
personnel numbers.
GET PERNR fills the internal tables of infotypes that are declared for each
employee using the INFOTYPES statement.
The internal infotype table is filled with all records e*isting between the lowest
and highest system date. The internal table has the name Pnnnn, where nnnn
is the infotype number.
The header of the internal table Pnnnn is undefined after the GET
PERNR action. #n particular$ you cannot assume that these headers
are reset to their initial alues if no records are found for a new
personnel number.
/or information on processing infotype records$ see #nfotype
Processing !PA)PA(".
PERNR is a (ata (ictionary structure without a database. 6ou must declare this
structure in the report using the TABLES statement.
Processing ')) Infotype !ecords
After the GET PERNR eent$ the internal tables of the infotypes contain records
and are ready for processing.
#nternal tables are generally processed line)by)line using the LOOP statement.
The internal tables of infotypes hae features which allow special processing.
These tables are defined for specific interals. #n HR$ these are time interals or
alidity periods.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Processing of infotype records is time)dependentU by this we mean dependent on
the data selection period entered on the selection screen. The data of seeral
infotypes can be processed at the same time and made aailable for a specific
partial period.
#nternal infotype tables are processed with the PROVIDE statement.
The synta* is as follows'
PROVIDE * FROM Pnnnn BETWEEN PN-BEGDA AND PN-ENDDA.
WRITE: / Pnnnn-<field>.
ENDPROVIDE.
nnnn stands for the four)digit infotype number. The relationship between the
infotype and the data selection period of the selection screen is established using
the PN/BEGDA and PN/ENDDA ariables.
#n the PROVIDE loop$ the data of an infotype record is aailable for processing in
the Pnnnn structure.

Processing a Specific Infotype !ecord
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
6ou often only re>uire the most recent or earliest infotype record$ not all infotype
records.
#n this case$ use one of the following statements'
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 aailable in the structure Pnnnn for infotype
nnnn .
#f the infotype has subtypes$ replace the SPACE parameter by the appropriate
subtype number.
+hen a record has been successfully read$ the return code PNP-SW-FOUND =
1 is returned.
E(amp)e report:
REPORT RPDEMO02.
TABLES: PERNR.
INFOTYPES: 0001.
GET PERNR.
RP_PROVIDE_FROM_LAST P0001 SPACE PN-BEGDA PN-ENDDA
IF PNP-SW-FOUND eq 1.
WRITE: / PERNR-PERNR, P0001-STELL, PN-BEGDA, PN-ENDDA.
ELSE.
REJECT.
ENDIF.
The aboe statements are A.AP macros.
Data Structures
Structure of ! "aster Data and Time Data Ta0)es
HR master data and time data are stored in the transparent tables PAnnnn. #n
addition to keys !client$ personnel number$ subtype$ object #($ lock indicator$
alidity period$ and se>uential number"$ these tables contain data for the infotype
nnnn.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Structure of Infotypes
The (ata (ictionary contains a Pnnnn structure for each infotype nnnn .
The infotype structure Pnnnn corresponds to the table PAnnnn. Howeer$ the
client$ for e*ample$ is missing$ therefore the infotype number is retained.
The infotype is defined in the (ata (ictionary as a structure without a database.
The Pnnnn structure of the infotype is used as the field structure for the infotype
entry screen.
+hen you declare an infotype using the INFOTYPES statement$ an internal table
Pnnnn with the structure Pnnnn is created and all records of the infotype are
transferred to this table'
DATA BEGIN OF Pnnnn OCCURS 10.
INCLUDE STRUCTURE Pnnnn.
DATA END OF Pnnnn VALID BETWEEN BEGDA AND ENDDA.
The infotype records can be processed using the infotype structure when the
report is run.
PERNR structure
Eent keywords for data retrieal from a logical database hae the following
synta*'
GET <TABLE> .
The logical HR database uses the table PERNR . 6ou must declare it in the
TABLES statement.
At the GET PERNR eent$ the PERNR structure contains the data for a personnel
number chosen on the basis of selection screen entries.
The PERNR-PERNR field contains the personnel number which is selected for
processing.
5nly the PERNR-PERNR field should be read from the work area of
the PERNR table. The other fields are intended for internal use only.

Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING

"'C!O "ODU.ES IN S'P
"acro "odu)es
Definition
An module that can be called within an A.AP program.
Use
<ike subprograms and function modules$ macro modules are a means of
presenting programs in modular form. %acro modules !macros" are used often in
the Hman Resor!es application component !HR".
Defining and Ca))ing "odu)es
Two options are proided'
%acros can be defined in reports or includes using the A.AP command
(E/#3E. A macro can be used within a report or within an include. #f a
macro is used in a report$ and the macro is defined in an include with the
(E/#3E command$ the include must be integrated.
%acros hae the following adantages'
#f a macro is changed$ each report using this macro is automatically
regenerated when it is e*ecuted.
%acros can also be defined as R%A- macros. The source code of these
modules is stored in the function section of the control table TR%A-
!%acros in A.AP Programs". The coding is grouped under a specific name
in the table key.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
According to conentions$ the first two letters of the name must stand for
the application. The rest of the name is freely definable.
-ustomer)specific R%A- modules should begin with a special
character.
The macros defined in the control table TR%A- can be used by all
reports.
+hen you change a R%A- macro in the table TR%A-$ the reports
that use this macro are not regenerated automatically. 6ou must
regenerate them manually.
RMAC Modules - RMAC module as referred to Macro, is a
special construct of ABAP/4 codes. Normally, the program code
of these modules is stored in tale !"RMAC!. "he tale #ey
comines the program code under a gi$en name. %t can also e
defined in programs."he RMAC defined in the "RMAC can e
used in all Reports. &hen an RMAC is changed, the report has to
e regenerated manually to reflect the change.
Reading %nfotypes - y using RMAC 'macro( RP-R)A*-%N+,"-P)
R)P,R" ./R00001.
%N+,"-P)2 0003.
PARAM)")R42 P)RNR 5%6) P0003-P)RNR.
RP-R)A*-%N+,"-P) P)RNR 0003 P0003 7B)8%N9 7)N*9.
PR,:%*) ; +R,M P0003
if ... then ...endif.
)N*PR,:%*).
Changing %nfotypes - y using RMAC 'macro( RP-R)A*-
%N+,"-P).
< "hree steps are in$ol$ed in changing infotypes2
1. 4elect the infotype records to e changed=
3. Ma#e the re>uired changes and store the records in an
alternati$e tale=
?. 4a$e this tale to the dataase=
"he RP-UPDATE macro updates the dataase. "he parameters of this
macro are the ,5* internal tale containing the unchanged records
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING
and the N)& internal tale containing the changed records. -ou cannot
create or delete data. ,nly modification is possile.
%N+,"-P)42 Pnnnn NAM) ,5*,
Pnnnn NAM) N)&.
8)" P)RNR.
PR,:%*) ; +R,M ,5*
&/)R) .... @ ... AChange old record
;4a$e old record in alternate tale
N)& @ ,5*.
)N*PR,:%*).
RP-BP*A") ,5* N)&. ABpdate changed record
Function "odu)es in !
/unction modules are program modules which hae a defined interface and allow
type testing of parameters.
They are managed with transaction SE9? and combined to function groups
according to releant criteria. 6ou can access this transaction under Tools
A"AP #or$%en!& Fn!tion "ilder.
The HR function groups use the naming conention RP** or HR** where ** is
an identifier of your choice.
6ou can use the SHO# F'N(TION * editor command to branch from report
processing to function module display.
Naveesh Surapureddy BASICS OF
ABAP HR PROGRAMMING

Vous aimerez peut-être aussi