Hashed table for single read access

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.

Getting ready

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.

How to do it...

For creating the program, proceed as follows:

  1. We define select-options for taking input of personnel number.
    How to do it...
  2. Next, we define a type 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.
    How to do it...
  3. Similarly, an address type ty_address is defined, along with a structure and internal table.
    How to do it...
  4. We then write two 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.
    How to do it...
  5. Finally, a loop is run on the addresses internal table 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.
    How to do it...

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.134.154