SAP E-Recruiting ABAP Code Snippets – Part 1

SAP E-Recruiting ABAP Code Snippets to reterieve information around Requisition, Candidacy, Candidate etc.

Code may not work out-of-box as I might not have taken out all references to other part of solutions on which I worked on.

Get list of Requisitions based on filters

  METHOD get_requisitions_list.

    CONSTANTS : lc_powl_type    TYPE powl_type_ty           VALUE 'ERC_WORKCENTER_TYPE_ALL_REQ',
                lc_job_specific TYPE rcf_requisition_type   VALUE '0'.

    DATA : lo_feeder     TYPE REF TO cl_hrrcf_m_requisition_powl_ui,
           lo_singleton  TYPE REF TO cl_hrrcf_requisition_01_wl_pl,
           lo_object_ref TYPE REF TO cl_abap_tabledescr,
           lr_results    TYPE REF TO data.

    DATA :  ls_selection_fix  TYPE rcf_s_req_query_selection_pl,
            lt_crit_para      TYPE rsparams_tt,
            lt_selection_var  TYPE rsparams_tt,
            ls_selection_var  TYPE rsparams,
            lt_visible_fields TYPE rcf_t_visible_field_pl,
            lt_messages       TYPE bapirettab,
            ls_requisition    TYPE your_structure.

    FIELD-SYMBOLS : <ft_results> TYPE ANY TABLE,
                    <fs_line>    TYPE any,
                    <fs_field>   TYPE any.

    CLEAR et_requisitions .

*--------------------------------------------------------------------*
*   Create result table from POWL feeder class
*--------------------------------------------------------------------*
    CREATE OBJECT lo_feeder .

    lo_feeder->if_powl_feeder~get_object_definition(
       EXPORTING
        i_selcrit_values = lt_crit_para
        i_langu = sy-langu
        i_type  = lc_powl_type
       IMPORTING
        e_object_def = lo_object_ref  ).

    CREATE DATA lr_results TYPE HANDLE lo_object_ref.
    ASSIGN lr_results->* TO <ft_results>.

*--------------------------------------------------------------------*
* Select requisition objects
*--------------------------------------------------------------------*
    ls_selection_fix-uname                 = sy-uname. "Hiring Manager
    ls_selection_fix-req_responsible-sclas = cl_hrtmc_ta_services=>mc_user_otype .
    ls_selection_fix-req_responsible-sobid = sy-uname. "Hiring Manager
    ls_selection_fix-req_type              = lc_job_specific . "Requisition type

    ls_selection_var-selname = 'HIRMAN' .
    ls_selection_var-sign    = if_qcontrol_constants=>gc_range_sign_i.
    ls_selection_var-option  = if_qcontrol_constants=>gc_range_option_eq .
    ls_selection_var-low     = sy-uname .             "Hiring Manager User
    APPEND ls_selection_var TO lt_selection_var .

    ls_selection_var-selname = 'REQ_TYPE' .
    ls_selection_var-sign    = if_qcontrol_constants=>gc_range_sign_i.
    ls_selection_var-option  = if_qcontrol_constants=>gc_range_option_eq .
    ls_selection_var-low     = lc_job_specific .               "Requisition type
    APPEND ls_selection_var TO lt_selection_var .

    ls_selection_var-selname = 'STATUS' .
    ls_selection_var-sign    = if_qcontrol_constants=>gc_range_sign_i.
    ls_selection_var-option  = if_qcontrol_constants=>gc_range_option_eq .
    ls_selection_var-low     = 1 .                             "Status Released
    APPEND ls_selection_var TO lt_selection_var .

    lo_singleton = cl_hrrcf_requisition_01_wl_pl=>get_instance( ).

    lo_singleton->read_objects(
      EXPORTING
        is_selection_fix  = ls_selection_fix
        it_selection_var  = lt_selection_var
        iv_langu          = sy-langu
        it_visible_fields = lt_visible_fields
        iv_powl_type      = lc_powl_type
      IMPORTING
        et_results        = <ft_results>
        et_messages       = lt_messages  ).

    LOOP AT <ft_results> ASSIGNING <fs_line> .
      ASSIGN COMPONENT 'REQUISITION' OF STRUCTURE <fs_line> TO <fs_field>  .
      IF sy-subrc = 0 .
        ls_requisition-requisition = <fs_field> .
      ENDIF.

      ASSIGN COMPONENT 'ALIAS' OF STRUCTURE <fs_line> TO <fs_field> .
      IF sy-subrc = 0 .
        ls_requisition-alias1 = <fs_field> .
      ENDIF.

      ASSIGN COMPONENT 'HEADER' OF STRUCTURE <fs_line> TO <fs_field> .
      IF sy-subrc = 0 .
        ls_requisition-header =  <fs_field> .
      ENDIF.

      APPEND ls_requisition TO your_internal_table .

    ENDLOOP .

  ENDMETHOD.
