sapdev logo background
sapdev logo sapdev logo
Comments

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.




comments powered by Disqus