This Blog is about to display the employee pay slip in Fiori Application. When user click on hyperlink in frontend we need to display the employee pay slip. Generally for PDF we use the Adobe forms/ SMART FORMS to prepare a layout, but here we don’t need any layout creation. We have standard pay slips in SAP, so we are going to use SAP HR pay slips to display in Fiori Application.

Below are the steps we followed and able to achieve the requirement as required.

Go to Tcode SEGW and create a new project and save it in object directory entry.

Now create an Entity type and Entity set and make sure the Media column in the created entity type should be checked and add the required properties.

  • Now redefine the get entity method in DPC Extension and add the below source code.
  METHOD hyperlinkset_get_entity.

    DATA: lv_seqnr     TYPE cdseq,
          lv_b64data   TYPE string,
          lv_begda     TYPE pc261-paydt,
          lv_value     TYPE xstring,
          lv_endda     TYPE pc261-paydt,
          lv_pernr     TYPE pernr_d,
          lv_molga     TYPE t500l-molga,
          lit_rgdir    TYPE TABLE OF pc261,
          lv_pdf_name  TYPE string,
          lv_mime_type TYPE w3conttype.

**__ Constants
    CONSTANTS: c_pernr(5)   VALUE 'Pernr',
               c_pbegda(06) VALUE 'Pbegda',
               c_pendda(06) VALUE 'Pendda'.

    DATA(lo_global) = NEW XXclass NameXX( ).

    LOOP AT it_key_tab INTO DATA(ls_key).
      CASE ls_key-name.
        WHEN c_pernr.
          lv_pernr = ls_key-value.
        WHEN c_pbegda.
          lv_begda = ls_key-value.
        WHEN c_pendda.
          lv_endda = ls_key-value.
      ENDCASE.
    ENDLOOP.

    lv_molga = '10'.
    CALL FUNCTION 'CU_READ_RGDIR'
      EXPORTING
        persnr          = lv_pernr
      IMPORTING
        molga           = lv_molga
      TABLES
        in_rgdir        = lit_rgdir
      EXCEPTIONS
        no_record_found = 1
        OTHERS          = 2.

    SORT lit_rgdir BY rundt DESCENDING.
    LOOP AT lit_rgdir INTO DATA(ls_rgdir) WHERE fpbeg LE lv_begda
                                            AND fpend GE lv_endda.
      IF ls_rgdir IS NOT INITIAL.
        lv_seqnr = ls_rgdir-seqnr.
        EXIT.
      ENDIF.
    ENDLOOP.

    IF lv_seqnr IS NOT INITIAL.
**__ Get binary PDF-data
      lo_global->get_pdf_data( EXPORTING iv_seqnr     = lv_seqnr
                                         iv_pernr     = lv_pernr
                                         is_rgdir     = ls_rgdir
                               IMPORTING ev_pdf_data  = lv_value
                                         ev_mime_type = lv_mime_type
                                         ev_pdf_name  = lv_pdf_name ).

**__ Convert the XString data into the Base 64 Data
      CALL FUNCTION 'SSFC_BASE64_ENCODE'
        EXPORTING
          bindata                  = lv_value
        IMPORTING
          b64data                  = lv_b64data
        EXCEPTIONS
          ssf_krn_error            = 1
          ssf_krn_noop             = 2
          ssf_krn_nomemory         = 3
          ssf_krn_opinv            = 4
          ssf_krn_input_data_error = 5
          ssf_krn_invalid_par      = 6
          ssf_krn_invalid_parlen   = 7
          OTHERS                   = 8.

      IF lv_b64data IS NOT INITIAL.
        er_entity-value = lv_b64data.
      ENDIF.
    ENDIF.

  ENDMETHOD.
=================================================================================================
**__ METHOD GET_PDF_DATA
METHOD GET_PDF_DATA.

  DATA: lv_molga          TYPE molga,
        lv_form_name      TYPE hrf_name,
