Subrutinas

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 27

*&---------------------------------------------------------------------*

*& Include ZESPY_PRO_IN_CONV_0008_F01


*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form GET_DATES
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_dates .

DATA: lv_fin LIKE sy-datum,


lv_aux(3),
lv_fin_aux LIKE sy-datum.

REFRESH: gt_periodos.
CLEAR: gt_periodos.

* IF rb_wrd IS NOT INITIAL.


*
* gt_periodos-fpper = pn-begda(6).
* gt_periodos-begda = pn-begda.
* gt_periodos-endda = pn-endda.
*
* APPEND gt_periodos.
*
* CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'
* EXPORTING
* dmm_datin = pn-begda
* dmm_count = gc_countdown
* dmm_oper = '-'
* dmm_pos = '1'
* IMPORTING
* dmm_daout = lv_fin
* EXCEPTIONS
* unknown = 1
* OTHERS = 2.
*
* IF sy-subrc <> 0.
* CLEAR: lv_fin.
* ENDIF.
*
* gv_begda_ini = lv_fin.
*
** IF lv_fin LT gc_date_sap.
** PERFORM get_bases_m4 USING lv_fin.
** ENDIF.
*
* lv_fin_aux = gt_periodos-begda.
*
* ELSE.

REFRESH p0000.

CALL FUNCTION 'HR_READ_INFOTYPE'


EXPORTING
pernr = PNPPERNR-LOW
infty = '0000'
TABLES
infty_tab = p0000[]
EXCEPTIONS
infty_not_found = 1
OTHERS = 2.

rp_provide_from_last p0000 space gc_begda gc_endda.

IF rb_wrd = 'X'.
DATA: COUNT_PERIOD TYPE i.
PERFORM import_rgdir.
SORT rgdir BY fpper DESCENDING.
IF rp-imp-cd-subrc = 0.
CLEAR: gt_periodos, COUNT_PERIOD.
LOOP AT rgdir WHERE srtza EQ 'A'.
COUNT_PERIOD = 1 + COUNT_PERIOD.
gt_periodos-fpper = rgdir-fpper.
gt_periodos-begda = rgdir-FPBEG.
gt_periodos-endda = rgdir-FPEND.
IF COUNT_PERIOD <= 6.
APPEND gt_periodos.
ELSE.
CLEAR gt_periodos.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
* Si no informan nada, por defecto todo.
IF so_datum-high IS INITIAL.
so_datum-high = sy-datum."gc_endda.
ENDIF.

* Si no informan nada, por defecto todo.


IF so_datum-low IS INITIAL.
LOOP AT P0000.
so_datum-low = p0000-begda."gc_begda.
EXIT.
ENDLOOP.

ENDIF.

gt_periodos-fpper = so_datum-high(6).
gt_periodos-begda = so_datum-high.
gt_periodos-endda = so_datum-high.

gt_periodos-begda+6(2) = '01'.

APPEND gt_periodos.

gv_begda_ini = lv_fin = so_datum-low.

lv_fin_aux = gt_periodos-begda.

* ENDIF.

WHILE lv_fin_aux GT lv_fin.

CALL FUNCTION 'HR_PT_ADD_MONTH_TO_DATE'


EXPORTING
dmm_datin = gt_periodos-begda
dmm_count = '1'
dmm_oper = '-'
dmm_pos = '1'
IMPORTING
dmm_daout = lv_fin_aux
EXCEPTIONS
unknown = 1
OTHERS = 2.

CALL FUNCTION 'LAST_DAY_OF_MONTHS'


EXPORTING
day_in = lv_fin_aux
IMPORTING
last_day_of_month = gt_periodos-endda
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.

IF sy-subrc EQ 0.
gt_periodos-begda = lv_fin_aux.
gt_periodos-fpper = gt_periodos-begda(6).

APPEND gt_periodos.
* CLEAR: gt_periodos.
ELSE.
lv_fin_aux = lv_fin.
ENDIF.

ENDWHILE.
CLEAR: gt_periodos.
SORT gt_periodos BY fpper.

ENDIF.

ENDFORM. " GET_DATES


*&---------------------------------------------------------------------*
*& Form FILL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fill_data .

CLEAR: gt_data_es.

gt_data_es-pernr = PNPPERNR-LOW.

PERFORM get_datos_empresa.

PERFORM get_representante.

PERFORM get_datos_empleado.

PERFORM get_bases_15_anyos.

IF gt_data_es IS NOT INITIAL.

datos_word = 'X'.
APPEND gt_data_es.

ENDIF.

ENDFORM. " FILL_DATA


*&---------------------------------------------------------------------*
*& Form GET_DATOS_EMPRESA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_datos_empresa .

