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

[ABAP] Z_CLEANUP_LRQ_WORKFLOWS

A cleanup report I’ve written some years ago, to end incomplete leave request workflows. I couldn’t figure out why some workflows hadn’t been completed over the years. Since the absences were from a long time ago, the goal was simply to clean up the system. Maybe someone else will need to do something similar someday.

*&---------------------------------------------------------------------*
*& Report Z_CLEANUP_LRQ_WORKFLOWS
*&---------------------------------------------------------------------*
*& This report was written to end old absence request workflows,
*& where the absence request got already approved,
*& but somehow the WF got not set to status 'COMPELTED'.
*& https://me.sap.com/notes/0002650820
*&---------------------------------------------------------------------*
REPORT z_cleanup_lrq_workflows.

TABLES: ptreq_header, swwwihead, pa0002.

TYPES:
  BEGIN OF ty_log,
    icon          TYPE icon-id,
    objid         TYPE objektid,
    vorna         TYPE vorna,
    nachn         TYPE nachn,
    request_id    TYPE ptreq_header-request_id,
    version_no    TYPE tim_req_version,
    request_type  TYPE tim_req_type,
    status        TYPE tim_req_status,
    mod_timestamp TYPE timestamp,
    timestamp     TYPE string,
    workitem_id	  TYPE sww_wiid,
    wi_stat       TYPE sww_wistat,
    wi_stat_new   TYPE sww_wistat,
    comment       TYPE string,
  END OF ty_log.

DATA gt_log     TYPE TABLE OF ty_log WITH DEFAULT KEY.
DATA return     TYPE TABLE OF swl_return.
DATA new_status TYPE sww_wistat.
DATA status     TYPE ptarq_uia_request-status.

INITIALIZATION.

  SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-b01.

    SELECT-OPTIONS: s_pernr FOR pa0002-pernr              MATCHCODE OBJECT prem,
                    s_guid  FOR ptreq_header-request_id,
                    s_rtype FOR ptreq_header-request_type DEFAULT 'ABSREQ',
                    s_statu FOR status                    DEFAULT 'POSTED',
                    wi_stat FOR swwwihead-wi_stat         DEFAULT 'STARTED'.

    PARAMETERS: fdate  TYPE datum DEFAULT '20180101',
                ftime  TYPE tims,
                tdate  TYPE datum DEFAULT '20231231',
                ttime  TYPE tims,
                p_test AS CHECKBOX DEFAULT abap_true.

  SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  CONVERT DATE fdate TIME ftime INTO TIME STAMP DATA(ts_from) TIME ZONE 'UTC'.
  CONVERT DATE tdate TIME ttime INTO TIME STAMP DATA(ts_upto) TIME ZONE 'UTC'.

  SELECT a~request_id, a~version_no, a~status, a~request_type, a~mod_timestamp, a~workitem_id, b~objid, c~wi_stat, d~vorna, d~nachn
    FROM ptreq_header    AS a
        JOIN ptreq_actor AS b ON a~initiator_ins = b~actor_id
        JOIN swwwihead   AS c ON a~workitem_id   = c~wi_id
        JOIN pa0002      AS d ON b~objid         = d~pernr
    INTO CORRESPONDING FIELDS OF TABLE @gt_log
    WHERE a~request_id    IN @s_guid
      AND a~status        IN @s_statu
      AND a~request_type  IN @s_rtype
      AND a~mod_timestamp BETWEEN @ts_from AND @ts_upto
      AND b~objid         IN @s_pernr
      AND c~wi_stat       IN @wi_stat.

