Retrieve multiple contracts for HR personnel and include in locical database selection/report

When you create a HR logical database report (i.e. GET PERNR.) you get a standard selection screen which automatically selects data based on what the user enters into it.

This works really well but can lead to problems if you have an organisation where users can have multiple contracts, and each of these contracts has a separate pernr.

For example if you run such a report for a single Organisation Unit but a selected personnel record (pernr) has a second contract within a different org unit this will be excluded from the results. There are times when you would not want this to work like this.

The following SAP ABAP code demonstrates how to retrieve the personnel numbers of these multiple contracts and feeds them into the selection screen before the selection is performed by the HR report.

**********
*DATA declarations for multiple contracts

SELECT-OPTIONS r_ppernr for pernr-pernr no-display.
TYPES: BEGIN OF t_pa0121.
        INCLUDE STRUCTURE pa0121.
TYPES: END OF t_pa0121.
DATA: it_pa0121 TYPE STANDARD TABLE OF t_pa0121 INITIAL SIZE 0,
      wa_pa0121 TYPE t_pa0121.
**********
**************************************************************
*AT SELECTION-SCREEN ON PNPPERNR
AT SELECTION-SCREEN ON pnppernr.
  r_ppernr[] = pnppernr[].
  READ TABLE pnppernr INDEX 1.
  IF NOT pnppernr IS INITIAL.
    READ TABLE pnpobjid INDEX 1.
    IF sy-subrc EQ 0 AND NOT pnpobjid-low IS INITIAL.
      REFRESH pnpobjid.
      MESSAGE i999(za) WITH 'Org unit refreshed'.
    ENDIF.
*   Retrieve all personnel with multiple contracts
    SELECT * FROM pa0121
      INTO TABLE it_pa0121.
    CLEAR:   pnppernr.
    REFRESH: pnppernr.
*   Re-build personnel number select option to include all contracts
*   relating to original user selection
    LOOP AT it_pa0121 INTO wa_pa0121 WHERE pernr IN r_ppernr.
      pnppernr-low    = wa_pa0121-pernr.
      pnppernr-sign   = 'I'.
      pnppernr-option = 'EQ'.
      APPEND pnppernr.
      pnppernr-low    = wa_pa0121-hpern.
      pnppernr-sign   = 'I'.
      pnppernr-option = 'EQ'.
      APPEND pnppernr.
    ENDLOOP.
*   Re-build personell number select option to include all contracts
    LOOP AT it_pa0121 INTO wa_pa0121 WHERE hpern IN pnppernr.
      pnppernr-low    = wa_pa0121-pernr.
      pnppernr-sign   = 'I'.
      pnppernr-option = 'EQ'.
      APPEND pnppernr.
    ENDLOOP.
    SORT pnppernr.
    DELETE ADJACENT DUPLICATES FROM pnppernr COMPARING low.
   endif.

Get multiple contract after screen select has happend
Using the above method you would need to control all fields on the selection screen to ensure the correct pernrs end up being passed to the selection screen. Another method is to control all the multiple contract processing after the GET pernr event. But this would depend on the report itself and how it retrieves all its data via the PROVIDE statement.

**********
*DATA declarations for multiple contracts

SELECT-OPTIONS r_ppernr for pernr-pernr no-display.
TYPES: BEGIN OF t_pa0121.
        INCLUDE STRUCTURE pa0121.
TYPES: END OF t_pa0121.
DATA: it_pa0121 TYPE STANDARD TABLE OF t_pa0121 INITIAL SIZE 0,
      wa_pa0121 TYPE t_pa0121,
      ld_pernr  type pernr-pernr,
      ld_tabix  type sy-tabix.
**********
*****************************************************************
*INITIALIZATION.
INITIALIZATION.
  SELECT * FROM pa0121
      INTO TABLE it_pa0121.
GET pernr.
  READ TABLE it_pa0121 into wa_pa0121 with key pernr = pernr-pernr.
  if sy-subrc eq 0.
*   Pernr is a multiple
    ld_pernr =  wa_pa0121-hpern.
    LOOP AT it_pa0121 INTO wa_pa0121 WHERE hpern eq ld_pernr and done ne 'X'.
      ld_tabix = sy-tabix.
      pernr-pernr = wa_pa0121-pernr.
**********************************
*Perform processing here....
**********************************
      wa_pa0121-done = 'X'.
      modify it_pa0121 from wa_pa0121 index ld_tabix.
    endloop.
  else.
**********************************
*Perform processing here....
**********************************
  endif.

Related Articles

Payroll results (ABAP)
Display organisational structure
SAP HR infotypes
GET PERNR LAST and GET PAYROL
SAP HR Development help - ABAP code and information on various areas of HR development in SAP
ABAP code to retrieve Absence type text(AWART) from SAP table
ABAP to retrieve country grouping for personnel with SAP
Deleting an SAP HR Infotype
SAP HR Infotype selection
Creating a New SAP Infotype using transaction PM01 and PPCI
Retrieve comment texts from cluster table for SAP infotype 19
SAP Function module to call ABAP report from managers desktop(MDT)
SAP User Exits to Add functionality to the PBO and PAI of HR infotypes
Create SAP HR report category for logical database selection within ABAP report
SAP HR Selection Screen example
Retrieve SAP personal work schedule
SAP HR Infotype Development Information, ABP and step by step instructions
Enhancing an Infotype - Add, change or modify fields of and SAP infotype
SAP Personal absence calander for SSP/SMP
ABAP Program to retrieve and display sickpay(SSP, SMP etc) with SAP
SAP Personal absence calendar (NCALE) using transaction PC00_M08_CLPC
Accessing NCALE data via the Results Log when running a payroll
Program to retrieve sickpay values
Processing the SAP HR Organisation unit
SAP HR Payroll results ( transaction code: PC_PAYRESULT)
Payroll results (ABAP)
Display Payroll results using SAP transaction PC_PAYRESULT