*        is_rgdir          TYPE pc261,
        lo_payslip_helper TYPE REF TO cl_hrxss_rem_helper,
        go_employee_api   TYPE REF TO cl_hcmfab_employee_api,
        ls_pmehf          TYPE pmehf,
        ls_p0001          TYPE p0001.

  CONSTANTS: c_formname TYPE hrf_name VALUE 'XXForm NameXX',

             BEGIN OF gc_mimetype,
               pdf  TYPE string VALUE 'application/pdf',
               jpeg TYPE string VALUE 'image/jpeg',
             END OF gc_mimetype .

  CLEAR: ev_pdf_data, ev_mime_type, ev_pdf_name.

* get form name
  ls_pmehf-rclas = 'CESS'.
  ls_pmehf-molga = 10.
  ls_pmehf-payty = is_rgdir-payty.

  CALL METHOD cl_hcmfab_utilities=>read_infotype_record            "MELN2648051
    EXPORTING
      iv_pernr         = iv_pernr
      iv_infty         = '0001'
      iv_begda         = is_rgdir-ipend
      iv_endda         = is_rgdir-ipend
      iv_no_auth_check = abap_true
    IMPORTING
      es_pnnnn         = ls_p0001.

  ls_pmehf-bukrs = ls_p0001-bukrs.
  ls_pmehf-werks = ls_p0001-werks.
  ls_pmehf-btrtl = ls_p0001-btrtl.
  ls_pmehf-persg = ls_p0001-persg.
  ls_pmehf-persk = ls_p0001-persk.
  ls_pmehf-abkrs = ls_p0001-abkrs.
  ls_pmehf-kostl = ls_p0001-kostl.
  ls_pmehf-juper = ls_p0001-juper.
  ls_pmehf-vdsk1 = ls_p0001-vdsk1.
  ls_pmehf-gsber = ls_p0001-gsber.

  CALL METHOD cl_hrpa_feature=>get_value
    EXPORTING
      feature       = 'HRFOR'
      struc_content = ls_pmehf
    IMPORTING
      return_value  = lv_form_name.

* retrieve actual binary data of the PDF
  CREATE OBJECT lo_payslip_helper
    EXPORTING
      iv_pernr = iv_pernr.

  lo_payslip_helper->get_payslip(
    EXPORTING
      is_rgdir                   = is_rgdir
      iv_form_name               = lv_form_name
    IMPORTING
      ev_document                = ev_pdf_data
    EXCEPTIONS
      ex_payslip_creation_failed = 1 ).

  IF sy-subrc <> 0.

    lv_form_name = c_formname.
    lo_payslip_helper->get_payslip(
    EXPORTING
      is_rgdir                   = is_rgdir
      iv_form_name               = lv_form_name
    IMPORTING
      ev_document                = ev_pdf_data
    EXCEPTIONS
      ex_payslip_creation_failed = 1 ).

    IF sy-subrc <> 0.
      "log system message for administrator
      me->mo_context->get_logger( )->log_message(
          iv_msg_type      = sy-msgty
          iv_msg_id        = sy-msgid
          iv_msg_number    = sy-msgno
          iv_msg_v1        = sy-msgv1
          iv_msg_v2        = sy-msgv2
          iv_msg_v3        = sy-msgv3
          iv_msg_v4        = sy-msgv4
          iv_agent         = 'LOGGER'
      ).

    ENDIF.
  ENDIF.

  ev_mime_type = gc_mimetype-pdf.
  ev_pdf_name  = 'Paystub' && '_' && is_rgdir-fpper && '.pdf'.

ENDMETHOD.

Now redefine the DEFINE Method in MPC Extension and add the below source code.

  METHOD define.

    super->define( ).

    DATA:
      lo_entity   TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
      lo_property TYPE REF TO /iwbep/if_mgw_odata_property.

    lo_entity = model->get_entity_type( iv_entity_name = 'HyperLink' ).

    IF lo_entity IS BOUND.

      lo_property = lo_entity->get_property( iv_property_name = 'Value' ).

      lo_property->set_as_content_type( ).
    ENDIF.

  ENDMETHOD.

OUTPUT:

 

Hope this Blog might help you. Thank you…

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x