END-OF-SELECTION.

  LOOP AT gt_log ASSIGNING FIELD-SYMBOL(<log>).

    <log>-timestamp = |{ <log>-mod_timestamp TIMESTAMP = ENVIRONMENT }|.

    IF p_test = abap_true.
      <log>-comment = |Testrun! No workflow changed!|.
      CONTINUE.
    ENDIF.

    IF <log>-wi_stat <> |STARTED|. CONTINUE. ENDIF.

    CALL FUNCTION 'SWL_ADM_WI_COMPLETE'
      EXPORTING
        wi_id                         = <log>-workitem_id
      TABLES
        return                        = return
      EXCEPTIONS
        workitem_not_found            = 1
        no_authority                  = 2
        wrong_workitem_type           = 3
        workflow_definition_not_found = 4
        internal_error                = 5
        action_canceled               = 6
        OTHERS                        = 7.
    IF sy-subrc <> 0.
      <log>-icon    = icon_red_light.
      <log>-comment = COND #( WHEN lines( return ) > 0 THEN return[ 1 ]-text
                                                       ELSE SWITCH #( sy-subrc WHEN 1 THEN |workitem_not_found|
                                                                               WHEN 2 THEN |no_authority|
                                                                               WHEN 3 THEN |wrong_workitem_type|
                                                                               WHEN 4 THEN |workflow_definition_not_found|
                                                                               WHEN 5 THEN |internal_error|
                                                                               WHEN 6 THEN |action_canceled|
                                                                               WHEN 7 THEN |OTHERS| ) ).
    ELSE.
      " Check if WF status really got changed
      SELECT SINGLE wi_stat FROM swwwihead INTO <log>-wi_stat_new WHERE wi_id = <log>-workitem_id.
      <log>-icon    = COND #( WHEN <log>-wi_stat_new <> |COMPLETED| THEN icon_red_light ELSE icon_green_light ).
      <log>-comment = COND #( WHEN <log>-wi_stat_new <> |COMPLETED| THEN |Something went wrong!| ).
    ENDIF.

  ENDLOOP.


  IF gt_log IS INITIAL.
    MESSAGE i002(wusl) DISPLAY LIKE 'E'.
  ELSE.
    TRY.
        cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv_table)
                                CHANGING  t_table      = gt_log ).

        alv_table->get_columns( )->get_column( 'ICON'          )->set_long_text( 'Icon' ).
        alv_table->get_columns( )->get_column( 'WI_STAT_NEW'   )->set_long_text( 'Neuer WF Status' ).
        alv_table->get_columns( )->get_column( 'WI_STAT_NEW'   )->set_medium_text( 'Neuer Status' ).
        alv_table->get_columns( )->get_column( 'COMMENT'       )->set_long_text( 'Kommentar' ).
        alv_table->get_columns( )->get_column( 'TIMESTAMP'     )->set_long_text( 'Letzte Änderung' ).
        alv_table->get_columns( )->get_column( 'COMMENT'       )->set_output_length( 100 ).
        alv_table->get_columns( )->get_column( 'TIMESTAMP'     )->set_output_length( 20 ).
        alv_table->get_columns( )->get_column( 'MOD_TIMESTAMP' )->set_visible( abap_false ).

        alv_table->display( ).

      CATCH cx_root.
    ENDTRY.
  ENDIF.

[ABAP] Display CL_BAL_LOGOBJ output as ALV in a splitcontainer

When developing a report that should also write logs (SLG1), I normaly use the class CL_BAL_LOGOBJ as described here. When using method lo_log->display( ) it displays the result in a popup. If you want to display the log as ALV some more logic is neede.

DATA ls_display_profile TYPE bal_s_prof.

TRY.
    DATA(lo_log) = NEW cl_bal_logobj(
      i_log_object        = 'Z_MY_LOG'
      i_default_subobject = 'GENERAL' ).

    lo_log->add_statustext( i_statustext = 'Processing started' ).

    lo_log->add_errortext( i_errortext = 'An error occurred during processing' ).

    CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
      IMPORTING
        e_s_display_profile = ls_display_profile.

    ls_display_profile-use_grid = abap_true.

    lo_log->display( i_disp_profile = ls_display_profile ).

  CATCH cx_bal_exception INTO DATA(lx_bal).
    MESSAGE lx_bal->get_text( ) TYPE 'I'.
ENDTRY.

In my case, I wanted to display the log next to the actual output of a report, so that I have my data result on the left side, and the application log on right side.

*--------------------------------------------------------------------*
* Create Split Container
*--------------------------------------------------------------------*

    " Create a splitter on default_screen
    DATA(o_splitter_main) = NEW cl_gui_splitter_container( parent                  = cl_gui_container=>default_screen
                                                           no_autodef_progid_dynnr = abap_true
                                                           rows                    = 1
                                                           columns                 = 2 ).

    " Width of left splitter in %
    o_splitter_main->set_column_width( id = 1 width = 75 ).

    " Get the ref from the left and right split containers
    DATA(o_container_1) = o_splitter_main->get_container( row = 1 column = 1 ).
    DATA(o_container_2) = o_splitter_main->get_container( row = 1 column = 2 ).

*--------------------------------------------------------------------*
* 1 ALV Output
*--------------------------------------------------------------------*

    TRY.
        cl_salv_table=>factory( EXPORTING r_container  = o_container_1
                                IMPORTING r_salv_table = DATA(o_salv)
                                CHANGING  t_table      = lt_sflight).
        o_salv->display( ).

      CATCH cx_salv_msg.
      CATCH cx_salv_not_found.
    ENDTRY.

