SAP E-Recruiting ABAP Code Snippets – Part 2

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 Posting Text

FORM c .

  DATA lv_posting_id TYPE rcf_posting.
  DATA lv_title TYPE rcf_itf_description .

  TRY .
      cl_hrrcf_posting_information=>read_posting_header_txt(
        EXPORTING
          posting_id         = lv_posting_id
        IMPORTING
          posting_header_txt = lv_title  ).

    CATCH cx_hrrcf.
  ENDTRY.

ENDFORM.
Substitutes in SAP E-Recruitment are stored in table T77RCF_SUBST

Update Activity Object

Below code update Activity status to Complete. You can get GUID of Activity by reading Activities using Candidacy objects. See blog.

FORM e .

  CONSTANTS : lc_act_status_complete  TYPE  rcf_activity_status VALUE 1 .

  DATA : lv_activity_guid TYPE rcf_act_guid,
         ls_activity      TYPE rcf_s_list_activities_x,
         ls_activity_read TYPE rcf_s_act_info_text_pl,
         ls_activity_upd  TYPE rcf_s_act_upd_pl.

  DATA : lt_return TYPE bapiret2_tab .


*--------------------------------------------------------------------*
*   Read activity details
*--------------------------------------------------------------------*
  cl_hrrcf_activity_mgmt_pl=>read_simple_activity(
    EXPORTING
      iv_act_guid = lv_activity_guid
    IMPORTING
      es_activity = ls_activity_read
      et_message  = lt_return ).

  IF lt_return IS NOT INITIAL .
    RETURN .
  ENDIF.

*--------------------------------------------------------------------*
*   Move values to update structure
*--------------------------------------------------------------------*
  ls_activity_upd-act_guid  = ls_activity_read-act_guid .
  ls_activity_upd-act_type  = ls_activity_read-act_type .
  ls_activity_upd-status    = lc_act_status_complete .  "update status
  ls_activity_upd-due_date  = ls_activity_read-due_date .
  ls_activity_upd-res_uname = sy-uname .                "agent
  ls_activity_upd-act_proc  = ls_activity_read-act_proc .
  ls_activity_upd-note_txt  = ls_activity_read-note_txt .

  cl_hrrcf_activity_mgmt_pl=>update_simple_activity(
    EXPORTING
      is_activity = ls_activity_upd
    IMPORTING
      et_message  = lt_return ) .

* COMMIT WORK .

ENDFORM.

Create Simple Activity under Candidacy Object

Below code snippet create Simple Activity under Candidacy object and also attach a pdf file during its creation. If you are looking for code to create other kind Activities like Simple correspondence, Qualifying event, Invitation, Status change, Data transfer, Questionnaires, Classification, Confirmation and Background check then refer code of method SAVE in COMPONENTCONTROLLER of Webdynpro ERC_C_ACTIVITY_MGMT_UI.

FORM z   USING  im_ocandidacy TYPE REF TO cl_hrrcf_candidacy
      CHANGING  et_return TYPE bapiret2_tab .

*--------------------------------------------------------------------*
*  Create Simple Activity
*--------------------------------------------------------------------*
  DATA : ls_activity TYPE rcf_s_act_create_pl,
         lt_hrobject TYPE rcf_t_hrobject,
         lt_message  TYPE bapirettab,
         lt_act_guid TYPE rcf_t_act_guid.

  CONSTANTS : lc_complete          TYPE rcf_activity_status VALUE '1',
              lc_process_offer_ver TYPE rcf_act_proc        VALUE '4',
              lc_subty_activity    TYPE subty               VALUE '0005',
              lc_contyp_pdf        TYPE w3conttype          VALUE  'application/pdf'.

  DATA :  lo_attach      TYPE REF TO cl_hrrcf_m_attachment_ui,
          ls_attach      TYPE rcf_s_attach_pl,
          ls_temp_attach TYPE t77rcf_attach_pl,
          lv_document    TYPE rcf_attachment_content.

*--------------------------------------------------------------------*
*   Get Pernr of current user
*--------------------------------------------------------------------*
  cl_hrrcf_activity_mgmt_pl=>get_pernr_for_user(
    EXPORTING
      iv_user    = sy-uname
    IMPORTING
      ev_pernr   = ls_activity-res_pernr
      et_message = et_return ).

  IF et_return IS NOT INITIAL .
    RETURN .
  ENDIF.