DATA: lv_provi_nisse LIKE t5e01-provn,


lv_land1 LIKE t001-land1.

DATA: l_nisse_data TYPE pess0_nisse_data.


DATA: l_juper_data TYPE pesw0_juper_data.

rp_provide_from_last p0001 space pn-begda pn-endda.

IF pnp-sw-found EQ 1.

CLEAR: gv_mocat.

gt_data_es-bukrs = p0001-bukrs.

SELECT SINGLE nisse mocat FROM t5e01


INTO (gt_data_es-nisse,gv_mocat)
WHERE werks EQ p0001-werks
AND btrtl EQ p0001-btrtl.

CALL FUNCTION 'HR_ES_GET_NISSE_DATA'


EXPORTING
p_i_nisse = gt_data_es-nisse
p_i_date = pn-endda
IMPORTING
p_e_nisse_data = l_nisse_data
EXCEPTIONS
error = 1
OTHERS = 2.

CALL FUNCTION 'HR_E_GET_JUPER_DATA'


EXPORTING
p_juper = p0001-juper
p_actual_date = pn-endda
IMPORTING
p_juper_data = l_juper_data
EXCEPTIONS
error = 1
OTHERS = 2.

* gt_data_es-codpos = l_nisse_data-s_niss1-codpos.
* gt_data_es-provincia = l_nisse_data-s_niss1-textprovn.
* gt_data_es-domicil = l_nisse_data-s_niss1-domicil.
* gt_data_es-ort01 = l_nisse_data-s_niss1-localidad.
gt_data_es-aeptx = l_juper_data-activ_econom_text.
DATA: WA_T536A TYPE TABLE OF T536A WITH HEADER LINE,
COD_PROV TYPE T005U-BLAND.

SELECT * FROM T536A INTO TABLE WA_T536A WHERE ANART = '/E' AND VARGU =
p0001-juper.
LOOP AT WA_T536A.
CASE WA_T536A-SEQNU.
WHEN '1'.
gt_data_es-butxt = WA_T536A-ANTXT.
WHEN '2'.
gt_data_es-domicil = WA_T536A-ANTXT.
WHEN '3'.
CONCATENATE gt_data_es-domicil '.' WA_T536A-ANTXT INTO gt_data_es-
domicil SEPARATED BY SPACE.
WHEN '4'.
CONCATENATE gt_data_es-domicil WA_T536A-ANTXT INTO gt_data_es-
domicil SEPARATED BY SPACE.
WHEN '9'.
gt_data_es-codpos = WA_T536A-ANTXT.
ENDCASE.
endloop.
SELECT SINGLE LOCALID FROM T5E35 INTO gt_data_es-ort01 WHERE COD_POS =
gt_data_es-codpos.

COD_PROV = gt_data_es-codpos(2).
SELECT SINGLE BEZEI FROM T005U INTO gt_data_es-provincia WHERE SPRAS = sy-
langu
AND LAND1 =
'ES'
AND BLAND =
COD_PROV.

* SELECT SINGLE domicil codpos aeptx


* FROM t5e12
* INTO (gt_data_es-domicil,gt_data_es-
codpos,gt_data_es-aeptx)
* WHERE nisse EQ gt_data_es-nisse
* AND begda LE pn-endda
* AND endda GE pn-begda.

ENDIF.
ENDFORM. " GET_DATOS_EMPRESA
*&---------------------------------------------------------------------*
*& Form GET_DATOS_EMPLEADO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_datos_empleado .

DATA: lv_endda LIKE p0000-endda.

LOCAL p0000.

* Buscamos la baja hasta el día 1 del mes siguiente, para encontrar


* las bajas que empiezan justo en el cambio de mes.
lv_endda = pn-endda + 1.

REFRESH p0000.

CALL FUNCTION 'HR_READ_INFOTYPE'


EXPORTING
pernr = PNPPERNR-LOW
infty = '0000'
TABLES
infty_tab = p0000[]
EXCEPTIONS
infty_not_found = 1
OTHERS = 2.

rp_provide_from_last p0000 space pn-begda lv_endda.

IF pnp-sw-found EQ 1.

IF p0000-stat2 EQ gc_activo.
gt_data_es-acti_si = 'X'.
gt_data_es-acti_no = ''.
ELSE.
gt_data_es-acti_no = 'X'.
gt_data_es-acti_si = ''.

IF p0000-massn EQ gc_massn_s5 OR
p0000-massn EQ gc_massn_09.

PERFORM get_motivo_baja USING p0000-massg


p0000-massn
CHANGING gt_data_es-sitbaja.

PERFORM get_fecha_baja CHANGING gt_data_es-datbaja.

