Skip to end of metadata
Go to start of metadata

Here is a Program to --Get the Details of Managers for the Active Employees.

OUTPUT: Personnel Number (PERNR),First Name,Last name,

 Manager's Pernr,manager first name,manager last name.

REPORT hr_om_emp_details.
*" Type declarations...................................................
*"--------------------------------------------------------------------*
* Type declaration of the structure to hold personal data of employee *
* from table PA0002. *
*"--------------------------------------------------------------------*
TYPES:
BEGIN OF type_s_name,
  vnamc TYPE pa0002-vnamc, " First Name
  nchmc TYPE pa0002-nchmc, " Last Name
END OF type_s_name.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
DATA:
  t_name TYPE type_s_name, " Holds name
  w_sobid TYPE hrp1001-sobid, " Object ID
  w_objid TYPE hrp1001-sobid. " Object ID

PARAMETERS:
  p_pernr TYPE hrp1001-sobid. " Personnel number
*"--------------------------------------------------------------------*
* START OF SELECTION EVENT *
*"--------------------------------------------------------------------*
START-OF-SELECTION.
  WRITE:/ 'Employee Details:'.
  PERFORM get_pernr_details USING p_pernr.
  SKIP.
  WRITE:/ 'Employee Managers Details:'.
  PERFORM get_manager_details.
*&---------------------------------------------------------------------*
*& Form GET_PERNR_DETAILS
*&---------------------------------------------------------------------*
* Retrieves First Name ,Last Name for the given corresponding
* Personnel number (pernr)
*----------------------------------------------------------------------*
FORM get_pernr_details USING value(i_pernr) TYPE hrp1001-sobid.
  SELECT vnamc
          nchmc
    FROM pa0002
    INTO t_name
    WHERE pernr EQ i_pernr.
  ENDSELECT.
  IF sy-subrc EQ 0.
    WRITE:/ 'Personnel Number:', i_pernr.
    WRITE:/ 'First Name' , ' Last Name',
          / t_name-vnamc ,
            t_name-nchmc .
  ENDIF.
ENDFORM. " GET_PERNR_DETAILS
*&---------------------------------------------------------------------*
*& Form GET_MANAGER_DETAILS
*&---------------------------------------------------------------------*
* Retreives Object Id (sobid) for the given Object Type,
* Relationship Specification etc.
*----------------------------------------------------------------------*
FORM get_manager_details .
*gets position 'S' for the holder 'P'
  SELECT SINGLE sobid
    INTO w_sobid
    FROM hrp1001
    WHERE otype EQ 'P'
      AND objid EQ p_pernr
      AND plvar EQ '01'
      AND rsign EQ 'B'
      AND relat EQ '008'
      AND sclas EQ 'S'.
  IF sy-subrc EQ 0.
    w_objid = w_sobid.
    CLEAR w_sobid.
*gets organisation 'O'for the position 'S'
    SELECT SINGLE sobid
      INTO w_sobid
      FROM hrp1001
      WHERE otype EQ 'S'
        AND objid EQ w_objid
        AND plvar EQ '01'
        AND rsign EQ 'A'
        AND relat EQ '003'
        AND sclas EQ 'O'.
    IF sy-subrc EQ 0.
      w_objid = w_sobid.
      CLEAR w_sobid.
*gets Managerial Position 'S' for the organisation 'O'
      SELECT SINGLE sobid
        INTO w_sobid
        FROM hrp1001
        WHERE otype EQ 'O'
          AND objid EQ w_objid
          AND plvar EQ '01'
          AND rsign EQ 'B'
          AND relat EQ '003'
          AND sclas EQ 'S'.
      IF sy-subrc EQ 0.
        w_objid = w_sobid.
        CLEAR w_sobid.
*gets the Personnel Number 'P' holding the Managerial Position 'S'
        SELECT SINGLE sobid
          INTO w_sobid
          FROM hrp1001
          WHERE otype EQ 'S'
            AND objid EQ w_objid
            AND plvar EQ '01'
            AND rsign EQ 'A'
            AND relat EQ '008'
            AND sclas EQ 'P'.
        IF sy-subrc EQ 0.
*displaying Personnel details-- first name , Last Name
          PERFORM get_pernr_details USING w_sobid.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM. " GET_MANAGER_DETAILS
 

 

Output:

1 Comment

  1. Hi, 

    This is a very useful program but it contains a bug. 

    It needs to check for the validity periods (fields BEGDA and ENDDA) in pretty much all the queries. 

    Pablo