*--------------------------------------------------------------------*
* 2 BAL Log
*--------------------------------------------------------------------*

    DATA ls_display_profile TYPE bal_s_prof.
    DATA lv_control_handle  TYPE balcnthndl.

    DATA(lt_log_handles) = VALUE bal_t_logh( ( mo_log->if_bal_logger~mv_loghandle ) ).

    CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
      IMPORTING
        e_s_display_profile = ls_display_profile.

    ls_display_profile-use_grid = abap_true.

    " Increase the width of the message text column
    LOOP AT ls_display_profile-mess_fcat ASSIGNING FIELD-SYMBOL(<ls_fcat>)
         WHERE ref_table = 'BAL_S_SHOW'
           AND ref_field = 'T_MSG'.
      <ls_fcat>-outputlen = 200.
    ENDLOOP.

    CALL FUNCTION 'BAL_CNTL_CREATE'
      EXPORTING
        i_container          = o_container_2
        i_s_display_profile  = ls_display_profile
        i_t_log_handle       = lt_log_handles
      IMPORTING
        e_control_handle     = lv_control_handle
      EXCEPTIONS
        profile_inconsistent = 1
        internal_error       = 2
        OTHERS               = 3.

  ENDMETHOD.

*--------------------------------------------------------------------*
*  Force output
*--------------------------------------------------------------------*
    WRITE: space.

I really like the result

[Firefox] Tab-Container für Fiori Launchpad

Seit Firefox 153 werden die Tab-Container standardmäßig unterstützt und machen die Erweiterung Firefox Multi-Account Containers überflüssig. Das ist besonders praktisch, wenn man häufiger mit Web-Anwendungen arbeitet, bei denen man verschiedene Benutzer testen muss. Da ich viel mit Fiori Apps und Workflows zu tun habe, muss ich hier häufig mit 3 oder 4 Benutzern abwechselnd testen, um einen Workflow vom Antrag bis zur Genehmigung durchzuspielen. Dafür habe ich mir nun einfach 4 Tab-Container definiert und kann mich in jedem Container mit einem separaten User am Fiori Launchpad anmelden. Super praktisch!

Eine vergleichbare Funktion konnte ich für Edge oder Chrome bisher nicht finden. Hier ist man meist auf das normale Fenster + ein privates Fenster beschränkt. Leider steht in den IT-Landschaften der Kunden Firefox immer seltener zur Verfügung …

[FI-TV] My Travel and Expenses for Business Traveler: Change submit disclaimer text

When submitting an expense report, a disclaimer text is shown, similar to this:

This note 2836713 describes how to change the disclaimer text.

View: T706_WEB_DOCU

FITVFELD_WEB

If the new text is not displayed, perhaps this note must be imported: 3764137. It adds the following get_submit_text method call in the service:

[HR] Integration mit SuccessFactors Employee Central – Transformationsvorlagengruppe auf Unternehmen einschränken

Vor einer Weile musste ich mich recht kurzfristig in das oben genannte Thema einarbeiten. Ich hatte bisher nie konkret damit zu tun und habe daher erstmal die entsprechende SAP Help Seite überflogen. Relativ schnell habe ich zum Glück den für mich relevanten Teil gefunden.

https://help.sap.com/docs/SAP_SUCCESSFACTORS_EMPLOYEE_CENTRAL_INTEGRATION_TO_SAP_BUSINESS_SUITE/a7f164924edd4dfe817b7bdc2fc4927a/56933b4271554a10a5a2594789419e85.html?locale=en-US&version=2511

Das relevante Customizing findet man in der SPRO hier:

Die Unternehmen findet man in SF z.B. unter Admin Center → Manage Date → Legal Entity

Report zum Testen: ECPAO_EE_ORG_REPL_QUERY

[FI-TV] My Travel and Expenses for Business Traveler: Change default approver

I was working with the Fiori App My Travel and Expenses for Business Traveler and implemented a new approval workflow. Unlike in the SAP standard workflow, the first approver was not the boss of the employee. The workflow was already working fine, but when sending the travel expense from the Fiori app, it still displayed the boss as approver.

Naturally, the Fiori app does not know anything from the changes on the workflow. So I had to figure out where this approver value comes from and how I could adjust it to match the workflow logic.

I first went to the official documentation to check if there is any BAdI to change/overwrite the approver.

I also checked the note 3260453 – Enablement of Custom Logic for Key User Extensibility option in S/4HANA FIORI app MTE, but it seems like no BAdI was doing the job.

Spoiler: Actually there is a BAdI called FIN_TRV_APPROVER_NAME, but it is not listed here or anywhere else in the documentation. As many times before, incomplete SAP documentation wasted hours of my life…..

Because I could not find a BAdI, I went to the RAP service, to check where the approver is set and if it’s possible to overwrite it in someway.

When clicking the Create and send button in Fiori, a POST request to the endpoint CheckTripAmounts is fired. The response of type cds_ui_travelexpensemanage.TravelExpenseType contains the required value in field TrvlExpnApproverName.

I already knew the corresponding package for RAP-Service.