ENDIF.

ENDIF.

ENDIF.

rp_provide_from_last p0002 space pn-begda pn-endda.

IF pnp-sw-found EQ 1.

gt_data_es-ename = p0001-ename.

PERFORM tratar_nif USING p0002-perid CHANGING gt_data_es-perid.


* gt_data_es-perid = p0002-perid.

gt_data_es-gbdat = p0002-gbdat.
gt_data_es-gbort = p0002-gbort.
gt_data_es-gbdep = p0002-gbdep.

PERFORM get_text_provincia USING p0002-gblnd


p0002-gbdep
CHANGING gt_data_es-provitxt.

ENDIF.

* ini mmg
* rp_provide_from_last p0006 '0001' pn-begda pn-endda.
rp_provide_from_last p0006 '1' pn-begda pn-endda.
* fin mmg

IF pnp-sw-found EQ 1.

* gt_data_es-stras = p0006-stras.

CONCATENATE p0006-stras '-' p0006-hsnmr INTO gt_data_es-stras SEPARATED BY


space.

gt_data_es-pstlz = p0006-pstlz.
gt_data_es-pobla = p0006-ort01.
PERFORM get_text_provincia USING p0006-land1
p0006-state
CHANGING gt_data_es-provi.
ENDIF.

rp_provide_from_last p0061 space pn-begda pn-endda.

IF pnp-sw-found EQ 1.

gt_data_es-natss = p0061-natss.
gt_data_es-berkt = p0061-berkt.

" Texto Categoría profesional


SELECT SINGLE ctext FROM t5e8s
INTO gt_data_es-ctext
WHERE sprsl EQ sy-langu
AND mocat EQ gv_mocat
AND categ EQ p0061-berkt.
DATA: LV_CODOCU TYPE STRING.
SELECT SINGLE CODOCU FROM PA0480 INTO LV_CODOCU WHERE PERNR = PERNR-PERNR
AND BEGDA <= p0000-begda AND ENDDA >= p0000-begda.
SELECT SINGLE TTEXT FROM T5E75 INTO gt_data_es-texto WHERE COD_OCU =
LV_CODOCU.
* NgA 02.04.2012 En el campo Texto debe informarse la Categoría del Inf61
* gt_data_es-texto = gt_data_es-ctext.

gt_data_es-grcot = p0061-grcot.

* PERFORM get_text_tarea USING p0061-nisse


* p0061-begda
* p0061-endda
* p0061-grcot
* CHANGING gt_data_es-texto.

ENDIF.

rp_provide_from_last p0008 space pn-begda pn-endda.

IF pnp-sw-found EQ 1.

* NgA 02.04.2012 En el campo CTEXT debe informarse el Grupo Prof. del Inf08
gt_data_es-ctext = p0008-trfgr.

ENDIF.

* Baja por ILT


gt_data_es-ilt_si = ''.
gt_data_es-ilt_no = 'X'.

rp_provide_from_last p2001 space pn-endda pn-endda.

IF pnp-sw-found EQ 1.
* IF p2001-awart IN r_awart.

IF p2001-awart(1) EQ '1'
OR p2001-awart(1) EQ '2'
OR p2001-awart(1) EQ '3'.

gt_data_es-ilt_si = 'X'.
gt_data_es-ilt_no = ''.
gt_data_es-bajamedica = p2001-begda.

IF p0061-pcilt IS NOT INITIAL.


gt_data_es-presta_si = ''.
gt_data_es-presta_no = 'X'.
ELSE.
gt_data_es-presta_si = 'X'.
gt_data_es-presta_no = ''.
ENDIF.

ENDIF.
ENDIF.

PERFORM get_periodos_activos.

ENDFORM. " GET_DATOS_EMPLEADO


*&---------------------------------------------------------------------*
*& Form GET_TEXT_PROVINCIA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_LAND1 text
* -->P_LV_PROVI_NISSE text
* <--P_GT_DATA_ES_PROVINCIA text
*----------------------------------------------------------------------*
FORM get_text_provincia USING p_land1
p_bland
CHANGING p_bezei.

SELECT SINGLE bezei FROM t005u


INTO p_bezei
WHERE spras EQ sy-langu
AND land1 EQ p_land1
AND bland EQ p_bland.

ENDFORM. " GET_TEXT_PROVINCIA


*&---------------------------------------------------------------------*
*& Form GET_TEXT_TAREA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P0061_NISSE text
* -->P_P0061_ENDDA text
* <--P_GT_DATA_ES_TARTXT text
*----------------------------------------------------------------------*
FORM get_text_tarea USING p_nisse
p_begda
p_endda
p_grcot
CHANGING p_text.

