Essa classe lê documentos contábeis e gera novas contrapartidas rateadas.
CLASS zcl_rateio_pep DEFINITION
PUBLIC
CREATE PUBLIC .
PUBLIC SECTION.
TYPES:
ty_r_belnr TYPE RANGE OF belnr_d .
TYPES:
BEGIN OF ty_s_bkpf,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
awtyp TYPE bkpf-awtyp,
awkey TYPE bkpf-awkey,
END OF ty_s_bkpf .
TYPES:
ty_t_bkpf TYPE SORTED TABLE OF ty_s_bkpf
WITH UNIQUE KEY bukrs belnr gjahr
WITH NON-UNIQUE SORTED KEY awkey COMPONENTS awkey .
TYPES:
BEGIN OF ty_s_bseg,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
buzei TYPE buzei,
END OF ty_s_bseg .
TYPES:
ty_t_bseg TYPE SORTED TABLE OF ty_s_bseg
WITH UNIQUE KEY bukrs belnr gjahr buzei .
METHODS constructor
IMPORTING
!i_background TYPE abap_bool OPTIONAL
!it_belnr TYPE ty_r_belnr OPTIONAL
!is_bkpf TYPE ty_s_bkpf OPTIONAL
!is_bseg TYPE ty_s_bseg OPTIONAL
!iv_aktyp TYPE aktyp OPTIONAL
!it_bkpf TYPE ty_t_bkpf OPTIONAL
!it_bseg TYPE ty_t_bseg OPTIONAL
!iv_vbeln TYPE vbeln_vf OPTIONAL
!iv_bukrs TYPE bukrs OPTIONAL
!iv_gjahr TYPE gjahr OPTIONAL
!iv_testrun TYPE abap_bool OPTIONAL .
METHODS execute .
PROTECTED SECTION.
DATA _background TYPE abap_bool .
DATA _bukrs TYPE bukrs .
DATA _gjahr TYPE gjahr .
DATA _handle TYPE balloghndl .
DATA _testrun TYPE abap_bool .
DATA _vbeln TYPE vbeln_vf .
PRIVATE SECTION.
TYPES:
"rldnr, rbukrs, gjahr, belnr, docln, hsl, wsl, awtyp, racct, ps_psp_pnr, ps_posid, ps_prj_pnr, ps_pspid
BEGIN OF ty_s_acdoca,
rldnr TYPE acdoca-rldnr,
rbukrs TYPE acdoca-rbukrs,
gjahr TYPE acdoca-gjahr,
belnr TYPE acdoca-belnr,
docln TYPE acdoca-docln,
rwcur TYPE acdoca-rwcur,
wsl TYPE acdoca-wsl,
rhcur TYPE acdoca-rhcur,
hsl TYPE acdoca-hsl,
racct TYPE acdoca-racct,
kokrs TYPE acdoca-kokrs,
ps_psp_pnr TYPE acdoca-ps_psp_pnr,
ps_posid TYPE acdoca-ps_posid,
ps_prj_pnr TYPE acdoca-ps_psp_pnr,
ps_pspid TYPE acdoca-ps_pspid,
END OF ty_s_acdoca .
TYPES:
ty_t_acdoca TYPE SORTED TABLE OF ty_s_acdoca
WITH UNIQUE KEY rldnr rbukrs gjahr belnr docln
WITH NON-UNIQUE SORTED KEY pspnr COMPONENTS ps_psp_pnr
WITH NON-UNIQUE SORTED KEY posid COMPONENTS ps_posid
WITH NON-UNIQUE SORTED KEY psphi COMPONENTS ps_prj_pnr
WITH NON-UNIQUE SORTED KEY pspid COMPONENTS ps_pspid .
TYPES:
BEGIN OF ty_s_wbs_element,
psphi TYPE prps-psphi,
pspnr TYPE prps-pspnr,
posid TYPE prps-posid,
posid_edit TYPE prps-posid_edit,
zztp_job TYPE prps-zztp_job,
usr06 TYPE prps-usr06,
use06 TYPE prps-use06,
usr07 TYPE prps-usr07,
END OF ty_s_wbs_element .
TYPES:
ty_t_wbs_elements TYPE SORTED TABLE OF ty_s_wbs_element
WITH UNIQUE KEY psphi pspnr posid .
TYPES:
BEGIN OF ty_s_acdoca_key,
rldnr TYPE acdoca-rldnr,
rbukrs TYPE acdoca-rbukrs,
gjahr TYPE acdoca-gjahr,
belnr TYPE acdoca-belnr,
docln TYPE acdoca-docln,
sgtxt TYPE acdoca-sgtxt,
xblnr TYPE bkpf-xblnr,
bktxt TYPE bkpf-bktxt,
END OF ty_s_acdoca_key .
TYPES:
ty_t_acdoca_keys TYPE SORTED TABLE OF ty_s_acdoca_key
WITH UNIQUE KEY rldnr rbukrs gjahr belnr docln
WITH NON-UNIQUE SORTED KEY sgtxt COMPONENTS sgtxt
WITH NON-UNIQUE SORTED KEY xblnr COMPONENTS xblnr
WITH NON-UNIQUE SORTED KEY bktxt COMPONENTS bktxt .
CONSTANTS c_0001 TYPE bukrs VALUE '0001' ##NO_TEXT.
CONSTANTS c_0057 TYPE bukrs VALUE '0057' ##NO_TEXT.
CONSTANTS c_0l TYPE rldnr VALUE '0L' ##NO_TEXT.
* types:
* ty_t_acdoca_keys TYPE STANDARD TABLE OF ty_s_acdoca_key with DEFAULT KEY .
CONSTANTS c_apoio TYPE ztp_job VALUE 'A' ##NO_TEXT.
CONSTANTS c_bkpf TYPE awtyp VALUE 'BKPF' ##NO_TEXT.
CONSTANTS c_pep TYPE j_obart VALUE 'PR' ##NO_TEXT.
CONSTANTS c_principal TYPE ztp_job VALUE 'P' ##NO_TEXT.
CONSTANTS c_vbrk TYPE awtyp VALUE 'VBRK' ##NO_TEXT.
DATA ms_bkpf TYPE ty_s_bkpf .
DATA ms_bseg TYPE ty_s_bseg .
DATA mt_bkpf TYPE ty_t_bkpf .
DATA mt_bseg TYPE ty_t_bseg .
DATA mt_open_items TYPE ty_t_acdoca .
DATA mt_processed_items TYPE ty_t_acdoca_keys .
DATA mt_wbs_elements TYPE ty_t_wbs_elements .
DATA r_belnr TYPE ty_r_belnr .
METHODS apportionment_calculate .
METHODS apportionment_calculate_cr .
METHODS apportionment_calculate_cr_fat .
METHODS apportionment_post
IMPORTING
!is_documentheader TYPE bapiache09
CHANGING
!ct_accountgl TYPE bapiacgl09_tab
!ct_currencyamount TYPE bapiaccr09_tab .
METHODS select_open_items .
METHODS select_wbs_elements .
METHODS select_processed_items .
METHODS wait_for_document_creation
RETURNING
VALUE(r_was_fully_created) TYPE abap_bool .
METHODS is_running_in_background
RETURNING
VALUE(r_background) TYPE abap_bool .
METHODS wait_until_selection_journal .
METHODS apportionment_check
IMPORTING
!is_documentheader TYPE bapiache09
CHANGING
!ct_accountgl TYPE bapiacgl09_tab
!ct_currencyamount TYPE bapiaccr09_tab .
ENDCLASS.
CLASS zcl_rateio_pep IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->APPORTIONMENT_CALCULATE
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD apportionment_calculate.
DATA:
lt_accountgl TYPE bapiacgl09_tab,
lt_currencyamount TYPE bapiaccr09_tab.
MESSAGE i041 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
LOOP AT mt_open_items ASSIGNING FIELD-SYMBOL(<key>)
GROUP BY ( rldnr = <key>-rldnr
rbukrs = <key>-rbukrs
gjahr = <key>-gjahr
belnr = <key>-belnr )
ASSIGNING FIELD-SYMBOL(<group>).
DATA(ls_acdoca_key) = VALUE ty_s_acdoca_key(
rldnr = <group>-rldnr
rbukrs = <group>-rbukrs
gjahr = <group>-gjahr
belnr = <group>-belnr ).
IF line_exists( mt_processed_items[ KEY sgtxt sgtxt = CONV #( ls_acdoca_key ) ] ) OR
line_exists( mt_processed_items[ KEY bktxt bktxt = CONV #( ls_acdoca_key ) ] ).
CONTINUE.
ENDIF.
MESSAGE i042 WITH <group>-rldnr <group>-rbukrs <group>-gjahr <group>-belnr INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
LOOP AT GROUP <group> INTO DATA(ls_member).
IF line_exists( mt_processed_items[ KEY xblnr xblnr = ls_member-belnr ] ).
CONTINUE.
ENDIF.
DATA(ls_documentheader) = VALUE bapiache09(
username = sy-uname
header_txt = |{ <group>-rldnr }{ <group>-rbukrs }{ <group>-gjahr }{ <group>-belnr }|
comp_code = ls_member-rbukrs
doc_date = sy-datum
pstng_date = sy-datum
fisc_year = ls_member-gjahr
ref_doc_no = ls_member-belnr ).
DATA(ls_1st_accountgl) = VALUE bapiacgl09(
itemno_acc = CONV posnr_acc( |{ lines( lt_accountgl ) + 1 }| )
gl_account = ls_member-racct
item_text = |{ <group>-rldnr }{ <group>-rbukrs }{ <group>-gjahr }{ <group>-belnr }|
ref_key_3 = |{ <group>-rbukrs }{ <group>-gjahr }{ <group>-belnr }{ ls_member-docln }|
doc_type = `SA`
comp_code = <group>-rbukrs
fisc_year = <group>-gjahr
pstng_date = sy-datum
wbs_element = ls_member-ps_posid ).
INSERT ls_1st_accountgl INTO TABLE lt_accountgl.
DATA(ls_1st_currencyamount) = VALUE bapiaccr09(
itemno_acc = CONV posnr_acc( |{ lines( lt_currencyamount ) + 1 }| )
curr_type = '00'
currency = ls_member-rwcur
currency_iso = ls_member-rwcur
amt_doccur = - ls_member-wsl ).
INSERT ls_1st_currencyamount INTO TABLE lt_currencyamount REFERENCE INTO DATA(lr_1st_currencyamount).
DATA(acumulado) = CONV fins_vhcur12( 0 ).
* DATA(saldo) = lr_1st_currencyamount->amt_doccur.
DATA(lt_filter) = FILTER #( mt_wbs_elements WHERE psphi = ls_member-ps_prj_pnr ).
* LOOP AT mt_wbs_elements ASSIGNING FIELD-SYMBOL(<filter>) WHERE psphi = ls_member-ps_prj_pnr .
LOOP AT lt_filter ASSIGNING FIELD-SYMBOL(<filter>).
DATA(ls_accountgl) = VALUE bapiacgl09(
itemno_acc = CONV posnr_acc( |{ lines( lt_accountgl ) + 1 }| )
gl_account = ls_member-racct
item_text = |{ <group>-rldnr }{ <group>-rbukrs }{ <group>-gjahr }{ <group>-belnr }|
ref_key_3 = |{ <group>-rbukrs }{ <group>-gjahr }{ <group>-belnr }{ ls_member-docln }|
doc_type = `SA`
comp_code = <group>-rbukrs
fisc_year = <group>-gjahr
pstng_date = sy-datum
wbs_element = <filter>-posid_edit ).
INSERT ls_accountgl INTO TABLE lt_accountgl.
DATA(ls_currencyamount) = VALUE bapiaccr09(
itemno_acc = CONV posnr_acc( |{ lines( lt_currencyamount ) + 1 }| )
curr_type = '00'
currency = ls_member-rwcur
currency_iso = ls_member-rwcur
amt_doccur = CONV fins_vhcur12( ( ls_member-wsl * <filter>-usr07 ) / 10 ) ).
* ADD ls_currencyamount-amt_doccur TO saldo.
AT LAST.
IF ( lr_1st_currencyamount->amt_doccur - acumulado ) > 0.
ls_currencyamount-amt_doccur = ( acumulado - lr_1st_currencyamount->amt_doccur ).
ELSE.
ls_currencyamount-amt_doccur = - ( lr_1st_currencyamount->amt_doccur - acumulado ).
ENDIF.
ENDAT.
SUBTRACT ls_currencyamount-amt_doccur FROM acumulado.
INSERT ls_currencyamount INTO TABLE lt_currencyamount.
ENDLOOP.
ENDLOOP.
LOG-POINT ID zcr047 FIELDS <group> lt_accountgl lt_currencyamount.
LOOP AT lt_accountgl ASSIGNING FIELD-SYMBOL(<accountgl_log>).
DATA(ls_currencyamount_log) = VALUE #( lt_currencyamount[ itemno_acc = <accountgl_log>-itemno_acc ] OPTIONAL ).
MESSAGE i043 WITH <accountgl_log>-wbs_element
<accountgl_log>-gl_account
ls_currencyamount_log-amt_doccur
INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDLOOP.
IF lt_accountgl[] IS NOT INITIAL AND lt_currencyamount[] IS NOT INITIAL.
IF _testrun IS INITIAL.
apportionment_post(
EXPORTING
is_documentheader = ls_documentheader
CHANGING
ct_accountgl = lt_accountgl
ct_currencyamount = lt_currencyamount ).
ELSE.
apportionment_check(
EXPORTING
is_documentheader = ls_documentheader
CHANGING
ct_accountgl = lt_accountgl
ct_currencyamount = lt_currencyamount ).
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->APPORTIONMENT_CALCULATE_CR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD apportionment_calculate_cr.
"CR79 lan�amento de documento atribu�do o n�mero do PEP ao cliente
DATA:
lt_accountgl TYPE bapiacgl09_tab,
ty_r_racct TYPE RANGE OF acdoca-racct,
lt_currencyamount TYPE bapiaccr09_tab.
SELECT SINGLE low
FROM tvarvc
INTO @DATA(gl_conta)
WHERE name EQ 'ZCR79_CONTA'.
CALL METHOD zcl_parametros=>obter_variaveis
EXPORTING
im_nome = 'ZCR79_RANGE_CONTA'
im_tipo = 'S'
IMPORTING
ex_range = ty_r_racct
EXCEPTIONS
nao_encontrado = 1
OTHERS = 2.
READ TABLE mt_open_items INTO DATA(gs_mt_open_items) INDEX 1.
SELECT *
FROM bkpf
WHERE bktxt = 'Rateio Receb�veis'
AND xblnr = @gs_mt_open_items-belnr
AND bukrs = @gs_mt_open_items-rbukrs
INTO TABLE @DATA(bkpf_check) .
IF bkpf_check[] IS NOT INITIAL.
SELECT *
FROM acdoca
FOR ALL ENTRIES IN @mt_open_items
WHERE rldnr = @c_0l
AND rbukrs = @mt_open_items-rbukrs
AND belnr = @mt_open_items-belnr
AND racct IN @ty_r_racct
AND budat = @sy-datum
AND awtyp = @c_vbrk
AND drcrk = 'S'
INTO TABLE @DATA(mt_open_items_cr) .
ENDIF.
MESSAGE i041 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
LOOP AT mt_open_items_cr ASSIGNING FIELD-SYMBOL(<key>)
GROUP BY ( rldnr = <key>-rldnr
rbukrs = <key>-rbukrs
gjahr = <key>-gjahr
belnr = <key>-belnr )
ASSIGNING FIELD-SYMBOL(<group>).
DATA(ls_acdoca_key) = VALUE ty_s_acdoca_key(
rldnr = <group>-rldnr
rbukrs = <group>-rbukrs
gjahr = <group>-gjahr
belnr = <group>-belnr ).
IF line_exists( mt_processed_items[ KEY sgtxt sgtxt = CONV #( ls_acdoca_key ) ] ) OR
line_exists( mt_processed_items[ KEY bktxt bktxt = CONV #( ls_acdoca_key ) ] ).
CONTINUE.
ENDIF.
MESSAGE i042 WITH <group>-rldnr <group>-rbukrs <group>-gjahr <group>-belnr INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
LOOP AT GROUP <group> INTO DATA(ls_member).
IF line_exists( mt_processed_items[ KEY xblnr xblnr = ls_member-belnr ] ).
CONTINUE.
ENDIF.
DATA(ls_documentheader) = VALUE bapiache09(
username = sy-uname
header_txt = 'Rateio Receb�veis'
comp_code = ls_member-rbukrs
doc_date = sy-datum
pstng_date = sy-datum
doc_type = `SA`
fisc_year = ls_member-gjahr
ref_doc_no = ls_member-belnr ).
DATA(ls_1st_accountgl) = VALUE bapiacgl09(
itemno_acc = CONV posnr_acc( |{ lines( lt_accountgl ) + 1 }| )
gl_account = gl_conta
item_text = 'Rateio do Contas a Receber'
doc_type = `SA`
comp_code = <group>-rbukrs
fisc_year = <group>-gjahr
pstng_date = sy-datum ).
INSERT ls_1st_accountgl INTO TABLE lt_accountgl.
DATA(ls_1st_currencyamount) = VALUE bapiaccr09(
itemno_acc = CONV posnr_acc( |{ lines( lt_currencyamount ) + 1 }| )
currency = ls_member-rhcur
amt_doccur = - ls_member-wsl ).
INSERT ls_1st_currencyamount INTO TABLE lt_currencyamount REFERENCE INTO DATA(lr_1st_currencyamount).
DATA(acumulado) = CONV fins_vhcur12( 0 ).
* DATA(saldo) = lr_1st_currencyamount->amt_doccur.
DATA(lt_filter) = FILTER #( mt_wbs_elements WHERE psphi = gs_mt_open_items-ps_prj_pnr ).
* LOOP AT mt_wbs_elements ASSIGNING FIELD-SYMBOL(<filter>) WHERE psphi = ls_member-ps_prj_pnr .
LOOP AT lt_filter ASSIGNING FIELD-SYMBOL(<filter>).
DATA(ls_accountgl) = VALUE bapiacgl09(
itemno_acc = CONV posnr_acc( |{ lines( lt_accountgl ) + 1 }| )
gl_account = gl_conta
item_text = 'Rateio do Contas a Receber'
doc_type = `SA`
comp_code = <group>-rbukrs
fisc_year = <group>-gjahr
pstng_date = sy-datum
wbs_element = <filter>-posid_edit ).
INSERT ls_accountgl INTO TABLE lt_accountgl.
DATA(ls_currencyamount) = VALUE bapiaccr09(
itemno_acc = CONV posnr_acc( |{ lines( lt_currencyamount ) + 1 }| )
currency = ls_member-rhcur
amt_doccur = CONV fins_vhcur12( ( ls_member-wsl * <filter>-usr07 ) / 100 ) ).
* ADD ls_currencyamount-amt_doccur TO saldo.
AT LAST.
IF ( lr_1st_currencyamount->amt_doccur - acumulado ) > 0.
ls_currencyamount-amt_doccur = ( acumulado - lr_1st_currencyamount->amt_doccur ).
ELSE.
ls_currencyamount-amt_doccur = - ( lr_1st_currencyamount->amt_doccur - acumulado ).
ENDIF.
ENDAT.
SUBTRACT ls_currencyamount-amt_doccur FROM acumulado.
INSERT ls_currencyamount INTO TABLE lt_currencyamount.
ENDLOOP.
ENDLOOP.
LOG-POINT ID zcr047 FIELDS <group> lt_accountgl lt_currencyamount.
LOOP AT lt_accountgl ASSIGNING FIELD-SYMBOL(<accountgl_log>).
DATA(ls_currencyamount_log) = VALUE #( lt_currencyamount[ itemno_acc = <accountgl_log>-itemno_acc ] OPTIONAL ).
MESSAGE i043 WITH <accountgl_log>-wbs_element
<accountgl_log>-gl_account
ls_currencyamount_log-amt_doccur
INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDLOOP.
IF lt_accountgl[] IS NOT INITIAL AND lt_currencyamount[] IS NOT INITIAL.
IF _testrun IS INITIAL.
apportionment_post(
EXPORTING
is_documentheader = ls_documentheader
CHANGING
ct_accountgl = lt_accountgl
ct_currencyamount = lt_currencyamount ).
ELSE.
apportionment_check(
EXPORTING
is_documentheader = ls_documentheader
CHANGING
ct_accountgl = lt_accountgl
ct_currencyamount = lt_currencyamount ).
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->APPORTIONMENT_CHECK
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_DOCUMENTHEADER TYPE BAPIACHE09
* | [<-->] CT_ACCOUNTGL TYPE BAPIACGL09_TAB
* | [<-->] CT_CURRENCYAMOUNT TYPE BAPIACCR09_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD apportionment_check.
MESSAGE i044 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(lt_return) = VALUE bapiret2_tab( ( ) ).
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = is_documentheader
* CUSTOMERCPD =
* CONTRACTHEADER =
TABLES
accountgl = ct_accountgl
* ACCOUNTRECEIVABLE =
* ACCOUNTPAYABLE =
* ACCOUNTTAX =
currencyamount = ct_currencyamount
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
return = lt_return
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.
LOG-POINT ID zcr047 FIELDS lt_return .
LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<return>).
MESSAGE ID <return>-id
TYPE <return>-type
NUMBER <return>-number
WITH <return>-message_v1 <return>-message_v2 <return>-message_v3 <return>-message_v4
INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
ENDLOOP.
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->APPORTIONMENT_POST
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_DOCUMENTHEADER TYPE BAPIACHE09
* | [<-->] CT_ACCOUNTGL TYPE BAPIACGL09_TAB
* | [<-->] CT_CURRENCYAMOUNT TYPE BAPIACCR09_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD apportionment_post.
MESSAGE i044 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(lt_return) = VALUE bapiret2_tab( ( ) ).
DATA(doc_no) = VALUE co_belnr( ).
DATA(obj_type) = VALUE bapiache09-obj_type( ). "#EC NEEDED
DATA(obj_key) = VALUE bapiache09-obj_key( ). "#EC NEEDED
DATA(obj_sys) = VALUE bapiache09-obj_sys( ). "#EC NEEDED
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = is_documentheader
* CUSTOMERCPD =
* CONTRACTHEADER =
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = ct_accountgl
* ACCOUNTRECEIVABLE =
* ACCOUNTPAYABLE =
* ACCOUNTTAX =
currencyamount = ct_currencyamount
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
return = lt_return
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.
LOG-POINT ID zcr047 FIELDS doc_no lt_return .
LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<return>).
MESSAGE ID <return>-id
TYPE <return>-type
NUMBER <return>-number
WITH <return>-message_v1 <return>-message_v2 <return>-message_v3 <return>-message_v4
INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
ENDLOOP.
zcl_ptool_helper=>bal_db_save( ).
IF NOT line_exists( lt_return[ type = CONV bapi_mtype( `E` ) ] ).
DATA(message) = VALUE #( lt_return[ type = CONV bapi_mtype( `S` )
id = CONV symsgid( `RW` )
number = CONV symsgno( `605` ) ] OPTIONAL ).
IF message IS NOT INITIAL.
SET PARAMETER ID 'BLN' FIELD message-message_v2(10).
SET PARAMETER ID 'BUK' FIELD message-message_v2+10(4).
SET PARAMETER ID 'GJR' FIELD message-message_v2+14(4).
MESSAGE ID 'ZPS' TYPE message-type NUMBER message-number WITH message-message_v2(10) message-message_v2+10(4) message-message_v2+14(4) INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true
* IMPORTING
* RETURN =
.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_RATEIO_PEP->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_BACKGROUND TYPE ABAP_BOOL(optional)
* | [--->] IT_BELNR TYPE TY_R_BELNR(optional)
* | [--->] IS_BKPF TYPE TY_S_BKPF(optional)
* | [--->] IS_BSEG TYPE TY_S_BSEG(optional)
* | [--->] IV_AKTYP TYPE AKTYP(optional)
* | [--->] IT_BKPF TYPE TY_T_BKPF(optional)
* | [--->] IT_BSEG TYPE TY_T_BSEG(optional)
* | [--->] IV_VBELN TYPE VBELN_VF(optional)
* | [--->] IV_BUKRS TYPE BUKRS(optional)
* | [--->] IV_GJAHR TYPE GJAHR(optional)
* | [--->] IV_TESTRUN TYPE ABAP_BOOL(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
_background = i_background.
r_belnr = it_belnr[].
ms_bkpf = is_bkpf.
ms_bseg = is_bseg.
mt_bkpf = it_bkpf.
mt_bseg = it_bseg.
_vbeln = iv_vbeln.
_bukrs = iv_bukrs.
_gjahr = iv_gjahr.
LOG-POINT ID zcr047 FIELDS sy-cprog sy-repid ms_bkpf ms_bseg mt_bkpf mt_bseg _vbeln _bukrs _gjahr.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_RATEIO_PEP->EXECUTE
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD execute.
DATA(timer) = cl_abap_runtime=>create_hr_timer( ).
DATA(t1) = timer->get_runtime( ).
_handle = zcl_ptool_helper=>bal_log_create( EXPORTING iv_object = `ZPS` iv_subobject = `RATEIO` ).
MESSAGE i036 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
IF is_running_in_background( ).
wait_for_document_creation( ).
wait_until_selection_journal( ).
ELSE.
select_open_items( ).
ENDIF.
select_processed_items( ).
select_wbs_elements( ).
apportionment_calculate( ).
apportionment_calculate_cr_fat( )."cr79
DATA(t2) = timer->get_runtime( ).
MESSAGE i047 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->IS_RUNNING_IN_BACKGROUND
* +-------------------------------------------------------------------------------------------------+
* | [<-()] R_BACKGROUND TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD is_running_in_background.
r_background = _background.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->SELECT_OPEN_ITEMS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD select_open_items.
MESSAGE i037 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(timer) = cl_abap_runtime=>create_hr_timer( ).
DATA(t1) = timer->get_runtime( ).
SELECT DISTINCT
rldnr, rbukrs, gjahr, belnr, docln,
rwcur, wsl, rhcur, hsl, racct, kokrs,
ps_psp_pnr, ps_posid, ps_prj_pnr, ps_pspid
FROM acdoca
WHERE rldnr = @c_0l
AND rbukrs BETWEEN @c_0001 AND @c_0057
AND belnr IN @r_belnr
AND budat = @sy-datum
AND accasty = @c_pep
AND awtyp = @c_vbrk
AND ( ps_psp_pnr ) IN ( SELECT pspnr
FROM prps
WHERE zztp_job = @c_principal )
* AND belnr IN @rl_belnr[]
ORDER BY rldnr, rbukrs, gjahr, belnr, docln
INTO TABLE @mt_open_items.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy. "#EC NEEDED
LOG-POINT ID zcr047 FIELDS mt_open_items.
MESSAGE i038 WITH |{ lines( mt_open_items ) }| INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->SELECT_PROCESSED_ITEMS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD select_processed_items.
CHECK mt_open_items[] IS NOT INITIAL.
MESSAGE i037 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
TYPES:
ty_r_xblnr TYPE RANGE OF bkpf-xblnr,
ty_r_bktxt TYPE RANGE OF bkpf-bktxt,
BEGIN OF ty_s_key,
sgtxt TYPE sgtxt,
END OF ty_s_key,
ty_t_keys TYPE SORTED TABLE OF ty_s_key
WITH NON-UNIQUE KEY sgtxt.
DATA lt_acdoca_keys TYPE ty_t_keys.
DATA(rl_xblnr) = VALUE ty_r_xblnr(
FOR <xblnr> IN mt_open_items
sign = `I`
option = `EQ`
( low = <xblnr>-belnr ) ).
SORT rl_xblnr.
DELETE ADJACENT DUPLICATES FROM rl_xblnr.
DATA(rl_bktxt) = VALUE ty_r_bktxt(
FOR <bktxt> IN mt_open_items
sign = `I`
option = `EQ`
( low = |{ <bktxt>-rldnr }{ <bktxt>-rbukrs }{ <bktxt>-gjahr }{ <bktxt>-belnr }| ) ).
SORT rl_bktxt.
DELETE ADJACENT DUPLICATES FROM rl_bktxt.
**
IF rl_xblnr[] IS NOT INITIAL OR rl_bktxt[] IS NOT INITIAL.
SELECT DISTINCT
a~rldnr, a~rbukrs, a~gjahr, a~belnr, a~docln, a~sgtxt,
k~xblnr, k~bktxt
FROM bkpf AS k
JOIN acdoca AS a ON a~rbukrs = k~bukrs
AND a~gjahr = k~gjahr
AND a~belnr = k~belnr
WHERE ( xblnr IN @rl_xblnr OR bktxt IN @rl_bktxt )
AND a~rldnr = @c_0l
INTO TABLE @DATA(lt_bkpf).
ENDIF.
lt_acdoca_keys = VALUE ty_t_keys(
FOR <key> IN mt_open_items
( sgtxt = |{ <key>-rldnr }{ <key>-rbukrs }{ <key>-gjahr }{ <key>-belnr }| ) ).
DELETE ADJACENT DUPLICATES FROM lt_acdoca_keys.
SELECT DISTINCT
a~rldnr, a~rbukrs, a~gjahr, a~belnr, a~docln, a~sgtxt,
k~xblnr, k~bktxt
FROM @lt_acdoca_keys AS i
JOIN acdoca AS a ON ( a~sgtxt = i~sgtxt )
JOIN bkpf AS k ON k~bukrs = a~rbukrs
AND k~gjahr = a~gjahr
AND k~belnr = a~belnr
WHERE a~rldnr = @c_0l
INTO TABLE @DATA(lt_processed_items).
* INSERT LINES OF lt_bkpf INTO TABLE mt_processed_items.
* INSERT LINES OF lt_processed_items INTO TABLE mt_processed_items.
mt_processed_items = VALUE #(
BASE mt_processed_items
( LINES OF VALUE #( FOR <bkpf> IN FILTER #( lt_bkpf
EXCEPT IN mt_processed_items
WHERE rldnr = rldnr
AND rbukrs = rbukrs
AND gjahr = gjahr
AND belnr = belnr
AND docln = docln )
( <bkpf> ) ) ) ).
mt_processed_items = VALUE #(
BASE mt_processed_items
( LINES OF VALUE #( FOR <processed> IN FILTER #( lt_processed_items
EXCEPT IN mt_processed_items
WHERE rldnr = rldnr
AND rbukrs = rbukrs
AND gjahr = gjahr
AND belnr = belnr
AND docln = docln )
( <processed> ) ) ) ).
LOG-POINT ID zcr047 FIELDS mt_processed_items.
MESSAGE i038 WITH |{ lines( mt_processed_items ) }| INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->SELECT_WBS_ELEMENTS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD select_wbs_elements.
CHECK mt_open_items[] IS NOT INITIAL.
MESSAGE i039 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(timer) = cl_abap_runtime=>create_hr_timer( ).
DATA(t1) = timer->get_runtime( ).
SELECT DISTINCT
p~psphi, p~pspnr, p~posid, p~posid_edit, p~zztp_job,
p~usr06, p~use06, p~usr07
FROM @mt_open_items AS i
JOIN prps AS p ON p~psphi = i~ps_prj_pnr
WHERE psphi IN ( SELECT psphi
FROM prps
WHERE zztp_job = @c_principal )
AND zztp_job IN ( @c_principal, @c_apoio )
ORDER BY psphi, pspnr, posid
INTO TABLE @mt_wbs_elements.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy. "#EC NEEDED
LOG-POINT ID zcr047 FIELDS mt_wbs_elements.
MESSAGE i040 WITH |{ lines( mt_wbs_elements ) }| INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->WAIT_FOR_DOCUMENT_CREATION
* +-------------------------------------------------------------------------------------------------+
* | [<-()] R_WAS_FULLY_CREATED TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD wait_for_document_creation.
MESSAGE i046 INTO DATA(dummy) WITH ms_bkpf-bukrs ms_bkpf-belnr ms_bkpf-gjahr. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(timer) = cl_abap_runtime=>create_hr_timer( ).
DATA(t1) = timer->get_runtime( ).
GET TIME STAMP FIELD DATA(lv_time_ini).
GET TIME STAMP FIELD DATA(lv_time_fim).
ADD 30 TO lv_time_fim.
WHILE lv_time_ini <= lv_time_fim.
GET TIME STAMP FIELD lv_time_ini.
IF _vbeln IS NOT INITIAL.
SELECT bukrs, belnr, gjahr, awtyp, awkey
FROM bkpf
WHERE bukrs = @_bukrs
AND gjahr = @_gjahr
AND awtyp = 'VBRK'
AND awkey = @_vbeln
INTO @ms_bkpf UP TO 1 ROWS.
ENDSELECT.
IF ms_bkpf-awkey = _vbeln.
LOG-POINT ID zcr047 FIELDS _bukrs _gjahr _vbeln ms_bkpf.
EXIT.
ENDIF.
ENDIF.
* IF mt_bkpf[] IS NOT INITIAL.
* SELECT COUNT(*)
* FROM @mt_bkpf AS i
* JOIN bkpf AS k ON k~bukrs = i~bukrs
* AND k~belnr = i~belnr
* AND k~gjahr = i~gjahr
* INTO @DATA(count_bkpf).
* IF count_bkpf = lines( mt_bkpf ).
* LOG-POINT ID zcr047 FIELDS count_bkpf mt_bkpf.
* EXIT.
* ENDIF.
* ENDIF.
ENDWHILE.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
IF ms_bkpf-awkey = _vbeln.
r_was_fully_created = abap_true.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->WAIT_UNTIL_SELECTION_JOURNAL
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD wait_until_selection_journal.
MESSAGE i037 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(timer) = cl_abap_runtime=>create_hr_timer( ).
DATA(t1) = timer->get_runtime( ).
GET TIME STAMP FIELD DATA(lv_time_ini).
GET TIME STAMP FIELD DATA(lv_time_fim).
ADD 10 TO lv_time_fim.
WHILE lv_time_ini <= lv_time_fim.
GET TIME STAMP FIELD lv_time_ini.
IF ms_bkpf IS NOT INITIAL.
SELECT DISTINCT
rldnr, rbukrs, gjahr, belnr, docln,
rhcur, hsl, rwcur, wsl, racct, kokrs,
ps_psp_pnr, ps_posid, ps_prj_pnr, ps_pspid
FROM acdoca
WHERE rldnr = @c_0l
AND rbukrs = @ms_bkpf-bukrs
AND gjahr = @ms_bkpf-gjahr
AND belnr = @ms_bkpf-belnr
AND budat = @sy-datum
AND ( awtyp = @c_vbrk OR
awtyp = @c_bkpf )
AND ( ps_psp_pnr ) IN ( SELECT pspnr
FROM prps
WHERE zztp_job = @c_principal )
ORDER BY rldnr, rbukrs, gjahr, belnr, docln
INTO TABLE @mt_open_items.
IF mt_open_items[] IS NOT INITIAL.
LOG-POINT ID zcr047 FIELDS mt_open_items ms_bkpf.
EXIT.
ENDIF.
ENDIF.
* IF mt_bkpf[] IS NOT INITIAL.
* SELECT DISTINCT
* a~rldnr, a~rbukrs, a~gjahr, a~belnr, a~docln,
* a~rhcur, a~hsl, a~rwcur, a~wsl, a~racct, a~kokrs,
* a~ps_psp_pnr, a~ps_posid, a~ps_prj_pnr, a~ps_pspid
* FROM @mt_bkpf AS i
* JOIN acdoca AS a ON a~rbukrs = i~bukrs
* AND a~gjahr = i~gjahr
* AND a~belnr = i~belnr
* WHERE a~rldnr = @c_0l
* AND a~rbukrs BETWEEN @c_0001 AND @c_0057
* AND a~budat = @sy-datum
** AND a~accasty = @c_pep
* AND ( a~awtyp = @c_vbrk OR
* a~awtyp = @c_bkpf )
* AND ( a~ps_psp_pnr ) IN ( SELECT pspnr
* FROM prps
* WHERE zztp_job = @c_principal )
* ORDER BY a~rldnr, a~rbukrs, a~gjahr, a~belnr, a~docln
* INTO TABLE @mt_open_items.
*
* IF lines( mt_open_items ) >= lines( mt_bseg ).
* LOG-POINT ID zcr047 FIELDS mt_open_items mt_bkpf.
* EXIT.
* ENDIF.
* ENDIF.
ENDWHILE.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy. "#EC NEEDED
MESSAGE i038 WITH |{ lines( mt_open_items ) }| INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_RATEIO_PEP->APPORTIONMENT_CALCULATE_CR_FAT
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD apportionment_calculate_cr_fat.
"CR79 lan�amento de documento atribu�do o n�mero do PEP ao cliente
DATA:
lt_accountgl TYPE bapiacgl09_tab,
lt_racct TYPE RANGE OF acdoca-racct,
lt_currencyamount TYPE bapiaccr09_tab.
CHECK mt_open_items[] IS NOT INITIAL.
SELECT SINGLE low
FROM tvarvc
INTO @DATA(gl_conta)
WHERE name = 'ZCR79_CONTA'.
CALL METHOD zcl_parametros=>obter_variaveis
EXPORTING
im_nome = 'ZCR79_RANGE_CONTA'
im_tipo = 'S'
IMPORTING
ex_range = lt_racct
EXCEPTIONS
nao_encontrado = 1
OTHERS = 2.
IF lt_racct[] IS NOT INITIAL.
READ TABLE mt_open_items INTO DATA(ls_open_items) INDEX 1.
SELECT *
FROM bkpf
WHERE bktxt = 'Rateio Receb�veis'
AND xblnr = @ls_open_items-belnr
AND bukrs = @ls_open_items-rbukrs
INTO TABLE @DATA(bkpf_check) .
IF bkpf_check[] IS INITIAL.
SELECT *
FROM acdoca
FOR ALL ENTRIES IN @mt_open_items
WHERE rldnr = @c_0l
AND rbukrs = @mt_open_items-rbukrs
AND belnr = @mt_open_items-belnr
AND racct IN @lt_racct[]
* AND budat = @sy-datum
AND awtyp = @c_vbrk
AND drcrk = 'S'
INTO TABLE @DATA(mt_open_items_cr) .
ENDIF.
MESSAGE i041 INTO DATA(dummy). "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
SELECT DISTINCT
p~psphi, p~pspnr, p~posid, p~posid_edit, p~zztp_job,
p~usr06, p~use06, p~usr07
FROM @mt_open_items AS i
JOIN prps AS p ON p~psphi = i~ps_prj_pnr
WHERE psphi IN ( SELECT psphi
FROM prps
WHERE zztp_job = @c_principal )
AND zztp_job IN ( @c_apoio )
AND usr07 NE '0.000'
INTO TABLE @DATA(lt_pep_check).
IF lt_pep_check[] IS INITIAL.
MESSAGE i090 INTO dummy. "#EC NEEDED
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDIF.
CHECK lt_pep_check[] IS NOT INITIAL.
LOOP AT mt_open_items_cr ASSIGNING FIELD-SYMBOL(<key>)
GROUP BY ( rldnr = <key>-rldnr
rbukrs = <key>-rbukrs
gjahr = <key>-gjahr
belnr = <key>-belnr )
ASSIGNING FIELD-SYMBOL(<group>).
DATA(ls_acdoca_key) = VALUE ty_s_acdoca_key( rldnr = <group>-rldnr
rbukrs = <group>-rbukrs
gjahr = <group>-gjahr
belnr = <group>-belnr ).
* IF line_exists( mt_processed_items[ KEY sgtxt sgtxt = CONV #( ls_acdoca_key ) ] ) OR
* line_exists( mt_processed_items[ KEY bktxt bktxt = CONV #( ls_acdoca_key ) ] ).
* CONTINUE.
* ENDIF.
MESSAGE i042 WITH <group>-rldnr <group>-rbukrs <group>-gjahr <group>-belnr INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
LOOP AT GROUP <group> INTO DATA(ls_member).
*
* IF line_exists( mt_processed_items[ KEY xblnr xblnr = ls_member-belnr ] ).
* CONTINUE.
* ENDIF.
DATA(ls_documentheader) = VALUE bapiache09( username = sy-uname
header_txt = 'Rateio Receb�veis'
comp_code = ls_member-rbukrs
doc_date = sy-datum
pstng_date = sy-datum
doc_type = 'SA'
fisc_year = ls_member-gjahr
ref_doc_no = ls_member-belnr ).
DATA(ls_1st_accountgl) = VALUE bapiacgl09( itemno_acc = CONV posnr_acc( |{ lines( lt_accountgl ) + 1 }| )
gl_account = gl_conta
item_text = 'Rateio do Contas a Receber'
doc_type = 'SA'
comp_code = <group>-rbukrs
fisc_year = <group>-gjahr
pstng_date = sy-datum ).
INSERT ls_1st_accountgl INTO TABLE lt_accountgl.
DATA(ls_1st_currencyamount) = VALUE bapiaccr09( itemno_acc = CONV posnr_acc( |{ lines( lt_currencyamount ) + 1 }| )
currency = ls_member-rhcur
currency_iso = ls_member-rhcur
amt_doccur = - ls_member-hsl ).
INSERT ls_1st_currencyamount INTO TABLE lt_currencyamount REFERENCE INTO DATA(lr_1st_currencyamount).
DATA(acumulado) = CONV fins_vhcur12( 0 ).
* DATA(saldo) = lr_1st_currencyamount->amt_doccur.
DATA(lt_filter) = FILTER #( mt_wbs_elements WHERE psphi = ls_open_items-ps_prj_pnr ).
* LOOP AT mt_wbs_elements ASSIGNING FIELD-SYMBOL(<filter>) WHERE psphi = ls_member-ps_prj_pnr .
LOOP AT lt_filter ASSIGNING FIELD-SYMBOL(<filter>).
DATA(ls_accountgl) = VALUE bapiacgl09( itemno_acc = CONV posnr_acc( |{ lines( lt_accountgl ) + 1 }| )
gl_account = gl_conta
item_text = 'Rateio do Contas a Receber'
doc_type = 'SA'
comp_code = <group>-rbukrs
fisc_year = <group>-gjahr
pstng_date = sy-datum
wbs_element = <filter>-posid_edit ).
INSERT ls_accountgl INTO TABLE lt_accountgl.
DATA(ls_currencyamount) = VALUE bapiaccr09( itemno_acc = CONV posnr_acc( |{ lines( lt_currencyamount ) + 1 }| )
currency = ls_member-rhcur
currency_iso = ls_member-rhcur
amt_doccur = CONV fins_vhcur12( ( ls_member-hsl * <filter>-usr07 ) / 10 ) ).
* ADD ls_currencyamount-amt_doccur TO saldo.
AT LAST.
IF ( lr_1st_currencyamount->amt_doccur - acumulado ) > 0.
ls_currencyamount-amt_doccur = ( acumulado - lr_1st_currencyamount->amt_doccur ).
ELSE.
ls_currencyamount-amt_doccur = - ( lr_1st_currencyamount->amt_doccur - acumulado ).
ENDIF.
ENDAT.
SUBTRACT ls_currencyamount-amt_doccur FROM acumulado.
INSERT ls_currencyamount INTO TABLE lt_currencyamount.
ENDLOOP.
ENDLOOP.
LOG-POINT ID zcr047 FIELDS <group> lt_accountgl lt_currencyamount.
LOOP AT lt_accountgl ASSIGNING FIELD-SYMBOL(<accountgl_log>).
DATA(ls_currencyamount_log) = VALUE #( lt_currencyamount[ itemno_acc = <accountgl_log>-itemno_acc ] OPTIONAL ).
MESSAGE i043 WITH <accountgl_log>-wbs_element
<accountgl_log>-gl_account
ls_currencyamount_log-amt_doccur
INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDLOOP.
IF lt_accountgl[] IS NOT INITIAL AND lt_currencyamount[] IS NOT INITIAL.
IF _testrun IS INITIAL.
apportionment_post(
EXPORTING
is_documentheader = ls_documentheader
CHANGING
ct_accountgl = lt_accountgl
ct_currencyamount = lt_currencyamount ).
ELSE.
apportionment_check(
EXPORTING
is_documentheader = ls_documentheader
CHANGING
ct_accountgl = lt_accountgl
ct_currencyamount = lt_currencyamount ).
ENDIF.
ENDIF.
CLEAR: ls_documentheader, lt_accountgl, lt_currencyamount .
ENDLOOP.
ENDIF.
ENDMETHOD.
ENDCLASS.