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.