Давненько писал программку по рассылке расчетных листов в SAP HCM. Косо-криво, но несколько лет уже работает на разных предприятиях 🙂 Ниже представлен исходный код программы. Пользуйтесь на свой страх и риск.

*&---------------------------------------------------------------------*
*& Report  ZHR_SEND_PAYSLIP
*& Программа отправки расчетных листов на email сотрудников
*&---------------------------------------------------------------------*
*& Http://www.virvit.ru
*& Виталий Поцелуев
*&---------------------------------------------------------------------*

REPORT  ZHR_SEND_PAYSLIP.

tables: pernr, t514v.

infotypes: 0000, 0002, 0105.

include:  PULOGRU0.

***********************
* Selection screen
***********************
SELECTION-SCREEN BEGIN OF LINE.                             "VKIK009593
SELECTION-SCREEN COMMENT 1(25) text-t01 FOR FIELD formular. "VKIK019923
SELECTION-SCREEN POSITION pos_low.
PARAMETERS:
  formular  LIKE rpcedtx0-prt_form.
SELECTION-SCREEN COMMENT 40(38) form_txt FOR FIELD formular.
SELECTION-SCREEN END OF LINE.

***********************
* Data declaration
***********************

data:
  fld_input   TYPE boolean,        "field for input open?  "VKIK045853
  fld_name    LIKE screen-name,    "field name F4-Help     "VKIK045853
  l_payslip   type table of ABAPLIST,
  lt_payslip  type table of char255,
  sender_email type string,
  recipient_email type string,
  subject     type string,
  period      type string.

** log nodes
data: begin of lt_log_pernr,
        node_key type hrpad_pal_node_key,
        pernr type p_pernr,
      end   of lt_log_pernr.
data: gt_log_pernr like standard table of lt_log_pernr with key node_key.

***********************
* Events
***********************

INITIALIZATION.
  formular = 'ZU10'.
  PNPXABKR = '50'.
  PERFORM RE514V USING SY-LANGU '33' FORMULAR FORM_TXT.     "VKIK009593

  perform init_log using space.

  CALL FUNCTION 'EFG_GEN_GET_USER_EMAIL'
    EXPORTING
      I_UNAME                 = sy-uname
   IMPORTING
     E_EMAIL_ADDRESS          = sender_email
*   EXCEPTIONS
*     NOT_QUALIFIED           = 1
*     USER_NOT_FOUND          = 2
*     ADDRESS_NOT_FOUND       = 3
*     OTHERS                  = 4
            .
  IF sender_email is initial.
    MESSAGE e016(rp) with 'В параметрах пользователя не указан email. Тр. su3'.
    Exit.
  ENDIF.


AT SELECTION-SCREEN OUTPUT.                                 "VKIK009593
  PERFORM RE514V USING SY-LANGU '33' FORMULAR FORM_TXT.     "VKIK009593

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FORMULAR.          "VKIK009593
  CALL FUNCTION 'F4_POPUP_FORML'
    EXPORTING
      MOLGA  = '33'
      FCLASS = 'CEDT'
    IMPORTING
      FORML  = FORMULAR
    EXCEPTIONS
      OTHERS = 1.

**********************************************************************
START-OF-SELECTION.

****************************
* Main proccessing
****************************

get pernr.

  data: ls_log_pernr like line of gt_log_pernr.
  data: isError type c.
  data: oref   TYPE REF TO cx_root.

  clear recipient_email.
  clear isError.

** Check for email
  provide * from p0105 between pn-begda and pn-endda.
    if p0105-subty = '0010'.
      recipient_email = p0105-usrid_long.
    endif.
  endprovide.

  if recipient_email is initial.
*    call method g_log->add_message_to_log_and_table
*      EXPORTING
*        im_pernr      = pernr
*        im_msg_id     = 'RP'
*        im_msg_type   = 'I'
*        im_msg_number = '016'
*        im_msg_msgv1  = 'Для сотрудника не указан email в ИТ0105/0010'.
    reject.
  endif.

** don't send payslip for fired
  provide stat2 from p0000 between pn-begda and pn-endda.
    if not p0000-stat2 eq 3.
      call method g_log->add_message_to_log_and_table
        EXPORTING
          im_pernr      = pernr
          im_msg_id     = 'RP'
          im_msg_type   = 'I'
          im_msg_number = '016'
          im_msg_msgv1  = 'Сотрудник уволен'.

      isError = 'X'.
    endif.
  endprovide.

