Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[ABAP] Read personnel area with text

  DATA p0001 TYPE p0001.
  cl_hcmfab_utilities=>read_infotype_record( EXPORTING iv_pernr = pernr
                                                       iv_infty = '0001'
                                             IMPORTING es_pnnnn = p0001 ).
  DATA(personnel_area_id)   = p0001-werks.
  DATA(personnel_area_text) = cl_hr_t500p=>read( p0001-werks )-name1.

Or using the class CL_HCMFAB_EMPLOYEE_API.

  DATA(lv_employee_details) = cl_hcmfab_employee_api=>get_instance( )->get_employee_details( iv_pernr          = pernr
                                                                                             iv_application_id = if_hcmfab_constants=>gc_application_id-mypersonaldata ).
  DATA(personnel_area_id)   = lv_employee_details-personnel_area_id.
  DATA(personnel_area_text) = lv_employee_details-personnel_area_text.

[HR] TMW – Time-Manager-Workplace BAdI

Transaktion: PTMW
BAdI: PT_BLP_USER

Badi Implementierung anlegen und Filter-Ausprägungen hinzufügen. Es muss für jede benötigte Filter-Ausprägung eine eigene BAdI Implementierung und Klasse angelegt werden.

Klasse anlegen und in der Interface Methode die Kundenlogik, wie in der Dokumentation empfohlen, in eine private Methode kapseln.
Bsp.:

  METHOD if_ex_pt_blp_user~process_data.


    CHECK i_record IS BOUND.

    IF  i_record->data->category = cl_pt_tmw_tdm_const=>cat_infty
    AND i_record->data->type     = '2001'.

      "hier die erforderliche Logik rein, z.B. weitere Prüfungen
      process_it2001( EXPORTING i_record    = i_record            " Aktueller Satz
                                i_time_data = i_time_data         " Aktuelle Zeitdaten
                      IMPORTING e_messages  = e_messages          " Ausgabemeldungen für die Transaktion
                                e_time_data = e_time_data   ).    " Neue und geänderte Daten

      "An den konkreten Infotypsatz kommt man z.B. folgendermaßen:
      DATA(record_data) = CAST cl_pt_td_it2001( i_record->data ).
      DATA(p2001)       = record_data->if_pt_td_it2001~p2001.

    ENDIF.


  ENDMETHOD.

[ABAP] OM – Lese Personen auf und unterhalb einer OE

Liefert unter einer Orgeinheit alle Personen. Auch in tieferen OE.

    DATA(lt_actor) = VALUE tswhactor( ).
    CALL FUNCTION 'RH_STRUC_GET'
      EXPORTING
        act_otype       = 'O'
        act_objid       = lv_oe
        act_wegid       = 'O-O-S-P'
        act_plvar       = '01'
        act_begda       = sy-datum
        act_endda       = sy-datum
        act_tflag       = space
        act_vflag       = space
        authority_check = space
      TABLES
        result_tab      = lt_actor
      EXCEPTIONS
        no_plvar_found  = 1
        no_entry_found  = 2
        OTHERS          = 3.
    IF sy-subrc <> 0.
      CONTINUE.
    ENDIF.

    " Nur Pernr's relevant
    DELETE lt_actor WHERE otype <> 'P'.
    " Doppelte Pernr's entfernen
    DELETE ADJACENT DUPLICATES FROM lt_actor.

[HR] Infotype – add PBO or PAI logic

There are many ways to add custom logic when processing an Infotype. Here are just a few:

SMOD
PBAS0001
PBAS0002

ZXPADU01 – when an infotype is called
ZXPADU02 – when an action is performed on an infotype

https://regotz.jimdofree.com/abap/dynpro/infotypen-pai-pbo/

BAdI’s

  • HRPAD00INFTY (method IN_UPDATE) is called by the old infotype framework (PA30, SAP50UPR)
  • HRPAD00INFTYDB (method UPDATE_DB) is called in the decoupled infotype framework

BAdI: HRPAD00INFTY – Verbucher / Infotyp-Pflege

This image has an empty alt attribute; its file name is image-1.png
This image has an empty alt attribute; its file name is image-2.png
Interface: IF_EX_HRPAD00INFTY

BAdI: HRPAD00INFTYDB – HR: Stammdaten, Infotype DB Update Logik

