SAP HCM ABAP PRESTAMOS
From SapWiki
- 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
EJEMPLO 01
*&---------------------------------------------------------------------* *& 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