Retrieve text for SAP HR Organisation unit

The ABAP code examples below provide a number of ways in which you can retrieve the SAP hr organisation unit text. If you get the org text directly from the SAP HRP1000 table or via the function module HR_READ_FOREIGN_OBJECT_TEXT then you will get the full text as seen in PA20 and PA30 etc where as using table t527x will only return the first 25 characters of the org. text.

* Retrieve org unit text from HRP1000 table 
infotypes: 0001.
DATA: ld_orgtx(40) type c.
*Retrieve Org. Unit text
  PERFORM get_org_unit USING p0001-orgeh
                             p0001-begda
                             p0001-endda
                       CHANGING ld_orgtx.
*&---------------------------------------------------------------------*
*&      Form  get_org_unit
*&---------------------------------------------------------------------*
* Retrieve Org. Unit text
*----------------------------------------------------------------------*
FORM get_org_unit USING    p_orgeh
                           p_begda
                           p_endda
                  CHANGING p_orgtx.
        select single stext
          from HRP1000
          into p_orgtx
         where plvar eq '01' and
               otype eq 'O' and
               objid eq p_orgeh and
               begda le p_begda and
               endda ge p_endda and
               langu eq sy-langu.
ENDFORM.                    " get_org_unit

* Retrieve org unit text using FM HR_READ_FOREIGN_OBJECT_TEXT 
infotypes: 0001.
DATA: ld_orgtx(40) type c.
*Retrieve Org. Unit text
  PERFORM get_org_unit USING p0001-orgeh
                             p0001-begda
                             p0001-endda
                       CHANGING ld_orgtx.
*&---------------------------------------------------------------------*
*&      Form  get_org_unit
*&---------------------------------------------------------------------*
* Retrieve Org. Unit text
*----------------------------------------------------------------------*
FORM get_org_unit USING    p_orgeh
                           p_begda
                           p_endda
                  CHANGING p_orgtx.
  DATA: orgeh_short(12) TYPE c,
        orgeh_stext(40) TYPE c,
        read_return TYPE i.
* Returns full orgunit text, entry in table t527x is sometimes
* truncated so that it fits into a 25 character field
  CALL FUNCTION 'HR_READ_FOREIGN_OBJECT_TEXT'
       EXPORTING
          otype                   = 'O'
*         otype                   = ot_orgunit
            objid                   = p_orgeh   "p0001-orgeh
            begda                   = p_begda   "p0001-begda
            endda                   = p_endda   "p0001-endda
            reference_date          = p_begda   "p0001-begda
       IMPORTING
            short_text              = orgeh_short
            object_text             = orgeh_stext
            return                  = read_return
       EXCEPTIONS
            nothing_found           = 1
            wrong_objecttype        = 2
            missing_costcenter_data = 3
            missing_object_id       = 4
            OTHERS                  = 5.
  IF sy-subrc EQ 0.
    p_orgtx = orgeh_stext.
  ELSE.
*     If function module fails return text from text table
      select single orgtx
        from t527x
        into p_orgtx
       where orgeh eq p_orgeh and  "Replace with org. unit field
             sprsl eq sy-langu and
             ( endda ge sy-datum and
               begda le sy-datum ).
  ENDIF.
ENDFORM.                    " get_org_unit

* Retrieve org unit text from t527x table 
infotypes: 0001.
DATA: ld_orgtx(40) type c.
*Retrieve Org. Unit text
  PERFORM get_org_unit USING p0001-orgeh
                             p0001-begda
                             p0001-endda
                       CHANGING ld_orgtx.
*&---------------------------------------------------------------------*
*&      Form  get_org_unit
*&---------------------------------------------------------------------*
* Retrieve Org. Unit text
*----------------------------------------------------------------------*
FORM get_org_unit USING    p_orgeh
                           p_begda
                           p_endda
                  CHANGING p_orgtx.
select single orgtx
        from t527x
        into p_orgtx
       where orgeh eq p_orgeh and  "Replace with org. unit field
             sprsl eq sy-langu and
             ( endda ge sy-datum and
               begda le sy-datum ).
ENDFORM.                    " get_org_unit

Related Articles

Add new entry to SAP HRP1001 and other infotype tables using ABAP Function Module
Delete infotype (i.e. HRP1001) relationship record by changing the validity date of entry
Retrieve SAP HR Organisation unit relationship within HRP1001
SAP Search helps for HR org unit values
Retrieve SAP Organisation unit from HR selection screen