“The BAdI is called, after the decoupled infotype framework writes the infotype data to the database. This is done during method FLUSH.”
Note: The Infotypes 2000-2999 are not decoupled yet! More here and here.

IF_EX_HRPAD00INFTYBL
IF_EX_HRPAD00INFTYDB

[HR] Abrechnungsergebnisse lesen

Reports:

RPCLSTRD – Anzeige des Clusters RD (Abrechnungsergebnisse Deutschland), Tcode: PC_PAYRESULT
H99_DISPLAY_PAYRESULT – Anzeigen von Abrechnungsergebnissen

Abrechnungsergebnistabelle:

Eine sehr schöne Übersicht über die Tabellen: https://l3consulting.de/die-tabellen-im-abrechnungscluster-des-sap-hcm-verstehen/
Die Tabelle RT enthält die Ergebnislohnarten der ausgewählten Abrechnungsperiode. (RT_ = komprimierte Darstellung)

Funktionsbausteine:

HR_GET_PAYROLL_RESULTS – Lesen von Abrechnungsergebnissen für Monats- und Jahresreports
PYXX_READ_PAYROLL_RESULT – Generischer Import von Abrechnungsergebnissen
HRCM_PAYROLL_RESULTS_GET – Abrechnungsdaten einer Person ermitteln

Hinweise zu Bausteinen: https://blog.hr-manager.de/2011/09/abap-abrechnungsergebnisse-lesen-per.html

Logische Datenbank:

Eine weitere Möglichkeit ist die Nutzung der logischen Datenbank PNP. Die Verwendung logischer Datenbanken ist jedoch obsolet (zumindest in anderen Modulen) und sollten daher eigentlich nicht mehr verwendet werden.

*&---------------------------------------------------------------------*
*& Report  ZGETPAYROLL
*& Eigenschaften: Selektionsbildvariante 900, HR-Reportklasse PY_DEF.
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZGETPAYROLL.

TABLES: PERNR, PYORGSCREEN, PYTIMESCREEN.

INFOTYPES: 0002.

NODES: PAYROLL TYPE PAYDE_RESULT.

DATA: WA_RT TYPE PC207.

START-OF-SELECTION.

GET PERNR.

RP_PROVIDE_FROM_LAST P0002 SPACE PN-BEGDA PN-ENDDA.

WRITE:/ PERNR-PERNR, P0002-VORNA, P0002-NACHN.

GET PAYROLL.

  LOOP AT PAYROLL-INTER-RT INTO WA_RT.
    WRITE:/ WA_RT-LGART, WA_RT-BETRG.
  ENDLOOP.

END-OF-SELECTION.

Oder in Kombination mit einem Fuba:

*&---------------------------------------------------------------------*
*& Report  ZGETPAYROLL
*& Eigenschaften: HR-Reportklasse __M00001.
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZGETPAYROLL.

TABLES: pernr.               "Necessary for get pernr

INFOTYPES: 0001,             "Organisatorische Zuord
           0002,             "Daten zur Person
           0006,             "Anschrift
           0057.             "Mitgliedschaften

DATA: l_payroll_result TYPE payat_result OCCURS 0 WITH HEADER LINE.


START-OF-SELECTION.

GET pernr.

rp_provide_from_last p0001 '' pn-begda pn-endda.

CALL FUNCTION 'HR_GET_PAYROLL_RESULTS'
    EXPORTING
      pernr                         = pernr-pernr
      permo                         = pn-permo
      pabrj                         = pn-pabrj
      pabrp                         = pn-pabrp
      actual                        = space         "X actual, ' ' retro-differences
      waers                         = 'EUR'
    TABLES
      result_tab                    = l_payroll_result
    EXCEPTIONS
      no_results                    = 0
      wrong_structure_of_result_tab = 2
      OTHERS                        = 4.
  IF sy-subrc NE 0.
    RETURN. "nächste Pernr
  ENDIF.

[ABAP] Read IT0008 lgart values

