Código Fonte
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 258
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.
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 230
Faz o cálculo da taxa média e de outras chaves de determinação.
CLASS zcl_ps_tx_media DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES zif_ps_tx_media .
TYPES:
BEGIN OF ty_data_shdb,
co_area TYPE string, "PWBR
fisc_year TYPE string, "2022
period_from TYPE string, "10
period_to TYPE string, "10
version TYPE string, "0
wbs_element TYPE string, "prps_posid
order_celem TYPE string, "3101010150
activity TYPE string, "12.AS1
value TYPE string, "lw_bseg-wrbtr
END OF ty_data_shdb .
TYPES:
BEGIN OF ty_s_period,
gjahr TYPE t009b-bdatj,
buper TYPE t009b-poper,
begda TYPE dats,
endda TYPE dats,
END OF ty_s_period .
TYPES:
ty_t_periods TYPE SORTED TABLE OF ty_s_period
WITH UNIQUE KEY gjahr buper .
METHODS constructor .
METHODS copy_1_of_calc_tx_media
IMPORTING
!kokrs TYPE coep-kokrs
!bukrs TYPE coep-bukrs
!pspnr TYPE prps-pspnr
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm
!objnr TYPE cosb-objnr
EXPORTING
!e_custo_plan TYPE wkgxxx
!e_horas_plan TYPE megxxx
!e_horas_real TYPE megxxx
!e_desp_incl TYPE wkgxxx .
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-METHODS factory
RETURNING
VALUE(ro_factory) TYPE REF TO zcl_ps_tx_media .
ENDCLASS.
CLASS zcl_ps_tx_media IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
zif_ps_tx_media~_handle = zcl_ptool_helper=>bal_log_create( iv_object = 'ZRA'
iv_subobject = 'KKA2' ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->COPY_1_OF_CALC_TX_MEDIA
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] BUKRS TYPE COEP-BUKRS
* | [--->] PSPNR TYPE PRPS-PSPNR
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* | [--->] OBJNR TYPE COSB-OBJNR
* | [<---] E_CUSTO_PLAN TYPE WKGXXX
* | [<---] E_HORAS_PLAN TYPE MEGXXX
* | [<---] E_HORAS_REAL TYPE MEGXXX
* | [<---] E_DESP_INCL TYPE WKGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD copy_1_of_calc_tx_media.
DATA(versn) = `000`.
DATA(period_begin) = CONV monat( `001` ).
DATA(period_end) = CONV monat( `012` ).
SELECT valsign AS sign,
valoption AS option,
valfrom AS low,
valto AS high
FROM setleaf AS s
WHERE setname = 'RA_DESP_INCLUDED'
INTO TABLE @DATA(rl_racct).
WITH
+desp_incl AS (
SELECT ps_psp_pnr, rtcur, SUM( tsl ) AS desp_incl
FROM acdoca
WHERE rldnr = '0L'
AND poper = @monat
AND racct IN @rl_racct
GROUP BY ps_psp_pnr, rtcur ),
* +htotal AS (
* SELECT rproj, workdate,
* SUM( CASE WHEN stokz IS INITIAL THEN catshours ELSE - catshours END ) AS htotal
* FROM catsco
* WHERE rproj = @pspnr
* GROUP BY rproj, workdate ),
+c_plan AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wkg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wkg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wkg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wkg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wkg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wkg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wkg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wkg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wkg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wkg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wkg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wkg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS custo
FROM v_cosp_view
WHERE wrttp = '01'
AND versn = @versn
AND gjahr = @gjahr
AND kstar = '3101010150'
GROUP BY objnr, twaer ),
"Horas Planejadas
+h_plan AS (
SELECT objnr, gjahr, twaer, meinh,
* CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wkg001 ) ELSE 0 END +
* CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wkg002 ) ELSE 0 END +
* CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wkg003 ) ELSE 0 END +
* CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wkg004 ) ELSE 0 END +
* CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wkg005 ) ELSE 0 END +
* CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wkg006 ) ELSE 0 END +
* CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wkg007 ) ELSE 0 END +
* CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wkg008 ) ELSE 0 END +
* CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wkg009 ) ELSE 0 END +
* CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wkg010 ) ELSE 0 END +
* CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wkg011 ) ELSE 0 END +
* CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wkg012 ) ELSE 0 END
* AS DEC( 23, 2 ) ) AS custo,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( meg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( meg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( meg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( meg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( meg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( meg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( meg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( meg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( meg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( meg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( meg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( meg012 ) ELSE 0 END
AS DEC( 15, 3 ) ) AS horas
FROM v_coss_view
WHERE versn = @versn
AND wrttp = '01'
AND kstar = '9040101000'
AND gjahr = @gjahr
GROUP BY objnr, gjahr, twaer, meinh ),
* +c_real AS (
* SELECT objnr, twaer,
* CAST( CASE WHEN '001' = @monat THEN SUM( wtg001 ) ELSE 0 END +
* CASE WHEN '002' = @monat THEN SUM( wtg002 ) ELSE 0 END +
* CASE WHEN '003' = @monat THEN SUM( wtg003 ) ELSE 0 END +
* CASE WHEN '004' = @monat THEN SUM( wtg004 ) ELSE 0 END +
* CASE WHEN '005' = @monat THEN SUM( wtg005 ) ELSE 0 END +
* CASE WHEN '006' = @monat THEN SUM( wtg006 ) ELSE 0 END +
* CASE WHEN '007' = @monat THEN SUM( wtg007 ) ELSE 0 END +
* CASE WHEN '008' = @monat THEN SUM( wtg008 ) ELSE 0 END +
* CASE WHEN '009' = @monat THEN SUM( wtg009 ) ELSE 0 END +
* CASE WHEN '010' = @monat THEN SUM( wtg010 ) ELSE 0 END +
* CASE WHEN '011' = @monat THEN SUM( wtg011 ) ELSE 0 END +
* CASE WHEN '012' = @monat THEN SUM( wtg012 ) ELSE 0 END
* AS DEC( 23, 2 ) ) AS custo
* FROM v_cosp_view
* WHERE kstar = '3101010150'
* AND versn = @versn
* AND wrttp = '04'
* AND gjahr = @gjahr
* GROUP BY objnr, twaer ),
+h_real AS (
SELECT objnr, twaer, meinh,
* CAST( CASE WHEN '001' = @monat THEN SUM( wkg001 ) ELSE 0 END +
* CASE WHEN '002' = @monat THEN SUM( wkg002 ) ELSE 0 END +
* CASE WHEN '003' = @monat THEN SUM( wkg003 ) ELSE 0 END +
* CASE WHEN '004' = @monat THEN SUM( wkg004 ) ELSE 0 END +
* CASE WHEN '005' = @monat THEN SUM( wkg005 ) ELSE 0 END +
* CASE WHEN '006' = @monat THEN SUM( wkg006 ) ELSE 0 END +
* CASE WHEN '007' = @monat THEN SUM( wkg007 ) ELSE 0 END +
* CASE WHEN '008' = @monat THEN SUM( wkg008 ) ELSE 0 END +
* CASE WHEN '009' = @monat THEN SUM( wkg009 ) ELSE 0 END +
* CASE WHEN '010' = @monat THEN SUM( wkg010 ) ELSE 0 END +
* CASE WHEN '011' = @monat THEN SUM( wkg011 ) ELSE 0 END +
* CASE WHEN '012' = @monat THEN SUM( wkg012 ) ELSE 0 END
* AS DEC( 23, 2 ) ) AS custo,
CAST( CASE WHEN '001' = @monat THEN SUM( meg001 ) ELSE 0 END +
CASE WHEN '002' = @monat THEN SUM( meg002 ) ELSE 0 END +
CASE WHEN '003' = @monat THEN SUM( meg003 ) ELSE 0 END +
CASE WHEN '004' = @monat THEN SUM( meg004 ) ELSE 0 END +
CASE WHEN '005' = @monat THEN SUM( meg005 ) ELSE 0 END +
CASE WHEN '006' = @monat THEN SUM( meg006 ) ELSE 0 END +
CASE WHEN '007' = @monat THEN SUM( meg007 ) ELSE 0 END +
CASE WHEN '008' = @monat THEN SUM( meg008 ) ELSE 0 END +
CASE WHEN '009' = @monat THEN SUM( meg009 ) ELSE 0 END +
CASE WHEN '010' = @monat THEN SUM( meg010 ) ELSE 0 END +
CASE WHEN '011' = @monat THEN SUM( meg011 ) ELSE 0 END +
CASE WHEN '012' = @monat THEN SUM( meg012 ) ELSE 0 END
AS DEC( 15, 3 ) ) AS horas
FROM v_coss_view
WHERE wrttp = '04'
AND versn = @versn
AND kstar = '9040101000'
AND gjahr = @gjahr
GROUP BY objnr, twaer, meinh ),
+result( pspnr, objnr, moeda,
* total,
custo_plan,
* twaer1, custo_horas1, meinh1, horas_plan,
meinh1, horas_plan,
* custo_real,
* twaer2, custo_horas2, meinh2, horas_real,
meinh2, horas_real,
desp_incl ) AS (
SELECT p~pspnr, p~objnr, p~pwpos AS moeda,
* t~htotal,
l~custo,
* a~twaer, a~custo, a~meinh AS meinh1, a~horas,
a~meinh AS meinh1, a~horas,
* r~custo,
* e~twaer, e~custo, e~meinh AS meinh2, e~horas,
e~meinh AS meinh2, e~horas,
d~desp_incl
FROM proj AS j
JOIN prps AS p ON p~psphi = j~pspnr
* LEFT JOIN +htotal AS t ON t~rproj = p~posid
* AND t~workdate BETWEEN j~plfaz AND j~plsez
LEFT JOIN +c_plan AS l ON l~objnr = p~objnr
AND l~twaer = p~pwpos
LEFT JOIN +h_plan AS a ON a~objnr = p~objnr
* LEFT JOIN +c_real AS r ON r~objnr = p~objnr
* AND r~twaer = p~pwpos
LEFT JOIN +h_real AS e ON e~objnr = p~objnr
LEFT JOIN +desp_incl AS d ON d~ps_psp_pnr = p~pspnr
AND d~rtcur = p~pwpos
WHERE p~pspnr = @pspnr OR p~posid = @posid )
SELECT * FROM +result INTO TABLE @DATA(results).
"Espera-se apenas 1 linha de resultado
LOOP AT results ASSIGNING FIELD-SYMBOL(<result>).
** DATA(taxa_media) = ( ( <result>-custo_plan / <result>-horas_plan ) * <result>-horas_real + desp_incl ) .
* r_taxa_media = ( ( <result>-custo_plan / <result>-horas_plan ) * <result>-horas_real ) .
e_custo_plan = <result>-custo_plan.
e_horas_plan = <result>-horas_plan.
e_horas_real = <result>-horas_real.
e_desp_incl = <result>-desp_incl.
ENDLOOP.
* IF planejado IS NOT INITIAL.
* planejado = planejado * poc.
* ENDIF.
*
* IF realizado IS NOT INITIAL.
* planejado = planejado + realizado.
* ENDIF.
*
* CHECK planejado IS NOT INITIAL.
*
* planejado = abs( planejado ).
*
* DATA(data_shdb) = VALUE ty_data_shdb(
* co_area = kokrs
* fisc_year = gjahr
* period_from = monat
* period_to = monat
* version = '0'
* wbs_element = posid
* order_celem = '3101010155'
* value = planejado ).
*
* REPLACE ALL OCCURRENCES OF '.' IN data_shdb-value WITH ','.
* CONCATENATE data_shdb-value '-' INTO data_shdb-value.
*
* "Chama SHDB
* executa( data_shdb ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Private Method ZCL_PS_TX_MEDIA=>FACTORY
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_FACTORY TYPE REF TO ZCL_PS_TX_MEDIA
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD factory.
ro_factory = NEW zcl_ps_tx_media( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~CALCULAR_TAXA_MEDIA
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_RECEITA TYPE WKGXXX
* | [--->] I_CUSTO_PLAN TYPE WKGXXX
* | [--->] I_HORAS_PLAN TYPE MEGXXX
* | [--->] I_HORAS_REAL TYPE MEGXXX
* | [--->] I_DESP_INCL TYPE WKGXXX
* | [<-()] R_TAXA_MEDIA TYPE WKGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~calcular_taxa_media.
DATA lv_percentual TYPE p DECIMALS 6.
IF i_horas_plan > 0.
lv_percentual = i_horas_real / i_horas_plan.
MESSAGE i009 WITH |{ lv_percentual }| INTO DATA(dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
IF lv_percentual > 1.
lv_percentual = 1.
ENDIF.
IF abs( i_receita ) >= abs( i_custo_plan ).
DATA(lv_diff) = CONV wkgxxx( abs( i_receita ) - abs( i_custo_plan ) ).
MESSAGE i010 WITH |{ lv_diff }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDIF.
r_taxa_media = - ( lv_diff * lv_percentual ) + abs( i_desp_incl ) .
MESSAGE i011 WITH |{ lv_diff }| |{ lv_percentual }| |{ abs( i_desp_incl ) }| |{ r_taxa_media }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
IF r_taxa_media < i_receita.
r_taxa_media = i_receita.
MESSAGE s081 WITH |{ i_receita - r_taxa_media }| DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~CALCULAR_TAXA_MEDIA_NOVO
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_RTP TYPE WKGXXX
* | [--->] I_DP TYPE WKGXXX
* | [--->] I_HP TYPE MEGXXX
* | [--->] I_DRI TYPE WKGXXX
* | [--->] I_HA TYPE MEGXXX
* | [<-()] R_TAXA_MEDIA TYPE WKGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~calcular_taxa_media_novo.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~CALC_TX_MEDIA
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] BUKRS TYPE COEP-BUKRS
* | [--->] PSPNR TYPE PRPS-PSPNR
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* | [--->] OBJNR TYPE COSB-OBJNR
* | [<---] E_RECEITA TYPE WKGXXX
* | [<---] E_CUSTO_PLAN TYPE WKGXXX
* | [<---] E_HORAS_PLAN TYPE MEGXXX
* | [<---] E_HORAS_REAL TYPE MEGXXX
* | [<---] E_DESP_INCL TYPE WKGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~calc_tx_media.
DATA(versn) = '000'.
DATA(period_begin) = CONV monat( '001' ).
DATA(period_end) = CONV monat( '012' ).
DATA horas_acumuladas TYPE megxxx.
MESSAGE i001 WITH posid monat gjahr INTO DATA(dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
SELECT valsign AS sign,
valoption AS option,
valfrom AS low,
valto AS high
FROM setleaf AS s
WHERE setname = 'RA_DESP_INCLUDED'
INTO TABLE @DATA(rl_racct).
* SELECT SINGLE
* plfaz, plsez
* FROM proj AS j
* JOIN prps AS p ON p~psphi = j~pspnr
* WHERE p~pspnr = @pspnr
* INTO @DATA(ls_periodo).
SELECT SINGLE
t~pstrt AS plfaz, t~pende AS plsez
FROM prps AS p
JOIN prte AS t ON t~posnr = p~pspnr
WHERE p~pspnr = @pspnr
INTO @DATA(ls_periodo).
IF sy-subrc = 0.
MESSAGE i002 WITH ls_periodo-plfaz ls_periodo-plsez INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA(lt_periodos) = zif_ps_tx_media~preencher_periodos( plfaz = ls_periodo-plfaz
plsez = ls_periodo-plsez ).
* LOOP AT lt_periodos ASSIGNING FIELD-SYMBOL(<periodo>).
*** LOOP AT lt_periodos ASSIGNING FIELD-SYMBOL(<key>)
*** GROUP BY <key>-gjahr WITHOUT MEMBERS
*** ASSIGNING FIELD-SYMBOL(<group>).
***
*** IF ( <group> < gjahr ).
***
**** SELECT c~objnr, c~gjahr, c~twaer, c~meinh,
**** CAST( SUM( c~meg001 ) + SUM( c~meg002 ) + SUM( c~meg003 ) +
**** SUM( c~meg004 ) + SUM( c~meg005 ) + SUM( c~meg006 ) +
**** SUM( c~meg007 ) + SUM( c~meg008 ) + SUM( c~meg009 ) +
**** SUM( c~meg010 ) + SUM( c~meg011 ) + SUM( c~meg012 )
**** AS DEC( 15, 3 ) ) AS horas
**** FROM prps AS p
**** JOIN v_coss_view AS c ON c~objnr = p~objnr
**** WHERE p~pspnr = @pspnr
**** AND c~versn = @versn
**** AND c~wrttp = '04'
**** AND c~gjahr = @<group>
**** AND c~kstar = '9040101000'
**** GROUP BY c~objnr, c~gjahr, c~twaer, c~meinh
**** INTO TABLE @DATA(lt_coss).
***
*** SELECT c~objnr, c~gjahr, c~meinh, SUM( c~mbgbtr ) AS horas
*** FROM prps AS p
*** LEFT JOIN coep AS c ON c~objnr = p~objnr
*** WHERE p~pspnr = @pspnr
*** AND c~versn = @versn
*** AND c~wrttp = '04'
*** AND c~gjahr = @<group>
*** AND c~vrgng IN ( 'RKL', 'RKU1' )
*** AND c~kstar = '9040101000'
*** GROUP BY c~objnr, c~gjahr, c~meinh
*** INTO TABLE @DATA(lt_coss).
***
*** ELSEIF <group> = gjahr.
***
**** SELECT c~objnr, c~gjahr, c~twaer, c~meinh,
**** CAST( CASE WHEN '001' BETWEEN '001' AND @monat THEN SUM( meg001 ) ELSE 0 END +
**** CASE WHEN '002' BETWEEN '002' AND @monat THEN SUM( meg002 ) ELSE 0 END +
**** CASE WHEN '003' BETWEEN '003' AND @monat THEN SUM( meg003 ) ELSE 0 END +
**** CASE WHEN '004' BETWEEN '004' AND @monat THEN SUM( meg004 ) ELSE 0 END +
**** CASE WHEN '005' BETWEEN '005' AND @monat THEN SUM( meg005 ) ELSE 0 END +
**** CASE WHEN '006' BETWEEN '006' AND @monat THEN SUM( meg006 ) ELSE 0 END +
**** CASE WHEN '007' BETWEEN '007' AND @monat THEN SUM( meg007 ) ELSE 0 END +
**** CASE WHEN '008' BETWEEN '008' AND @monat THEN SUM( meg008 ) ELSE 0 END +
**** CASE WHEN '009' BETWEEN '009' AND @monat THEN SUM( meg009 ) ELSE 0 END +
**** CASE WHEN '010' BETWEEN '010' AND @monat THEN SUM( meg010 ) ELSE 0 END +
**** CASE WHEN '011' BETWEEN '011' AND @monat THEN SUM( meg011 ) ELSE 0 END +
**** CASE WHEN '012' BETWEEN '012' AND @monat THEN SUM( meg012 ) ELSE 0 END
**** AS DEC( 23, 2 ) ) AS horas
**** FROM prps AS p
**** JOIN v_coss_view AS c ON c~objnr = p~objnr
**** WHERE p~pspnr = @pspnr
**** AND c~versn = @versn
**** AND c~wrttp = '04'
**** AND c~gjahr = @<group>
**** AND c~kstar = '9040101000'
**** GROUP BY c~objnr, c~gjahr, c~twaer, c~meinh
**** APPENDING TABLE @lt_coss.
***
*** SELECT c~objnr, c~gjahr, c~meinh, SUM( c~mbgbtr ) AS horas
*** FROM prps AS p
*** LEFT JOIN coep AS c ON c~objnr = p~objnr
*** WHERE c~perio BETWEEN '001' AND @monat
*** AND p~pspnr = @pspnr
*** AND c~versn = @versn
*** AND c~wrttp = '04'
*** AND c~gjahr = @<group>
*** AND c~vrgng IN ( 'RKL', 'RKU1' )
*** AND c~kstar = '9040101000'
*** GROUP BY c~objnr, c~gjahr, c~meinh
*** APPENDING TABLE @lt_coss.
***
*** ENDIF.
***
*** ENDLOOP.
DATA(lv_ano) = '0000'.
DATA(lv_mes) = '00'.
LOOP AT lt_periodos ASSIGNING FIELD-SYMBOL(<periodo>).
CHECK ( ( <periodo>-begda(4) < gjahr ) OR
( <periodo>-begda(4) = gjahr AND <periodo>-begda+4(2) <= monat ) ).
IF lv_ano <> <periodo>-begda(4) OR lv_mes <> <periodo>-begda+4(2).
SELECT c~objnr, c~gjahr, c~meinh, SUM( c~mbgbtr ) AS horas
FROM prps AS p
LEFT JOIN coep AS c ON c~objnr = p~objnr
WHERE p~pspnr = @pspnr
AND c~versn = @versn
AND c~wrttp = '04'
AND ( ( c~gjahr = @<periodo>-begda(4) AND c~perio = @<periodo>-begda+4(2) )
AND ( c~gjahr = @<periodo>-endda(4) AND c~perio = @<periodo>-endda+4(2) ) )
AND c~vrgng IN ( 'RKL', 'RKU1' )
AND c~kstar = '9040101000'
GROUP BY c~objnr, c~gjahr, c~meinh
APPENDING TABLE @DATA(lt_coss).
lv_ano = <periodo>-begda(4).
lv_mes = <periodo>-endda+4(2).
ENDIF.
ENDLOOP.
horas_acumuladas = REDUCE mbgxxx(
INIT _horas = horas_acumuladas
FOR <horas> IN lt_coss
NEXT _horas += <horas>-horas ).
ENDIF.
MESSAGE i003 WITH horas_acumuladas INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
WITH
+desp_incl AS (
SELECT ps_psp_pnr, rtcur, SUM( tsl ) AS desp_incl
FROM acdoca
WHERE rldnr = '0L'
AND poper = @monat
AND racct IN @rl_racct
GROUP BY ps_psp_pnr, rtcur ),
+c_plan AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wkg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wkg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wkg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wkg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wkg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wkg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wkg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wkg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wkg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wkg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wkg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wkg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS custo
FROM v_cosp_view
WHERE wrttp = '01'
AND versn = @versn
AND kstar = '3101010150'
GROUP BY objnr, twaer ),
"Custo Planejado, todos os períodos, todos os exercícios
+p_plan AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' BETWEEN '01' AND '12' THEN SUM( wkg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN '01' AND '12' THEN SUM( wkg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN '01' AND '12' THEN SUM( wkg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN '01' AND '12' THEN SUM( wkg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN '01' AND '12' THEN SUM( wkg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN '01' AND '12' THEN SUM( wkg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN '01' AND '12' THEN SUM( wkg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN '01' AND '12' THEN SUM( wkg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN '01' AND '12' THEN SUM( wkg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN '01' AND '12' THEN SUM( wkg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN '01' AND '12' THEN SUM( wkg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN '01' AND '12' THEN SUM( wkg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS custo
FROM v_cosp_view
WHERE wrttp = '01'
AND versn = @versn
AND kstar IN @rl_racct
GROUP BY objnr, twaer ),
"Horas Planejadas
+h_plan AS (
SELECT objnr, gjahr, twaer, meinh,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( meg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( meg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( meg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( meg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( meg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( meg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( meg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( meg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( meg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( meg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( meg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( meg012 ) ELSE 0 END
AS DEC( 15, 3 ) ) AS horas
FROM v_coss_view
WHERE versn = @versn
AND wrttp = '01'
AND kstar = '9040101000'
* AND gjahr <= @gjahr
GROUP BY objnr, gjahr, twaer, meinh ),
** "Horas Planejadas
** +h_plan AS (
** SELECT objnr, gjahr, twaer, meinh,
** CAST( CASE WHEN ( gjahr < @gjahr AND '001' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '001' <= @monat ) THEN SUM( meg001 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '002' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '002' <= @monat ) THEN SUM( meg002 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '003' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '003' <= @monat ) THEN SUM( meg003 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '004' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '004' <= @monat ) THEN SUM( meg004 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '005' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '005' <= @monat ) THEN SUM( meg005 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '006' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '006' <= @monat ) THEN SUM( meg006 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '007' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '007' <= @monat ) THEN SUM( meg007 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '008' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '008' <= @monat ) THEN SUM( meg008 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '009' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '009' <= @monat ) THEN SUM( meg009 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '010' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '010' <= @monat ) THEN SUM( meg010 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '011' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '011' <= @monat ) THEN SUM( meg011 ) ELSE 0 END +
** CASE WHEN ( gjahr < @gjahr AND '012' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '012' <= @monat ) THEN SUM( meg012 ) ELSE 0 END
** AS DEC( 15, 3 ) ) AS horas
** FROM v_coss_view
** WHERE versn = @versn
** AND wrttp = '01'
** AND kstar = '9040101000'
** GROUP BY objnr, gjahr, twaer, meinh ),
* +h_real AS (
* SELECT objnr, twaer, meinh,
* CAST( CASE WHEN '001' <= @monat THEN SUM( meg001 ) ELSE 0 END +
* CASE WHEN '002' <= @monat THEN SUM( meg002 ) ELSE 0 END +
* CASE WHEN '003' <= @monat THEN SUM( meg003 ) ELSE 0 END +
* CASE WHEN '004' <= @monat THEN SUM( meg004 ) ELSE 0 END +
* CASE WHEN '005' <= @monat THEN SUM( meg005 ) ELSE 0 END +
* CASE WHEN '006' <= @monat THEN SUM( meg006 ) ELSE 0 END +
* CASE WHEN '007' <= @monat THEN SUM( meg007 ) ELSE 0 END +
* CASE WHEN '008' <= @monat THEN SUM( meg008 ) ELSE 0 END +
* CASE WHEN '009' <= @monat THEN SUM( meg009 ) ELSE 0 END +
* CASE WHEN '010' <= @monat THEN SUM( meg010 ) ELSE 0 END +
* CASE WHEN '011' <= @monat THEN SUM( meg011 ) ELSE 0 END +
* CASE WHEN '012' <= @monat THEN SUM( meg012 ) ELSE 0 END
* AS DEC( 15, 3 ) ) AS horas
* FROM v_coss_view
* WHERE wrttp = '04'
* AND versn = @versn
* AND kstar = '9040101000'
* AND gjahr <= @gjahr
* GROUP BY objnr, twaer, meinh ),
+h_real AS (
SELECT objnr, gjahr, twaer, meinh,
CAST( CASE WHEN ( gjahr < @gjahr AND '01' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '001' <= @monat ) THEN SUM( meg001 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '02' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '002' <= @monat ) THEN SUM( meg002 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '03' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '003' <= @monat ) THEN SUM( meg003 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '04' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '004' <= @monat ) THEN SUM( meg004 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '05' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '005' <= @monat ) THEN SUM( meg005 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '06' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '006' <= @monat ) THEN SUM( meg006 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '07' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '007' <= @monat ) THEN SUM( meg007 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '08' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '008' <= @monat ) THEN SUM( meg008 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '09' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '009' <= @monat ) THEN SUM( meg009 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '10' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '010' <= @monat ) THEN SUM( meg010 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '11' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '011' <= @monat ) THEN SUM( meg011 ) ELSE 0 END +
CASE WHEN ( gjahr < @gjahr AND '12' BETWEEN @period_begin AND @period_end ) OR ( gjahr = @gjahr AND '012' <= @monat ) THEN SUM( meg012 ) ELSE 0 END
AS DEC( 15, 3 ) ) AS horas
FROM v_coss_view
WHERE wrttp = '04'
AND versn = @versn
AND kstar = '9040101000'
GROUP BY objnr, gjahr, twaer, meinh ),
+result( pspnr, objnr, moeda,
receita,
custo_plan,
gjahr_plan, meinh_plan, horas_plan,
gjahr_real, meinh_real, horas_real,
desp_incl ) AS (
SELECT p~pspnr, p~objnr, p~pwpos AS moeda,
l~custo,
b~custo,
a~gjahr, a~meinh, a~horas,
e~gjahr, e~meinh, e~horas,
d~desp_incl
FROM proj AS j
JOIN prps AS p ON p~psphi = j~pspnr
LEFT JOIN +c_plan AS l ON l~objnr = p~objnr
AND l~twaer = p~pwpos
LEFT JOIN +p_plan AS b ON b~objnr = p~objnr
AND b~twaer = p~pwpos
LEFT JOIN +h_plan AS a ON a~objnr = p~objnr
LEFT JOIN +h_real AS e ON e~objnr = p~objnr
LEFT JOIN +desp_incl AS d ON d~ps_psp_pnr = p~pspnr
AND d~rtcur = p~pwpos
WHERE p~pspnr = @pspnr OR p~posid = @posid )
SELECT * FROM +result INTO TABLE @DATA(results).
SORT results BY gjahr_plan.
DATA(lv_gjahr_plan) = '0000'.
LOOP AT results ASSIGNING FIELD-SYMBOL(<result>).
e_receita = <result>-receita.
e_custo_plan = <result>-custo_plan.
e_desp_incl = <result>-desp_incl.
IF lv_gjahr_plan <> <result>-gjahr_plan.
e_horas_plan += <result>-horas_plan.
ENDIF.
lv_gjahr_plan = <result>-gjahr_plan.
ENDLOOP.
SORT results BY gjahr_real.
DATA(lv_gjahr_real) = '0000'.
LOOP AT results ASSIGNING <result>.
IF lv_gjahr_real <> <result>-gjahr_real.
e_horas_real += <result>-horas_real.
ENDIF.
lv_gjahr_real = <result>-gjahr_real.
ENDLOOP.
MESSAGE i004 WITH e_receita INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
MESSAGE i005 WITH e_custo_plan INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
MESSAGE i006 WITH e_horas_plan INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
MESSAGE i007 WITH e_horas_real INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
MESSAGE i008 WITH e_desp_incl INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_ps_tx_media~_handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~EXECUTA
* +-------------------------------------------------------------------------------------------------+
* | [--->] IW_DATA_SHDB TYPE TY_DATA_SHDB
* | [--->] IV_FIRST_SCREEN TYPE ABAP_BOOL(optional)
* | [<-()] RV_BOOL TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~executa.
rv_bool = abap_true.
DATA lt_msg TYPE TABLE OF bdcmsgcoll.
IF iv_first_screen = abap_true.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLSPO4' iv_value = '0300' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=FURT' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'SVALD-VALUE(01)' iv_value = iw_data_shdb-co_area ). "'PWBR' ).
ENDIF.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP0' iv_value = '1000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CSUB' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP1B-ONLY' iv_value = 'X' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(01)' iv_value = iw_data_shdb-version ). "'0' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(02)' iv_value = iw_data_shdb-period_from )."'10' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(03)' iv_value = iw_data_shdb-period_to ). "'10' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(04)' iv_value = iw_data_shdb-fisc_year ). "'2022' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(06)' iv_value = iw_data_shdb-wbs_element )."'PC.005.0000004' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(07)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(08)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(09)' iv_value = iw_data_shdb-order_celem )."'3101010150' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(10)' iv_value = space ).
* zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(11)' iv_value = space ).
IF iw_data_shdb-activity IS NOT INITIAL.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(12)' iv_value = iw_data_shdb-activity ).
ENDIF.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP2' iv_value = '0112' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '/00' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'Z-BDC03(01)' iv_value = iw_data_shdb-value )."'-6000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP2' iv_value = '0112' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CBUC' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP0' iv_value = '1000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '/ECABR' ).
DATA(ls_params) = VALUE ctu_params( dismode = 'N' updmode = 'S' defsize = abap_true ).
CALL TRANSACTION 'CJR2' USING zif_ps_tx_media~t_bdcdata OPTIONS FROM ls_params MESSAGES INTO lt_msg.
LOOP AT lt_msg ASSIGNING FIELD-SYMBOL(<msg>).
IF <msg>-msgtyp = 'E'.
CLEAR rv_bool.
ENDIF.
IF <msg>-msgid = 'K8' AND <msg>-msgnr = '037'.
CLEAR rv_bool.
ENDIF.
IF <msg>-msgid = '00' AND <msg>-msgnr = '347'.
CLEAR rv_bool.
ENDIF.
ENDLOOP.
SORT lt_msg BY msgid msgnr.
READ TABLE lt_msg TRANSPORTING NO FIELDS
WITH KEY msgid = '00'
msgnr = '344' BINARY SEARCH.
CHECK sy-subrc IS INITIAL.
CLEAR: lt_msg.
DO 4 TIMES.
DELETE zif_ps_tx_media~t_bdcdata INDEX 1.
ENDDO.
CALL TRANSACTION 'CJR2' USING zif_ps_tx_media~t_bdcdata OPTIONS FROM ls_params MESSAGES INTO lt_msg.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~LANCAR_PLANEJAMENTO
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* | [--->] VALUE TYPE WTGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~lancar_planejamento.
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = kokrs
fisc_year = gjahr
period_from = monat
period_to = monat
version = '0'
wbs_element = posid
order_celem = '3101010155'
value = value ).
REPLACE ALL OCCURRENCES OF '.' IN data_shdb-value WITH ','.
* CONCATENATE data_shdb-value '-' INTO data_shdb-value.
"Chama SHDB
zif_ps_tx_media~executa( data_shdb ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~LANCAR_TAXA_MEDIA
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* | [--->] VALUE TYPE WTGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~lancar_taxa_media.
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = kokrs
fisc_year = gjahr
period_from = monat
period_to = monat
version = '0'
wbs_element = posid
order_celem = '3101010155'
value = value ).
REPLACE ALL OCCURRENCES OF '.' IN data_shdb-value WITH ','.
* CONCATENATE data_shdb-value '-' INTO data_shdb-value.
"Chama SHDB
zif_ps_tx_media~executa( data_shdb ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~MONTAR_ATIVIDADES
* +-------------------------------------------------------------------------------------------------+
* | [--->] CO_AREA TYPE COEP-KOKRS (default ='PWBR')
* | [--->] VERSION TYPE VERSN (default ='0')
* | [--->] WBS_ELEMENT TYPE PRPS-POSID
* | [--->] YEAR TYPE XKALXKAG-ABGRJ
* | [--->] PERIOD_FROM TYPE XKALXKAG-ABGRM
* | [--->] PERIOD_TO TYPE XKALXKAG-ABGRM
* | [--->] ORDER_CELEM TYPE KOSTL(optional)
* | [--->] ACTIVITY TYPE LSTAR(optional)
* | [--->] QUANTITY TYPE MEGXXX(optional)
* | [--->] VALUE TYPE WTGXXX(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~montar_atividades.
CHECK quantity IS SUPPLIED OR value IS SUPPLIED.
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = co_area
fisc_year = year
period_from = period_from
period_to = period_to
version = version
wbs_element = wbs_element
order_celem = order_celem
activity = activity
value = COND #( WHEN quantity IS SUPPLIED THEN |{ quantity NUMBER = USER }| ELSE |{ value NUMBER = USER }| ) ).
"Chama SHDB
zif_ps_tx_media~planejar_atividades( data_shdb ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~MONTAR_DESPESAS
* +-------------------------------------------------------------------------------------------------+
* | [--->] CO_AREA TYPE COEP-KOKRS (default ='PWBR')
* | [--->] VERSION TYPE VERSN (default ='0')
* | [--->] WBS_ELEMENT TYPE PRPS-POSID
* | [--->] YEAR TYPE XKALXKAG-ABGRJ
* | [--->] PERIOD_FROM TYPE XKALXKAG-ABGRM
* | [--->] PERIOD_TO TYPE XKALXKAG-ABGRM
* | [--->] ORDER_CELEM TYPE KOSTL(optional)
* | [--->] ACTIVITY TYPE LSTAR(optional)
* | [--->] QUANTITY TYPE MEGXXX(optional)
* | [--->] VALUE TYPE WTGXXX(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~montar_despesas.
CHECK quantity IS SUPPLIED OR value IS SUPPLIED.
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = co_area
fisc_year = year
period_from = period_from
period_to = period_to
version = version
wbs_element = wbs_element
order_celem = order_celem
activity = activity
value = COND #( WHEN quantity IS SUPPLIED THEN |{ quantity NUMBER = USER }| ELSE |{ value NUMBER = USER }| ) ).
"Chama SHDB
zif_ps_tx_media~planejar_despesas( data_shdb ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~MONTAR_RECEITAS
* +-------------------------------------------------------------------------------------------------+
* | [--->] CO_AREA TYPE COEP-KOKRS (default ='PWBR')
* | [--->] VERSION TYPE VERSN (default ='0')
* | [--->] WBS_ELEMENT TYPE PRPS-POSID
* | [--->] YEAR TYPE XKALXKAG-ABGRJ
* | [--->] PERIOD_FROM TYPE XKALXKAG-ABGRM
* | [--->] PERIOD_TO TYPE XKALXKAG-ABGRM
* | [--->] ORDER_CELEM TYPE KOSTL(optional)
* | [--->] ACTIVITY TYPE LSTAR(optional)
* | [--->] QUANTITY TYPE MEGXXX(optional)
* | [--->] VALUE TYPE WTGXXX(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~montar_receitas.
CHECK quantity IS SUPPLIED OR value IS SUPPLIED.
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = co_area
fisc_year = year
period_from = period_from
period_to = period_to
version = version
wbs_element = wbs_element
order_celem = order_celem
activity = activity
value = COND #( WHEN quantity IS SUPPLIED THEN |{ quantity NUMBER = USER }| ELSE |{ value NUMBER = USER }| ) ).
"Chama SHDB
zif_ps_tx_media~planejar_despesas( data_shdb ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~PLANEJAR_ATIVIDADES
* +-------------------------------------------------------------------------------------------------+
* | [--->] IW_DATA_SHDB TYPE TY_DATA_SHDB
* | [--->] IV_FIRST_SCREEN TYPE ABAP_BOOL(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~planejar_atividades.
DATA: lw_params TYPE ctu_params,
lt_msg TYPE TABLE OF bdcmsgcoll,
lv_size TYPE string VALUE 'X',
lv_mode TYPE string VALUE 'N',
lv_upd TYPE string VALUE 'S'.
IF iv_first_screen = abap_true.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLSPO4' iv_value = '0300' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=FURT' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'SVALD-VALUE(01)' iv_value = iw_data_shdb-co_area ). "'PWBR' ).
ENDIF.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP0' iv_value = '1000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '/ECNLA' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP0' iv_value = '1000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CSUB' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP1B-ONLY' iv_value = 'X' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(01)' iv_value = iw_data_shdb-version ). "'0' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(02)' iv_value = iw_data_shdb-period_from )."'10' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(03)' iv_value = iw_data_shdb-period_to ). "'10' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(04)' iv_value = iw_data_shdb-fisc_year ). "'2022' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(06)' iv_value = iw_data_shdb-wbs_element )."'PC.005.0000004' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(07)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(08)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(09)' iv_value = iw_data_shdb-order_celem )."'3101010150' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(10)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(11)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(12)' iv_value = iw_data_shdb-activity ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(13)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(14)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP2' iv_value = '0112' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'Z-BDC03(01)' iv_value = iw_data_shdb-value )."'-6000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CBUC' ).
MOVE: lv_mode TO lw_params-dismode,
lv_upd TO lw_params-updmode,
lv_size TO lw_params-defsize.
CALL TRANSACTION 'CJR2' USING zif_ps_tx_media~t_bdcdata OPTIONS FROM lw_params MESSAGES INTO lt_msg.
* SORT lt_msg BY msgid msgnr.
* READ TABLE lt_msg TRANSPORTING NO FIELDS
* WITH KEY msgid = '00'
* msgnr = '344' BINARY SEARCH.
* IF sy-subrc <> 0.
* CLEAR: lt_msg.
* DO 4 TIMES.
* DELETE t_bdcdata INDEX 1.
* ENDDO.
* CALL TRANSACTION 'CJR2' USING t_bdcdata OPTIONS FROM lw_params MESSAGES INTO lt_msg.
* ENDIF.
CLEAR zif_ps_tx_media~t_bdcdata.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~PLANEJAR_DESPESAS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IW_DATA_SHDB TYPE TY_DATA_SHDB
* | [--->] IV_FIRST_SCREEN TYPE ABAP_BOOL(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~planejar_despesas.
DATA: lw_params TYPE ctu_params,
lt_msg TYPE TABLE OF bdcmsgcoll,
lv_size TYPE string VALUE 'X',
lv_mode TYPE string VALUE 'N',
lv_upd TYPE string VALUE 'S'.
IF iv_first_screen = abap_true.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLSPO4' iv_value = '0300' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=FURT' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'SVALD-VALUE(01)' iv_value = iw_data_shdb-co_area ). "'PWBR' ).
ENDIF.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP0' iv_value = '1000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CSUB' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP1B-ONLY' iv_value = 'X' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(01)' iv_value = iw_data_shdb-version ). "'0' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(02)' iv_value = iw_data_shdb-period_from )."'01' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(03)' iv_value = iw_data_shdb-period_to ). "'12' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(04)' iv_value = iw_data_shdb-fisc_year ). "'2022' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(06)' iv_value = iw_data_shdb-wbs_element )."'PC.005.0000004' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(07)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(08)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(09)' iv_value = iw_data_shdb-order_celem )."'3101010150' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(10)' iv_value = space ).
* zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(12)' iv_value = space ).
* zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(13)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP2' iv_value = '0112' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'Z-BDC03(01)' iv_value = iw_data_shdb-value ). "'-6000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CBUC' ).
MOVE: lv_mode TO lw_params-dismode,
lv_upd TO lw_params-updmode,
lv_size TO lw_params-defsize.
CALL TRANSACTION 'CJR2' USING zif_ps_tx_media~t_bdcdata OPTIONS FROM lw_params MESSAGES INTO lt_msg.
* SORT lt_msg BY msgid msgnr.
* READ TABLE lt_msg TRANSPORTING NO FIELDS
* WITH KEY msgid = '00'
* msgnr = '344' BINARY SEARCH.
* IF sy-subrc <> 0.
* CLEAR: lt_msg.
* DO 4 TIMES.
* DELETE t_bdcdata INDEX 1.
* ENDDO.
* CALL TRANSACTION 'CJR2' USING t_bdcdata OPTIONS FROM lw_params MESSAGES INTO lt_msg.
* ENDIF.
CLEAR zif_ps_tx_media~t_bdcdata.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~PLANEJAR_RECEITAS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IW_DATA_SHDB TYPE TY_DATA_SHDB
* | [--->] IV_FIRST_SCREEN TYPE ABAP_BOOL(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~planejar_receitas.
DATA: lw_params TYPE ctu_params,
lt_msg TYPE TABLE OF bdcmsgcoll,
lv_size TYPE string VALUE 'X',
lv_mode TYPE string VALUE 'N',
lv_upd TYPE string VALUE 'S'.
IF iv_first_screen = abap_true.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLSPO4' iv_value = '0300' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=FURT' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'SVALD-VALUE(01)' iv_value = iw_data_shdb-co_area ). "'PWBR' ).
ENDIF.
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP0' iv_value = '1000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CSUB' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP1B-ONLY' iv_value = 'X' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(01)' iv_value = iw_data_shdb-version ). "'0' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(02)' iv_value = iw_data_shdb-period_from )."'01' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(03)' iv_value = iw_data_shdb-period_to ). "'12' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(04)' iv_value = iw_data_shdb-fisc_year ). "'2022' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(06)' iv_value = iw_data_shdb-wbs_element )."'PC.005.0000004' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(07)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(08)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(09)' iv_value = iw_data_shdb-order_celem )."'3101010150' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'KPP0B-VALUE(10)' iv_value = space ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = 'X' iv_name = 'SAPLKPP2' iv_value = '0112' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'Z-BDC03(01)' iv_value = iw_data_shdb-value ). "'-6000' ).
zif_ps_tx_media~preenche_bdc( iv_dynbegin = ' ' iv_name = 'BDC_OKCODE' iv_value = '=CBUC' ).
MOVE: lv_mode TO lw_params-dismode,
lv_upd TO lw_params-updmode,
lv_size TO lw_params-defsize.
CALL TRANSACTION 'CJR2' USING zif_ps_tx_media~t_bdcdata OPTIONS FROM lw_params MESSAGES INTO lt_msg.
CLEAR zif_ps_tx_media~t_bdcdata.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~POC_CUSTOS_BILLABLE
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] BUKRS TYPE COEP-BUKRS
* | [--->] PSPNR TYPE PRPS-PSPNR
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* | [--->] OBJNR TYPE COSB-OBJNR
* | [<-()] R_CUSTO_BILLABLE TYPE WKGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~poc_custos_billable.
SELECT valsign, valoption, valfrom, valto
FROM setleaf
INTO TABLE @DATA(lr_kstar)
WHERE setname = 'RA_RECEITAS'.
CHECK sy-subrc IS INITIAL.
DATA(fiscyearper) = |{ gjahr }{ monat }|.
SELECT rtcur, SUM( hsl ) AS hsl
FROM acdoca
WHERE rldnr = '0L'
AND rbukrs = @bukrs
AND blart = 'RV'
AND ps_psp_pnr = @pspnr
* AND racct IN @lr_kstar
* AND fiscyearper = @fiscyearper
GROUP BY rtcur
INTO TABLE @DATA(lt_acdoca).
LOOP AT lt_acdoca ASSIGNING FIELD-SYMBOL(<acdoca>).
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = kokrs
fisc_year = gjahr
period_from = monat
period_to = monat
version = '0'
wbs_element = posid
order_celem = COND #( WHEN <acdoca>-rtcur = 'BRL' THEN '3101030100' ELSE '3101030200' )
value = <acdoca>-hsl ).
REPLACE ALL OCCURRENCES OF '.' IN data_shdb-value WITH ','.
CONCATENATE data_shdb-value '-' INTO data_shdb-value.
"Chama SHDB
zif_ps_tx_media~executa( data_shdb ).
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~POC_CUSTOS_INCLUDED
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] BUKRS TYPE COEP-BUKRS
* | [--->] PSPNR TYPE PRPS-PSPNR
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* | [--->] OBJNR TYPE COSB-OBJNR
* | [<-()] R_CUSTO_INCLUDED TYPE WKGXXX
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~poc_custos_included.
TYPES ty_r_kstar TYPE RANGE OF kstar .
TYPES ty_s_conta TYPE rgsb4 .
TYPES ty_t_contas TYPE STANDARD TABLE OF ty_s_conta WITH DEFAULT KEY .
DATA mt_contas TYPE ty_t_contas .
DATA r_kstar TYPE ty_r_kstar .
DATA(versn) = '000'.
DATA(period_begin) = CONV monat( monat ).
DATA(period_end) = CONV monat( monat ).
DATA(year) = gjahr.
CALL FUNCTION 'G_SET_GET_ALL_VALUES'
EXPORTING
client = sy-mandt
setnr = 'RA_DESP_INCLUDED'
class = '0000'
no_descriptions = abap_false
TABLES
set_values = mt_contas
EXCEPTIONS
set_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
r_kstar = VALUE #( FOR <conta> IN mt_contas ( sign = 'I' option = 'EQ' low = <conta>-from ) ).
WITH
"Desp Incluídas = Soma do faturamento realizado no período
"nas contas específicas RA_DESP_INCLUDED
+desp_incl AS (
SELECT objnr, gjahr, twaer,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wkg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wkg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wkg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wkg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wkg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wkg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wkg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wkg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wkg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wkg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wkg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wkg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS desp_incl
FROM v_cosp_view
WHERE wrttp = '01'
AND kstar IN @r_kstar
AND versn = @versn
AND gjahr = @year
GROUP BY objnr, gjahr, twaer ),
+result( pspnr, posid, pedit, objnr, moeda,
gjahr,
desp_incl ) AS (
SELECT
p~pspnr, p~posid, p~posid_edit, p~objnr, p~pwpos AS moeda,
e~gjahr,
e~desp_incl
FROM proj AS j
JOIN prps AS p ON p~psphi = j~pspnr
LEFT JOIN +desp_incl AS e ON e~objnr = p~objnr
AND e~twaer = p~pwpos
WHERE p~pspnr = @pspnr )
SELECT * FROM +result INTO TABLE @DATA(results).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~PREENCHER_PERIODOS
* +-------------------------------------------------------------------------------------------------+
* | [--->] PLFAZ TYPE PROJ-PLFAZ
* | [--->] PLSEZ TYPE PROJ-PLSEZ
* | [<-()] RT_PERIODS TYPE TY_T_PERIODS
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~preencher_periodos.
DATA:
date_pl TYPE dats,
begda TYPE dats,
endda TYPE dats,
buper TYPE t009b-poper,
gjahr TYPE t009b-bdatj,
buper_ini TYPE t009b-poper,
gjahr_ini TYPE t009b-bdatj,
buper_fim TYPE t009b-poper,
gjahr_fim TYPE t009b-bdatj.
DO 2 TIMES.
IF sy-index = 1.
date_pl = plfaz.
ELSE.
date_pl = plsez.
ENDIF.
CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'
EXPORTING
i_date = date_pl
* I_MONMIT = 00
i_periv = 'S6'
IMPORTING
e_buper = buper
e_gjahr = gjahr
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
RETURN.
ENDIF.
IF sy-index = 1.
buper_ini = buper.
gjahr_ini = gjahr.
ELSE.
buper_fim = buper.
gjahr_fim = gjahr.
ENDIF.
ENDDO.
DO.
CALL FUNCTION 'FIRST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = gjahr_ini
* I_MONMIT = 00
i_periv = 'S6'
i_poper = buper_ini
IMPORTING
e_date = begda
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = gjahr_ini
* I_MONMIT = 00
i_periv = 'S6'
i_poper = buper_ini
IMPORTING
e_date = endda
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
INSERT VALUE #( buper = buper_ini gjahr = gjahr_ini begda = begda endda = endda ) INTO TABLE rt_periods.
IF buper_ini = buper_fim AND gjahr_ini = gjahr_fim.
EXIT.
ELSE.
buper_ini += 1.
IF buper_ini > 12.
buper_ini = 1.
gjahr_ini += 1.
ENDIF.
ENDIF.
ENDDO.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~PREENCHE_BDC
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_DYNBEGIN TYPE STRING
* | [--->] IV_NAME TYPE STRING
* | [--->] IV_VALUE TYPE ANY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~preenche_bdc.
DATA: lw_bdcdata LIKE LINE OF zif_ps_tx_media~t_bdcdata.
IF iv_dynbegin = abap_true."Se for tela inicial
lw_bdcdata-dynbegin = abap_true. "Tela Inicial
lw_bdcdata-program = iv_name. "Nome da Tela
lw_bdcdata-dynpro = iv_value. "Número de Tela
ELSE."Caso contrário
lw_bdcdata-fnam = iv_name. "Nome do Campo
lw_bdcdata-fval = iv_value. "Valor do Campo
ENDIF.
APPEND lw_bdcdata TO zif_ps_tx_media~t_bdcdata.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~RECEITA_PLANEJADA
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] BUKRS TYPE COEP-BUKRS
* | [--->] PSPNR TYPE PRPS-PSPNR
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~receita_planejada.
DATA rl_racct TYPE RANGE OF acdoca-racct.
rl_racct = VALUE #( sign = 'I' option = 'EQ' ( low = '3101030100' ) ( low = '3101030200' ) ).
DATA(versn) = '000'.
WITH
"Custo planejado do periodo/exercício informado na KKA2
+c_plan AS (
SELECT objnr, twaer,
CAST( CASE WHEN '001' = @monat THEN SUM( wkg001 ) ELSE 0 END +
CASE WHEN '002' = @monat THEN SUM( wkg002 ) ELSE 0 END +
CASE WHEN '003' = @monat THEN SUM( wkg003 ) ELSE 0 END +
CASE WHEN '004' = @monat THEN SUM( wkg004 ) ELSE 0 END +
CASE WHEN '005' = @monat THEN SUM( wkg005 ) ELSE 0 END +
CASE WHEN '006' = @monat THEN SUM( wkg006 ) ELSE 0 END +
CASE WHEN '007' = @monat THEN SUM( wkg007 ) ELSE 0 END +
CASE WHEN '008' = @monat THEN SUM( wkg008 ) ELSE 0 END +
CASE WHEN '009' = @monat THEN SUM( wkg009 ) ELSE 0 END +
CASE WHEN '010' = @monat THEN SUM( wkg010 ) ELSE 0 END +
CASE WHEN '011' = @monat THEN SUM( wkg011 ) ELSE 0 END +
CASE WHEN '012' = @monat THEN SUM( wkg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS custo
FROM v_cosp_view
WHERE wrttp = '01'
AND versn = @versn
AND gjahr = @gjahr
AND kstar = '3101010150'
GROUP BY objnr, twaer ),
+fatur AS (
SELECT ps_psp_pnr, rtcur, abs( SUM( wsl ) ) AS fatur
FROM acdoca
WHERE rldnr = '0L'
AND ps_psp_pnr = @pspnr
AND racct IN @rl_racct
GROUP BY ps_psp_pnr, rtcur ),
+result( pspnr, objnr, moeda,
custo_plan,
fatur ) AS (
SELECT p~pspnr, p~objnr, p~pwpos AS moeda,
c~custo,
f~fatur
FROM proj AS j
JOIN prps AS p ON p~psphi = j~pspnr
LEFT JOIN +c_plan AS c ON c~objnr = p~objnr
AND c~twaer = p~pwpos
LEFT JOIN +fatur AS f ON f~ps_psp_pnr = p~pspnr
AND f~rtcur = p~pwpos
WHERE p~pspnr = @pspnr OR p~posid = @posid )
SELECT * FROM +result INTO TABLE @DATA(results).
"espera-se apenas 1 linha
LOOP AT results ASSIGNING FIELD-SYMBOL(<result>).
DATA(lv_diff) = CONV wtgxxx( <result>-fatur - <result>-custo_plan ).
IF lv_diff >= 0 .
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = kokrs
fisc_year = gjahr
period_from = monat
period_to = monat
version = '0'
wbs_element = posid
order_celem = '3101010155'
value = abs( <result>-custo_plan ) ).
REPLACE ALL OCCURRENCES OF '.' IN data_shdb-value WITH ','.
CONCATENATE data_shdb-value '-' INTO data_shdb-value.
"Chama SHDB
zif_ps_tx_media~executa( data_shdb ).
ELSE.
MESSAGE e082.
ENDIF.
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_TX_MEDIA->ZIF_PS_TX_MEDIA~RECONHECER_RECEITA
* +-------------------------------------------------------------------------------------------------+
* | [--->] KOKRS TYPE COEP-KOKRS
* | [--->] BUKRS TYPE COEP-BUKRS
* | [--->] PSPNR TYPE PRPS-PSPNR
* | [--->] POSID TYPE PRPS-POSID
* | [--->] GJAHR TYPE XKALXKAG-ABGRJ
* | [--->] MONAT TYPE XKALXKAG-ABGRM
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_ps_tx_media~reconhecer_receita.
SELECT valsign, valoption, valfrom, valto
FROM setleaf
INTO TABLE @DATA(lr_kstar)
WHERE setname = 'RA_RECEITAS'.
CHECK sy-subrc IS INITIAL.
DATA(fiscyearper) = |{ gjahr }{ monat }|.
SELECT abs( SUM( tsl ) )
FROM acdoca
WHERE rldnr = '0L'
AND rbukrs = @bukrs
AND blart IN ( 'RV', 'ZE', 'EE' )
AND ps_psp_pnr = @pspnr
AND racct IN @lr_kstar
AND fiscyearper = @fiscyearper
INTO @DATA(tsl).
DATA(data_shdb) = VALUE ty_data_shdb(
co_area = kokrs
fisc_year = gjahr
period_from = monat
period_to = monat
version = '0'
wbs_element = posid
order_celem = '3101010155'
value = tsl ).
REPLACE ALL OCCURRENCES OF '.' IN data_shdb-value WITH ','.
CONCATENATE data_shdb-value '-' INTO data_shdb-value.
"Chama SHDB
zif_ps_tx_media~executa( data_shdb ).
ENDMETHOD.
ENDCLASS.
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 241
Interface do cálculo da taxa média.
INTERFACE zif_ps_tx_media
PUBLIC .
TYPES:
BEGIN OF ty_data_shdb,
co_area TYPE string, "PWBR
fisc_year TYPE string, "2022
period_from TYPE string, "10
period_to TYPE string, "10
version TYPE string, "0
wbs_element TYPE string, "prps_posid
order_celem TYPE string, "3101010150
activity TYPE string, "12.AS1
value TYPE string, "lw_bseg-wrbtr
END OF ty_data_shdb .
TYPES:
BEGIN OF ty_s_period,
gjahr TYPE t009b-bdatj,
buper TYPE t009b-poper,
begda TYPE dats,
endda TYPE dats,
END OF ty_s_period .
TYPES:
ty_t_periods TYPE SORTED TABLE OF ty_s_period
WITH UNIQUE KEY gjahr buper .
DATA t_bdcdata TYPE tab_bdcdata .
DATA _handle TYPE balloghndl .
METHODS calcular_taxa_media_novo
IMPORTING
!i_rtp TYPE wkgxxx
!i_dp TYPE wkgxxx
!i_hp TYPE megxxx
!i_dri TYPE wkgxxx
!i_ha TYPE megxxx
RETURNING
VALUE(r_taxa_media) TYPE wkgxxx .
METHODS calcular_taxa_media
IMPORTING
!i_receita TYPE wkgxxx
!i_custo_plan TYPE wkgxxx
!i_horas_plan TYPE megxxx
!i_horas_real TYPE megxxx
!i_desp_incl TYPE wkgxxx
RETURNING
VALUE(r_taxa_media) TYPE wkgxxx .
METHODS calc_tx_media
IMPORTING
!kokrs TYPE coep-kokrs
!bukrs TYPE coep-bukrs
!pspnr TYPE prps-pspnr
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm
!objnr TYPE cosb-objnr
EXPORTING
!e_receita TYPE wkgxxx
!e_custo_plan TYPE wkgxxx
!e_horas_plan TYPE megxxx
!e_horas_real TYPE megxxx
!e_desp_incl TYPE wkgxxx .
METHODS executa
IMPORTING
!iw_data_shdb TYPE ty_data_shdb
!iv_first_screen TYPE abap_bool OPTIONAL
RETURNING
VALUE(rv_bool) TYPE abap_bool .
METHODS lancar_planejamento
IMPORTING
!kokrs TYPE coep-kokrs
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm
!value TYPE wtgxxx .
METHODS lancar_taxa_media
IMPORTING
!kokrs TYPE coep-kokrs
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm
!value TYPE wtgxxx .
METHODS montar_atividades
IMPORTING
!co_area TYPE coep-kokrs DEFAULT 'PWBR'
!version TYPE versn DEFAULT '0'
!wbs_element TYPE prps-posid
!year TYPE xkalxkag-abgrj
!period_from TYPE xkalxkag-abgrm
!period_to TYPE xkalxkag-abgrm
!order_celem TYPE kostl OPTIONAL
!activity TYPE lstar OPTIONAL
!quantity TYPE megxxx OPTIONAL
!value TYPE wtgxxx OPTIONAL .
METHODS montar_despesas
IMPORTING
!co_area TYPE coep-kokrs DEFAULT 'PWBR'
!version TYPE versn DEFAULT '0'
!wbs_element TYPE prps-posid
!year TYPE xkalxkag-abgrj
!period_from TYPE xkalxkag-abgrm
!period_to TYPE xkalxkag-abgrm
!order_celem TYPE kostl OPTIONAL
!activity TYPE lstar OPTIONAL
!quantity TYPE megxxx OPTIONAL
!value TYPE wtgxxx OPTIONAL .
METHODS montar_receitas
IMPORTING
!co_area TYPE coep-kokrs DEFAULT 'PWBR'
!version TYPE versn DEFAULT '0'
!wbs_element TYPE prps-posid
!year TYPE xkalxkag-abgrj
!period_from TYPE xkalxkag-abgrm
!period_to TYPE xkalxkag-abgrm
!order_celem TYPE kostl OPTIONAL
!activity TYPE lstar OPTIONAL
!quantity TYPE megxxx OPTIONAL
!value TYPE wtgxxx OPTIONAL .
METHODS planejar_atividades
IMPORTING
!iw_data_shdb TYPE ty_data_shdb
!iv_first_screen TYPE abap_bool OPTIONAL .
METHODS planejar_despesas
IMPORTING
!iw_data_shdb TYPE ty_data_shdb
!iv_first_screen TYPE abap_bool OPTIONAL .
METHODS planejar_receitas
IMPORTING
!iw_data_shdb TYPE ty_data_shdb
!iv_first_screen TYPE abap_bool OPTIONAL .
METHODS poc_custos_billable
IMPORTING
!kokrs TYPE coep-kokrs
!bukrs TYPE coep-bukrs
!pspnr TYPE prps-pspnr
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm
!objnr TYPE cosb-objnr
RETURNING
VALUE(r_custo_billable) TYPE wkgxxx .
METHODS poc_custos_included
IMPORTING
!kokrs TYPE coep-kokrs
!bukrs TYPE coep-bukrs
!pspnr TYPE prps-pspnr
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm
!objnr TYPE cosb-objnr
RETURNING
VALUE(r_custo_included) TYPE wkgxxx .
METHODS preencher_periodos
IMPORTING
!plfaz TYPE proj-plfaz
!plsez TYPE proj-plsez
RETURNING
VALUE(rt_periods) TYPE ty_t_periods .
METHODS preenche_bdc
IMPORTING
!iv_dynbegin TYPE string
!iv_name TYPE string
!iv_value TYPE any .
METHODS receita_planejada
IMPORTING
!kokrs TYPE coep-kokrs
!bukrs TYPE coep-bukrs
!pspnr TYPE prps-pspnr
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm .
METHODS reconhecer_receita
IMPORTING
!kokrs TYPE coep-kokrs
!bukrs TYPE coep-bukrs
!pspnr TYPE prps-pspnr
!posid TYPE prps-posid
!gjahr TYPE xkalxkag-abgrj
!monat TYPE xkalxkag-abgrm .
ENDINTERFACE.
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 270
Excel ABAP Helper
Criei essa classe para tarefas de leitura de arquivos Excel (xlsx). O diferencial é a tratativa dos campos fica no programa que chama essa classe ou seja, eu posso ter tratativas diferentes para arquivos diferentes. Isso é feito usando o evento excel_loaded
que dispara o perform do programa chamador.
CLASS zcl_migration_cockpit_helper DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES zif_migration_cockpit_helper .
CLASS-DATA _instance TYPE REF TO zcl_migration_cockpit_helper .
EVENTS excel_loaded
EXPORTING
VALUE(ir_data) TYPE REF TO data .
CLASS-METHODS class_constructor .
METHODS constructor .
METHODS bupa_change_bpkind
IMPORTING
!iv_partner TYPE bp_partner
!iv_partnertype TYPE bu_bpkind
RETURNING
VALUE(rt_return) TYPE bapiret2_tab .
METHODS bupa_change_vip
IMPORTING
!iv_partner TYPE bp_partner
!iv_vip TYPE bp_vip_partner
RETURNING
VALUE(rt_return) TYPE bapiret2_tab .
CLASS-METHODS get_instance
RETURNING
VALUE(ro_instance) TYPE REF TO zcl_migration_cockpit_helper .
PROTECTED SECTION.
PRIVATE SECTION.
METHODS load_excel
FOR EVENT load_excel OF zcl_copia_proj_audit
IMPORTING
!ir_data .
ENDCLASS.
CLASS zcl_migration_cockpit_helper IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->BUPA_CHANGE_BPKIND
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PARTNER TYPE BP_PARTNER
* | [--->] IV_PARTNERTYPE TYPE BU_BPKIND
* | [<-()] RT_RETURN TYPE BAPIRET2_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bupa_change_bpkind.
* DATA(ls_centraldata) = VALUE bapibus1006_central( partnertype = iv_partnertype ).
* DATA(ls_centraldata_x) = VALUE bapibus1006_central_x( partnertype = abap_true ).
*
* CALL FUNCTION 'BAPI_BUPA_CENTRAL_CHANGE'
* EXPORTING
* businesspartner = iv_partner
* centraldata = ls_centraldata
* centraldata_x = ls_centraldata_x
* TABLES
* return = rt_return.
*
* LOOP AT rt_return INTO DATA(ls_return).
* MESSAGE ID ls_return-id
* TYPE ls_return-type
* NUMBER ls_return-number
* WITH ls_return-message_v1 ls_return-message_v2 ls_return-message_v3 ls_return-message_v4 INTO DATA(lv_dummy).
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* ENDLOOP.
* zcl_ptool_helper=>bal_db_save( ).
*
* IF NOT line_exists( rt_return[ type = |E| ] ).
*
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = abap_true
* IMPORTING
* return = ls_return.
*
* IF ls_return IS NOT INITIAL.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_dummy.
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* zcl_ptool_helper=>bal_db_save( ).
* ELSE.
* MESSAGE ID 'ZBUPA' TYPE 'S' NUMBER '000' WITH iv_partner iv_partnertype DISPLAY LIKE 'S'.
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* zcl_ptool_helper=>bal_db_save( ).
* ENDIF.
*
* ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->BUPA_CHANGE_VIP
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_PARTNER TYPE BP_PARTNER
* | [--->] IV_VIP TYPE BP_VIP_PARTNER
* | [<-()] RT_RETURN TYPE BAPIRET2_TAB
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bupa_change_vip.
* DATA(ls_bp001) = VALUE bp001( vip = abap_true ).
* DATA(ls_bp001_x) = VALUE bp001_x( vip = abap_true ).
*
* CALL FUNCTION 'FS_API_BP001_SET'
* EXPORTING
* iv_partner = iv_partner
* is_bp001 = ls_bp001
* is_bp001_x = ls_bp001_x
* TABLES
* et_return = rt_return.
*
* LOOP AT rt_return INTO DATA(ls_return).
* MESSAGE ID ls_return-id
* TYPE ls_return-type
* NUMBER ls_return-number
* WITH ls_return-message_v1 ls_return-message_v2 ls_return-message_v3 ls_return-message_v4 INTO DATA(lv_dummy).
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* ENDLOOP.
* zcl_ptool_helper=>bal_db_save( ).
*
* IF NOT line_exists( rt_return[ type = |E| ] ).
*
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = abap_true
* IMPORTING
* return = ls_return.
*
* IF ls_return IS NOT INITIAL.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_dummy.
* ELSE.
* MESSAGE ID 'ZBUPA' TYPE 'S' NUMBER '002' WITH iv_partner INTO lv_dummy.
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* zcl_ptool_helper=>bal_db_save( ).
* ENDIF.
*
* ENDIF.
*
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_MIGRATION_COCKPIT_HELPER=>CLASS_CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD class_constructor.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
zif_migration_cockpit_helper~_handle = zcl_ptool_helper=>bal_log_create( iv_object = |ZBUPA| ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_MIGRATION_COCKPIT_HELPER=>GET_INSTANCE
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_INSTANCE TYPE REF TO ZCL_MIGRATION_COCKPIT_HELPER
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_instance.
IF _instance IS NOT BOUND.
_instance = NEW #( ).
ENDIF.
ro_instance = _instance.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_MIGRATION_COCKPIT_HELPER->LOAD_EXCEL
* +-------------------------------------------------------------------------------------------------+
* | [--->] IR_DATA LIKE
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD load_excel.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->ZIF_MIGRATION_COCKPIT_HELPER~CONVERT_FILE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FILELENGTH TYPE I
* | [--->] IT_RECORDS TYPE SOLIX_TAB
* | [<-()] RV_HEADERXSTRING TYPE XSTRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_migration_cockpit_helper~convert_file.
CHECK it_records[] IS NOT INITIAL.
MESSAGE ID 'ZBUPA' TYPE 'S' NUMBER '004' INTO DATA(lv_dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_migration_cockpit_helper~_handle ).
zcl_ptool_helper=>bal_db_save( ).
"convert binary data to xstring
"if you are using cl_fdt_xl_spreadsheet in odata then skips this step
"as excel file will already be in xstring
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = iv_filelength
IMPORTING
buffer = rv_headerxstring
TABLES
binary_tab = it_records
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc = 0.
* DATA(lv_message) = |Convertendo arquivo...|.
ELSE.
* lv_message = |N�o foi poss�vel converter o arquivo!|.
ENDIF.
* WRITE: / lv_message.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->ZIF_MIGRATION_COCKPIT_HELPER~OPEN_EXCEL
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FILE TYPE STRING
* | [--->] IV_HEADERXSTRING TYPE XSTRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_migration_cockpit_helper~open_excel.
FIELD-SYMBOLS : <fs_table> TYPE STANDARD TABLE.
DATA: lo_excel_ref TYPE REF TO cl_fdt_xl_spreadsheet .
CHECK iv_headerxstring IS NOT INITIAL.
TRY .
lo_excel_ref = NEW cl_fdt_xl_spreadsheet(
document_name = iv_file
xdocument = iv_headerxstring ).
CATCH cx_fdt_excel_core INTO DATA(lx_excel).
WRITE: |Erro convertendo Excel...|.
RETURN.
"Implement suitable error handling here
ENDTRY .
CHECK lo_excel_ref IS NOT INITIAL.
"Get List of Worksheets
lo_excel_ref->if_fdt_doc_spreadsheet~get_worksheet_names(
IMPORTING
worksheet_names = DATA(lt_worksheets) ).
IF NOT lt_worksheets IS INITIAL.
READ TABLE lt_worksheets INTO DATA(lv_woksheetname) INDEX 1.
zif_migration_cockpit_helper~_data = lo_excel_ref->if_fdt_doc_spreadsheet~get_itab_from_worksheet( lv_woksheetname ).
"now you have excel work sheet data in dyanmic internal table
* ASSIGN lo_data_ref->* TO <fs_table>.
* WRITE: / |Processando Excel...|.
MESSAGE ID 'ZBUPA' TYPE 'S' NUMBER '003' INTO DATA(lv_dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = zif_migration_cockpit_helper~_handle ).
zcl_ptool_helper=>bal_db_save( ).
RAISE EVENT excel_loaded EXPORTING ir_data = zif_migration_cockpit_helper~_data.
* PERFORM f_process IN PROGRAM (sy-cprog) IF FOUND.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->ZIF_MIGRATION_COCKPIT_HELPER~READ_FILE
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_migration_cockpit_helper~read_file.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = zif_migration_cockpit_helper~_filename
filetype = CONV char10( `BIN` )
IMPORTING
filelength = zif_migration_cockpit_helper~_filelength
CHANGING
data_tab = zif_migration_cockpit_helper~_records
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_MIGRATION_COCKPIT_HELPER->ZIF_MIGRATION_COCKPIT_HELPER~SET_FILENAME
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_FILENAME TYPE STRING
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD zif_migration_cockpit_helper~set_filename.
zif_migration_cockpit_helper~_filename = iv_filename.
ENDMETHOD.
ENDCLASS.
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 245
CATS, CATSDB, CATSCO
Esta classe lê dados de uma tabela Z e cria ou apaga apontamentos na transação CATS e também transferências dos apontamentos realizados com sucesso para CO.
CLASS zcl_apontamento_horas_new DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES:
ty_r_project_id TYPE RANGE OF zwfs_allocation-project_id .
TYPES:
ty_r_zdate TYPE RANGE OF zwfs_allocation-zdate .
TYPES:
ty_r_batch_id TYPE RANGE OF zwfs_allocation-batch_id .
TYPES:
ty_r_record_id TYPE RANGE OF zwfs_allocation-record_id .
TYPES:
ty_r_employee_id TYPE RANGE OF zwfs_allocation-employee_id .
TYPES:
ty_r_erdat TYPE RANGE OF zwfs_allocation-erdat .
TYPES:
ty_r_aedat TYPE RANGE OF zwfs_allocation-aedat .
TYPES:
ty_r_pay_code TYPE RANGE OF zwfs_allocation-pay_code .
TYPES:
ty_r_status TYPE RANGE OF zwfs_allocation-status .
TYPES:
ty_t_allocation TYPE STANDARD TABLE OF zst_allocation_salv
WITH NON-UNIQUE KEY mandt batch_id record_id .
DATA r_project_id TYPE ty_r_project_id .
DATA r_zdate TYPE ty_r_zdate .
DATA r_batch_id TYPE ty_r_batch_id .
DATA r_record_id TYPE ty_r_record_id .
DATA r_employee_id TYPE ty_r_employee_id .
DATA r_erdat TYPE ty_r_erdat .
DATA r_aedat TYPE ty_r_aedat .
DATA r_pay_code TYPE ty_r_pay_code .
DATA r_status TYPE ty_r_status .
CLASS-DATA mo_allocation TYPE REF TO zcl_apontamento_horas_new .
CLASS-METHODS factory
RETURNING
VALUE(ro_allocation) TYPE REF TO zcl_apontamento_horas_new .
METHODS constructor
IMPORTING
!process_type TYPE abap_bool OPTIONAL
!testrun TYPE abap_bool OPTIONAL .
METHODS executar
RETURNING
VALUE(results) TYPE ztt_allocation_without_key .
METHODS get_data
RETURNING
VALUE(rt_alloc) TYPE ztt_allocation .
METHODS reprocessar
IMPORTING
!it_allocation TYPE ty_t_allocation .
METHODS selecionar_apontamentos .
METHODS selecionar_reprocessamento
IMPORTING
!it_allocation TYPE ty_t_allocation .
METHODS set_filter
IMPORTING
!it_project_id TYPE ty_r_project_id OPTIONAL
!it_zdate TYPE ty_r_zdate OPTIONAL
!it_batch_id TYPE ty_r_batch_id OPTIONAL
!it_record_id TYPE ty_r_record_id OPTIONAL
!it_employee_id TYPE ty_r_employee_id OPTIONAL
!it_erdat TYPE ty_r_erdat OPTIONAL
!it_aedat TYPE ty_r_aedat OPTIONAL
!it_pay_code TYPE ty_r_pay_code OPTIONAL
!it_status TYPE ty_r_status OPTIONAL .
METHODS set_mt_allocation
IMPORTING
!it_allocation TYPE ztt_allocation .
METHODS redefinir
IMPORTING
!it_allocation TYPE ztt_allocation
!iv_status TYPE zwfs_status .
PROTECTED SECTION.
DATA _ersda TYPE catsdb-ersda .
DATA _erstm TYPE catsdb-erstm .
DATA _handle TYPE balloghndl .
DATA _process_type TYPE abap_bool .
DATA _testrun TYPE abap_bool .
PRIVATE SECTION.
TYPES:
tt_bapicats1 TYPE STANDARD TABLE OF bapicats1 WITH DEFAULT KEY .
TYPES:
BEGIN OF ENUM ty_e_status BASE TYPE n ,
new VALUE IS INITIAL,
processing VALUE 1,
error VALUE 2,
success VALUE 3,
eliminado VALUE 4,
migrar_co VALUE 5,
waiting VALUE 6,
END OF ENUM ty_e_status .
TYPES:
BEGIN OF ty_s_catsco,
counter TYPE catsco-counter,
stokz TYPE catsco-stokz,
pernr TYPE catsco-pernr,
workdate TYPE catsco-workdate,
catshours TYPE catsco-catshours,
belnr TYPE catsco-belnr,
transfer TYPE catsco-transfer,
END OF ty_s_catsco .
TYPES:
ty_t_catsco TYPE SORTED TABLE OF ty_s_catsco
WITH UNIQUE KEY counter
WITH NON-UNIQUE SORTED KEY migrar COMPONENTS pernr workdate belnr .
TYPES ty_s_catsdb TYPE catsdb .
TYPES:
ty_t_catsdb TYPE SORTED TABLE OF ty_s_catsdb
WITH UNIQUE KEY counter
WITH NON-UNIQUE SORTED KEY ltxa1 COMPONENTS ltxa1 .
TYPES:
BEGIN OF ty_s_workdate,
pernr TYPE pa0000-pernr,
workdate TYPE catsdb-workdate,
catshours TYPE catsdb-catshours,
END OF ty_s_workdate .
TYPES:
ty_t_workdates TYPE SORTED TABLE OF ty_s_workdate
WITH UNIQUE KEY pernr workdate .
TYPES:
ty_r_pernr TYPE RANGE OF catsdb-pernr .
TYPES:
ty_r_belnr TYPE RANGE OF catsdb-belnr .
TYPES:
ty_r_wdate TYPE RANGE OF catsdb-workdate .
CONSTANTS c_extra TYPE zwfs_pay_code VALUE 'PROJ_HOURS_OT' ##NO_TEXT.
CONSTANTS c_proj_name TYPE char8 VALUE 'PROJ_PWC' ##NO_TEXT.
DATA mt_allocation TYPE ztt_allocation .
DATA mt_catsco TYPE ty_t_catsco .
DATA mt_catsdb TYPE ty_t_catsdb .
DATA mt_migra_co TYPE ztt_allocation_std_without_key .
DATA mt_results TYPE ztt_allocation_without_key .
DATA mt_return TYPE bapiret2_tab .
DATA mt_workdates TYPE ty_t_workdates .
DATA mt_apontados TYPE ztt_allocation_without_key .
DATA mt_zwfs_allocation TYPE ztt_allocation_without_key .
METHODS add_time
IMPORTING
!startdate TYPE datum
!starttime TYPE enduz
!addtime TYPE thour
EXPORTING
!enddate TYPE datum
!endtime TYPE enduz .
METHODS apontar .
METHODS buscar_projetos .
METHODS chamar_bapi_para_apontar
IMPORTING
!it_catsrecords TYPE tt_bapicats1 .
METHODS chamar_bapi_para_eliminar
IMPORTING
!it_catsrecords TYPE cats_esa_delete_rec_t .
METHODS destravar_apontamentos .
METHODS eliminar_apontamentos .
METHODS esperar_transferencia_co
IMPORTING
!it_pernr TYPE ty_r_pernr OPTIONAL
!it_belnr TYPE ty_r_belnr OPTIONAL
!it_wdate TYPE ty_r_wdate OPTIONAL
!it_migra_co TYPE ztt_allocation_std_without_key OPTIONAL .
METHODS get_proj_status
IMPORTING
!i_projid TYPE zwfs_project_id
RETURNING
VALUE(r_status) TYPE bapi_user_status_text .
METHODS limpar_dados .
METHODS migrar_dados_co
IMPORTING
!it_migra_co TYPE ztt_allocation_std_without_key
RETURNING
VALUE(result) TYPE abap_bool .
METHODS selecionar_wfs_allocation .
METHODS travar_apontamentos .
METHODS executar_job_migrar_co
IMPORTING
!it_pernr TYPE ty_r_pernr OPTIONAL
!it_belnr TYPE ty_r_belnr OPTIONAL
!it_wdate TYPE ty_r_wdate OPTIONAL
!iv_count TYPE i
RETURNING
VALUE(rv_finished) TYPE abap_bool .
ENDCLASS.
CLASS zcl_apontamento_horas_new IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->ADD_TIME
* +-------------------------------------------------------------------------------------------------+
* | [--->] STARTDATE TYPE DATUM
* | [--->] STARTTIME TYPE ENDUZ
* | [--->] ADDTIME TYPE THOUR
* | [<---] ENDDATE TYPE DATUM
* | [<---] ENDTIME TYPE ENDUZ
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD add_time.
CALL FUNCTION 'CATT_ADD_TO_TIME'
EXPORTING
idate = startdate
itime = starttime
stdaz = addtime
IMPORTING
edate = enddate
etime = endtime.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->APONTAR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD apontar.
MESSAGE i067 INTO DATA(dummy).
LOG-POINT ID zps20 FIELDS dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
DATA lt_catsrecords TYPE STANDARD TABLE OF bapicats1.
DATA(lv_continue) = abap_false.
LOOP AT mt_allocation ASSIGNING FIELD-SYMBOL(<key>)
USING KEY operation
WHERE operation = CONV zwfs_operation( 1 )
GROUP BY ( type = <key>-type
code = <key>-pay_code
stat = <key>-status
indx = GROUP INDEX
size = GROUP SIZE )
ASSIGNING FIELD-SYMBOL(<group>).
CHECK <group>-type IS NOT INITIAL. "ORDEM, PEP
"Somente esses Status podem ser re/processados
CHECK <group>-stat = CONV zwfs_status( new ) OR
<group>-stat = CONV zwfs_status( processing ) OR
<group>-stat = CONV zwfs_status( error ).
LOOP AT GROUP <group> ASSIGNING FIELD-SYMBOL(<allocation>).
TRY.
IF lv_continue = abap_true.
lv_continue = abap_false.
CONTINUE.
ENDIF.
<allocation>-status = CONV #( processing ).
IF VALUE #( mt_catsdb[ KEY ltxa1 ltxa1 = CONV catsshortt( |{ <allocation>-batch_id }{ <allocation>-record_id }| ) ] OPTIONAL ) IS NOT INITIAL OR
VALUE #( mt_catsdb[ KEY ltxa1 ltxa1 = CONV catsshortt( |{ <allocation>-batch_id }_{ <allocation>-record_id }| ) ] OPTIONAL ) IS NOT INITIAL.
<allocation>-status = CONV #( success ).
CONTINUE.
ENDIF.
DATA(workdate) = <allocation>-zdate.
DATA(saldo) = <allocation>-zhour.
* DATA(available) = COND d( WHEN <allocation>-zhour > 24 THEN |{ <allocation>-zdate(6) }01| ELSE <allocation>-zdate ).
DATA(available) = <allocation>-zdate.
WHILE saldo > 0.
DATA(catshours) = COND catsdb-catshours( WHEN <allocation>-zhour < 24 THEN <allocation>-zhour
WHEN saldo < 22 THEN saldo
ELSE 22 ).
* DATA(catshours) = <allocation>-zhour.
IF ( saldo = <allocation>-zhour ) AND ( <allocation>-zhour > 24 ).
INSERT VALUE #( pernr = <allocation>-pernr workdate = <allocation>-zdate catshours = catshours ) INTO TABLE mt_workdates.
workdate = <allocation>-zdate.
ELSE.
DATA(indx) = line_index( mt_workdates[ pernr = <allocation>-pernr workdate = available ] ).
IF indx > 0.
LOOP AT mt_workdates ASSIGNING FIELD-SYMBOL(<workdate>)
FROM indx
WHERE pernr = <allocation>-pernr.
IF <workdate>-workdate > available.
EXIT.
ELSEIF <workdate>-catshours >= 22.
available += 1.
ELSE.
catshours = COND #( WHEN ( 22 - <workdate>-catshours ) > saldo THEN saldo ELSE ( 22 - <workdate>-catshours ) ).
<workdate>-catshours += catshours.
ENDIF.
* IF <workdate>-workdate > available.
* EXIT.
* ELSEIF catshours >= 22.
* available += 1.
* ELSE.
* catshours = COND #( WHEN ( 22 - <workdate>-catshours ) >= catshours THEN catshours ELSE catshours - ( 22 - <workdate>-catshours ) ).
* <workdate>-catshours += catshours.
* ENDIF.
ENDLOOP.
ENDIF.
IF saldo <= catshours.
catshours = saldo.
ENDIF.
INSERT VALUE #( pernr = <allocation>-pernr workdate = available catshours = catshours ) INTO TABLE mt_workdates.
workdate = available.
ENDIF.
add_time(
EXPORTING
startdate = <allocation>-zdate
starttime = `000000`
addtime = CONV #( catshours )
IMPORTING
endtime = DATA(endtime) ). "#EC NEEDED
DATA(ls_catsrecord) = VALUE bapicats1(
workdate = workdate
employeenumber = <allocation>-pernr
send_cctr = <allocation>-kostl
acttype = <allocation>-lstar
extra_pay_indic = COND #( WHEN <allocation>-pay_code = c_extra THEN `+` ELSE abap_false )
rec_order = COND #( WHEN <group>-type = `ORDEM` THEN <allocation>-objnr ELSE abap_false )
wbs_element = COND #( WHEN <group>-type = `PEP` THEN <allocation>-objnr ELSE abap_false )
catshours = catshours
* starttime = `000000`
unit = `H`
isocode_unit = `H`
abs_att_type = `0800`
* endtime = endtime
shorttext = |{ <allocation>-batch_id }{ <allocation>-record_id }| ).
INSERT ls_catsrecord INTO TABLE lt_catsrecords.
SUBTRACT catshours FROM saldo.
ENDWHILE.
CATCH cx_dynamic_check INTO DATA(lx_dynamic).
<allocation>-status = CONV #( error ).
<allocation>-message = lx_dynamic->get_longtext( ).
<allocation>-aedat = sy-datum.
<allocation>-aezet = sy-uzeit.
<allocation>-aenam = sy-uname.
<allocation>-processing_time = utclong_current( ).
DATA(alloc) = CORRESPONDING zwfs_allocation( <allocation> ).
UPDATE zwfs_allocation FROM alloc.
lv_continue = abap_true.
RETRY.
ENDTRY.
ENDLOOP.
IF lt_catsrecords IS NOT INITIAL.
* Executa a BAPI em blocos de documentos
chamar_bapi_para_apontar( lt_catsrecords ).
ENDIF.
CLEAR:
lt_catsrecords,
mt_workdates,
mt_return.
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->BUSCAR_PROJETOS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD buscar_projetos.
LOG-POINT ID zps20 FIELDS mt_migra_co.
* CHECK mt_migra_co[] IS NOT INITIAL.
MESSAGE i070 INTO DATA(dummy).
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
DATA lt_migra_co TYPE ztt_allocation_std_without_key.
DATA lt_migra_co_pendentes TYPE ztt_allocation_std_without_key.
DATA(type) = CONV zst_allocation-type( `PEP` ).
* lt_migra_co = VALUE #(
* LET _migrar = FILTER #( mt_allocation USING KEY status WHERE status = CONV zwfs_status( migrar_co ) )
* IN
* ( LINES OF FILTER #( _migrar EXCEPT IN mt_migra_co WHERE mandt = mandt AND batch_id = batch_id AND record_id = record_id ) ) ).
lt_migra_co_pendentes = mt_migra_co[].
lt_migra_co_pendentes = VALUE #(
BASE lt_migra_co_pendentes
( LINES OF FILTER #(
FILTER #( mt_allocation USING KEY status WHERE status = CONV zwfs_status( migrar_co ) )
EXCEPT IN mt_migra_co WHERE mandt = mandt
AND batch_id = batch_id
AND record_id = record_id
AND employee_id = employee_id
AND counter = counter
AND belnr = belnr ) ) ).
lt_migra_co_pendentes = VALUE #(
BASE lt_migra_co_pendentes
( LINES OF FILTER #(
FILTER #( mt_allocation USING KEY status WHERE status = CONV zwfs_status( waiting ) )
EXCEPT IN mt_migra_co WHERE mandt = mandt
AND batch_id = batch_id
AND record_id = record_id
AND employee_id = employee_id
AND counter = counter
AND belnr = belnr ) ) ).
MESSAGE i057 INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* LOOP AT mt_migra_co ASSIGNING FIELD-SYMBOL(<migrar>)
* USING KEY type.
LOOP AT lt_migra_co_pendentes ASSIGNING FIELD-SYMBOL(<migrar>) USING KEY type.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = |{ dummy } { sy-tabix } / { lines( mt_migra_co ) }|
i_processed = sy-tabix
i_total = lines( mt_migra_co )
i_output_immediately = abap_true ).
<migrar>-aedat = sy-datum.
<migrar>-aezet = sy-uzeit.
<migrar>-aenam = sy-uname.
<migrar>-processing_time = utclong_current( ).
CHECK <migrar>-type = 'PEP'.
IF <migrar>-type = type.
CASE <migrar>-profl.
WHEN 'ZPS0001'.
DATA(ls_status) = get_proj_status( <migrar>-project_id ).
IF ls_status = 'PREP'.
<migrar>-status = CONV #( waiting ).
UPDATE zwfs_allocation FROM <migrar>.
ELSE.
INSERT <migrar> INTO TABLE lt_migra_co.
ENDIF.
WHEN 'ZPS0002'.
INSERT <migrar> INTO TABLE lt_migra_co.
WHEN OTHERS.
<migrar>-status = CONV #( success ).
UPDATE zwfs_allocation FROM <migrar>.
ENDCASE.
ELSE.
<migrar>-status = CONV #( success ).
UPDATE zwfs_allocation FROM <migrar>.
ENDIF.
ENDLOOP.
mt_results = FILTER ztt_allocation_without_key( mt_migra_co USING KEY status WHERE status = CONV #( success ) ).
mt_results = VALUE #(
BASE mt_results
( LINES OF FILTER #( lt_migra_co
EXCEPT IN mt_migra_co
WHERE mandt = mandt
AND batch_id = batch_id
AND record_id = record_id
AND employee_id = employee_id
AND counter = counter
AND belnr = belnr
) ) ).
* Alterar status dos itens migrados (os demais ja estarao com status atualizados
LOG-POINT ID zps20 FIELDS lt_migra_co.
IF lt_migra_co IS NOT INITIAL.
MESSAGE i058 INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
migrar_dados_co( lt_migra_co ).
ENDIF.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i071 WITH |{ lines( lt_migra_co ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* | [--->] PROCESS_TYPE TYPE ABAP_BOOL(optional)
* | [--->] TESTRUN TYPE ABAP_BOOL(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
_ersda = sy-datum.
_erstm = sy-uzeit.
_handle = zcl_ptool_helper=>bal_log_create( iv_object = `ZPS`
iv_subobject = `APONTAMENTO` ).
_process_type = process_type.
_testrun = testrun.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->ELIMINAR_APONTAMENTOS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD eliminar_apontamentos.
DATA lt_eliminar TYPE ztt_allocation.
DATA lt_catsrecords TYPE cats_esa_delete_rec_t.
MESSAGE i065 INTO DATA(dummy).
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
* DATA(lt_peps) = FILTER #( mt_allocation USING KEY type WHERE type = CONV #( 'PEP' ) AND operation = CONV #( '0' ) ).
SELECT DISTINCT
* z~batch_id, z~record_id, z~project_id,
* a~usrid,
* b~kostl,
* d~lstar,
* c~counter, c~pernr, c~workdate, c~rproj, c~status, c~belnr, c~catshours
c~counter, c~extsystem, c~extapplication, c~extdocumentno
FROM @mt_allocation AS z
JOIN pa0105 AS a ON a~usrid = z~employee_id
AND a~subty = '0002'
AND ( a~endda >= @sy-datum AND a~begda <= @sy-datum )
JOIN pa0001 AS b ON b~pernr = a~pernr
AND ( b~endda >= @sy-datum AND b~begda <= @sy-datum )
JOIN pa0315 AS d ON d~pernr = a~pernr
AND ( d~endda >= @sy-datum AND d~begda <= @sy-datum )
JOIN prps AS p ON p~posid_edit = z~project_id
JOIN catsdb AS c ON c~pernr = a~pernr
AND c~rproj = p~pspnr
AND c~record_id = z~record_id
WHERE z~type = 'PEP'
AND z~operation = '0'
AND z~status IN @r_status[]
AND c~status <> '60'
INTO TABLE @lt_catsrecords.
* DATA(lt_ordens) = FILTER #( mt_allocation USING KEY type WHERE type = 'ORDEM' AND operation = CONV #( '0' ) ).
SELECT DISTINCT
c~counter, c~extsystem, c~extapplication, c~extdocumentno
FROM @mt_allocation AS z
JOIN pa0105 AS a ON a~usrid = z~employee_id
AND a~subty = '0002'
AND ( a~endda >= @sy-datum AND a~begda <= @sy-datum )
JOIN pa0001 AS b ON b~pernr = a~pernr
AND ( b~endda >= @sy-datum AND b~begda <= @sy-datum )
JOIN pa0315 AS d ON d~pernr = a~pernr
AND ( d~endda >= @sy-datum AND d~begda <= @sy-datum )
JOIN aufk AS p ON p~aufnr = z~project_id
JOIN catsdb AS c ON c~pernr = a~pernr
AND c~raufnr = p~aufnr
AND c~record_id = z~record_id
WHERE z~type = 'ORDEM'
AND z~operation = '0'
AND z~status IN @r_status[]
AND c~status <> '60'
APPENDING TABLE @lt_catsrecords.
* IF mt_catsdb[] IS NOT INITIAL.
*
* DATA(lt_keys) = VALUE ty_t_allocation(
* FOR <key> IN mt_catsdb
* ( batch_id = <key>-batch_id
* record_id = <key>-record_id ) ).
*
* SELECT DISTINCT
* z~*
* FROM @lt_keys AS i
* JOIN zwfs_allocation AS z ON z~batch_id = i~batch_id
* AND z~record_id = i~record_id
* WHERE z~counter IS NOT INITIAL
* INTO CORRESPONDING FIELDS OF TABLE @lt_eliminar.
*
* ENDIF.
*
* DATA(lt_catsrecords) = VALUE cats_esa_delete_rec_t(
** FOR <eliminar> IN mt_allocation USING KEY operation WHERE ( operation = CONV zwfs_operation( 0 ) )
* FOR <eliminar> IN lt_eliminar USING KEY counter
** FOR <catsdb> IN mt_catsdb WHERE ( batch_id = <eliminar>-batch_id AND
** record_id = <eliminar>-record_id )
** FOR <catsdb> IN mt_catsdb
** USING KEY ltxa1
** WHERE ( ltxa1 = CONV catsshortt( |{ <eliminar>-batch_id }{ <eliminar>-record_id }| ) )
** LET _counter = VALUE #( mt_apontados[ record_id = <eliminar>-record_id ]-counter OPTIONAL )
** IN
* ( counter = <eliminar>-counter ) ).
*
* lt_catsrecords = VALUE cats_esa_delete_rec_t(
* BASE lt_catsrecords
* FOR <reprocessar> IN mt_allocation USING KEY status WHERE ( status = '0' )
* FOR <catsdb> IN mt_catsdb WHERE ( batch_id = <reprocessar>-batch_id AND
* record_id = <reprocessar>-record_id )
* ( counter = <catsdb>-counter ) ).
*
** lt_catsrecords = VALUE cats_esa_delete_rec_t(
** BASE lt_catsrecords
** FOR <eliminar> IN mt_allocation USING KEY operation WHERE ( operation = CONV zwfs_operation( 0 ) )
*** FOR <catsdb> IN mt_catsdb
*** USING KEY ltxa1
*** WHERE ( ltxa1 = CONV catsshortt( |{ <eliminar>-batch_id }_{ <eliminar>-record_id }| ) )
** LET _counter = VALUE #( mt_apontados[ record_id = <eliminar>-record_id ]-counter OPTIONAL )
** IN
** ( counter = _counter
** extdocumentno = <catsdb>-belnr
** extapplication = <catsdb>-extapplication
** extsystem = <catsdb>-extsystem ) ).
*
DELETE ADJACENT DUPLICATES FROM lt_catsrecords.
chamar_bapi_para_eliminar( it_catsrecords = lt_catsrecords ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->EXECUTAR
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RESULTS TYPE ZTT_ALLOCATION_WITHOUT_KEY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD executar.
* DATA: callstack_tab TYPE abap_callstack,
* syscall_tab TYPE sys_callst.
*
* CALL FUNCTION 'SYSTEM_CALLSTACK'
* IMPORTING
* callstack = callstack_tab
* et_callstack = syscall_tab.
*
* READ TABLE syscall_tab TRANSPORTING NO FIELDS WITH KEY eventname = 'FUNC'
* eventtype = 'Z_FM_PS_WFS_APONTAMENTO'.
* IF sy-subrc = 0.
* DATA(func) = abap_true.
* ENDIF.
*
* CALL FUNCTION 'ENQUEUE_ESTERM'
* EXPORTING
* mode_tstc = 'E'
* tcode = 'Z_APONTHORAS_RFC'
* EXCEPTIONS
* foreign_lock = 1
* system_failure = 2
* OTHERS = 3.
*
* IF sy-subrc = 1.
* DATA(bloq_rfc) = abap_true.
* ENDIF.
MESSAGE i072 INTO DATA(dummy).
LOG-POINT ID zps20 FIELDS dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
* IF bloq_rfc IS INITIAL.
* Ler apontamentos para processar
selecionar_apontamentos( ).
* Trava os registros para evitar conflitos
travar_apontamentos( ).
* Elimina registros inv�lidos do processamento e grava log
limpar_dados( ).
* Elimina registros nulos
eliminar_apontamentos( ).
* Busca projeto e migra dados CO
buscar_projetos( ).
CLEAR mt_migra_co.
* Cria apontamentos
apontar( ).
* Busca projeto e migra dados CO
buscar_projetos( ).
destravar_apontamentos( ).
* ELSE.
* MESSAGE i000 WITH |Outro processo j� est� em execu��o via RFC|.
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* MESSAGE i000 WITH |Processamento abortado|.
* zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
* zcl_ptool_helper=>bal_db_save( ).
*
* IF func IS INITIAL.
* MESSAGE s000 WITH |Outro processo j� est� em execu��o via RFC| DISPLAY LIKE 'E'.
* ENDIF.
* ENDIF.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i073 INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
results = mt_results[].
* CALL FUNCTION 'DEQUEUE_ESTERM'
* EXPORTING
* mode_tstc = 'E'
* tcode = 'Z_APONTHORAS_RFC'
* x_tcode = ' '
* _scope = '3'
* _synchron = ' '
* _collect = ' '.
* CLEAR bloq_rfc.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->GET_PROJ_STATUS
* +-------------------------------------------------------------------------------------------------+
* | [--->] I_PROJID TYPE ZWFS_PROJECT_ID
* | [<-()] R_STATUS TYPE BAPI_USER_STATUS_TEXT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_proj_status.
DATA:
lt_wbs_elements TYPE STANDARD TABLE OF bapi_wbs_elements,
lt_system_status TYPE STANDARD TABLE OF bapi_wbs_system_status,
lt_user_status TYPE STANDARD TABLE OF bapi_wbs_user_status,
ls_wbs_elements TYPE bapi_wbs_elements,
ls_user_status TYPE bapi_wbs_user_status.
ls_wbs_elements-wbs_element = i_projid.
APPEND ls_wbs_elements TO lt_wbs_elements.
CALL FUNCTION 'BAPI_BUS2054_GET_STATUS'
TABLES
i_wbs_elements = lt_wbs_elements
e_system_status = lt_system_status
e_user_status = lt_user_status.
READ TABLE lt_user_status INTO ls_user_status INDEX 1.
r_status = ls_user_status-user_status.
* TYPES:
* ty_r_status TYPE RANGE OF rvari_val_255,
* ty_r_istat TYPE RANGE OF istat.
*
* DATA lt_status TYPE ty_r_status.
*
* SELECT sign, opti, low, high
* FROM tvarvc
* WHERE name = 'ZPS_STATUS_BLOQ'
* AND type = 'S'
* INTO TABLE @lt_status.
*
* SELECT DISTINCT
* p~pspnr, p~posid, p~posid_edit, p~objnr, j~stat, x~txt04
* FROM @mt_allocation as i
* JOIN jest AS j ON j~objnr = p~objnr
* AND j~inact = ' '
* JOIN tj02 AS t ON t~istat = j~stat
* JOIN tj02t AS x ON x~istat = t~istat
* AND x~spras = 'P'
* WHERE posid_edit IN ( 'PC.001.0001653-B.002', 'PC.037.0000116-I.001', 'PC.001.0000006-B.001' )
* AND ( j~istat IN rl_stat1 OR j~istat IN rl_stat1 OR j~istat IN rl_stat1 )
* ORDER BY p~pspnr, p~posid, p~posid_edit, p~objnr, j~stat
* INTO TABLE @data(mt_status).
*
*
* LOOP AT lt_status INTO DATA(ls_status).
*
* SPLIT ls_status AT '+' INTO TABLE DATA(lt_split).
* DATA(rl_status) = VALUE ty_r_istat( FOR <status> IN lt_split sign = `I` option = `EQ` ( low = <status>-low ) ).
*
* select count( * )
* from @mt_status as i
* where stat in rl_status
* into @data(lv_status).
*
* ENDLOOP.
*
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->LIMPAR_DADOS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD limpar_dados.
* BREAK-POINT.
MESSAGE i063 INTO DATA(dummy).
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
DATA(lt_broken) = VALUE ztt_allocation(
FOR <notype> IN FILTER #( mt_allocation USING KEY type WHERE type = ' ' )
( VALUE #(
BASE <notype> status = `2`
message = 'N�o foi poss�vel determinar o tipo do apontamento'(004)
aedat = sy-datum
aezet = sy-uzeit
aenam = sy-uname
processing_time = utclong_current( ) ) ) ).
lt_broken = VALUE ztt_allocation(
BASE lt_broken
FOR <noemployee> IN FILTER #( mt_allocation EXCEPT IN lt_broken
WHERE mandt = mandt AND batch_id = batch_id AND record_id = record_id )
USING KEY pernr WHERE ( pernr = CONV persno( 0 ) )
( VALUE #( BASE <noemployee> status = `2`
message = 'N�o foi poss�vel determinar o funcion�rio'(001)
aedat = sy-datum
aezet = sy-uzeit
aenam = sy-uname
processing_time = utclong_current( ) ) ) ).
lt_broken = VALUE ztt_allocation(
BASE lt_broken
FOR <noemployee> IN FILTER #( mt_allocation EXCEPT IN lt_broken
WHERE mandt = mandt AND batch_id = batch_id AND record_id = record_id )
USING KEY lstar WHERE ( lstar IS INITIAL )
( VALUE #( BASE <noemployee> status = `2`
message = 'N�o foi poss�vel determinar o tipo de atividade'(002)
aedat = sy-datum
aezet = sy-uzeit
aenam = sy-uname
processing_time = utclong_current( ) ) ) ).
lt_broken = VALUE ztt_allocation(
BASE lt_broken
FOR <noemployee> IN FILTER #( mt_allocation EXCEPT IN lt_broken
WHERE mandt = mandt AND batch_id = batch_id AND record_id = record_id )
USING KEY kostl WHERE ( kostl IS INITIAL )
( VALUE #( BASE <noemployee> status = `2`
message = 'N�o foi poss�vel determinar o centro de custo emissor'(003)
aedat = sy-datum
aezet = sy-uzeit
aenam = sy-uname
processing_time = utclong_current( ) ) ) ).
UPDATE zwfs_allocation FROM TABLE @lt_broken.
mt_allocation = FILTER #( mt_allocation EXCEPT IN lt_broken WHERE mandt = mandt AND batch_id = batch_id AND record_id = record_id ).
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i064 WITH |{ lines( lt_broken ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->MIGRAR_DADOS_CO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_MIGRA_CO TYPE ZTT_ALLOCATION_STD_WITHOUT_KEY
* | [<-()] RESULT TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD migrar_dados_co.
CHECK it_migra_co[] IS NOT INITIAL.
DATA:
rl_pernr TYPE RANGE OF catsdb-pernr,
rl_belnr TYPE RANGE OF catsdb-belnr,
rl_wdate TYPE RANGE OF catsdb-workdate.
CONSTANTS lc_jobname TYPE tbtcjob-jobname VALUE 'ZAPONTAMENTO_HORAS'.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = 'Aguardando JOB de transfer�ncia p/controlling...'(011)
i_output_immediately = abap_true ).
LOOP AT it_migra_co ASSIGNING FIELD-SYMBOL(<migrar>).
INSERT VALUE #( sign = 'I' option = 'EQ' low = <migrar>-pernr ) INTO TABLE rl_pernr.
INSERT VALUE #( sign = 'I' option = 'EQ' low = <migrar>-belnr ) INTO TABLE rl_belnr.
IF <migrar>-date_cats IS NOT INITIAL.
INSERT VALUE #( sign = 'I' option = 'EQ' low = <migrar>-date_cats ) INTO TABLE rl_wdate.
ELSE.
SELECT SINGLE counter, workdate FROM catsdb WHERE counter = @<migrar>-counter INTO @DATA(castsdb).
IF sy-subrc = 0.
INSERT VALUE #( sign = 'I' option = 'EQ' low = castsdb-workdate ) INTO TABLE rl_wdate.
ELSE.
INSERT VALUE #( sign = 'I' option = 'EQ' low = <migrar>-zdate ) INTO TABLE rl_wdate.
ENDIF.
ENDIF.
DATA(finished) = executar_job_migrar_co( EXPORTING it_pernr = rl_pernr[]
it_belnr = rl_belnr[]
it_wdate = rl_wdate[]
iv_count = sy-index ).
CLEAR:
rl_pernr,
rl_belnr,
rl_wdate.
ENDLOOP.
"Devido a limita��o do Range ABAP a espera pelo commit dos
"registros tamb�m foi adaptada
* esperar_transferencia_co( it_pernr = rl_pernr[] it_belnr = rl_belnr[] it_wdate = rl_wdate[] ).
esperar_transferencia_co( it_migra_co = it_migra_co[] ).
IF finished = abap_true.
result = abap_true.
LOOP AT it_migra_co ASSIGNING FIELD-SYMBOL(<migrar_co>).
ASSIGN mt_allocation[ mandt = sy-mandt
batch_id = <migrar_co>-batch_id
record_id = <migrar_co>-record_id ]
TO FIELD-SYMBOL(<migrado>).
IF sy-subrc = 0.
<migrado>-aedat = sy-datum.
<migrado>-aezet = sy-uzeit.
<migrado>-processing_time = utclong_current( ).
IF <migrar>-date_cats IS NOT INITIAL.
DATA(date) = <migrado>-date_cats.
ELSE.
SELECT SINGLE counter, workdate FROM catsdb WHERE counter = @<migrado>-counter INTO @DATA(castsdbx).
IF sy-subrc = 0.
date = castsdbx-workdate .
ELSE.
date = <migrado>-zdate.
ENDIF.
ENDIF.
IF line_exists( mt_catsco[ KEY migrar pernr = <migrar_co>-pernr
workdate = date
belnr = <migrar_co>-belnr ] ).
<migrado>-status = CONV #( success ).
<migrado>-message = 'Apontamento e Migra��o CO realizados com sucesso'(008).
ELSE.
<migrado>-status = CONV #( migrar_co ).
<migrado>-message = 'Erro ao migrar para CO'(007).
ENDIF.
UPDATE zwfs_allocation FROM <migrado>.
ENDIF.
ENDLOOP.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->CHAMAR_BAPI_PARA_APONTAR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_CATSRECORDS TYPE TT_BAPICATS1
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD chamar_bapi_para_apontar.
MESSAGE i068 INTO DATA(dummy).
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
LOG-POINT ID zps20 FIELDS it_catsrecords .
DATA catsrecords_out TYPE STANDARD TABLE OF bapicats2.
DATA longtext TYPE STANDARD TABLE OF bapicats8.
DO lines( it_catsrecords ) TIMES.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = |{ dummy } { sy-index } / { lines( it_catsrecords ) }|
i_processed = sy-index
i_total = lines( it_catsrecords )
i_output_immediately = abap_false ).
DATA(catsrecords_in) = VALUE tt_bapicats1( FOR <catsrecord> IN it_catsrecords FROM sy-index TO sy-index ( <catsrecord> ) ).
DATA(extensionin) = VALUE bapiparex_tab(
FOR <ext> IN catsrecords_in INDEX INTO _tabix
( structure = 'BAPI_TE_CATSDB'
valuepart1 = VALUE bapi_te_catsdb(
row = CONV #( _tabix )
batch_id = <ext>-shorttext(10)
record_id = <ext>-shorttext+10(10) ) ) ).
MESSAGE i055 WITH catsrecords_in[ 1 ]-workdate
catsrecords_in[ 1 ]-employeenumber
COND #( WHEN catsrecords_in[ 1 ]-rec_order IS INITIAL
THEN catsrecords_in[ 1 ]-wbs_element
ELSE catsrecords_in[ 1 ]-rec_order )
catsrecords_in[ 1 ]-shorttext
INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
CALL FUNCTION 'BAPI_CATIMESHEETMGR_INSERT'
EXPORTING
profile = c_proj_name
testrun = _testrun
TABLES
catsrecords_in = catsrecords_in
catsrecords_out = catsrecords_out
extensionin = extensionin
longtext = longtext
return = mt_return.
LOOP AT mt_return ASSIGNING FIELD-SYMBOL(<return>)
WHERE type <> `W`.
MESSAGE ID <return>-id ##NEEDED
TYPE <return>-type
NUMBER <return>-number
WITH <return>-message_v1 <return>-message_v2 <return>-message_v3 <return>-message_v4
INTO DATA(lv_dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
ENDLOOP.
zcl_ptool_helper=>bal_db_save( ).
IF catsrecords_out IS NOT INITIAL.
ASSIGN mt_allocation[ mandt = sy-mandt
batch_id = catsrecords_out[ 1 ]-shorttext(10)
record_id = catsrecords_out[ 1 ]-shorttext+10(10) ]
TO FIELD-SYMBOL(<processado>).
IF sy-subrc = 0.
* IF <processado>-zdate = catsrecords_out[ 1 ]-workdate .
<processado>-counter = catsrecords_out[ 1 ]-counter.
<processado>-belnr = catsrecords_out[ 1 ]-cats_doc_no.
<processado>-date_cats = catsrecords_out[ 1 ]-workdate.
<processado>-status = CONV #( success ).
<processado>-aedat = sy-datum.
<processado>-aezet = sy-uzeit.
<processado>-aenam = sy-uname.
<processado>-processing_time = utclong_current( ).
<processado>-message = 'Apontamento realizado com sucesso'(009).
IF <processado>-type = 'PEP'.
<processado>-status = CONV #( migrar_co ).
INSERT VALUE #( BASE <processado> zdate = catsrecords_out[ 1 ]-workdate zhour = catsrecords_out[ 1 ]-catshours ) INTO TABLE mt_migra_co.
ENDIF.
* ENDIF.
DATA(alloc) = CORRESPONDING zwfs_allocation( <processado> ).
UPDATE zwfs_allocation FROM alloc.
ENDIF.
LOG-POINT ID zps20 FIELDS <processado>.
ELSE.
ASSIGN mt_allocation[ mandt = sy-mandt
batch_id = catsrecords_in[ 1 ]-shorttext(10)
record_id = catsrecords_in[ 1 ]-shorttext+10(10) ]
TO FIELD-SYMBOL(<erro>).
IF <erro>-zdate = catsrecords_in[ 1 ]-workdate .
<erro>-status = CONV #( error ).
<erro>-message = 'Ocorreu um erro no lan�amento, acessar SLG1 para mais detalhes'(005).
<erro>-aedat = sy-datum.
<erro>-aezet = sy-uzeit.
<erro>-aenam = sy-uname.
<erro>-processing_time = utclong_current( ).
CLEAR alloc.
alloc = CORRESPONDING zwfs_allocation( <erro> ).
UPDATE zwfs_allocation FROM alloc.
ENDIF.
LOG-POINT ID zps20 FIELDS <erro>.
ENDIF.
LOG-POINT ID zps20 FIELDS catsrecords_out .
CLEAR:
catsrecords_out,
extensionin,
mt_return.
ENDDO.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i069 WITH |{ lines( it_catsrecords ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->CHAMAR_BAPI_PARA_ELIMINAR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_CATSRECORDS TYPE CATS_ESA_DELETE_REC_T
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD chamar_bapi_para_eliminar.
DATA lt_migrar TYPE ztt_allocation_without_key.
DATA migrar_new TYPE STANDARD TABLE OF zst_allocation.
MESSAGE i065 INTO DATA(dummy).
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( ).
LOG-POINT ID zps20 FIELDS it_catsrecords .
DO lines( it_catsrecords ) TIMES.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = |{ dummy } { sy-index } / { lines( it_catsrecords ) }|
i_processed = sy-index
i_total = lines( it_catsrecords )
i_output_immediately = abap_false ).
DATA(catsrecords) = VALUE cats_esa_delete_rec_t( FOR <catsrecord> IN it_catsrecords FROM sy-index TO sy-index ( <catsrecord> ) ).
MESSAGE i056 WITH catsrecords[ 1 ]-counter INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
CALL FUNCTION 'BAPI_CATIMESHEETMGR_DELETE'
EXPORTING
profile = c_proj_name
testrun = _testrun
release_data = abap_true
TABLES
catsrecords = catsrecords
return = mt_return.
LOOP AT mt_return ASSIGNING FIELD-SYMBOL(<return>)
WHERE type <> `W`.
MESSAGE ID <return>-id
TYPE <return>-type
NUMBER <return>-number
WITH <return>-message_v1 <return>-message_v2 <return>-message_v3 <return>-message_v4
INTO DATA(lv_dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
IF ( <return>-type = `E` ).
UPDATE zwfs_allocation SET status = `2`
message = lv_dummy
WHERE counter = <return>-message_v1.
ENDIF.
ENDLOOP.
zcl_ptool_helper=>bal_db_save( ).
IF NOT line_exists( mt_return[ type = 'E' ] ).
DATA(lv_counter) = catsrecords[ 1 ]-counter.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
SELECT DISTINCT
z~mandt, z~batch_id, z~record_id, z~employee_id, z~zdate,
c~counter, c~belnr, z~pay_code, z~project_id, z~zhour, z~operation,
z~erdat, z~erzet, z~ernam, z~aedat, z~aezet, z~aenam,
utcl_current( ) AS register_time, utcl_current( ) AS processing_time,
z~status, z~message,
a~pernr, b~kostl, a~usrid, d~lstar, j~pspnr, j~profl,
coalesce( p~posid_edit, k~aufnr ) AS objnr,
coalesce( CASE WHEN p~posid_edit IS NOT NULL THEN 'PEP' END,
CASE WHEN k~aufnr IS NOT NULL THEN 'ORDEM' END )
AS type,
@space AS locked,
c~workdate
FROM zwfs_allocation AS z
LEFT JOIN pa0105 AS a ON a~usrid = z~employee_id
AND a~subty = '0002'
AND ( a~endda >= @sy-datum AND a~begda <= @sy-datum )
LEFT JOIN pa0001 AS b ON b~pernr = a~pernr
AND ( b~endda >= @sy-datum AND b~begda <= @sy-datum )
LEFT JOIN pa0315 AS d ON d~pernr = a~pernr
AND ( d~endda >= @sy-datum AND d~begda <= @sy-datum )
LEFT JOIN prps AS p ON p~posid_edit = z~project_id
LEFT JOIN aufk AS k ON k~aufnr = z~project_id
LEFT JOIN proj AS j ON j~pspnr = p~psphi
JOIN catsdb AS c ON c~batch_id = z~batch_id
AND c~record_id = z~record_id
WHERE ( c~counter = @lv_counter OR c~refcounter = @lv_counter )
INTO TABLE @lt_migrar.
DATA(lv_utclong) = utclong_current( ).
LOOP AT lt_migrar ASSIGNING FIELD-SYMBOL(<migrar>).
UPDATE zwfs_allocation SET status = '4',
message = @text-006,
aedat = @sy-datum,
aezet = @sy-uzeit,
aenam = @sy-uname,
processing_time = @lv_utclong
WHERE record_id = @<migrar>-record_id
AND employee_id = @<migrar>-employee_id
AND operation = '1'.
UPDATE zwfs_allocation SET status = '3',
message = @text-006,
aedat = @sy-datum,
aezet = @sy-uzeit,
aenam = @sy-uname,
processing_time = @lv_utclong
WHERE record_id = @<migrar>-record_id
AND employee_id = @<migrar>-employee_id
AND operation = '0'.
ENDLOOP.
ENDIF.
mt_migra_co = VALUE #( BASE mt_migra_co ( LINES OF FILTER #( lt_migrar EXCEPT IN mt_migra_co WHERE mandt = mandt
AND batch_id = batch_id
AND record_id = record_id
AND employee_id = employee_id
AND counter = counter
AND belnr = belnr ) ) ).
CLEAR:
catsrecords,
mt_return.
ENDDO.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i066 WITH |{ lines( it_catsrecords ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->DESTRAVAR_APONTAMENTOS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD destravar_apontamentos.
CALL FUNCTION 'DEQUEUE_EZWFS_ALLOC'.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->ESPERAR_TRANSFERENCIA_CO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_PERNR TYPE TY_R_PERNR(optional)
* | [--->] IT_BELNR TYPE TY_R_BELNR(optional)
* | [--->] IT_WDATE TYPE TY_R_WDATE(optional)
* | [--->] IT_MIGRA_CO TYPE ZTT_ALLOCATION_STD_WITHOUT_KEY(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD esperar_transferencia_co.
DATA migra_co TYPE STANDARD TABLE OF zst_allocation.
CHECK it_migra_co[] IS NOT INITIAL.
GET TIME STAMP FIELD DATA(lv_time_ini).
GET TIME STAMP FIELD DATA(lv_time_fim).
ADD 60 TO lv_time_fim.
migra_co = it_migra_co.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
WHILE lv_time_ini <= lv_time_fim.
GET TIME STAMP FIELD lv_time_ini.
" Devido � limita��o do Range este select foi adaptado
" para um JOIN ao inv�s de Ranges
* SELECT DISTINCT
* counter, stokz, pernr, workdate, catshours, belnr, transfer
* FROM catsco
* WHERE stokz = @abap_false
* AND pernr IN @it_pernr[]
* AND belnr IN @it_belnr[]
* AND workdate IN @it_wdate[]
* INTO TABLE @DATA(lt_catsco).
SELECT DISTINCT
c~counter, c~stokz, c~pernr, c~workdate, c~catshours, c~belnr, c~transfer
FROM @migra_co AS i
JOIN catsco AS c ON c~stokz = @abap_false
AND c~pernr = i~pernr
AND c~belnr = i~belnr
* AND c~workdate = i~zdate
INTO TABLE @DATA(lt_catsco).
IF sy-subrc = 0.
EXIT.
ENDIF.
ENDWHILE.
mt_catsco = VALUE #(
BASE mt_catsco
( LINES OF VALUE #(
FOR <catsco> IN FILTER #( lt_catsco EXCEPT IN mt_catsco
WHERE counter = counter ) ( <catsco> ) ) ) ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->SELECIONAR_APONTAMENTOS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD selecionar_apontamentos.
TYPES ty_r_status TYPE RANGE OF zwfs_status.
MESSAGE i061 INTO DATA(dummy).
LOG-POINT ID zps20 FIELDS dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
IF r_status[] IS INITIAL.
CASE _process_type.
WHEN 'P'.
r_status = VALUE ty_r_status(
sign = 'I'
option = 'EQ'
( low = '0' ) ( low = '6' ) ).
WHEN 'R'.
r_status = VALUE ty_r_status(
sign = 'I'
option = 'EQ'
( low = '2' ) ( low = '5' ) ( low = '6' ) ).
WHEN OTHERS.
r_status = VALUE ty_r_status(
sign = 'I'
option = 'EQ'
( low = '0' ) ( low = '2' ) ( low = '5' ) ( low = '6' ) ).
ENDCASE.
ENDIF.
SELECT DISTINCT
z~mandt, z~batch_id, z~record_id, z~employee_id, z~zdate,
z~counter, z~belnr, z~pay_code, z~project_id, z~zhour, z~operation,
z~erdat, z~erzet, z~ernam, z~aedat, z~aezet, z~aenam,
utcl_current( ) AS register_time, utcl_current( ) AS processing_time,
z~status, z~message,
a~pernr, b~kostl, a~usrid, c~lstar, j~pspnr, j~profl,
coalesce( p~posid_edit, k~aufnr ) AS objnr,
coalesce( CASE WHEN p~posid_edit IS NOT NULL THEN 'PEP' END,
CASE WHEN k~aufnr IS NOT NULL THEN 'ORDEM' END )
AS type,
@space AS locked
FROM zwfs_allocation AS z
LEFT JOIN pa0105 AS a ON a~usrid = z~employee_id
AND a~subty = '0002'
AND ( a~endda >= @sy-datum AND a~begda <= @sy-datum )
LEFT JOIN pa0001 AS b ON b~pernr = a~pernr
AND ( b~endda >= @sy-datum AND b~begda <= @sy-datum )
LEFT JOIN pa0315 AS c ON c~pernr = a~pernr
AND ( c~endda >= @sy-datum AND c~begda <= @sy-datum )
LEFT JOIN prps AS p ON p~posid_edit = z~project_id
LEFT JOIN aufk AS k ON k~aufnr = z~project_id
LEFT JOIN proj AS j ON j~pspnr = p~psphi
WHERE z~batch_id IN @r_batch_id[]
AND z~record_id IN @r_record_id[]
AND z~zdate IN @r_zdate[]
AND z~employee_id IN @r_employee_id[]
AND z~project_id IN @r_project_id[]
AND z~erdat IN @r_erdat[]
AND z~aedat IN @r_aedat[]
AND z~pay_code IN @r_pay_code[]
AND z~status IN @r_status[]
INTO TABLE @mt_allocation.
IF sy-subrc = 0.
LOG-POINT ID zps20 FIELDS mt_allocation[].
SELECT DISTINCT
c~pernr, c~workdate, CAST( SUM( c~catshours ) AS QUAN( 15, 3 ) ) AS catshours
FROM @mt_allocation AS i
JOIN catsdb AS c ON c~pernr = i~pernr
AND c~workdate = concat( substring( i~zdate, 1, 6 ), '01' )
GROUP BY c~pernr, c~workdate
INTO TABLE @DATA(mt_workdates).
SELECT DISTINCT
e~*
FROM @mt_allocation AS i
JOIN zwfs_allocation AS e ON e~record_id = i~record_id
WHERE i~operation = 1 "eliminar apontamento
AND e~status = 3 "apontamentos com sucesso
INTO TABLE @mt_apontados.
SELECT DISTINCT
c~*
FROM @mt_allocation AS i
JOIN catsdb AS c ON ( ( c~record_id = i~record_id )
OR ( c~ltxa1 = concat( i~batch_id, i~record_id )
OR c~ltxa1 = concat( i~batch_id, concat( '_', i~record_id ) ) ) )
AND c~status <> '60' "estornado
WHERE i~operation = 0
INTO TABLE @mt_catsdb.
ENDIF.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i062 WITH |{ lines( mt_allocation ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->TRAVAR_APONTAMENTOS
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD travar_apontamentos.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = 'Travando os apontamentos selecionados...'(010)
i_output_immediately = abap_true ).
LOOP AT mt_allocation ASSIGNING FIELD-SYMBOL(<alloc>).
CALL FUNCTION 'ENQUEUE_EZWFS_ALLOC'
EXPORTING
mode_zwfs_allocation = 'E'
mandt = sy-mandt
batch_id = <alloc>-batch_id
record_id = <alloc>-record_id
x_batch_id = ' '
x_record_id = ' '
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
CLEAR <alloc>-locked.
ELSE.
<alloc>-locked = abap_true.
ENDIF.
ENDLOOP.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->SET_MT_ALLOCATION
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_ALLOCATION TYPE ZTT_ALLOCATION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD set_mt_allocation.
mt_zwfs_allocation = CORRESPONDING #( it_allocation ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->SET_FILTER
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_PROJECT_ID TYPE TY_R_PROJECT_ID(optional)
* | [--->] IT_ZDATE TYPE TY_R_ZDATE(optional)
* | [--->] IT_BATCH_ID TYPE TY_R_BATCH_ID(optional)
* | [--->] IT_RECORD_ID TYPE TY_R_RECORD_ID(optional)
* | [--->] IT_EMPLOYEE_ID TYPE TY_R_EMPLOYEE_ID(optional)
* | [--->] IT_ERDAT TYPE TY_R_ERDAT(optional)
* | [--->] IT_AEDAT TYPE TY_R_AEDAT(optional)
* | [--->] IT_PAY_CODE TYPE TY_R_PAY_CODE(optional)
* | [--->] IT_STATUS TYPE TY_R_STATUS(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD set_filter.
r_project_id = it_project_id[].
r_zdate = it_zdate[].
r_batch_id = it_batch_id[].
r_record_id = it_record_id[].
r_employee_id = it_employee_id[].
r_erdat = it_erdat[].
r_aedat = it_aedat[].
r_pay_code = it_pay_code[].
r_status = it_status[].
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->SELECIONAR_WFS_ALLOCATION
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD selecionar_wfs_allocation.
TYPES ty_r_status TYPE RANGE OF zwfs_status.
MESSAGE i061 INTO DATA(dummy).
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
CASE _process_type.
WHEN `P`.
DATA(rl_status) = VALUE ty_r_status(
sign = `I`
option = `EQ`
( low = `0` ) ).
WHEN `R`.
rl_status = VALUE ty_r_status(
sign = `I`
option = `EQ`
( low = `2` ) ( low = `5` ) ).
WHEN OTHERS.
rl_status = VALUE ty_r_status(
sign = `I`
option = `EQ`
( low = `0` ) ( low = `2` ) ( low = `5` ) ).
ENDCASE.
SELECT DISTINCT
*
FROM zwfs_allocation
WHERE status IN @rl_status
INTO TABLE @mt_zwfs_allocation.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i062 WITH |{ lines( mt_allocation ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->SELECIONAR_REPROCESSAMENTO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_ALLOCATION TYPE TY_T_ALLOCATION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD selecionar_reprocessamento.
MESSAGE i061 INTO DATA(dummy).
LOG-POINT ID zps20 FIELDS dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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
z~*,
a~pernr, b~kostl, a~usrid, c~lstar, j~pspnr, j~profl,
coalesce( p~posid_edit, k~aufnr ) AS objnr,
coalesce( CASE WHEN p~posid_edit IS NOT NULL THEN 'PEP' END,
CASE WHEN k~aufnr IS NOT NULL THEN 'ORDEM' END )
AS type,
@space AS locked
FROM @it_allocation AS i
JOIN zwfs_allocation AS z ON ( z~batch_id = i~batch_id
AND z~record_id = i~record_id )
LEFT JOIN pa0105 AS a ON a~usrid = z~employee_id
AND a~subty = '0002'
AND ( a~endda >= @sy-datum AND a~begda <= @sy-datum )
LEFT JOIN pa0001 AS b ON b~pernr = a~pernr
AND ( b~endda >= @sy-datum AND b~begda <= @sy-datum )
LEFT JOIN pa0315 AS c ON c~pernr = a~pernr
AND ( c~endda >= @sy-datum AND c~begda <= @sy-datum )
LEFT JOIN prps AS p ON p~posid_edit = z~project_id
LEFT JOIN aufk AS k ON k~aufnr = z~project_id
LEFT JOIN proj AS j ON j~pspnr = p~psphi
WHERE z~batch_id IN @r_batch_id[]
AND z~record_id IN @r_record_id[]
AND z~zdate IN @r_zdate[]
AND z~employee_id IN @r_employee_id[]
AND z~project_id IN @r_project_id[]
AND z~erdat IN @r_erdat[]
AND z~aedat IN @r_aedat[]
AND z~pay_code IN @r_pay_code[]
AND z~status IN @r_status[]
INTO TABLE @mt_allocation.
IF sy-subrc = 0.
LOG-POINT ID zps20 FIELDS mt_allocation[].
SELECT DISTINCT
c~pernr, c~workdate, CAST( SUM( c~catshours ) AS QUAN( 15, 3 ) ) AS catshours
FROM @mt_allocation AS i
JOIN catsdb AS c ON c~pernr = i~pernr
AND c~workdate = concat( substring( i~zdate, 1, 6 ), '01' )
GROUP BY c~pernr, c~workdate
INTO TABLE @DATA(mt_workdates).
SELECT DISTINCT
e~*
FROM @mt_allocation AS i
JOIN zwfs_allocation AS e ON e~record_id = i~record_id
WHERE i~operation = 1 "criar apontamento
AND e~status = 3 "apontamentos com sucesso
INTO TABLE @mt_apontados.
SELECT DISTINCT
c~*
FROM @mt_allocation AS i
JOIN catsdb AS c ON ( ( c~record_id = i~record_id )
OR ( c~ltxa1 = concat( i~batch_id, i~record_id )
OR c~ltxa1 = concat( i~batch_id, concat( '_', i~record_id ) ) ) )
AND c~status <> '60' "estornado
INTO TABLE @mt_catsdb.
ENDIF.
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i062 WITH |{ lines( mt_allocation ) }| INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->REPROCESSAR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_ALLOCATION TYPE TY_T_ALLOCATION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD reprocessar.
MESSAGE i072 INTO DATA(dummy).
LOG-POINT ID zps20 FIELDS dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
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( ).
* Ler apontamentos para processar
selecionar_reprocessamento( it_allocation ).
* Trava os registros para evitar conflitos
travar_apontamentos( ).
* Elimina registros inv�lidos do processamento e grava log
limpar_dados( ).
* Elimina registros nulos
eliminar_apontamentos( ).
* Cria apontamentos
apontar( ).
* Busca projeto e migra dados CO
buscar_projetos( ).
* Destrava os registros
destravar_apontamentos( ).
DATA(t2) = timer->get_runtime( ).
MESSAGE i099 WITH |{ ( t2 - t1 ) / 1000 }| INTO dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
MESSAGE i073 INTO dummy.
cl_progress_indicator=>progress_indicate(
EXPORTING
i_text = dummy
i_output_immediately = abap_true ).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
zcl_ptool_helper=>bal_db_save( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->REDEFINIR
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_ALLOCATION TYPE ZTT_ALLOCATION
* | [--->] IV_STATUS TYPE ZWFS_STATUS
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD redefinir.
LOOP AT it_allocation ASSIGNING FIELD-SYMBOL(<alloc>).
CASE iv_status.
WHEN 0.
UPDATE zwfs_allocation
SET status = iv_status
aedat = sy-datum
aenam = sy-uname
aezet = sy-uzeit
belnr = abap_false
counter = abap_false
processing_time = utclong``
message = abap_false
WHERE batch_id = <alloc>-batch_id
AND record_id = <alloc>-record_id.
WHEN 1.
UPDATE zwfs_allocation
SET status = iv_status
aedat = sy-datum
aenam = sy-uname
aezet = sy-uzeit
belnr = abap_false
counter = abap_false
processing_time = utclong``
message = abap_false
WHERE batch_id = <alloc>-batch_id
AND record_id = <alloc>-record_id.
WHEN 2.
UPDATE zwfs_allocation
SET status = iv_status
WHERE batch_id = <alloc>-batch_id
AND record_id = <alloc>-record_id.
WHEN 3.
UPDATE zwfs_allocation
SET status = iv_status
WHERE batch_id = <alloc>-batch_id
AND record_id = <alloc>-record_id.
WHEN 4.
UPDATE zwfs_allocation
SET status = iv_status
WHERE batch_id = <alloc>-batch_id
AND record_id = <alloc>-record_id.
WHEN 5.
UPDATE zwfs_allocation
SET status = iv_status
WHERE batch_id = <alloc>-batch_id
AND record_id = <alloc>-record_id.
ENDCASE.
ENDLOOP.
COMMIT WORK.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_APONTAMENTO_HORAS_NEW->GET_DATA
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RT_ALLOC TYPE ZTT_ALLOCATION
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_data.
rt_alloc = mt_allocation[].
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_APONTAMENTO_HORAS_NEW=>FACTORY
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_ALLOCATION TYPE REF TO ZCL_APONTAMENTO_HORAS_NEW
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD factory.
ro_allocation = NEW zcl_apontamento_horas_new( ).
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Private Method ZCL_APONTAMENTO_HORAS_NEW->EXECUTAR_JOB_MIGRAR_CO
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_PERNR TYPE TY_R_PERNR(optional)
* | [--->] IT_BELNR TYPE TY_R_BELNR(optional)
* | [--->] IT_WDATE TYPE TY_R_WDATE(optional)
* | [--->] IV_COUNT TYPE I
* | [<-()] RV_FINISHED TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD executar_job_migrar_co.
DATA:
lv_jobcount TYPE tbtcjob-jobcount,
aborted TYPE c.
CONSTANTS lc_jobname TYPE tbtcjob-jobname VALUE 'ZAPONTAMENTO_HORAS'.
DATA(lv_jobname) = CONV tbtcjob-jobname( |{ lc_jobname }_{ iv_count }| ).
LOG-POINT ID zps20 FIELDS it_pernr[] it_belnr[] it_wdate[] lv_jobname.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid ##NEEDED
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
INTO DATA(lv_dummy).
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
ENDIF.
SUBMIT rcatstco WITH p_pernr IN it_pernr[]
WITH p_belnr IN it_belnr[]
WITH p_date IN it_wdate[]
WITH p_test = _testrun
WITH p_warn = abap_true
USER sy-uname
VIA JOB lv_jobname
NUMBER lv_jobcount
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
strtimmed = 'X'
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
INTO lv_dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
ENDIF.
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.
CALL FUNCTION 'SHOW_JOBSTATE'
EXPORTING
jobcount = lv_jobcount
jobname = lv_jobname
IMPORTING
aborted = aborted
finished = rv_finished
EXCEPTIONS
jobcount_missing = 1
jobname_missing = 2
job_notex = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
INTO lv_dummy.
zcl_ptool_helper=>bal_log_msg_add( iv_handle = _handle ).
ENDIF.
IF aborted = abap_true OR rv_finished = abap_true.
LOG-POINT ID zps20 FIELDS aborted rv_finished.
EXIT.
ENDIF.
ENDWHILE.
ENDMETHOD.
ENDCLASS.