Esta función permite crear una Evento de HR
Transacción: S_AHR_61011887
FUNCTION z_hr_uc33_curso_sap.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(BEGDA) TYPE BEGDA OPTIONAL
*" VALUE(ENDDA) TYPE ENDDA OPTIONAL
*" VALUE(OBJETO_PADRE) TYPE HROBJID OPTIONAL
*" VALUE(DES_BREVE) TYPE SHORT_D OPTIONAL
*" VALUE(DES_LARGA) TYPE STEXT OPTIONAL
*" VALUE(DIAS) TYPE DAYCT
*" VALUE(HORAS) TYPE HRSCT
*" VALUE(CAP_MIN) TYPE KAPZ1 DEFAULT '1'
*" VALUE(CAP_OPT) TYPE KAPZ2
*" VALUE(CAP_MAX) TYPE KAPZ3
*" VALUE(PRECIO_INTERNO) TYPE IKOST
*" VALUE(PRECIO_EXTERNO) TYPE EXKOS
*" VALUE(SENCE) TYPE TEXT10
*" EXPORTING
*" VALUE(OBJETO_CREADO) TYPE OBJID
*" VALUE(E_RETURN) TYPE BAPIRET2
*" TABLES
*" PTXT1002 STRUCTURE PT1002
*"----------------------------------------------------------------------
DATA: it1000 LIKE hrp1000.
DATA: l_objid LIKE plog-objid .
DATA: l_repid LIKE sy-repid.
DATA: lt_1001 TYPE TABLE OF p1001.
FIELD-SYMBOLS: <wa_1001> TYPE p1001.
DATA: it1042 LIKE hrp1042 OCCURS 0 WITH HEADER LINE.
DATA: it1024 LIKE hrp1024 OCCURS 0 WITH HEADER LINE.
DATA: it1021 LIKE hrp1021 OCCURS 0 WITH HEADER LINE.
DATA: sw TYPE c.
CLEAR sw.
IF begda IS INITIAL.
begda = sy-datum.
ENDIF.
IF endda IS INITIAL.
endda = '99991231'.
ENDIF.
CALL FUNCTION 'RH_GET_NEXT_NUMBER'
EXPORTING
action = 'GIVE'
ext_number = l_objid
otype = 'D'
plvar = '01'
* TEST_MODE =
IMPORTING
number = l_objid
EXCEPTIONS
invalid_action = 1
number_must_be_zero = 2
invalid_object = 3
no_external_interval_found = 4
no_internal_interval_found = 5
invalid_number = 6
no_more_numbers_available = 7
OTHERS = 8
.
IF sy-subrc <> 0.
PERFORM get_message USING sy-msgty sy-msgid sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
CHANGING e_return.
ELSE.
it1000-mandt = sy-mandt.
it1000-plvar = '01'.
it1000-otype = 'D'.
it1000-objid = l_objid.
it1000-istat = '1'.
it1000-begda = begda.
it1000-endda = endda.
it1000-langu = 'S'.
CONCATENATE it1000-otype it1000-objid INTO it1000-otjid SEPARATED BY space.
it1000-infty = '1000'.
it1000-aedtm = sy-datum.
it1000-uname = sy-uname.
it1000-short = des_breve.
it1000-stext = des_larga.
it1000-mc_short = des_breve.
it1000-mc_stext = des_larga.
*concatenate IT1000-MC_SHORT IT1000-MC_STEXT into IT1000-MC_SEARK.
INSERT hrp1000 FROM it1000.
IF sy-subrc = 0.
l_repid = sy-repid.
APPEND INITIAL LINE TO lt_1001 ASSIGNING <wa_1001>.
<wa_1001>-mandt = sy-mandt.
<wa_1001>-plvar = '01'.
<wa_1001>-otype = 'D'.
<wa_1001>-objid = l_objid.
<wa_1001>-infty = '1001'.
<wa_1001>-rsign = 'A'.
<wa_1001>-relat = '003'. "Is Delegator of
<wa_1001>-istat = '1'.
<wa_1001>-begda = begda.
<wa_1001>-endda = endda.
CONCATENATE 'L' objeto_padre INTO <wa_1001>-varyf SEPARATED BY space.
<wa_1001>-aedtm = sy-datum.
<wa_1001>-uname = sy-uname.
<wa_1001>-sclas = 'L'.
<wa_1001>-sobid = objeto_padre.
CALL FUNCTION 'RH_INSERT_INFTY'
EXPORTING
vtask = 'D'
repid = l_repid
TABLES
innnn = lt_1001
EXCEPTIONS
no_authorization = 1
error_during_insert = 2
repid_form_initial = 3
corr_exit = 4
begda_greater_endda = 5
OTHERS = 6.
IF sy-subrc <> 0.
PERFORM get_message USING sy-msgty sy-msgid sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
CHANGING e_return.
EXIT.
ELSE.
objeto_creado = l_objid.
ENDIF.
else.
e_return-type = 'E'.
e_return-message = 'No se pudo crear objeto en infotipo 1000'.
exit.
ENDIF.
CALL FUNCTION 'RH_OBJECT_DESCRIPTION_WRITE'
EXPORTING
langu = 'S'
plvar = '01'
otype = 'D'
objid = l_objid
begda = begda
endda = endda
subty = '0004'
duty = ' '
vtask = 'D'
TABLES
ptxt1002 = ptxt1002
EXCEPTIONS
object_not_found = 1
description_required = 2
no_authority = 3
error_during_insert = 4
invalid_date = 5
undefined = 6
OTHERS = 7.
IF sy-subrc <> 0.
PERFORM get_message USING sy-msgty sy-msgid sy-msgno
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
CHANGING e_return.
EXIT.
ENDIF.
* HORAS
it1042-mandt = sy-mandt.
it1042-plvar = '01'.
it1042-otype = 'D'.
it1042-objid = l_objid.
it1042-infty = '1042'.
it1042-subty = '0001'.
it1042-istat = '1'.
it1042-begda = begda.
it1042-endda = endda.
CONCATENATE 'D' l_objid INTO it1042-otjid SEPARATED BY space.
it1042-aedtm = sy-datum.
it1042-uname = sy-uname.
it1042-ndays = dias.
it1042-nhours = horas.
INSERT hrp1042 FROM it1042.
* validad cantidades.
IF NOT ( cap_min IS INITIAL AND
cap_opt IS INITIAL AND
cap_max IS INITIAL ).
IF cap_opt IS INITIAL.
IF cap_min = 0.
cap_opt = 1.
ELSE.
cap_opt = cap_min.
ENDIF.
ENDIF.
IF cap_max IS INITIAL.
cap_max = cap_opt.
ENDIF.
IF cap_min > cap_opt OR cap_opt > cap_max.
e_return-type = 'E'.
e_return-number = '99'.
e_return-message = 'Introduzca capacidades válidas (mínimo =< óptimo =< máximo)'.
sw = 'X'.
ENDIF.
ENDIF.
* CAPACIDAD
IF sw IS INITIAL.
it1024-mandt = sy-mandt.
it1024-plvar = '01'.
it1024-otype = 'D'.
it1024-objid = l_objid.
it1024-istat = '1'.
it1024-begda = begda.
it1024-endda = endda.
it1024-infty = '1024'.
CONCATENATE 'D' l_objid INTO it1024-otjid SEPARATED BY space.
it1024-aedtm = sy-datum.
it1024-uname = sy-uname.
it1024-kapz1 = cap_min.
it1024-kapz2 = cap_opt.
it1024-kapz3 = cap_max.
INSERT hrp1024 FROM it1024.
ENDIF.
* PRECIO
it1021-mandt = sy-mandt.
it1021-plvar = '01'.
it1021-otype = 'D'.
it1021-objid = l_objid.
it1021-istat = '1'.
it1021-begda = begda.
it1021-endda = endda.
it1021-infty = '1021'.
CONCATENATE 'D' l_objid INTO it1021-otjid SEPARATED BY space.
it1021-aedtm = sy-datum.
it1021-uname = sy-uname.
it1021-ikost = precio_interno.
DIVIDE it1021-ikost BY 100.
it1021-iwaer = 'CLP'.
it1021-ekost = precio_externo.
DIVIDE it1021-ekost BY 100.
it1021-ewaer = 'CLP'.
it1021-zzsence = sence.
INSERT hrp1021 FROM it1021.
e_return-type = 'S'.
e_return-message = 'Curso creado'.
ENDIF.
ENDFUNCTION.