DATA: lv_tpccc LIKE t5e08-tpccc.

CLEAR: p_text, lv_tpccc.

SELECT SINGLE tpccc FROM t5e08


INTO lv_tpccc
WHERE nisse EQ p_nisse
AND begda LE p_endda
AND endda GE p_begda.

SELECT SINGLE text FROM t5e4jt


INTO p_text
WHERE spras EQ sy-langu
AND tpccc EQ lv_tpccc
AND grcot EQ p_grcot.

ENDFORM. " GET_TEXT_TAREA


*&---------------------------------------------------------------------*
*& Form GET_BASES_15_ANYOS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_bases_15_anyos .

DATA: lt_bases TYPE zespy_str_conv_008-base_coti WITH HEADER LINE.


DATA: lt_rt TYPE hrpay99_rt WITH HEADER LINE.
DATA: lv_dss_vnd LIKE rt-anzhl,
lv_fech_ini TYPE string,
lv_fech_fin TYPE datum.

RANGES: r_lgart FOR pc207-lgart.

CLEAR r_lgart.
r_lgart-sign = 'I'.
r_lgart-option = 'EQ'.
r_lgart-low = '/302'.
APPEND r_lgart.
r_lgart-low = '/342'.
APPEND r_lgart.
r_lgart-low = '/3AC'.
APPEND r_lgart.
r_lgart-low = '/3AH'.
APPEND r_lgart.
r_lgart-low = '/3VG'.
APPEND r_lgart.
r_lgart-low = '/3VH'.
APPEND r_lgart.
r_lgart-low = '/3VM'.
APPEND r_lgart.
r_lgart-low = '/3VA'.
APPEND r_lgart.
* break smeri15.
* ini mmg
IF gv_begda_ini LT gc_date_sap.
PERFORM get_bases_m4 USING gv_begda_ini.
ENDIF.
* fin mmg

LOOP AT gt_periodos.

REFRESH: lt_rt.
CLEAR: lt_rt.

CLEAR: lt_bases.

IF gt_periodos-begda LT gc_date_sap.
* break smeri15.
" Recoger datos de la tabla ZHRPY_CONV_0001
LOOP AT gt_bases_m4 WHERE pernr EQ gt_data_es-pernr
AND anyo EQ gt_periodos-fpper(4)
AND mes EQ gt_periodos-fpper+4(2).

lt_bases-fpper = gt_periodos-fpper.
lt_bases-dias = lt_bases-dias + gt_bases_m4-dias_cot.
lt_bases-base = lt_bases-base + gt_bases_m4-base_cot.
lt_bases-waers = gt_bases_m4-waers.

ENDLOOP.

ELSE.

PERFORM import_rgdir.

IF rp-imp-cd-subrc = 0.

CLEAR: lv_dss_vnd.

LOOP AT rgdir WHERE fpper EQ gt_periodos-fpper


AND srtza EQ 'A'.

PERFORM import_cluster_re.

IF rp-imp-re-subrc = 0.

LOOP AT rt WHERE lgart IN r_lgart.

lt_bases-fpper = gt_periodos-fpper.
lt_bases-waers = versc-waers.

CASE rt-lgart.
WHEN '/302' OR '/342'.
lt_bases-base = lt_bases-base + rt-betrg.
WHEN '/3AC'.
lt_bases-dias = lt_bases-dias + rt-anzhl.
WHEN '/3AH'.
lt_bases-dias = lt_bases-dias - rt-anzhl.
WHEN '/3VM'.
lv_dss_vnd = rt-anzhl.
WHEN '/3VG'.
PERFORM fill_future_vnd TABLES lt_bases USING gt_periodos-
fpper rt.
WHEN '/3VA'.
gt_data_es-base_vac = gt_data_es-base_vac + rt-betrg.
gt_data_es-dias_vac = gt_data_es-dias_vac + rt-
anzhl."lv_dss_vnd = rt-anzhl.
ENDCASE.

ENDLOOP.
ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

IF lt_bases IS NOT INITIAL.

COLLECT lt_bases.

* Chequeamos si ha habido VND del mes anterior, para modificar los días.
IF lv_dss_vnd IS NOT INITIAL.

* Informamos lo días que encontramos en el mes en curso y no los que


* provienen de VND del mes anterior
IF lv_dss_vnd LT lt_bases-dias.
lv_dss_vnd = lt_bases-dias.
ENDIF.

READ TABLE lt_bases WITH KEY fpper = lt_bases-fpper.


IF sy-subrc = 0.

lt_bases-dias = lv_dss_vnd.
MODIFY lt_bases INDEX sy-tabix TRANSPORTING dias.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

rp_provide_from_last p0000 space pn-begda pn-endda.