In package ODATA_TRV_MTE_UI_MANAGE I found the root view entity C_TravelExpense which contained the property TrvlExpnApproverName. Its projection I_TravelExpense was located in package VDM_TRV_MTE_UI_MANAGE. I was already afraid, that the approver is somehow read via some CDS association, but it turned out to be added as empty field and properly therefore is manually filled in some behavior implementation.

cast ( ' ' as vdm_trvlexpnapprovername )                                                                             as TrvlExpnApproverName,

The related behavior implementation was in class CL_BP_I_TRAVELEXPENSE and there I found the CheckTripAmounts method, which matched the POST request I saw in the Dev console. And here I found the following logic.

    DATA l_trvlexpnapprovername TYPE char40.
    cl_trv_business_data_s4=>get_approver( EXPORTING iv_employeenumber = api->get_header( )->get_pernr( )
                                                     io_header = api->get_header(  )
                                           IMPORTING ev_approver_name  = l_trvlexpnapprovername
                                                     et_messages       = lt_return ).

When looking in the get_approver method I found the default approver logic via OM, but also a BAdI call at the end.

    DATA lo_badi TYPE REF TO fin_trv_approver_name.
    TRY.
        GET BADI lo_badi.
        DATA(ls_general_data) = io_header->get_general_data( ).
        CALL BADI lo_badi->change_approver_name
          EXPORTING
            iv_traveller_pernr = iv_employeenumber
            is_general_data    = ls_general_data
          CHANGING
            cv_approver_name   = ev_approver_name
            cv_approver_pernr  = ev_approver_pernr.
      CATCH cx_root.
    ENDTRY.

Turned out, there is BAdI to overwrite the approver, it was just not documented…………………. all other eight BAdI’s are mentionend in the documentation.

[Fiori] Meine Formulare: Entgeltnachweise ausblenden “in Vertretung von” (onBehalf)

Möchte man Führungskräften die Möglichkeit geben, in der MyForms App die Formulare ihrer Mitarbeiter einzusehen, kann dies einfach über den HCMFAB_B_COMMON BAdI in der Methode GET_CONFIGURATION realisiert werden.

      IF iv_application_id = gc_application_id-myhrforms.
        ev_enable_onbehalf = boolc( go_employee_api->is_manager( iv_application_id = iv_application_id
                                                                 iv_pernr          = iv_employee_number ) = abap_true ).
      ENDIF.

Im Standard werden der Zeitnachweis und Entgeltnachweis angezeigt. Möchte man nun für die Führungskraft den Entgeltnachweis ausblenden, kann dies über den BAdI HCMFAB_BI_MYFORMS gemacht werden.

In der Methode GET_HIDE_REM_TIME_STATEMENT kann dies z.B. so realisiert werden.

        ev_hide_rem  = abap_false.
        ev_hide_time = abap_false.

        DATA(ownpernr) = go_employee_api->get_employeenumber_from_user( ).

        IF iv_pernr <> ownpernr.
          ev_hide_rem = abap_true.
        ENDIF.

Die Variable ev_hide_rem verhindert das Hinzufügen des Entgeltnachweises im folgenden, wie ab Zeile 25 zu sehen.

Jedoch ist nach meiner Beobachtung das noch nicht ausreichend, da in der Methode FILL_FORM_TYPES der Entgeltnachweis dann doch wieder hinzugefügt wird.

Daher habe ich den Entgeltnachweis zusätzlich noch in der Methode FILL_FORM_TYPES entfernt.

      DATA(ownpernr) = go_employee_api->get_employeenumber_from_user( ).

      IF iv_pernr <> ownpernr. " Manager dürfen nur Zeitnachweise ihrer Mitarbeiter sehen
        DELETE ct_form_types WHERE form_type <> 'SAP_INT_TIM_STM'.
        RETURN.
      ENDIF.

Die Führungskraft kann nun ausschließlich den Zeitnachweis des Mitarbeiters sehen. Er selbst kann alle Formulare wie gewohnt einsehen.

[Fiori] Meine Formulare: Zeitnachweis Spalten ausblenden

In der Meine Formulare App können über den BAdI HCMFAB_B_MYFORMS ganz einfach Spalten ausgeblendet werden. Dafür eine BAdI Implementierung anlegen und die Methode FILL_FORM_SPECIFIC_FIELDS ausprogrammieren. Zum Entfernen einer Spalte muss diese einfach aus dem CHANGING Parameter ct_form_specific_fields gelöscht werden.

Dabei einfach über den FORM_TYPE auf das entsprechende Formular filtern und die gewünschte Spalte entfernen:

DELETE ct_form_specific_fields WHERE form_type = 'SAP_INT_TIM_STM' AND field_id = 'DEVIATION'.  "Abweichung entfernen