*--------------------------------------------------------------------*
*   Fill in activity details
*--------------------------------------------------------------------*
  ls_activity-act_type  = 'XXXX' .  "Activity type for creation - Change as per your requirement
  ls_activity-status    = lc_complete .          "complete
  ls_activity-due_date  = sy-datum .             "due date
  ls_activity-act_proc  = lc_process_offer_ver . "Offer and Verification

  APPEND im_ocandidacy->hrobject TO lt_hrobject .

  cl_hrrcf_activity_mgmt_pl=>create_simple_activity(
    EXPORTING
      is_activity = ls_activity
      it_hrobject = lt_hrobject
    IMPORTING
      et_message  = et_return
      et_act_guid = lt_act_guid ).

  IF et_return IS NOT INITIAL .
    RETURN .
  ENDIF.

*--------------------------------------------------------------------*
*   Generate PDF
*--------------------------------------------------------------------*
* Code to put pdf file in xstring format in variable lv_document

*--------------------------------------------------------------------*
*   Load pdf document in temp area
*--------------------------------------------------------------------*

  CREATE OBJECT lo_attach .

  ls_attach-act_subtype = space.

  CALL METHOD lo_attach->set_subtype
    EXPORTING
      iv_subtype = lc_subty_activity. "Subtype activities

  ls_attach-att_header   = 'FileName' .                      "Attachment file name to appear in UI
  ls_attach-language     = 'E' .                             "English
  ls_attach-language_txt = 'English' .                       "English
  ls_attach-att_type     = '0011' .                         "Attachment type
  ls_attach-att_type_txt = 'Other' .                        "Attahment type
  ls_attach-attach_title = 'C:\fakepath\Samplepdf.pdf' .    "Madepup path
  ls_attach-content_type = lc_contyp_pdf .                  "pdf

*--------------------------------------------------------------------*
*   Check Attcahment Before adding to the Buffer - Virus
*--------------------------------------------------------------------*
  CALL METHOD lo_attach->check_attachment
    EXPORTING
      is_attachment_details = ls_attach
      iv_document           = lv_document
    IMPORTING
      et_message            = et_return.

  IF et_return IS NOT INITIAL .
    RETURN .
  ENDIF.

*--------------------------------------------------------------------*
*   Create GUID to hold attachment in buffer
*--------------------------------------------------------------------*
  CALL FUNCTION 'GUID_CREATE'                       "#EC FB_OLDED
    IMPORTING
      ev_guid_32 = ls_attach-tmp_attachment_guid.

*--------------------------------------------------------------------*
*   Add PDF to buffer
*--------------------------------------------------------------------*
  CALL METHOD lo_attach->add_attachment_buffer
    EXPORTING
      is_attachment_details = ls_attach
      iv_document           = lv_document
    IMPORTING
      et_message            = et_return.

*--------------------------------------------------------------------*
*   Set guid from activity
*--------------------------------------------------------------------*
  CALL METHOD lo_attach->set_guid
    EXPORTING
      it_act_guid = lt_act_guid.

*--------------------------------------------------------------------*
*   Save attachment in activity
*--------------------------------------------------------------------*
  CALL METHOD lo_attach->save_attachment_activity
    IMPORTING
      et_message = et_return.

  IF et_return IS NOT INITIAL .
    RETURN .
  ENDIF.

* COMMIT WORK
ENDFORM.

SAP E-Recruiting-Related Constants

Object Constant Value
Application Object IF_HRRCF_CONSTANTS_PL=>GC_OTYPE_APPLICATION ‘ND’
Candidacy IF_HRRCF_CONSTANTS_PL=>GC_OTYPE_CANDIDACY ‘NE’
Candidate IF_HRRCF_CONSTANTS_PL=>GC_OTYPE_CANDIDATE ‘NA’
Job Postings IF_HRRCF_CONSTANTS_PL=>GC_OTYPE_POSTING ‘NC’
Requisition Object IF_HRRCF_CONSTANTS_PL=>GC_OTYPE_REQUISITION ‘NB’

Leave a Reply