IF p0000-MASSN(1) = 'B' AND gt_data_es-dias_vac is not initial.
MOVE gt_data_es-dias_vac TO lv_fech_ini.
lv_fech_fin = p0000-begda + lv_fech_ini.
CONCATENATE 'Desde' ':' p0000-begda+6(2) '/' p0000-begda+4(2) '/' p0000-
begda(4) '-' 'hasta' ':' SPACE lv_fech_fin+6(2) '/' lv_fech_fin+4(2) '/'
lv_fech_fin(4) INTO gt_data_es-vac_fecha SEPARATED BY SPACE.
ENDIF.
gt_data_es-base_coti[] = lt_bases[].
ENDFORM. " GET_BASES_15_ANYOS
*&---------------------------------------------------------------------*
*& Form GET_BASES_M4
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_bases_m4 USING p_date.

REFRESH: gt_bases_m4.
CLEAR: gt_bases_m4.

* data lv_pernr(8).
*
* lv_pernr = pernr-pernr.
*
* while lv_pernr(1) = 0.
* lv_pernr = lv_pernr+1.
* endwhile.

SELECT * FROM zespy_tab_conv_1


INTO CORRESPONDING FIELDS OF TABLE gt_bases_m4
WHERE pernr = PNPPERNR-LOW. "lv_pernr
* AND ( anyo GT p_date(4)
* OR ( anyo EQ p_date(4)
* AND mes GE p_date+4(2) ) ).

ENDFORM. " GET_BASES_M4


*&---------------------------------------------------------------------*
*& Form TRATAMIENTO_PLANTILLA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_PLANTILLA text
* -->P_CLASSNAME text
* -->P_CLASSTYPE text
* -->P_OBJECT_KEY text
* <--P_V_WORDOC text
* <--P_V_PATH text
*----------------------------------------------------------------------*
FORM tratamiento_plantilla USING p_plantilla
p_classname
p_classtype
p_object_key
CHANGING p_wordoc
p_path.
*-- Variables locales
DATA lv_plantilla LIKE file_table-filename.

*-- Recuperamos el directorio local SAPWORKDIR


CALL METHOD cl_gui_frontend_services=>get_sapgui_workdir
CHANGING
sapworkdir = gv_sapworkdir
EXCEPTIONS
get_sapworkdir_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

*.. Crea la instancia del SAP DOI ActiveX Control


CALL METHOD c_oi_container_control_creator=>get_container_control
IMPORTING
control = gv_control.

*-- Crea un contenedor Desktop Office Integration In-Place


CREATE OBJECT gv_container
EXPORTING
container_name = 'CONTAINER'.

*-- Inicializa el control


CALL METHOD gv_control->init_control
EXPORTING
r3_application_name = 'R/3 application'
parent = gv_container
inplace_enabled = 'X'.

*-- Crea instancia del documento


CALL METHOD gv_control->get_document_proxy
EXPORTING
document_type = gc_document_type
IMPORTING
document_proxy = gv_document.

*--
CLEAR: i_components, i_signature, i_connections, i_uris.
REFRESH: i_components, i_signature, i_connections, i_uris.
*-- Recuperamos la clave del objeto word
IF p_object_key IS INITIAL.
CALL FUNCTION 'BDS_BUSINESSDOCUMENT_GET_INFO'
EXPORTING
classname = p_classname
classtype = p_classtype
client = sy-mandt
* object_key = v_object_key
all = ' '
check_state = ' '
TABLES
components = i_components
signature = i_signature
connections = i_connections
EXCEPTIONS
nothing_found = 1
parameter_error = 2
not_allowed = 3
error_kpro = 4
internal_error = 5
not_authorized = 6
OTHERS = 7.

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CLEAR lv_plantilla.
lv_plantilla = p_plantilla.

LOOP AT i_components.
TRANSLATE: i_components-comp_id TO UPPER CASE,
lv_plantilla TO UPPER CASE.
CHECK i_components-comp_id = lv_plantilla.
READ TABLE i_signature WITH KEY doc_count = i_components-doc_count.
READ TABLE i_connections WITH KEY doc_id = i_signature-doc_id.
gv_object_key = i_connections-object_key.
EXIT.
ENDLOOP.
ELSE.
gv_object_key = p_object_key.
ENDIF.

*-- Llamada al módulo de función que recupera la localización del


*-- documento
CALL FUNCTION 'BDS_BUSINESSDOCUMENT_GET_URL'
EXPORTING
classname = p_classname
classtype = p_classtype
client = sy-mandt
object_key = gv_object_key "c_object_key
TABLES
uris = i_uris
signature = i_signature
EXCEPTIONS
nothing_found = 1
parameter_error = 2
not_allowed = 3
error_kpro = 4
internal_error = 5
not_authorized = 6
OTHERS = 7.

