DATA(kostl_text) = NEW cl_hrpa_ui_convert_0859( )->get_txt_costcenter( iv_kokrs = lv_kokrs iv_kostl = lv_kostl iv_date = sy-datum ).
# Class is using FUBA 'HRCA_COSTCENTER_GETDETAIL'
Tag: HR
[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

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.

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

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.

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.

[ABAP] User ↔ Employeenumber
Class:
– CL_HCMFAB_EMPLOYEE_API
Methods:
– GET_USERID_FROM_EMPLOYEENUMBER
– GET_EMPLOYEENUMBER_FROM_USER

How to use the class:
TRY.
DATA(lv_pernr) = cl_hcmfab_employee_api=>get_instance( )->get_employeenumber_from_user( sy-uname ).
CATCH cx_hcmfab_common.
ENDTRY.
TRY.
DATA(lv_uname) = cl_hcmfab_employee_api=>get_instance( )->get_userid_from_employeenumber( lv_pernr ).
CATCH cx_hcmfab_common.
ENDTRY.
[Fiori] Leave Request Approval Steps with Custom Workflow
If you want to copy the standard workflow of the leave request approval process (WS12300111) and are adding another approval step (or you just want to add an escalation where you set the approve workitem to obsolete and create a new approval step for the next approver) you have to implement the following BAdI. In detail you only have to add the new step ID in the filter, else the approver will not see any approval or reject buttons in his inbox. See details here.
BAdI: /IWWRK/BADI_WF_BEFORE_UPD_IB



As second step you have to add the Workflow in the customizing. You’ll find further information here.



[Fiori] MyInbox BAdI’s
Paket: SWL = Business Workflow: Worklist Client

Paket: SWW = Business Workflow: Workitems

Also usefull:

[Fiori] HCM Fiori Apps: OData Classes, Functionsmodules and BAdI’s
Transactions:
PTARQ | Testumgebung Abwesenheitsmitteilung |
PTCOR | Testumgebung Zeitbuchungskorrektur |
HCM Fiori OData Services:

Request database :

BAdI’s:




Leave Request Functionsmodules:

[ABAP] Find employee subtitutes
cl_swl_substitution=>get_pers_substitutes( EXPORTING i_substituted_person = ls_substituted_person
i_start_date = sy-datum
i_end_date = sy-datum
IMPORTING et_substitutes = DATA(lt_substitutes)
EXCEPTIONS user_not_found = 1 " Benutzer existiert nicht
plan_variant_not_found = 2 " Planvariante ist nicht gepflegt
time_period_not_valid = 3 " Zeitraum ungültig
no_personal_substitution = 4 " Es handelt sich um keine persönliche Vertretung
OTHERS = 5 ).
[ABAP] Leave Request Approval Workflow with Escalation
During the leave request approval process the standard workflow WS12300111 does not include any deadlines. To archieve this you can simply copy the workflow and add a deadline at the approval task (Step 38). There are two possible ways to forward the approval step to the next processor:
1. When deadline is reached, forward the current workitem to the next approver.
2. When deadlines is reached, set current workitem to obsolete and create a new workitem and assign it to the next approver. Then you also have to add the new step ID to this BAdI Filter.
I selected the first option. In my demo the escalation is triggered after just three minutes.

The deadline generates a new exit on the approval step.

In this new exit you are able to call your own logic on finding the new approver, forward the workitem and inform him via mail if necessary.

To forward the request to the next approver, you have to forward the workitem and also set this new approver as next processor in the current leave request.
So first identify the next approver. I used RH_GET_LEADER for this.
*--------------------------------------------------*
* Get next approver
*--------------------------------------------------*
CALL FUNCTION 'RH_GET_LEADER'
EXPORTING
plvar = '01'
keydate = sy-datum
otype = is_approver-otype
objid = CONV realo( is_approver-objid )
IMPORTING
leader_type = lv_leader_type
leader_id = lv_leader_id
EXCEPTIONS
no_leader_found = 1
no_leading_position_found = 2
OTHERS = 3.
CHECK lv_leader_type EQ 'P' AND lv_leader_id IS NOT INITIAL.
CALL FUNCTION 'HR_GET_USER_FROM_EMPLOYEE'
EXPORTING
pernr = CONV pernr_d( lv_leader_id )
iv_with_authority = abap_false
IMPORTING
user = lv_userid_approver.
ev_approver-otype = |US|.
ev_approver-objid = lv_userid_approver.
Then set this new approver as next processor in your request. While doing this, it’s recommended to enqueue and dequeue the request. To get the current request object use class cl_pt_req_badi.
*--------------------------------------------------*
* Set new approver in request
*--------------------------------------------------*
" Enqueue the request
CALL FUNCTION 'ENQUEUE_EPTREQ'
EXPORTING
mode_ptreq_header = 'S'
mandt = sy-mandt
request_id = io_req->req_id
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
" Get the request object instance
CALL METHOD cl_pt_req_badi=>get_request
EXPORTING
im_req_id = io_req->req_id
IMPORTING
ex_request = DATA(lcl_request).
CALL METHOD lcl_request->set_next_processor
EXPORTING
im_actor_type = 'P'
im_plvar = '01'
im_otype = 'P'
im_objid = CONV #( lv_leader_id ). " PERNR of Next Approver
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
ENDIF.
" Dequeue the request
CALL FUNCTION 'DEQUEUE_EPTREQ'
EXPORTING
mode_ptreq_header = 'S'
request_id = io_req->req_id.
Finally forward the workitem to the new approver. There of course you need the right workitem ID of the approving step.
*--------------------------------------------------*
* Forward workitem to next approver
*--------------------------------------------------*
CALL FUNCTION 'SAP_WAPI_FORWARD_WORKITEM'
EXPORTING
workitem_id = iv_wi_id "woritem id of approving step
user_id = lv_userid_approver
language = sy-langu
do_commit = 'X'
IMPORTING
return_code = lv_subrc.
IF lv_subrc <> 0.
ENDIF.