Código Fonte
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 244
BALLOG Helper
Este é um helper que fiz para gravar logs na transação SLG1.
CLASS zcl_ptool_helper DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES:
BEGIN OF ty_s_result,
kostl TYPE kostl,
prctr TYPE prctr,
END OF ty_s_result .
TYPES:
ty_t_result TYPE HASHED TABLE OF ty_s_result
WITH UNIQUE KEY kostl prctr .
TYPES:
ty_r_kostl TYPE RANGE OF kostl .
CLASS-METHODS bal_db_delete
IMPORTING
!it_log_header TYPE balhdr_t .
CLASS-METHODS bal_db_save .
CLASS-METHODS bal_db_search
IMPORTING
!iv_subobject TYPE balsubobj OPTIONAL
!iv_object TYPE balobj_d
RETURNING
VALUE(rt_log_header) TYPE balhdr_t .
CLASS-METHODS bal_log_create
IMPORTING
!iv_extnumber TYPE balnrext OPTIONAL
!iv_subobject TYPE balsubobj OPTIONAL
!iv_object TYPE balobj_d
RETURNING
VALUE(r_handle) TYPE balloghndl .
CLASS-METHODS bal_log_hdr_read
IMPORTING
!iv_handle TYPE balloghndl
RETURNING
VALUE(rs_statistics) TYPE bal_s_scnt .
CLASS-METHODS bal_log_msg_add
IMPORTING
!iv_handle TYPE balloghndl
!iv_tabname TYPE baltabname OPTIONAL
!iv_sort_field TYPE char6 OPTIONAL
!iv_field TYPE text60 OPTIONAL
!iv_field_text TYPE text60 OPTIONAL .
CLASS-METHODS bal_log_refresh
IMPORTING
!iv_handle TYPE balloghndl
RETURNING
VALUE(r_bool) TYPE abap_bool .
CLASS-METHODS select_cost_centers
IMPORTING
!it_kostl TYPE ty_r_kostl
RETURNING
VALUE(rt_result) TYPE ty_t_result .
PROTECTED SECTION.
PRIVATE SECTION.
CONSTANTS c_object TYPE balobj_d VALUE 'ZPS' ##NO_TEXT.
CONSTANTS c_subobject TYPE balsubobj VALUE 'PTOOL' ##NO_TEXT.
ENDCLASS.
CLASS zcl_ptool_helper IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_DB_DELETE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_LOG_HEADER TYPE BALHDR_T
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_db_delete.
IF NOT it_log_header IS INITIAL.
DATA(lt_log_handle) = VALUE bal_t_logh( FOR <fs_handle> IN it_log_header ( <fs_handle>-log_handle ) ).
IF lt_log_handle[] IS NOT INITIAL.
CALL FUNCTION 'BAL_DB_DELETE'
EXPORTING
* I_T_LOGS_TO_DELETE =
i_t_log_handle = lt_log_handle
* I_T_LOGNUMBER =
i_client = sy-mandt
* I_IN_UPDATE_TASK = ' '
i_with_commit_work = abap_true
* I_PACKAGE_SIZE = 100
EXCEPTIONS
no_logs_specified = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_DB_SAVE
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_db_save.
* Encerrando BALLOG
DATA(lv_second_connection) = VALUE dbcon_name( ) .
DATA(lt_new) = VALUE bal_t_lgnm( ( ) ).
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_client = sy-mandt
* i_in_update_task = abap_true
i_save_all = abap_true
* i_t_log_handle = iv_handle
i_2th_connection = abap_true
i_2th_connect_commit = abap_true
* I_LINK2JOB = 'X'
IMPORTING
e_new_lognumbers = lt_new
* e_second_connection = lv_second_connection
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 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 DATA(lv_dummy).
* Implement suitable error handling here
ENDIF.
*
* CALL FUNCTION 'BAL_DB_SAVE'
* EXPORTING
* i_save_all = abap_true
* EXCEPTIONS
* log_not_found = 1
* save_not_allowed = 2
* numbering_error = 3
* OTHERS = 4.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_DB_SEARCH
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_SUBOBJECT TYPE BALSUBOBJ(optional)
* | [--->] IV_OBJECT TYPE BALOBJ_D
* | [<-()] RT_LOG_HEADER TYPE BALHDR_T
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_db_search.
DATA(is_log_filter) = VALUE bal_s_lfil(
object = VALUE bal_r_obj( sign = |I| option = |EQ| ( low = iv_object ) )
subobject = VALUE bal_r_sub( sign = |I| option = |EQ| ( low = iv_subobject ) ) ).
CALL FUNCTION 'BAL_DB_SEARCH'
EXPORTING
i_client = sy-mandt
i_s_log_filter = is_log_filter
* I_T_SEL_FIELD =
* I_TZONE =
IMPORTING
e_t_log_header = rt_log_header
EXCEPTIONS
log_not_found = 1
no_filter_criteria = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_CREATE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_EXTNUMBER TYPE BALNREXT(optional)
* | [--->] IV_SUBOBJECT TYPE BALSUBOBJ(optional)
* | [--->] IV_OBJECT TYPE BALOBJ_D
* | [<-()] R_HANDLE TYPE BALLOGHNDL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_create.
DATA(ls_log) = VALUE bal_s_log(
extnumber = iv_extnumber
object = iv_object
subobject = iv_subobject
aldate = sy-datum
altime = sy-uzeit
aluser = sy-uname
alprog = sy-repid
aldate_del = sy-datum + 7
del_before = abap_false ).
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = r_handle
EXCEPTIONS
OTHERS = 1.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_HDR_READ
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_HANDLE TYPE BALLOGHNDL
* | [<-()] RS_STATISTICS TYPE BAL_S_SCNT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_hdr_read.
CHECK NOT iv_handle IS INITIAL.
* are there any messages in this log ?
CALL FUNCTION 'BAL_LOG_HDR_READ'
EXPORTING
i_log_handle = iv_handle
IMPORTING
e_statistics = rs_statistics
EXCEPTIONS
OTHERS = 1.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_MSG_ADD
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_HANDLE TYPE BALLOGHNDL
* | [--->] IV_TABNAME TYPE BALTABNAME(optional)
* | [--->] IV_SORT_FIELD TYPE CHAR6(optional)
* | [--->] IV_FIELD TYPE TEXT60(optional)
* | [--->] IV_FIELD_TEXT TYPE TEXT60(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_msg_add.
DATA(ls_log_msg) = VALUE bal_s_msg(
msgty = sy-msgty
msgid = sy-msgid
msgno = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv2
msgv3 = sy-msgv3
msgv4 = sy-msgv4
context = VALUE bal_s_cont( tabname = iv_tabname
value = VALUE bal_s_ex07( sort_field = iv_sort_field
field = iv_field
field_text = iv_field_text ) ) ).
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = iv_handle
i_s_msg = ls_log_msg
EXCEPTIONS
OTHERS = 1.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_REFRESH
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_HANDLE TYPE BALLOGHNDL
* | [<-()] R_BOOL TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_refresh.
IF NOT iv_handle IS INITIAL.
CALL FUNCTION 'BAL_LOG_REFRESH'
EXPORTING
i_log_handle = iv_handle
EXCEPTIONS
OTHERS = 1.
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_bool = abap_true.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>SELECT_COST_CENTERS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_KOSTL TYPE TY_R_KOSTL
* | [<-()] RT_RESULT TYPE TY_T_RESULT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD select_cost_centers.
SELECT DISTINCT
kostl, prctr
INTO TABLE @rt_result
FROM csks
WHERE kokrs = 'PWBR'
AND kostl IN @it_kostl
AND datbi > @sy-datum.
ENDMETHOD.
ENDCLASS.
- Details
- Written by: Administrator
- Category: Código Fonte
- Hits: 319
SQL CTE - Common Table Expression
SELECT usando WITH (SQL CTE - Common Table Expression) :
METHOD select_data.
get_dates( IMPORTING e_first_day = DATA(first_day) e_last_day = DATA(last_day) ).
get_period( IMPORTING fiscal_year = DATA(year_begin)
fiscal_period = DATA(period_begin) ).
get_period( IMPORTING fiscal_year = DATA(year_end) "#EC NEEDED
fiscal_period = DATA(period_end) ). "#EC NEEDED
period_begin = r_poper[ 1 ]-low.
period_end = COND #( WHEN r_poper[ 1 ]-high IS NOT INITIAL THEN r_poper[ 1 ]-high ELSE period_begin ).
DATA(period_prev) = CONV poper( period_begin - 1 ).
DATA(year_prev) = year_begin.
DATA(versn) = `000`.
IF period_prev IS INITIAL.
period_prev = `012`.
year_prev = year_begin - 1.
ENDIF.
DATA(period_start) = CONV poper( `01` ).
DATA(timer) = cl_abap_runtime=>create_hr_timer( ).
DATA(t1) = timer->get_runtime( ).
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
"Faturamento realizado
+fatur AS (
SELECT ps_psp_pnr, rtcur, SUM( tsl ) AS fatur_brt
FROM acdoca
WHERE rldnr = '0L'
AND blart = 'RV'
GROUP BY ps_psp_pnr, rtcur ),
"Desp Incluídas = Soma do faturamento realizado no período
"nas contas específicas RA_DESP_INCLUDED
+desp_incl AS (
SELECT ps_psp_pnr, rtcur, SUM( tsl ) AS desp_incl
FROM acdoca
WHERE rldnr = '0L'
AND poper BETWEEN @period_begin AND @period_end
AND racct IN @rl_racct
GROUP BY ps_psp_pnr, rtcur ),
* "Despesas Acumuldas = Soma do faturamento total
* "nas contas específicas RA_DESP_INCLUDED
* +desp_acum AS (
* SELECT ps_psp_pnr, rtcur, SUM( tsl ) AS desp_acum
* FROM acdoca
* WHERE rldnr = '0L'
* AND racct IN @rl_racct
* GROUP BY ps_psp_pnr, rtcur ),
"Honorário bruto = Soma de custo total do período para conta específica
+honor AS (
SELECT objnr, twaer,
SUM( wtg001 ) AS acca_brt,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wtg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wtg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wtg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wtg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wtg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wtg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wtg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wtg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wtg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wtg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wtg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wtg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS honor_brt
FROM v_cosp_view
WHERE kstar = '3101010150'
AND versn = @versn
GROUP BY objnr, twaer ),
"Desp Incl. realizadas acum. = Soma de custo total do período anterior
+desp_acum AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' = @period_prev THEN SUM( wtg001 ) ELSE 0 END +
CASE WHEN '02' = @period_prev THEN SUM( wtg002 ) ELSE 0 END +
CASE WHEN '03' = @period_prev THEN SUM( wtg003 ) ELSE 0 END +
CASE WHEN '04' = @period_prev THEN SUM( wtg004 ) ELSE 0 END +
CASE WHEN '05' = @period_prev THEN SUM( wtg005 ) ELSE 0 END +
CASE WHEN '06' = @period_prev THEN SUM( wtg006 ) ELSE 0 END +
CASE WHEN '07' = @period_prev THEN SUM( wtg007 ) ELSE 0 END +
CASE WHEN '08' = @period_prev THEN SUM( wtg008 ) ELSE 0 END +
CASE WHEN '09' = @period_prev THEN SUM( wtg009 ) ELSE 0 END +
CASE WHEN '10' = @period_prev THEN SUM( wtg010 ) ELSE 0 END +
CASE WHEN '11' = @period_prev THEN SUM( wtg011 ) ELSE 0 END +
CASE WHEN '12' = @period_prev THEN SUM( wtg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS desp_acum
FROM v_cosp_view
WHERE gjahr = @year_prev
AND kstar = '3101010150'
AND versn = @versn
GROUP BY objnr, twaer ),
"Horas incorridas acumuladas = Soma das horas lançadas e transferidas CO do período anterior
+hreal AS (
SELECT objnr, gjahr, meinh,
CAST( CASE WHEN '01' = @period_prev THEN SUM( meg001 ) ELSE 0 END +
CASE WHEN '02' = @period_prev THEN SUM( meg002 ) ELSE 0 END +
CASE WHEN '03' = @period_prev THEN SUM( meg003 ) ELSE 0 END +
CASE WHEN '04' = @period_prev THEN SUM( meg004 ) ELSE 0 END +
CASE WHEN '05' = @period_prev THEN SUM( meg005 ) ELSE 0 END +
CASE WHEN '06' = @period_prev THEN SUM( meg006 ) ELSE 0 END +
CASE WHEN '07' = @period_prev THEN SUM( meg007 ) ELSE 0 END +
CASE WHEN '08' = @period_prev THEN SUM( meg008 ) ELSE 0 END +
CASE WHEN '09' = @period_prev THEN SUM( meg009 ) ELSE 0 END +
CASE WHEN '10' = @period_prev THEN SUM( meg010 ) ELSE 0 END +
CASE WHEN '11' = @period_prev THEN SUM( meg011 ) ELSE 0 END +
CASE WHEN '12' = @period_prev THEN SUM( meg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS horas_brt2
FROM v_coss_view
WHERE kstar = '9040101000'
AND versn = @versn
AND wrttp = '04'
GROUP BY objnr, gjahr, meinh ),
"Taxa Budget
+budget AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wtg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wtg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wtg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wtg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wtg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wtg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wtg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wtg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wtg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wtg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wtg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wtg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS taxa_budget
FROM v_cosp_view
WHERE kstar = '3101010150'
AND versn = @versn
GROUP BY objnr, twaer ),
+receit AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' BETWEEN @period_start AND @period_end THEN SUM( wtg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_start AND @period_end THEN SUM( wtg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_start AND @period_end THEN SUM( wtg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_start AND @period_end THEN SUM( wtg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_start AND @period_end THEN SUM( wtg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_start AND @period_end THEN SUM( wtg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_start AND @period_end THEN SUM( wtg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_start AND @period_end THEN SUM( wtg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_start AND @period_end THEN SUM( wtg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_start AND @period_end THEN SUM( wtg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_start AND @period_end THEN SUM( wtg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_start AND @period_end THEN SUM( wtg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS receit_plan
FROM v_cosp_view
WHERE kstar = '3101010150'
AND versn = @versn
GROUP BY objnr, twaer ),
+progr AS (
SELECT objnr, twaer,
CAST( CASE WHEN '01' BETWEEN @period_begin AND @period_end THEN SUM( wtg001 ) ELSE 0 END +
CASE WHEN '02' BETWEEN @period_begin AND @period_end THEN SUM( wtg002 ) ELSE 0 END +
CASE WHEN '03' BETWEEN @period_begin AND @period_end THEN SUM( wtg003 ) ELSE 0 END +
CASE WHEN '04' BETWEEN @period_begin AND @period_end THEN SUM( wtg004 ) ELSE 0 END +
CASE WHEN '05' BETWEEN @period_begin AND @period_end THEN SUM( wtg005 ) ELSE 0 END +
CASE WHEN '06' BETWEEN @period_begin AND @period_end THEN SUM( wtg006 ) ELSE 0 END +
CASE WHEN '07' BETWEEN @period_begin AND @period_end THEN SUM( wtg007 ) ELSE 0 END +
CASE WHEN '08' BETWEEN @period_begin AND @period_end THEN SUM( wtg008 ) ELSE 0 END +
CASE WHEN '09' BETWEEN @period_begin AND @period_end THEN SUM( wtg009 ) ELSE 0 END +
CASE WHEN '10' BETWEEN @period_begin AND @period_end THEN SUM( wtg010 ) ELSE 0 END +
CASE WHEN '11' BETWEEN @period_begin AND @period_end THEN SUM( wtg011 ) ELSE 0 END +
CASE WHEN '12' BETWEEN @period_begin AND @period_end THEN SUM( wtg012 ) ELSE 0 END
AS DEC( 23, 2 ) ) AS progr_brt
FROM v_coss_view
WHERE kstar = '9040101000'
AND versn = @versn
GROUP BY objnr, twaer ),
+hplan AS (
SELECT objnr, gjahr, 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( 23, 2 ) ) AS horas_brt
FROM v_coss_view
WHERE kstar = '9040101000'
AND wrttp = '01'
GROUP BY objnr, gjahr, meinh ),
* +hreal AS (
* SELECT rproj, meinh, SUM( catshours ) AS horas_brt2
* FROM catsdb
* GROUP BY rproj, meinh ),
+quant AS (
SELECT rproj, meinh, SUM( catshours ) AS wip_mes
FROM catsdb
WHERE workdate BETWEEN @first_day AND @last_day
GROUP BY rproj, meinh ),
+result( pspnr, posid, pedit, objnr, prart, pratx, verna, astna, moeda,
partner1, partner2,
gjahr,
meinh1, horas_brt,
meinh2, horas_brt2,
etc,
meinh3, wip_mes,
fatur_brt,
progr_brt,
desp_incl,
desp_acum,
taxa_budget,
receit_plan,
acca_brt, honor_brt,
acca_bruto ) AS (
SELECT
p~pspnr, p~posid, p~posid_edit, p~objnr, p~prart, x~pratx, p~verna, p~astna, p~pwpos AS moeda,
b~name_org1 AS partner1, u~name_org1 AS partner2,
h~gjahr,
h~meinh AS meinh1, h~horas_brt,
d~meinh AS meinh2, d~horas_brt2,
( h~horas_brt - d~horas_brt2 ) AS etc,
q~meinh AS meinh3, q~wip_mes,
a~fatur_brt,
s~progr_brt,
e~desp_incl,
i~desp_acum,
f~taxa_budget,
g~receit_plan,
c~acca_brt, c~honor_brt,
( c~acca_brt - c~honor_brt ) AS acca_bruto
FROM proj AS j
JOIN prps AS p ON p~psphi = j~pspnr
LEFT JOIN tcj1t AS x ON x~prart = p~prart
AND x~langu = @sy-langu
LEFT JOIN but000 AS b ON b~partner = substring( j~usr00, 1, 10 )
LEFT JOIN but000 AS u ON u~partner = right( j~usr01, 10 )
LEFT JOIN +hplan AS h ON h~objnr = p~objnr
LEFT JOIN +hreal AS d ON d~objnr = p~objnr
LEFT JOIN +quant AS q ON q~rproj = p~pspnr
LEFT JOIN +fatur AS a ON a~ps_psp_pnr = p~pspnr
AND a~rtcur = p~pwpos
LEFT JOIN +desp_incl AS e ON e~ps_psp_pnr = p~pspnr
AND e~rtcur = p~pwpos
LEFT JOIN +desp_acum AS i ON i~objnr = p~objnr
AND i~twaer = p~pwpos
LEFT JOIN +budget AS f ON f~objnr = p~objnr
AND f~twaer = p~pwpos
LEFT JOIN +receit AS g ON g~objnr = p~objnr
AND g~twaer = p~pwpos
LEFT JOIN +progr AS s ON s~objnr = p~objnr
AND s~twaer = p~pwpos
LEFT JOIN +honor AS c ON c~objnr = p~objnr
AND c~twaer = p~pwpos
WHERE p~verna IN @r_verna[]
AND p~astnr IN @r_astnr[]
AND p~posid IN @r_posid[]
AND p~prart IN @r_prart[]
AND p~pkokr IN @r_kokrs[] )
SELECT * FROM +result INTO TABLE @DATA(results).
_time = ( timer->get_runtime( ) - t1 ) / 1000.
mt_psxra = CORRESPONDING #( results MAPPING unidade = meinh1 ).
ENDMETHOD.