IF sy-subrc <> 0.
RAISE nothing_found.
ENDIF.

CLEAR: gv_doc_id, gv_doc_ver_no, gv_doc_var_id.

gv_doc_id = i_signature-doc_id.
gv_doc_ver_no = i_signature-doc_ver_no.
gv_doc_var_id = i_signature-doc_var_id.

*-- Bloqueamos la plantilla WORD


CALL FUNCTION 'BDS_BUSINESSDOCUMENT_ENQUEUE'
EXPORTING
classname = p_classname
classtype = p_classtype
client = sy-mandt
object_key = gv_object_key
doc_id = gv_doc_id
doc_ver_no = gv_doc_ver_no
doc_var_id = gv_doc_var_id
EXCEPTIONS
nothing_found = 1
parameter_error = 2
not_allowed = 3
error_kpro = 4
internal_error = 5
not_authorized = 6
foreign_lock = 7
OTHERS = 8.

CASE sy-subrc.
WHEN '1'.
RAISE nothing_found.
WHEN '2'.
RAISE parameter_error.
WHEN '3'.
RAISE not_allowed.
WHEN '4'.
RAISE error_kpro.
WHEN '5'.
RAISE internal_error.
WHEN '6'.
RAISE not_authorized.
WHEN '7'.
*-- Se asterisca esta opción debido a que en ocasiones se queda
*-- bloqueada la plantilla
* RAISE foreign_lock.
WHEN '8'.
RAISE others.
ENDCASE.

gv_uri = i_uris-uri.

*-- Abre el documento plantilla y obtiene su manejador


CALL METHOD gv_document->open_document
EXPORTING
document_url = gv_uri
* open_inplace = ' '.
open_inplace = 'X'.
* IMPORTING
* error = error
* retcode = retcode.

CONCATENATE: gv_sapworkdir

*&---------------------------------------------------------------------*
*& Include ZESPY_PRO_IN_CONV_0008_F02
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_data .

IF rb_wrd IS NOT INITIAL.


IF datos_word = 'X'.

PERFORM find_planti.

PERFORM word_open.
PERFORM datos_contrato USING 'BASE_COTI'.

clear_carta.
PERFORM cabecera_contratos.

SORT gt_data_es BY pernr.


LOOP AT gt_data_es.
PERFORM enviar_datos.
ENDLOOP.

PERFORM descarga_carta.
* PERFORM extrar_nombre_word.
PERFORM abrir_word.
PERFORM word_open.
ENDIF.

ELSE.

PERFORM fill_alv.

PERFORM display_alv.

ENDIF.

ENDFORM. " DISPLAY_DATA


*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form WORD_OPEN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM word_open .

* Inicio de la automatización OLE.


* Abrir Word en modo Basico. Sin Ventanas ni nada.
* create object wordobj 'Word.Basic'.
CREATE OBJECT worddoc 'Word.Document'.
GET PROPERTY OF worddoc 'Application' = wordapp.
SET PROPERTY OF wordapp 'Visible' = 1.
GET PROPERTY OF wordapp 'WordBasic' = wordobj.
CALL METHOD OF wordobj 'FileClose'.
* Mostrar la ventada del fichero anterior.
CALL METHOD OF wordobj 'AppShow'.

ENDFORM. " WORD_OPEN


*&---------------------------------------------------------------------*
*& Form CABECERA_CONTRATOS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM cabecera_contratos .

DATA: lv_per(25),
lv_data_per(25),
lv_dia(25),
lv_data_dia(25),
lv_bas(25),
lv_data_bas(25),
lv_index(3) TYPE n.

FIELD-SYMBOLS: <fs_per>,
<fs_dia>,
<fs_bas>.

MOVE 'nompers' TO gt_carta-nompers.


