Tips and Tricks for the ABAP® Programming Language

ZHR0001 – Reading of HR organizational data

Reading of InfoType 0001 and translating the key figures to text.

ABAP-Source-Code

You can copy and paste the source code directly into the ABAP-Workbench.

REPORT ZHR0001.
*
**********************         HEADER                    **************
*
* Copyright (c) 2001 by xxxx xxx, 44318 Anywhere, http://xxxxx
* or: Copyright (c) 2001 by X.X. from X.
*
*     You can use or modify this report for your own work as long
*               as you don't try to sell or republish it.
*      In no event will the author be liable for indirect, special,
*        Incidental, or consequental damages (if any) arising out of
*                       the use of this report.
*//////////////////////////////////////////////////////////////////////*
* Append your coding here ...
TABLES: PERNR, T500P, T001P, PA0001, PA0003, PA0006, CSKT, T513S,
        PA0002, T503T, PA0008.

INFOTYPES: 0000, 0001, 0002, 0006, 0016, 0008, 0007.

DATA:  BEGIN OF TAB OCCURS 50,
         BUKRS LIKE P0001-BUKRS,
         KOSTL LIKE P0001-KOSTL,
         TXT3(25),
         PERNR LIKE P0001-PERNR,
         NAME(50),
         TXT1(25),
         TXT2(25),
         PK(25),
         TXT4(25),
         GEBTG(10),
         STRAS LIKE P0006-STRAS,
         PSTLZ LIKE P0006-PSTLZ,
         ORT01 LIKE P0006-ORT01,
         EINDT(10),
         SACHA LIKE P0001-SACHA,
         SCHKZ LIKE P0007-SCHKZ,
         BSGRD(6),
         TRFGB LIKE P0008-TRFGB,
         TRFGR LIKE P0008-TRFGR,
*        sumbb like q0008-sumbb,
*        anzahl(2) type p value 1,     " Anzahl der selektierten MA
       END OF TAB.

DATA:  BEGIN OF TAB2 OCCURS 50,
         BUKRS LIKE P0001-BUKRS,       "Buchungskreis
         KOSTL LIKE P0001-KOSTL,       "Kostenstelle
         TXT3(25),                     "Text Kostenstelle
         PERNR LIKE P0001-PERNR,       "Personalnummer
         NAME(50),                     "Name
         TXT1(25),                     "Text Personalbereich
         TXT2(25),                     "Text Personalteilbereich
         PK(25),                       "Vertragsart
         TXT4(25),                     "Text Stelle
         GEBTG(10),                    "Geburtsdatum
         STRAS LIKE P0006-STRAS,       "Strasse
         PSTLZ LIKE P0006-PSTLZ,       "Postleitzahl
         ORT01 LIKE P0006-ORT01,       "Wohnort
         EINDT(10),                    "Eintrittsdatum IT 0016
         SACHA LIKE P0001-SACHA,       "Sachbearbeiter Abrechnung
         SCHKZ LIKE P0007-SCHKZ,       "Arbeitszeitplan
         BSGRD(6),                     "Beschäftigungsgrad
         TRFGB LIKE P0008-TRFGB,       "Tarifgebiet
         TRFGR LIKE P0008-TRFGR,       "Tarifgruppe
*        sumbb like q0008-sumbb,            "Summe Basisbezüge
*        anzahl(3),
       END OF TAB2.

DATA: BEGIN OF FIELDNAMES OCCURS 20,   " Für Excel-Tabelle, 20 Spalten
        TEXT(60), TABNAME(10), FIELDNAME(10), TYP,
      END OF FIELDNAMES.

DATA: COMPANYCODE LIKE HRCA_COMPANY-COMP_CODE,
      COMPANYTEXT LIKE HRCA_COMPANY-COMP_NAME,
      PK(25).

* parameter ------------------------------------------------------
PARAMETERS:
      P_LISTE(1) TYPE C DEFAULT 'J',   "Ausgabe Excel/Word
      P_GESCH(1) TYPE C DEFAULT '*',   "Geschlecht
      P_SORT(1) TYPE C DEFAULT 'J'.    "Sort nach Kostst

* initialization -------------------------------------------------
INITIALIZATION.
  RP-SEL-EIN-AUS-INIT.                 "Status Austritt
  PNPPERNR-LOW = '1'.                  "Feld Persnr vorbesetzen mit 1
  APPEND PNPPERNR.
  PNPTIMED = 'D'.                      "Stichtag heute

GET PERNR.
* Selektion des letzten gueltigen Arbeitsplatzsatzes ===================
  RP_PROVIDE_FROM_LAST P0001
    SPACE PN-BEGDA PN-ENDDA.
  MOVE-CORRESPONDING P0001 TO TAB.
* endprovide.

* Ceck des Geschlechts =================================================
  IF P_GESCH EQ '*'.
    CHECK P0002-GESCH EQ '1' OR P0002-GESCH EQ '2'.
  ENDIF.
  IF P_GESCH EQ 'M'.
    CHECK P0002-GESCH EQ '1'.
  ENDIF.
  IF P_GESCH EQ 'W'.
    CHECK P0002-GESCH EQ '2'.
  ENDIF.