All classes related with E-recuitment starts with CL_HRRCF.

Get Position and Position text of Requisition

FORM a .

  DATA : lo_requisition    TYPE REF TO cl_hrrcf_requisition,
         lv_position_id    TYPE hrobjid,
         lv_position_text  TYPE hrp1000-stext,
         lv_requisition_id TYPE hrobjid.

  DATA : lt_vacancy_list TYPE rcf_t_requisition_vacancy,
         ls_vacancy      TYPE rcf_s_requisition_vacancy.


*--------------------------------------------------------------------*
* Intialise requisition object
*--------------------------------------------------------------------*
  TRY.
      cl_hrrcf_requisition=>get(
        EXPORTING
          id          = lv_requisition_id
        IMPORTING
          requisition = lo_requisition ).
    CATCH cx_hrrcf .
      "Error
  ENDTRY.

*--------------------------------------------------------------------*
*    Get Position and Position text for requisition
*--------------------------------------------------------------------*
  CLEAR : lv_position_id ,
          lv_position_text .

  TRY.
      lo_requisition->get_vacancy_of_requisition(
        IMPORTING
          vacancy_list = lt_vacancy_list ).
    CATCH cx_hrrcf_infotype_operation .
      EXIT .
  ENDTRY.

*--------------------------------------------------------------------*
* There could be multiple - you might prefer to loop instad of loop
*--------------------------------------------------------------------*
  READ TABLE lt_vacancy_list INTO ls_vacancy
  WITH KEY sclas = cl_hrtm_wd_ui_constants=>c_otype_position .
  IF sy-subrc = 0 .
    lv_position_id = ls_vacancy-sobid .
    lv_position_text = ls_vacancy-description .
  ENDIF.

ENDFORM.

Get Candidacy Objects from Requisition

FORM b .

  DATA : lo_requisition    TYPE REF TO cl_hrrcf_requisition,
         lt_candidacy_list TYPE rcf_t_candidacy,
         lv_requisition_id TYPE hrobjid,
         lo_candidacy      TYPE REF TO cl_hrrcf_candidacy.

*--------------------------------------------------------------------*
* Intialise requisition object
*--------------------------------------------------------------------*
  TRY.
      cl_hrrcf_requisition=>get(
        EXPORTING
          id          = lv_requisition_id
        IMPORTING
          requisition = lo_requisition ).
    CATCH cx_hrrcf .
      EXIT . "Error skip requisition
  ENDTRY.

*--------------------------------------------------------------------*
* Get candidacies from requisition
*--------------------------------------------------------------------*
  TRY.
      lo_requisition->get_candidacies(
        IMPORTING
           candidacy_list = lt_candidacy_list ).
    CATCH cx_hrrcf .
      EXIT . "Error skip candidacy
  ENDTRY.

  LOOP AT lt_candidacy_list INTO lo_candidacy .
    "Process Candidacy Object
  ENDLOOP .

ENDFORM.

Get Activities for Candidacy Object

FORM c .

  DATA : ls_candidacy_obj TYPE hrobject,
         lt_activity_list TYPE  rcf_t_list_activities_x.

  ls_candidacy_obj-plvar = cl_hrpiq00const=>c_istat_active .
  ls_candidacy_obj-otype = if_hrrcf_constants_pl=>gc_otype_candidacy .
  ls_candidacy_obj-objid = 'XXXXXXXX' .


*--------------------------------------------------------------------*
* Get Activities for Candidacy Object
*--------------------------------------------------------------------*
  TRY.
      cl_hrrcf_activity_factory=>get_activities_for_candidacy(
        EXPORTING
          ps_hrobject      = ls_candidacy_obj
        IMPORTING
          pt_activity_list = lt_activity_list
             ).
    CATCH cx_hrrcf .
      EXIT . "Error skip candidacy
  ENDTRY.

ENDFORM.

Leave a Reply