[SAP ABAP] - HR Funtion Module for Get Organizational Structure

FUNCTION zsapifm_orgstruct.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(PERSNO) TYPE  P_PERNR
*"  TABLES
*"      PERNR_TAB TYPE  PTIM_PERNR_TAB
*"----------------------------------------------------------------------

  DATA: ld_sobid LIKE hrp1001-sobid.

* Get team member based on reporting structure
  CLEAR: t_pernr, hrp1001.
  REFRESH t_pernr.
  SELECT sobid FROM hrp1001
               INTO ld_sobid
              WHERE otype = 'P'
                AND objid = persno
                AND plvar = '01'
                AND rsign = 'B'
                AND relat = '008'
                AND istat = '1'
                AND begda LE sy-datum
                AND endda GE sy-datum
                AND sclas = 'S'.
    SELECT sobid FROM hrp1001
                 INTO hrp1001-sobid
                WHERE otype = 'S'
                  AND objid = ld_sobid
                  AND plvar = '01'
                  AND rsign = 'B'
                  AND relat = '002'
                  AND istat = '1'
                  AND begda LE sy-datum
                  AND endda GE sy-datum
                  AND sclas = 'S'.
      SELECT sobid FROM hrp1001
                  APPENDING TABLE t_pernr
                  WHERE otype = 'S'
                    AND objid = hrp1001-sobid
                    AND plvar = '01'
                    AND rsign = 'A'
                    AND relat = '008'
                    AND istat = '1'
                    AND begda LE sy-datum
                    AND endda GE sy-datum
                    AND sclas = 'P'.
      PERFORM f_get_child USING hrp1001-sobid.
    ENDSELECT.
  ENDSELECT.

  pernr_tab[] = t_pernr[].

ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  f_get_child "Baca bawahan
*&---------------------------------------------------------------------*
FORM f_get_child USING fu_sobid.

  SELECT sobid FROM hrp1001
               INTO hrp1001-sobid
              WHERE otype = 'S'
                AND objid = fu_sobid
                AND plvar = '01'
                AND rsign = 'B'
                AND relat = '002'
                AND istat = '1'
                AND begda LE sy-datum
                AND endda GE sy-datum
                AND sclas = 'S'.
    SELECT sobid FROM hrp1001
                APPENDING TABLE t_pernr
                WHERE otype = 'S'
                  AND objid = hrp1001-sobid
                  AND plvar = '01'
                  AND rsign = 'A'
                  AND relat = '008'
                  AND istat = '1'
                  AND begda LE sy-datum
                  AND endda GE sy-datum
                  AND sclas = 'P'.
    PERFORM f_get_child USING hrp1001-sobid.
  ENDSELECT.

ENDFORM.                    " f_get_child

Comments