* Selektieren der Personalnummer =======================================
  SELECT * FROM PA0001
  WHERE PERNR EQ PERNR-PERNR.
  ENDSELECT.

* Selektieren der MA mit Abrechnung ====================================
  SELECT * FROM PA0003
  WHERE PERNR EQ PERNR-PERNR.
  ENDSELECT.
  CHECK PA0003-ABRSP NE 'X'.           " Abrechnung gesperrt

* Selektieren des Textes des Personalbereiches =========================
  SELECT * FROM T500P
  WHERE PERSA EQ PA0001-WERKS.         " Personalbereich
  ENDSELECT.
  TAB-TXT1 = T500P-NAME1.

* Selektieren des Textes des Personalteilbereiches =====================
  SELECT * FROM T001P
  WHERE BTRTL EQ PA0001-BTRTL.         " Personalteilbereich
  ENDSELECT.
  TAB-TXT2 = T001P-BTEXT.

* Selektieren des Textes der Kostenstelle ==============================
  SELECT * FROM CSKT
  WHERE KOSTL EQ PA0001-KOSTL.         " Kostenstelle
  ENDSELECT.
  TAB-TXT3 = CSKT-KTEXT.

* Selektieren der Stelle ===============================================
  SELECT * FROM T513S
  WHERE STELL EQ PA0001-STELL.         " Stellenbezeichnung
  ENDSELECT.
  TAB-TXT4 = T513S-STLTX.

* Selektieren der Vertragsart ==========================================
  SELECT * FROM T503T
  WHERE PERSK EQ PA0001-PERSK.         " Vertragsart
  ENDSELECT.
  TAB-PK = T503T-PTEXT.

* Selektieren des Namens ===============================================
  MOVE P0002-NACHN TO TAB-NAME.        " Name
  MOVE P0002-VORNA TO TAB-NAME+25.
  CONDENSE TAB-NAME.

* Selektieren des Geburtsdatum =========================================
  WRITE P0002-GBPAS TO TAB-GEBTG.      " Geburtsdatum

* Selektieren der Strasse ==============================================
  WRITE P0006-STRAS TO TAB-STRAS.      " Strasse

* Selektieren der PLZ ==================================================
  WRITE P0006-PSTLZ TO TAB-PSTLZ.      " Postleitzahl

* Selektieren des Ortes ================================================
  WRITE P0006-ORT01 TO TAB-ORT01.      " Wohnort

* Selektieren des Eintrittsdatums ======================================
  WRITE P0016-EINDT TO TAB-EINDT.      " Eintrittsdatum IT 0016

* Selektieren des Sachbearbeiters ======================================
  WRITE P0001-SACHA TO TAB-SACHA.      " Sachbearbeiter Abrechnung

* Selektieren des Arbeitszeitplanes ====================================
  WRITE P0007-SCHKZ TO TAB-SCHKZ.      " Arbeitszeitplan

* Selektieren des Beschäftigungsgrades =================================
  SELECT * FROM PA0002 WHERE PERNR EQ PERNR-PERNR.
  ENDSELECT.
  SELECT * FROM PA0008 WHERE PERNR EQ PERNR-PERNR.
  ENDSELECT.
  WRITE P0008-BSGRD TO TAB-BSGRD.      " Beschäftigungsgrad

* Selektieren des Tarifgebiets =========================================
  WRITE P0008-TRFGB TO TAB-TRFGB.      " Tarifgebiet

* Selektieren der Tarifgruppe ==========================================
  WRITE P0008-TRFGR TO TAB-TRFGR.      " Tarifgruppe

* Selektieren der Kostenstelle =========================================
  WRITE P0001-KOSTL TO TAB-KOSTL.      " Kostenstelle

* Selektieren der Summe Basisbezüge ====================================
* write q0008-sumbb to tab-sumbb.      " Summe Basisbezüge

  COLLECT TAB.

* Verarbeitung am Ende der Datenselektion
END-OF-SELECTION.
  SORT TAB.                            " sortieren von Tab
  LOOP AT TAB.
    AT NEW BUKRS.
      COMPANYCODE = TAB-BUKRS.
      CALL FUNCTION 'HRCA_COMPANYCODE_GETDETAIL'
           EXPORTING
                COMPANYCODE       = COMPANYCODE
                LANGUAGE          = SY-LANGU
           IMPORTING
                COMP_NAME         = COMPANYTEXT
*               CITY              =
*               COUNTRY           =
*               CURRENCY          =
*               LANGU             =
*               CHRT_ACCTS        =
*               FY_VARIANT        =
*               FI_MANAGEMENTAREA =
*               JURISDICTION      =
*               RATE_DEVIATION    =
*               ADDRESS           =
           EXCEPTIONS
                NOT_FOUND         = 1
                OTHERS            = 2.

      IF SY-SUBRC <> 0.
        CLEAR COMPANYTEXT.
        WRITE: / 'Text konnte nicht bestimmt werden'(001).
      ENDIF.

    ENDAT.

  ENDLOOP.