MOVE 'carrec' TO gt_carta-carrec.
MOVE 'butxt' TO gt_carta-butxt.
MOVE 'aeptx' TO gt_carta-aeptx.
MOVE 'nisse' TO gt_carta-nisse.
MOVE 'domicil' TO gt_carta-domicil.
MOVE 'codpos' TO gt_carta-codpos.
MOVE 'ort01' TO gt_carta-ort01.
MOVE 'provincia' TO gt_carta-provincia.
MOVE 'ename' TO gt_carta-ename.
MOVE 'perid' TO gt_carta-perid.
MOVE 'gbdat' TO gt_carta-gbdat.
MOVE 'gbort' TO gt_carta-gbort.
MOVE 'provitxt' TO gt_carta-provitxt.
MOVE 'natss' TO gt_carta-natss.
MOVE 'stras' TO gt_carta-stras.
MOVE 'pstlz' TO gt_carta-pstlz.
MOVE 'pobla' TO gt_carta-pobla.
MOVE 'provi' TO gt_carta-provi.
MOVE 'ctext' TO gt_carta-ctext.
MOVE 'grcot' TO gt_carta-grcot.
MOVE 'texto' TO gt_carta-texto.
MOVE 'acti_si' TO gt_carta-acti_si.
MOVE 'acti_no' TO gt_carta-acti_no.
MOVE 'sitbaja' TO gt_carta-sitbaja.
MOVE 'datbaja' TO gt_carta-datbaja.
MOVE 'ilt_si' TO gt_carta-ilt_si.
MOVE 'ilt_no' TO gt_carta-ilt_no.
MOVE 'bajamedica' TO gt_carta-bajamedica.
MOVE 'presta_si' TO gt_carta-presta_si.
MOVE 'presta_no' TO gt_carta-presta_no.
MOVE 'period01' TO gt_carta-period01.
MOVE 'period02' TO gt_carta-period02.
MOVE 'period03' TO gt_carta-period03.
MOVE 'period04' TO gt_carta-period04.
MOVE 'period05' TO gt_carta-period05.
MOVE 'period06' TO gt_carta-period06.
MOVE 'dref' TO gt_carta-dref.
MOVE 'mref' TO gt_carta-mref.
MOVE 'aref' TO gt_carta-aref.
MOVE 'base_vac' TO gt_carta-base_vac.
MOVE 'dias_vac' TO gt_carta-dias_vac.
MOVE 'vac_fecha' TO gt_carta-vac_fecha.

CLEAR: lv_per, lv_dia, lv_bas, lv_index,


lv_data_per, lv_data_dia, lv_data_bas.

lv_index = 1.

DO 288 TIMES.

CONCATENATE 'per' lv_index INTO lv_per.


CONCATENATE 'GT_CARTA-PER' lv_index INTO lv_data_per.

UNASSIGN <fs_per>.
ASSIGN (lv_data_per) TO <fs_per>.

IF sy-subrc EQ 0.
MOVE lv_per TO <fs_per>.
ENDIF.

CONCATENATE 'dia' lv_index INTO lv_dia.


CONCATENATE 'GT_CARTA-DIA' lv_index INTO lv_data_dia.

UNASSIGN <fs_dia>.
ASSIGN (lv_data_dia) TO <fs_dia>.

IF sy-subrc EQ 0.
MOVE lv_dia TO <fs_dia>.
ENDIF.

CONCATENATE 'bas' lv_index INTO lv_bas.


CONCATENATE 'GT_CARTA-BAS' lv_index INTO lv_data_bas.

UNASSIGN <fs_bas>.
ASSIGN (lv_data_bas) TO <fs_bas>.

IF sy-subrc EQ 0.
MOVE lv_bas TO <fs_bas>.
ENDIF.

lv_index = lv_index + 1.

ENDDO.

CONDENSE gt_carta NO-GAPS.


APPEND gt_carta.
CLEAR gt_carta.

ENDFORM. " CABECERA_CONTRATOS


*&---------------------------------------------------------------------*
*& Form ENVIAR_DATOS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM enviar_datos .

DATA: lv_per(25),
lv_data_per(25),
lv_dia(25),
lv_data_dia(25),
lv_bas(25),
lv_data_bas(25),
lv_index(3) TYPE n,
lv_initial(10).

DATA: lt_bases TYPE zespy_str_conv_008-base_coti WITH HEADER LINE.


FIELD-SYMBOLS: <fs_per>,
<fs_dia>,
<fs_bas>.

clear_carta.

MOVE gt_data_es-nompers TO gt_carta-nompers.


MOVE gt_data_es-carrec TO gt_carta-carrec.
MOVE gt_data_es-butxt TO gt_carta-butxt.
MOVE gt_data_es-aeptx TO gt_carta-aeptx.
MOVE gt_data_es-nisse TO gt_carta-nisse.
MOVE gt_data_es-domicil TO gt_carta-domicil.
MOVE gt_data_es-codpos TO gt_carta-codpos.
MOVE gt_data_es-ort01 TO gt_carta-ort01.
MOVE gt_data_es-provincia TO gt_carta-provincia.
MOVE gt_data_es-ename TO gt_carta-ename.
MOVE gt_data_es-perid TO gt_carta-perid.
IF gt_data_es-gbdat IS NOT INITIAL.
WRITE gt_data_es-gbdat TO gt_carta-gbdat.
ELSE.
gt_carta-gbdat = lv_initial.
ENDIF.
MOVE gt_data_es-gbort TO gt_carta-gbort.
MOVE gt_data_es-provitxt TO gt_carta-provitxt.
MOVE gt_data_es-natss TO gt_carta-natss.
MOVE gt_data_es-stras TO gt_carta-stras.
MOVE gt_data_es-pstlz TO gt_carta-pstlz.
MOVE gt_data_es-pobla TO gt_carta-pobla.
MOVE gt_data_es-provi TO gt_carta-provi.
MOVE gt_data_es-ctext TO gt_carta-ctext.
MOVE gt_data_es-grcot TO gt_carta-grcot.
MOVE gt_data_es-texto TO gt_carta-texto.
WRITE gt_data_es-acti_si TO gt_carta-acti_si RIGHT-JUSTIFIED.
WRITE gt_data_es-acti_no TO gt_carta-acti_no RIGHT-JUSTIFIED.

