In this recipe, we will create a program that will use a hashed
table and a standard table for accessing and displaying employee data from two tables PA0003
and PA0006
. There may be many solutions to this requirement. We will use SELECT
clause and hashed
tables.
In this recipe, we create a program that will take as input personnel number and then print the last payroll run date of the employee (from PA0003
) and the permanent residence address (subtype 1) stored in the STRAS
field of the table PA0006
. For simplicity's sake, only one data field of each table has been shown.
For creating the program, proceed as follows:
select-options
for taking input of personnel number.ty_payroll
based on payroll infotype fields pernr
and abrdt
. A structure and a hashed table based on this type are also defined. The hashed table has a unique key pernr
.ty_address
is defined, along with a structure and internal table.select
statements. The first reads PA0003
for all personnel numbers specified and the date of last payroll run (abrdt
). The second select
statement is used to read all the stras
addresses corresponding to permanent address type (subty
= 1
) valid at the system date.it_address
. Within the loop, the read table
statement is used for reading the payroll table it_payroll
(the hashed table) for each of the personnel number processed. Within the loop, the personnel number, abrdt
date, and the address field stras
are displayed. We have used field symbols instead of work areas, in conjunction with loop
and read
statements for better performance.Two internal tables it_address
and it_payroll
are defined. it_payroll
is a hashed table. We read data from both the database tables PA0003
and PA0006
into the internal tables it_payroll
and it_address
respectively. We need to print each employee number and the corresponding data from each of the two tables.
Therefore, a loop is carried out on the internal table it_adrress
and within the loop, a read table
is used to read the hashed table, the row corresponding to the employee number in question. Since it is a single entry access from the internal table it_payroll
which is a hashed table with the value corresponding to the hash key (pernr
) being passed, the read
statement is very quick. All the values that we need are there within the
loop after the read
statement. These values are then outputted using a write
statement.
18.117.99.71