* Druckoption ==========================================================
  IF P_LISTE EQ 'J'.
    PERFORM BASIC_LIST.
  ELSE.
    PERFORM TAB-ZEILE.
  ENDIF.

*-----------------------------------------------------------------
* Drucken der Zeile
FORM TAB-ZEILE.
  IF P_SORT EQ 'J'.
    SORT TAB BY KOSTL.
  ELSE.
    SORT TAB BY PERNR.
  ENDIF.
  LOOP AT TAB.

    WRITE: /20 TAB-BUKRS,'*', TAB-KOSTL,'*', TAB-TXT3,'*',
               TAB-PERNR,'*', TAB-NAME,'*',
               TAB-TXT1,'*', TAB-TXT2,'*', TAB-PK,'*', TAB-TXT4,'*',
               TAB-GEBTG DD/MM/YYYY,'*', TAB-STRAS,'*', TAB-PSTLZ,'*',
               TAB-ORT01,'*', TAB-EINDT DD/MM/YYYY, '*', TAB-SACHA,'*',
               TAB-SCHKZ,'*', TAB-BSGRD,'*', TAB-TRFGB,'*', TAB-TRFGR.
    ULINE.
  ENDLOOP.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM BASIC_LIST                                               *
*---------------------------------------------------------------------*
FORM BASIC_LIST.
  IF P_SORT EQ 'J'.
    SORT TAB BY KOSTL.
  ELSE.
    SORT TAB BY PERNR.
  ENDIF.
  LOOP AT TAB.
    MOVE-CORRESPONDING TAB TO TAB2.

    APPEND TAB2.
  ENDLOOP.
  PERFORM SPALTEN_UEB.                 "Spaltenueberschrift
  CALL FUNCTION 'HR_DISPLAY_BASIC_LIST'
       EXPORTING
          BASIC_LIST_TITLE     = SY-TITLE
          FILE_NAME            = 'ZP270002'
          HEAD_LINE1           = 'Organisatorische Zuordnung'
*         HEAD_LINE2           = ' '
*         FOOT_NOTE1           = ' '
*         FOOT_NOTE2           = ' '
*         FOOT_NOTE3           = ' '
*         lay_out              = 0
*         DYN_PUSHBUTTON_TEXT1 =
*         DYN_PUSHBUTTON_TEXT2 =
*         DYN_PUSHBUTTON_TEXT3 =
*         DYN_PUSHBUTTON_TEXT4 =
*         DYN_PUSHBUTTON_TEXT5 =
*         DYN_PUSHBUTTON_TEXT6 =
*         DATA_STRUCTURE       = ' '
*         HEAD_LINE3           = ' '
*         HEAD_LINE4           = ' '
*         CURRENT_REPORT       =
*         LIST_LEVEL           = ' '
*         ADDITIONAL_OPTIONS   = ' '
*         WORD_DOCUMENT        =
*    IMPORTING
*         RETURN_CODE          =
       TABLES
          DATA_TAB             = TAB2
          FIELDNAME_TAB        = FIELDNAMES
*         SELECT_TAB           =
*         ERROR_TAB            =
       EXCEPTIONS
            DOWNLOAD_PROBLEM     = 1
            NO_DATA_TAB_ENTRIES  = 2
            TABLE_MISMATCH       = 3
            PRINT_PROBLEMS       = 4
            OTHERS               = 5.
ENDFORM.

*---------------------------------------------------------------------*
* Spaltenueberschriften fuer EXCEL-Tabelle
*---------------------------------------------------------------------*
FORM SPALTEN_UEB.
  PERFORM INIT_FIELDNAMES USING 'Bukr     '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Kostst   '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Kosttext '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Persnr   '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Name     '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'PB       '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'PTB      '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Vertragsart'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Stelle   '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Geburtsdatum'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Strasse  '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'PLZ      '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Ort      '    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Eintrittsdatum'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Sachbearbeiter'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Arbeitszeitplan'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Beschäftigungsgrad'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Tarifgebiet'    ' '  ' ' SPACE.
  PERFORM INIT_FIELDNAMES USING 'Tarifgruppe'    ' '  ' ' SPACE.
* perform init_fieldnames using 'Summe Basisbez.'    ' '  ' ' space.
  PERFORM INIT_FIELDNAMES USING '         '    ' '  ' ' SPACE.
ENDFORM.

*&---------------------------------------------------------------------*
*       Fuellen der Strukturtabelle fieldnames.                        *
*----------------------------------------------------------------------*
*  -->  field1, field2, field3, field4.
*----------------------------------------------------------------------*
FORM INIT_FIELDNAMES USING FIELD1 FIELD2 FIELD3 FIELD4.
  FIELDNAMES-TEXT = FIELD1.
  FIELDNAMES-TABNAME = FIELD2.
  FIELDNAMES-FIELDNAME = FIELD3.
  FIELDNAMES-TYP = FIELD4.
  APPEND FIELDNAMES. CLEAR FIELDNAMES.
ENDFORM.                               " INIT_FIELDNAMES