CALL FUNCTION 'LIST_FREE_MEMORY'.

  SUBMIT HRUCEDT0
          WITH FORMULAR eq FORMULAR
          WITH PNPABKRS eq PNPXABKR
          WITH PNPPERNR eq PERNR-PERNR
          WITH PNPXABKR eq PNPXABKR
          WITH RUECKR eq 'A'
          WITH PNPTIMR9 eq PNPTIMR9
          WITH PNPTIMRA eq PNPTIMRA
          WITH PNPPABRP eq PNPPABRP
          WITH PNPPABRJ eq PNPPABRJ
          WITH PRT_PROT eq ' '
  EXPORTING LIST TO MEMORY
  AND RETURN.

*  if sy-subrc <> 0.
*    call method g_log->add_message_to_log_and_table
*      EXPORTING
*        im_pernr      = pernr
*        im_msg_id     = 'RP'
*        im_msg_type   = 'E'
*        im_msg_number = '016'
*        im_msg_msgv1  = 'Не удалось сформировать расчетный лист'.
*
*    isError = 'X'.
*  endif.

  clear l_payslip.
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      LISTOBJECT = l_payslip
    EXCEPTIONS
      NOT_FOUND  = 1
      OTHERS     = 2.

  IF SY-SUBRC <> 0.
    call method g_log->add_message_to_log_and_table
      EXPORTING
        im_pernr      = pernr
        im_msg_id     = 'RP'
        im_msg_type   = 'E'
        im_msg_number = '016'
        im_msg_msgv1  = 'Не удалось получить сформированный расчетный лист'.

    isError = 'X'.
  ENDIF.

  clear lt_payslip.
  CALL FUNCTION 'LIST_TO_TXT'
    TABLES
      LISTTXT            = lt_payslip
      LISTOBJECT         = l_payslip
    EXCEPTIONS
      EMPTY_LIST         = 1
      LIST_INDEX_INVALID = 2
      OTHERS             = 3.

  IF SY-SUBRC <> 0.
    call method g_log->add_message_to_log_and_table
      EXPORTING
        im_pernr      = pernr
        im_msg_id     = 'RP'
        im_msg_type   = 'E'
        im_msg_number = '016'
        im_msg_msgv1  = 'Не удалось преобразовать расчетный лист'.

    isError = 'X'.
  ENDIF.

  data: l_begda(10) type c,
        l_endda(10) type c.

  write PNPDISBD to l_begda dd/mm/yyyy.
  write PNPDISED to l_endda dd/mm/yyyy.

  concatenate 'Расчетный лист за ' l_begda '-' l_endda INTO subject separated by space.

  if isError = ''.
    CALL FUNCTION 'HR_FBN_GENERATE_SEND_EMAIL'
      EXPORTING
        SUBJECT    = subject
        SENDER     = sender_email
        RECIPIENT  = recipient_email
      TABLES
        EMAIL_TEXT = lt_payslip
      EXCEPTIONS
        FAILED     = 1
        OTHERS     = 2.

    IF SY-SUBRC <> 0.
      call method g_log->add_message_to_log_and_table
        EXPORTING
          im_pernr      = pernr
          im_msg_id     = 'RP'
          im_msg_type   = 'E'
          im_msg_number = '016'
          im_msg_msgv1  = 'Не удалось отправить расчетный лист'.
    ENDIF.

  endif.

  call method g_log->add_employee_node
    EXPORTING
      im_pernr        = pernr
      im_add_messages = 'X'
    IMPORTING
      ev_node_key     = ls_log_pernr-node_key.


end-of-selection.

  call method g_log->display_log2.


***********************
* Other routines
***********************
FORM RE514V USING VALUE($SPRSL)                             "VKIK009593
                  VALUE($MOLGA)
                  VALUE($FORML)
                  FORM_TXT.
  IF T514V-SPRSL NE $SPRSL
  OR T514V-MOLGA NE $MOLGA
  OR T514V-FORML NE $FORML.
    SELECT SINGLE * FROM T514V WHERE SPRSL EQ $SPRSL
                               AND   MOLGA EQ $MOLGA
                               AND   FORML EQ $FORML.
    IF SY-SUBRC NE 0.
      CLEAR T514V.
    ENDIF.
  ENDIF.
  FORM_TXT = T514V-FTEXT.
ENDFORM.                                                    "RE514V