MOVE gt_data_es-sitbaja TO gt_carta-sitbaja .


IF gt_data_es-datbaja IS NOT INITIAL.
WRITE gt_data_es-datbaja TO gt_carta-datbaja.
ELSE.
gt_carta-datbaja = lv_initial.
ENDIF.
WRITE gt_data_es-ilt_si TO gt_carta-ilt_si RIGHT-JUSTIFIED.
WRITE gt_data_es-ilt_no TO gt_carta-ilt_no RIGHT-JUSTIFIED.
IF gt_data_es-bajamedica IS NOT INITIAL.
WRITE gt_data_es-bajamedica TO gt_carta-bajamedica.
ELSE.
gt_carta-bajamedica = lv_initial.
ENDIF.
WRITE gt_data_es-presta_si TO gt_carta-presta_si RIGHT-JUSTIFIED.
WRITE gt_data_es-presta_no TO gt_carta-presta_no RIGHT-JUSTIFIED.
MOVE gt_data_es-period01 TO gt_carta-period01.
MOVE gt_data_es-period02 TO gt_carta-period02.
MOVE gt_data_es-period03 TO gt_carta-period03.
MOVE gt_data_es-period04 TO gt_carta-period04.
MOVE gt_data_es-period05 TO gt_carta-period05.
MOVE gt_data_es-period06 TO gt_carta-period06.
MOVE gt_data_es-base_vac TO gt_carta-base_vac.
MOVE gt_data_es-dias_vac TO gt_carta-dias_vac.
MOVE gt_data_es-vac_fecha TO gt_carta-vac_fecha.
MOVE p_fecref(4) TO gt_carta-aref.
MOVE p_fecref+4(2) TO gt_carta-mref.
mes gt_carta-mref.
MOVE p_fecref+6(2) TO gt_carta-dref.

CLEAR: lv_per, lv_dia, lv_bas, lv_index,


lv_data_per, lv_data_dia, lv_data_bas.

REFRESH: lt_bases.
CLEAR: lt_bases.

lt_bases[] = gt_data_es-base_coti[].

lv_index = 1.

SORT lt_bases BY fpper ASCENDING.

LOOP AT lt_bases.

CONCATENATE 'GT_CARTA-PER' lv_index INTO lv_data_per.

UNASSIGN <fs_per>.
ASSIGN (lv_data_per) TO <fs_per>.

IF sy-subrc EQ 0.
CONCATENATE lt_bases-fpper+4(2) '/' lt_bases-fpper(4) INTO <fs_per>.
ENDIF.

CONCATENATE 'GT_CARTA-DIA' lv_index INTO lv_data_dia.

UNASSIGN <fs_dia>.
ASSIGN (lv_data_dia) TO <fs_dia>.
IF sy-subrc EQ 0.
WRITE lt_bases-dias TO <fs_dia> DECIMALS 0.
ENDIF.

CONCATENATE 'GT_CARTA-BAS' lv_index INTO lv_data_bas.

UNASSIGN <fs_bas>.
ASSIGN (lv_data_bas) TO <fs_bas>.

IF sy-subrc EQ 0.
WRITE lt_bases-base TO <fs_bas>.
ENDIF.

lv_index = lv_index + 1.

ENDLOOP.

* CONDENSE gt_carta.
APPEND gt_carta.

ENDFORM. " ENVIAR_DATOS


*&---------------------------------------------------------------------*
*& Form DESCARGA_CARTA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM descarga_carta .

DATA: l_filename TYPE string.


l_filename = gv_datos.

IF NOT ( gt_carta[] IS INITIAL ).


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
TABLES
data_tab = gt_carta
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.

IF sy-subrc EQ 2.

CALL FUNCTION 'GUI_CREATE_DIRECTORY'


EXPORTING
dirname = 'C:

You might also like