SAP HCM ABAP PRESTAMOS
From SapWiki
Revision as of 16:24, 16 May 2024 by WikiSysop (talk | contribs) (→Función HRXSS_IN_INSERT_P0045 para crear prestamos)
Contents
EJEMPLO 01
*cl_hrpa_loan_computations=>compute_estimated_end_of_loan *cl_hrpa_loan_computations=>read_payments_for_loan_id *cl_hrpa_loan_computations=>compute_repayment_plan *&---------------------------------------------------------------------* *& Report Y_TEST_LOAN *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT y_test_loan. TABLES pernr. INFOTYPES: 0045. DATA instance TYPE REF TO cl_hrpa_loan_computations. DATA gd_pclo_id TYPE pclo_id. DATA gd_estimated_end_of_loan TYPE d. DATA data_ref TYPE REF TO data. DATA gd_message_handler TYPE REF TO if_hrpa_message_handler. data gt_pagos type PCLO_PAYMENTS_TAB. data gt_P0078_TAB type P0078_TAB. data: gt_PCLO_REPAY_TAB type PCLO_REPAY_TAB, gt_PCLO_LOAN_CHANGES_TAB type PCLO_LOAN_CHANGES_TAB. * create dummy message handler data dummy_handler type ref to cl_hrpa_dummy_message_handler. create object dummy_handler. message_handler = dummy_handler. START-OF-SELECTION. GET pernr. PROVIDE * FROM p0045 BETWEEN pn-begda AND pn-endda. CALL METHOD cl_hrpa_loan_computations=>get_loan_id_from_p0045 EXPORTING p0045 = p0045 RECEIVING loan_id = gd_pclo_id. * CALCULO DE FECHA FINAL PRESTAMO TRY. CALL METHOD cl_hrpa_loan_computations=>compute_estimated_end_of_loan EXPORTING tclas = 'A' loan_id = gd_pclo_id message_handler = dummy_handler RECEIVING estimated_end_of_loan = gd_estimated_end_of_loan. ENDTRY. * PAGOS DE PRESTAMO TRY. CALL METHOD cl_hrpa_loan_computations=>read_payments_for_loan_id EXPORTING tclas = 'A' loan_id = gd_pclo_id * ZAHLA = '*' * SPRPS = '*' * BEGDA = LOW_DATE * ENDDA = HIGH_DATE * NO_AUTH_CHECK = FALSE IMPORTING PAYMENTS_TAB = gt_pagos * DATA_EXISTS = * MISSING_AUTH = . CATCH CX_HRPA_VIOLATED_ASSERTION . ENDTRY. TRY. CALL METHOD cl_hrpa_loan_computations=>read_p0078_for_loan_id EXPORTING tclas = 'A' loan_id = gd_pclo_id * ZAHLA = '*' * SPRPS = '*' * BEGDA = LOW_DATE * ENDDA = HIGH_DATE * NO_AUTH_CHECK = FALSE IMPORTING P0078_TAB = gt_P0078_TAB * DATA_EXISTS = * MISSING_AUTH = . CATCH CX_HRPA_VIOLATED_ASSERTION . ENDTRY. * GENERAR PLAN DE AMORTIZACION TRY. CALL METHOD cl_hrpa_loan_computations=>compute_repayment_plan EXPORTING tclas = 'A' loan_id = gd_pclo_id * NEW_CURRENCY = message_handler = dummy_handler IMPORTING REPAYMENT_PLAN = gt_PCLO_REPAY_TAB LOAN_CHANGES = gt_PCLO_LOAN_CHANGES_TAB * IS_OK = . CATCH CX_HRPA_VIOLATED_ASSERTION . ENDTRY. endPROVIDE. END-OF-SELECTION.
Calculo fecha fin de préstamo
FORM calcula_fecha_fin using p0045 type p0045 CHANGING p_endda. TYPES: BEGIN OF tp_dynfi, initf TYPE c, " initialize if marked key LIKE sy-tabix, darbt LIKE p0078-betrg, dbtcu LIKE p0078-btrcu, "currency for repayment plan rate LIKE p0045-anrte, ratec LIKE p0045-dbtcu, tilbg LIKE p0045-tilbg, zahld LIKE p0078-zahld, vari TYPE disvariant, END OF tp_dynfi. DATA ps_dynfi TYPE tp_dynfi. DATA: lt_p0078 TYPE p0078 OCCURS 0 WITH HEADER LINE. DATA lt_p0045 TYPE TABLE OF p0045 WITH HEADER LINE. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_p0078 FROM pa0078 WHERE pernr = p0045-pernr AND dlart = p0045-dlart AND objid = p0045-objps. ps_dynfi-rate = p0045-anrte. ps_dynfi-ratec = p0045-dbtcu. ps_dynfi-tilbg = p0045-begda. ps_dynfi-dbtcu = p0045-dbtcu. CALL FUNCTION 'PCLO_BUILD_REPAYMENT_PLAN' EXPORTING ps_p0045 = p0045 pf_fday = p0045-begda pf_lday = p0045-endda ""'99991231' pt_paym = lt_p0078[] pf_rate = ps_dynfi-rate pf_ratecurr = ps_dynfi-ratec "GWY534928 pf_tilbg = ps_dynfi-tilbg pf_curr = ps_dynfi-dbtcu "GWY428607-5 pf_variant = ps_dynfi-vari pf_nodisp = '1' IMPORTING * ps_paper = gs_paper pf_dlend = p0045-dlend * pf_effin = gf_effin pt_plan = gt_pclo_repay_tab. "amounts have currency pf_curr p_endda = p0045-dlend. ENDFORM. "CALCULa_fecha_fin
Obtener datos de préstamo
*Copiado de MP004500 FORM get_loan_results TABLES pt_savp STRUCTURE gt_savp USING pf_pernr pf_dlart pf_objps pf_dbtcu CHANGING pfx_opelo pfx_paylo pfx_abrdt pfx_subrc. DATA: ltx_rgdir LIKE pc261 OCCURS 0 WITH HEADER LINE, lt_rgdir TYPE hrpy_tt_rgdir, "GWY839032 lsx_rgdir LIKE ltx_rgdir, lsx_result TYPE pay99_result, lsx_v0 LIKE LINE OF lsx_result-inter-v0, lsx_rt LIKE LINE OF lsx_result-inter-rt, lfx_relid LIKE pcl2-relid, lfx_molga LIKE t500l-molga, lsx_t500l LIKE t500l, lfx_amount LIKE q0045-darbt, lfx_line LIKE sy-tabix, lfx_fday TYPE d, lfx_lday TYPE d, lfx_opecu LIKE q0045-opecu, ls_paper TYPE pc2paper, lf_payment_value_date TYPE datum, ls_loid_33 TYPE pclo_id. "Note 834827 *##--BEGIN--## CLEAR: pfx_opelo, pfx_paylo, pfx_abrdt, pfx_subrc. CALL FUNCTION 'CU_READ_RGDIR_NEW' EXPORTING persnr = pf_pernr check_read_authority = space IMPORTING molga = lfx_molga TABLES in_rgdir = ltx_rgdir EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. MOVE sy-subrc TO pfx_subrc. ELSE. MOVE sy-subrc TO pfx_subrc. CALL FUNCTION 'CD_READ_LAST_RESULT_IN_RGDIR' IMPORTING ptx_rgdir_nv = lsx_rgdir TABLES pt_rgdir = ltx_rgdir. LOOP AT ltx_rgdir. APPEND ltx_rgdir TO lt_rgdir. ENDLOOP. MOVE lsx_rgdir-fpend TO pfx_abrdt. * get relid SELECT SINGLE * FROM t500l INTO lsx_t500l WHERE molga = lfx_molga. MOVE lsx_t500l-relid TO lfx_relid. CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT' EXPORTING clusterid = lfx_relid employeenumber = pf_pernr sequencenumber = lsx_rgdir-seqnr read_only_international = 'X' check_read_authority = ' ' CHANGING payroll_result = lsx_result EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. MOVE sy-subrc TO pfx_subrc. ELSE. MOVE sy-subrc TO pfx_subrc. * get loan result ..... LOOP AT lsx_result-inter-v0 INTO lsx_v0 WHERE v0typ = 'L'. IF pf_dlart = lsx_v0-vinfo+0(4) AND pf_objps = lsx_v0-vinfo+4(2). LOOP AT lsx_result-inter-rt INTO lsx_rt WHERE v0typ = 'L' AND v0znr = lsx_v0-v0znr AND lgart = '/LLB'. MOVE: lsx_result-inter-versc-waers TO lfx_opecu, lsx_rt-betrg TO pfx_opelo. * PERFORM convert_to_local_currency * USING pfx_opelo * lfx_opecu * pf_dbtcu * pfx_abrdt * 'W' "called from PBO * SPACE "use BAPI for conversion * pf_pernr * lfx_molga * lt_rgdir * CHANGING pfx_opelo. EXIT. ENDLOOP. IF sy-subrc <> 0. "no open loan MOVE '9' TO pfx_subrc. EXIT. "the loop "GWY458200 ELSE. "GWY458200 MOVE '0' TO pfx_subrc. "found open loan "GWY458200 EXIT. "the loop "GWY458200 ENDIF. ELSE. "this loan is not yet processed in payroll MOVE '7' TO pfx_subrc. ENDIF. ENDLOOP. * get the correct payment for loans paid back already: * in a productive system one can assume that a loan with * q0045-begdaf < pfx_abrdt will be eather be open or paid back CHECK p0045-begda < pfx_abrdt. "#EC PORTABLE "GWY458200 * calculate ammount beeing payed so far PERFORM clear_ltrgdir TABLES ltx_rgdir. DESCRIBE TABLE ltx_rgdir LINES lfx_line. SORT ltx_rgdir ASCENDING BY seqnr. READ TABLE ltx_rgdir INDEX 1. lfx_fday = ltx_rgdir-fpbeg. READ TABLE ltx_rgdir INDEX lfx_line. lfx_lday = ltx_rgdir-fpend. SORT pt_savp ASCENDING BY zahld. LOOP AT pt_savp WHERE pydir = 'O' AND sprps = space. IF pt_savp-zahld >= lfx_fday AND pt_savp-zahld <= lfx_lday. LOOP AT ltx_rgdir WHERE fpbeg <= pt_savp-zahld AND fpend >= pt_savp-zahld. EXIT. ENDLOOP. IF sy-subrc NE 0. "JLA1532930 CONTINUE. ENDIF. ls_paper-pabrj = ltx_rgdir-fpper(4). ls_paper-pabrp = ltx_rgdir-fpper+4(2). CALL FUNCTION 'PCLO_GET_VALUE_DATE_PAYMENT' "GWY839032 EXPORTING pf_zahla = pt_savp-zahla pf_payment_begda = pt_savp-zahld pf_payment_endda = pt_savp-endda pf_molga = lfx_molga pf_abkrs = ltx_rgdir-abkrs * PF_ABKRS_BEGDA = '19000101' * PF_ABKRS_ENDDA = '99991231' pf_paper = ls_paper IMPORTING pfx_value_date = lf_payment_value_date EXCEPTIONS error = 1 payment_not_in_period = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * PERFORM convert_to_local_currency * USING pt_savp-betrg * pt_savp-btrcu * pf_dbtcu * lf_payment_value_date * 'W' "called from PBO * SPACE "use BAPI for conversion * pf_pernr * lfx_molga * lt_rgdir * CHANGING pt_savp-betrg. ADD pt_savp-betrg TO lfx_amount. ENDIF. ENDLOOP. MOVE lfx_amount TO pfx_paylo. ENDIF. ENDIF. ENDFORM. " GET_LOAN_RESULTS
Función HRXSS_IN_INSERT_P0045 para crear prestamos
REPORT ytest_prestamos_2. PARAMETERS: p_pernr TYPE p0045-pernr, p_begda TYPE p0045-begda, p_endda TYPE p0045-endda. DATA im_zthcmes001 TYPE zthcmes001. DATA gt_msg TYPE hrpbsinbapiret. im_zthcmes001-pernr = p_pernr. im_zthcmes001-begda = p_begda. im_zthcmes001-endda = p_endda. im_zthcmes001-ufsolicitada = 4. im_zthcmes001-valor_cuota = 1. PERFORM insert_record_p0045 USING im_zthcmes001 CHANGING gt_msg. LOOP AT gt_msg INTO DATA(ls_msg). ENDLOOP. if sy-subrc <> 0. COMMIT WORK AND WAIT. ENDIF. FORM insert_record_p0045 USING im_zthcmes001 TYPE zthcmes001 CHANGING p_gt_messages TYPE hrpbsinbapiret. DATA: ls_0045 TYPE pa0045, lt_0078 TYPE p0078_tab, ls_p0078 LIKE LINE OF lt_0078. DATA p0045 TYPE p0045. CLEAR p_gt_messages[]. CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE' EXPORTING number = im_zthcmes001-pernr. ls_0045-pernr = im_zthcmes001-pernr. ls_0045-subty = 'ZV01'. ls_0045-dlart = 'ZV01'. ls_0045-begda = im_zthcmes001-begda. ls_0045-endda = '99991231'. ls_0045-darbt = im_zthcmes001-ufsolicitada * 1000. "Importe de préstamo autorizado ls_0045-dbtcu = 'UF'. ls_0045-dkond = '01'. ls_0045-tilbt = im_zthcmes001-valor_cuota * 1000. "Cuota amortiz. ls_0045-tilcu = 'UF'. ls_0045-tilbg = ls_0045-begda. "Inicio de la amortización ls_0045-datbw = ls_0045-begda. "Fecha de la autorización MOVE-CORRESPONDING ls_0045 to p0045. PERFORM calcula_fecha_fin USING p0045. ls_0045-endda = p0045-endda. ls_0045-dlend = p0045-dlend. * MOVE-CORRESPONDING ls_0045 TO p0045. * PERFORM set_objps USING p0045 CHANGING ls_0045-objps. ls_p0078-subty = '0300'. ls_p0078-zahla = ls_p0078-subty. "payment type ls_p0078-dlart = ls_0045-dlart. "Clase de préstamo ls_p0078-pernr = ls_0045-darbt-pernr. ls_p0078-begda = ls_0045-darbt-begda. "Begin date ls_p0078-endda = ls_0045-darbt-begda. "End date ls_p0078-zahld = ls_0045-darbt-begda. "Payment date ls_p0078-betrg = ls_0045-darbt. "Importe de pago ls_p0078-btrcu = ls_0045-dbtcu. "Clave de moneda APPEND ls_p0078 TO lt_0078. DATA l_clear_buffer(1) VALUE ''. IF p_gt_messages[] IS INITIAL. CALL FUNCTION 'HRXSS_IN_INSERT_P0045' EXPORTING wa0045 = ls_0045 it0078 = lt_0078 clear_buffer = l_clear_buffer IMPORTING err_messages = p_gt_messages. ENDIF. ENDFORM. " insert_record_p0045 FORM calcula_fecha_fin CHANGING p_p0045 TYPE p0045. TYPES: BEGIN OF tp_dynfi, initf TYPE c, " initialize if marked key LIKE sy-tabix, darbt LIKE p0078-betrg, dbtcu LIKE p0078-btrcu, "currency for repayment plan rate LIKE p0045-anrte, ratec LIKE p0045-dbtcu, tilbg LIKE p0045-tilbg, zahld LIKE p0078-zahld, vari TYPE disvariant, END OF tp_dynfi. DATA ps_dynfi TYPE tp_dynfi. DATA: lt_p0078 TYPE p0078 OCCURS 0 WITH HEADER LINE. DATA p0045 TYPE p0045. MOVE-CORRESPONDING p_p0045 TO p0045. p0045-infty = '0045'. lt_p0078-pernr = p0045-pernr. lt_p0078-dlart = p0045-dlart. lt_p0078-objid = p0045-objps. lt_p0078-subty = '0300'. "external payment lt_p0078-zahla = '0300'. "external payment lt_p0078-begda = p0045-begda. lt_p0078-endda = p0045-begda. lt_p0078-betrg = p0045-darbt. lt_p0078-btrcu = p0045-dbtcu. APPEND lt_p0078. ps_dynfi-rate = p0045-anrte. ps_dynfi-ratec = p0045-dbtcu. ps_dynfi-tilbg = p0045-begda. ps_dynfi-dbtcu = p0045-dbtcu. CALL FUNCTION 'PCLO_BUILD_REPAYMENT_PLAN' EXPORTING ps_p0045 = p0045 pf_fday = p0045-begda pf_lday = p0045-endda ""'99991231' pt_paym = lt_p0078[] pf_rate = ps_dynfi-rate pf_ratecurr = ps_dynfi-ratec "GWY534928 pf_tilbg = ps_dynfi-tilbg pf_curr = ps_dynfi-dbtcu "GWY428607-5 pf_variant = ps_dynfi-vari pf_nodisp = '1' IMPORTING * ps_paper = gs_paper pf_dlend = p_p0045-dlend * pf_effin = gf_effin * pt_plan = gt_rplan "amounts have currency pf_curr . p_p0045-endda = p_p0045-dlend. ENDFORM. "CALCULa_fecha_fin
Si al ejecutar la función da este error
No existe ningún período de parámetro de período 01 que se encuentre en 01.01.2041 ( No period of period parameter xx that contains dd.mm.yyyy was found" (Exception of class CX_HRPY_PAYROLL_AREA) )
Hay que aplicar la nota SAP 2469209
Resolution
Start report RPUCTP00.
Generate payroll periods for the next 80 years and the period parameter from the error message.
(Internally, 60 years from today are needed to generate the repayment plan of a loan. But in order to avoid getting the same error in the near future, we recommend to generate periods for 80 years.)
Otras funciones relacionadas
- HRXSS_IN_INSERT_P0015
- HRXSS_IN_INSERT_P0045
- HRXSS_IN_INSERT_P0078
- HRXSS_IN_INSERT_P0267