Esta función permite crear una Instancia o Tipo de Evento de HR
Transacción: PSV2
FUNCTION z_hr_uc34_secciones.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(OBJETO_PADRE) TYPE HROBJID
*" VALUE(DATUM) TYPE DATUM
*" EXPORTING
*" VALUE(OBJETO_CREADO) TYPE OBJID
*" VALUE(E_RETURN) TYPE BAPIRET2
*"----------------------------------------------------------------------
DATA: it1000 LIKE hrp1000.
DATA: l_objid LIKE plog-objid .
DATA: l_repid LIKE sy-repid.
DATA: lt_1001 TYPE TABLE OF p1001.
* DATA: lt_1035 TYPE TABLE OF p1035.
DATA: it_1042 LIKE hrp1042.
DATA: it1021 LIKE hrp1021.
DATA: it1024 LIKE hrp1024.
DATA: it1026 LIKE hrp1026.
DATA: pt1035 LIKE hrt1035 OCCURS 0 WITH HEADER LINE.
DATA: it1035 LIKE hrp1035.
FIELD-SYMBOLS: <wa_1001> TYPE p1001.
* FIELD-SYMBOLS: <wa_1035> TYPE p1035.
DATA: dias LIKE hrp1042-ndays.
DATA: begda TYPE begda.
DATA: endda TYPE endda.
DATA: fecha TYPE begda.
DATA: k TYPE i.
DATA: number TYPE hrpointer.
DATA: l_tabnr LIKE hrp1035-tabnr.
SELECT SINGLE *
FROM hrp1000
INTO it1000
WHERE plvar = '01'
AND otype = 'D'
AND objid = objeto_padre.
IF sy-subrc <> 0.
e_return-type = 'E'.
e_return-message = 'Error: No existe objeto padre'.
EXIT.
ENDIF.
SELECT SINGLE ndays
FROM hrp1042
INTO dias
WHERE plvar = '01'
AND otype = 'D'
AND objid = objeto_padre.
CALL FUNCTION 'RH_GET_NEXT_NUMBER'
EXPORTING
action = 'GIVE'
ext_number = l_objid
otype = 'E'
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.
begda = datum.
endda = datum + dias - 1.
it1000-mandt = sy-mandt.
it1000-plvar = '01'.
it1000-otype = 'E'.
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.
*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 = 'E'.
<wa_1001>-objid = l_objid.
<wa_1001>-infty = '1001'.
<wa_1001>-rsign = 'A'.
<wa_1001>-relat = '020'. "Is Delegator of
<wa_1001>-istat = '1'.
<wa_1001>-begda = begda.
<wa_1001>-endda = endda.
CONCATENATE 'D' objeto_padre INTO <wa_1001>-varyf SEPARATED BY space.
<wa_1001>-aedtm = sy-datum.
<wa_1001>-uname = sy-uname.
<wa_1001>-sclas = 'D'.
<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 = 'Error: No se pudo crear objeto en infotipo 1000'.
EXIT.
ENDIF.
* PRECIO
SELECT SINGLE *
FROM hrp1021
INTO it1021
WHERE plvar = '01'
AND otype = 'D'
AND objid = objeto_padre.
it1021-otype = 'E'.
it1021-objid = l_objid.
it1021-istat = '1'.
it1021-begda = begda.
it1021-endda = endda.
it1021-infty = '1021'.
CONCATENATE 'E' l_objid INTO it1021-otjid SEPARATED BY space.
it1021-aedtm = sy-datum.
it1021-uname = sy-uname.
CLEAR it1021-zzsence.
INSERT hrp1021 FROM it1021.
* 1024
SELECT SINGLE *
FROM hrp1024
INTO it1024
WHERE plvar = '01'
AND otype = 'D'
AND objid = objeto_padre.
it1024-mandt = sy-mandt.
it1024-plvar = '01'.
it1024-otype = 'E'.
it1024-objid = l_objid.
it1024-istat = '1'.
it1024-begda = begda.
it1024-endda = endda.
it1024-infty = '1024'.
CONCATENATE 'E' l_objid INTO it1024-otjid SEPARATED BY space.
it1024-aedtm = sy-datum.
it1024-uname = sy-uname.
INSERT hrp1024 FROM it1024.
it1026-mandt = sy-mandt.
it1026-plvar = '01'.
it1026-otype = 'E'.
it1026-objid = l_objid.
it1026-istat = '1'.
it1026-begda = begda.
it1026-endda = endda.
it1026-infty = '1026'.
CONCATENATE 'E' l_objid INTO it1026-otjid SEPARATED BY space.
it1026-aedtm = sy-datum.
it1026-uname = sy-uname.
it1026-langu = 'S'.
INSERT hrp1026 FROM it1026.
* 1035
SELECT SINGLE *
FROM hrp1042
INTO it_1042
WHERE plvar = '01'
AND otype = 'D'
AND objid = objeto_padre.
IF sy-subrc = 0.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = 'IN'
object = 'HRTABNR'
quantity = '1'
IMPORTING
number = number
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 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.
EXIT.
ELSE.
CONCATENATE 'D01-----100A' number INTO l_tabnr.
it1035-mandt = sy-mandt.
it1035-plvar = '01'.
it1035-otype = 'E'.
it1035-objid = l_objid.
it1035-infty = '1035'.
it1035-istat = '1'.
it1035-begda = begda.
it1035-endda = endda.
CONCATENATE 'E' l_objid INTO it1035-otjid SEPARATED BY space.
it1035-aedtm = sy-datum.
it1035-uname = sy-uname.
it1035-ndays = it_1042-ndays.
it1035-nhours = it_1042-nhours.
it1035-tabnr = l_tabnr.
INSERT hrp1035 FROM it1035.
fecha = begda.
k = 0.
WHILE fecha <= endda.
pt1035-mandt = sy-mandt.
pt1035-tabseqnr = k + 1.
pt1035-evdat = fecha.
pt1035-tabnr = l_tabnr.
APPEND pt1035.
fecha = fecha + 1.
k = k + 1.
ENDWHILE.
LOOP AT pt1035.
INSERT hrt1035 FROM pt1035.
ENDLOOP.
ENDIF.
ENDIF.
e_return-type = 'S'.
e_return-message = 'Sección creada'.
ENDIF.
ENDFUNCTION.