Oldschool abap…

  DATA: BEGIN OF i0008,               
        lgart LIKE p0008-lga01,                         
        betrg LIKE p0008-bet01,
        anzhl LIKE p0008-anz01,
        eitxt LIKE p0008-ein01,
        opken LIKE p0008-opk01,
        indbw LIKE p0008-ind01,                                  
        END OF i0008.

  rp-provide-from-last p0008 space pn-begda pn-endda.    

  DO 40 TIMES                                                   
           VARYING i0008-lgart FROM p0008-lga01 NEXT p0008-lga02
           VARYING i0008-betrg FROM p0008-bet01 NEXT p0008-bet02
           VARYING i0008-anzhl FROM p0008-anz01 NEXT p0008-anz02
           VARYING i0008-eitxt FROM p0008-ein01 NEXT p0008-ein02
           VARYING i0008-opken FROM p0008-opk01 NEXT p0008-opk02
           VARYING i0008-indbw FROM p0008-ind01 NEXT p0008-ind02.
      IF i0008-lgart = '2001'.
        EXIT.
      ENDIF.
  ENDDO.

[Fiori] Send notification mail if workitem is forwarded in MyInbox

Workitem function modules

If you forward a workitem manually from the MyInbox or via function module SAP_WAPI_FORWARD_WORKITEM, the function module SWW_WI_FORWARD will be called. There the SAP implemented a BAdI call of the BAdI WF_WI_FORWARD.

BAdI WF_WI_FORWARD

The BAdI provides a method to add additional checks, when forwarding a workitem. I will use it, to send notification mails.

BAdI Filter

Create your own BAdI implementation and add a task id as filter. In my case it’s the task TS21500003 of the leave request approval workflow.
Now your implementation will only be called, if this specific workitem is forwarded. Now we implement the method CHECK_BEFORE_FORWARD. The method has enough parameters to get all necessary information to enrich the mail text.

IF_EX_WF_WI_WORKITEM~CHECK_BEFORE_FORWARD Paramter

First the workitem container is read out of the context. There we get the _WI_OBJECT_ID element, which contains the request object reference. With this information we are able to get the current request object out of the workflow. I pass this into antother class where I already have a mail sending implementation.

  METHOD if_ex_wf_wi_workitem~check_before_forward.
*---------------------------------------------------------------------------------*
* This BAdI implementation is used to send an info mail when a workitem is forwarded.
*---------------------------------------------------------------------------------*

    TRY.

        "Get workitem container and requestId
        DATA(container) = im_workitem_context->get_wi_container( ).

        container->get_value_ref( EXPORTING name       = |_WI_OBJECT_ID|
                                  IMPORTING value_ref  = DATA(lr_req_id) ).

        ASSIGN lr_req_id->* TO FIELD-SYMBOL(<lpor>).

        "Get current request object
        DATA(lo_req) = NEW cl_pt_req_wf_attribs( )->bi_persistent~find_by_lpor( lpor = <lpor> ).

        "Send an info mail to each new agent (should be only one)
        LOOP AT im_table_new_agents INTO DATA(new_agent).
          zcl_hcm_leave_request_assist=>send_mail( io_req         = CAST cl_pt_req_wf_attribs( lo_req )
                                                   iv_tdname      = mc_mailtext
                                                   iv_pernr       = cl_hcmfab_employee_api=>get_instance( )->get_employeenumber_from_user( iv_user = new_agent-objid ) ).
        ENDLOOP.


      CATCH cx_hcmfab_common.
      CATCH cx_swf_cnt_elem_not_found.
      CATCH cx_swf_cnt_container.
        "In error case, do nothing. The workitem should still be forwarded.
        RETURN.
    ENDTRY.

    "Write Info to WF Log
    MESSAGE s001(00) WITH |Forward: Mail { mc_mailtext }| INTO DATA(lv_message).
    im_workitem_context->set_message_to_log( im_function = CONV #( lv_message )         "max char30
                                             im_message = VALUE #( msgid = sy-msgid
                                                                   msgty = sy-msgty
                                                                   msgno = sy-msgno
                                                                   msgv1 = sy-msgv1 ) ).
    COMMIT WORK.
  ENDMETHOD.

At the end I’m writing a little notification in the workflow log. The workitem context provides the method set_message_to_log for this. The log will look like this.

[ABAP] Access leave request attributes

cl_pt_req_badi=>get_request( EXPORTING im_req_id  = request_id
                             IMPORTING ex_request = DATA(request) ).

request->get_all_attribs( IMPORTING ex_attribs_struc = DATA(req_attribs) ).

DATA(req_begda) = req_attribs-version-item_tab[ 10 ]-value.

Take a look in the item_tab to see the specific request values.