SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Cost Center Rolling Trend Summary Report



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> CO
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Fri Jan 18, 2008 2:07 pm    Post subject: Cost Center Rolling Trend Summary Report Reply with quote

[code:1:5004ed15bf]***********************************************************************
* Program Name : Cost Center Rolling Trend Summary Report *
* *
* Request No. : DEVK905041 *
* Requester : Jocelyn Ordanza *
* Program Type : Report *
* Programmer : Aruna Pitla *
* Date programmed : 09/24/2002 *
* Transaction code : ZF04 *
* Brief Description : This Summary Report will show a total of six *
* quarters in two plan versions based on selected *
* periods and cost center/cost element combination
* and a grand total of all the costs
*---------------------------------------------------------------------*
* Mandatory field(s) - Fiscal year *
* Plan/Fcst Version1 *
* Plan/Fcst Version2 *
* From Period *
* To Period *
* *
* Optional field(s) - Cost center group(if cost center not entered) *
* Cost center(if cost center group not entered) *
* Cost element group(if cost element not entered)*
* Cost element(if cost element group not entered)*
*---------------------------------------------------------------------*
* Remark: *
***********************************************************************
***********************************************************************
* Modification Log *
*---------------------------------------------------------------------*
* Date Programmer Change Request # *
* ---------- ---------- ---------------- *

REPORT zfi_costcntr_rolling_trend_smr
NO STANDARD PAGE HEADING
MESSAGE-ID zfi
LINE-COUNT 65(3) LINE-SIZE 161.

************************************************************************
* Declaration of Database tables
************************************************************************
TABLES : cosp, " CO Object: Line Items (by Period)
setleaf, " Values in Sets
cosr, " CO Object: Statistical Key Figure Totals
csks, " Cost Center Master Data
tkt03, " Stat. key figure texts
rksb1. " Work fields line-item reports

************************************************************************
* Declaration of Internal tables
************************************************************************
DATA : BEGIN OF it_output OCCURS 0,
cst_ele LIKE cosp-kstar,
cost_ctr LIKE csks-kostl,
qt1_tot TYPE p DECIMALS 0,
qt2_tot TYPE p DECIMALS 0,
qt3_tot TYPE p DECIMALS 0,
qt4_tot TYPE p DECIMALS 0,
qt5_tot TYPE p DECIMALS 0,
qt6_tot TYPE p DECIMALS 0,
yr_tot1 TYPE p DECIMALS 0,
yr_tot2 TYPE p DECIMALS 0,
yr_tot3 TYPE p DECIMALS 0,
highlevel1 LIKE bapiset_hier-descript,
highlevel2 LIKE bapiset_hier-descript,
highlevel3 LIKE bapiset_hier-descript,
highlevel4 LIKE bapiset_hier-descript,
descript LIKE bapiset_hier-descript,
key_desc LIKE bapiset_hier-descript,
hierlevel LIKE bapiset_hier-hierlevel,
sortord LIKE sy-tabix,
sortord1 LIKE sy-tabix,
END OF it_output.

* Final internal table
DATA : BEGIN OF it_out OCCURS 0,
highlevel1 LIKE bapiset_hier-descript,
highlevel2 LIKE bapiset_hier-descript,
highlevel3 LIKE bapiset_hier-descript,
highlevel4 LIKE bapiset_hier-descript,
descript LIKE bapiset_hier-descript,
cst_ele LIKE cosp-kstar,
cost_ctr LIKE csks-kostl,
qt1_tot TYPE p DECIMALS 0,
qt2_tot TYPE p DECIMALS 0,
qt3_tot TYPE p DECIMALS 0,
qt4_tot TYPE p DECIMALS 0,
qt5_tot TYPE p DECIMALS 0,
qt6_tot TYPE p DECIMALS 0,
yr_tot1 TYPE p DECIMALS 0,
yr_tot2 TYPE p DECIMALS 0,
yr_tot3 TYPE p DECIMALS 0,
END OF it_out.

DATA : BEGIN OF it_cntrnodes OCCURS 0.
INCLUDE STRUCTURE bapiset_hier.
DATA : END OF it_cntrnodes.

DATA : BEGIN OF it_cstnodes OCCURS 0.
INCLUDE STRUCTURE bapiset_hier.
DATA : END OF it_cstnodes.

DATA : BEGIN OF it_costcenters OCCURS 0.
INCLUDE STRUCTURE bapi1112_values.
DATA : END OF it_costcenters.

DATA : BEGIN OF it_costelements OCCURS 0.
INCLUDE STRUCTURE bapi1112_values.
DATA : END OF it_costelements.

DATA: BEGIN OF it_idynpfields OCCURS 0,
fieldname LIKE dpov-fldname,
stepl LIKE dynpread-stepl,
fieldvalue LIKE dynpread-fieldvalue,
fieldinp LIKE dynpread-fieldinp,
END OF it_idynpfields.

DATA: it_bdctab LIKE bdcdata OCCURS 0 WITH HEADER LINE.

DATA it_output1 LIKE it_output OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF it_node OCCURS 0,
highlevel1 LIKE bapiset_hier-descript,
highlevel2 LIKE bapiset_hier-descript,
highlevel3 LIKE bapiset_hier-descript,
highlevel4 LIKE bapiset_hier-descript,
descript LIKE it_cntrnodes-descript,
valfrom LIKE bapi1113_values-valfrom ,
valto LIKE bapi1113_values-valto,
sortord1 LIKE sy-tabix,
END OF it_node.

RANGES : r_year FOR cosp-gjahr.

************************************************************************
* Global variables
************************************************************************
DATA : v_toperiod(30),
v_ncnt(3) TYPE n,
v_toprd LIKE setleaf-valto,
v_cnt TYPE i,
v_ver_start TYPE i.

FIELD-SYMBOLS <fs>.

DATA : v_qt1_tot LIKE it_output-qt2_tot,
v_qt2_tot LIKE it_output-qt2_tot,
v_qt3_tot LIKE it_output-qt2_tot,
v_qt4_tot LIKE it_output-qt2_tot,
v_qt5_tot LIKE it_output-qt2_tot,
v_qt6_tot LIKE it_output-qt2_tot.

DATA : v_times TYPE i.

DATA : v_title1(60), "report title1
v_title2(60). "report title2

* Variables for totals
DATA : v_total1 TYPE p DECIMALS 0,
v_total2 TYPE p DECIMALS 0,
v_total3 TYPE p DECIMALS 0,
v_total4 TYPE p DECIMALS 0,
v_total5 TYPE p DECIMALS 0,
v_total6 TYPE p DECIMALS 0,
v_total7 TYPE p DECIMALS 0,
v_total8 TYPE p DECIMALS 0,
v_total9 TYPE p DECIMALS 0.

* Variables for Grand Total
DATA : v_gtotal1 TYPE p DECIMALS 0,
v_gtotal2 TYPE p DECIMALS 0,
v_gtotal3 TYPE p DECIMALS 0,
v_gtotal4 TYPE p DECIMALS 0,
v_gtotal5 TYPE p DECIMALS 0,
v_gtotal6 TYPE p DECIMALS 0,
v_gtotal7 TYPE p DECIMALS 0,
v_gtotal8 TYPE p DECIMALS 0,
v_gtotal9 TYPE p DECIMALS 0.


************************************************************************
* selection-screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-020.
PARAMETERS : p_year LIKE cosp-gjahr MEMORY ID gjr OBLIGATORY,
" Fiscal year
p_versn1 LIKE cosp-versn OBLIGATORY, " Plan/Fcst
" Version 1
p_versn2 LIKE coep-versn OBLIGATORY, " Plan/Fcst
" Version 2
p_frprd LIKE coep-perio OBLIGATORY, " From Period
p_toprd LIKE coep-perio OBLIGATORY. " To Period

SELECT-OPTIONS : s_skey FOR cosr-stagr. " Statistical key figure
SELECT-OPTIONS : s_wrttp FOR cosp-wrttp NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-021.

PARAMETERS : p_cntrgp LIKE rksb1-ksgru MEMORY ID ksg.
" Cost Center Group
SELECT-OPTIONS : s_cntr FOR csks-kostl MEMORY ID kos. " Cost Center
PARAMETERS : p_cstgp LIKE rksb1-kagru. " Cost Element Group
SELECT-OPTIONS : s_cstele FOR cosp-kstar. " Cost Element
SELECTION-SCREEN END OF BLOCK b2.

DATA v_cost_element LIKE rksb1-kagru.
DATA v_cstcenter LIKE rksb1-ksgru.
* Include standard page heading
*INCLUDE z_std_heading.

************************************************************************
* Initialization
************************************************************************
INITIALIZATION.
v_title1 = 'Cost Center Rolling Trend Summary'(001).

************************************************************************
* at selection-screen
************************************************************************
* Validation for from period
AT SELECTION-SCREEN ON p_frprd.
PERFORM validate_period.

* Validation for to period
AT SELECTION-SCREEN ON p_toprd.
PERFORM validate_toperiod.

* Validation for version1
AT SELECTION-SCREEN ON p_versn1.
PERFORM validate_version1.

* Validation for version2
AT SELECTION-SCREEN ON p_versn2.
PERFORM validate_version2.

AT SELECTION-SCREEN.
* Validation for cost center
PERFORM validate_costcenter.

* Validation for cost center group
PERFORM validate_costcentergp.

* Validation for cost element
PERFORM validate_costelement.

* Validation for cost element group
PERFORM validate_costelementgp.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_cntrgp.
* Search help for cost center group
PERFORM cost_cntr_gp_valuehelp.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_cstgp.
* Search help for cost element group
PERFORM cost_ele_gp_valuehelp.

************************************************************************
* Top-of-page
************************************************************************
TOP-OF-PAGE.
* Display standard page heading
* PERFORM pgh_standard_heading USING v_title1 v_title2.

* Display selection screen
PERFORM display_selection_screen.

* Display column headings
PERFORM display_heading.

************************************************************************
* start-of-selection
************************************************************************
START-OF-SELECTION.
* Extraction of Data.
PERFORM frm_extract_data.

************************************************************************
* end-of-selection
************************************************************************
END-OF-SELECTION.
IF NOT it_out[] IS INITIAL.
* Display report output
PERFORM display_report.

ELSE.
MESSAGE i005 WITH 'No record found for Selected Criteria'(034).
EXIT.

ENDIF.
*&---------------------------------------------------------------------*
*& Form display_selection_screen
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_selection_screen.
IF NOT p_year IS INITIAL.
WRITE :/3 'Year'(023), 34 p_year.
ENDIF.
IF NOT p_versn1 IS INITIAL.
WRITE :/3 'Version 1'(024), 34 p_versn1.
ENDIF.
IF NOT p_versn2 IS INITIAL.
WRITE :/3 'Version 2'(025), 34 p_versn2.
ENDIF.


IF NOT p_frprd IS INITIAL.
WRITE :/3 'From Period'(026), 34 p_frprd .
ENDIF.

IF NOT p_toprd IS INITIAL.
WRITE :/3 'To Period'(027), 34 p_toprd .
ENDIF.

IF NOT s_skey[] IS INITIAL AND p_cntrgp EQ space.
WRITE :/3 'Statistical key'(028),34 s_skey-low .
IF NOT s_skey-high IS INITIAL.
WRITE : 50 'to'(029), 53 s_skey-high.
ENDIF.
ENDIF.

IF NOT p_cntrgp IS INITIAL.
WRITE :/3 'Cost Center Grp'(030),34 p_cntrgp.
ENDIF.

IF NOT s_cntr-low IS INITIAL AND p_cntrgp EQ space.
WRITE :/3 'Cost Center'(031),34 s_cntr-low .
IF NOT s_cntr-high IS INITIAL.
WRITE : 50 'to'(029), 53 s_cntr-high.
ENDIF.
ENDIF.

IF NOT p_cstgp IS INITIAL.
WRITE :/3 'Cost Element Grp'(032),34 p_cstgp.
ENDIF.

IF NOT s_cstele-low IS INITIAL.
WRITE :/3 'Cost Element'(033),34 s_cstele-low .
IF NOT s_cstele-high IS INITIAL.
WRITE : 50 'to'(029), 53 s_cstele-high.
ENDIF.
ENDIF.
ENDFORM. " display_selection_screen
*&---------------------------------------------------------------------*
*& Form frm_extract_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_extract_data.

PERFORM display_cst_element.

IF s_cntr[] IS INITIAL.
* Get Cost Center data
PERFORM get_cost_center.
ENDIF.

IF s_cstele[] IS INITIAL.
* Get Cost element data
PERFORM get_cost_element.
ENDIF.

* Get Object data
PERFORM get_obj_data.

* Transfer the data to the internal table it_out.
PERFORM transfer_data.
ENDFORM. " frm_extract_data
*&---------------------------------------------------------------------*
*& Form get_cost_center
*&---------------------------------------------------------------------*
* Getting the details of cost center
*----------------------------------------------------------------------*
FORM get_cost_center.
CALL FUNCTION 'BAPI_COSTCENTERGROUP_GETDETAIL'
EXPORTING
controllingarea = 'EGLS'
groupname = p_cntrgp
TABLES
hierarchynodes = it_cntrnodes
hierarchyvalues = it_costcenters.


IF sy-subrc = 0.
LOOP AT it_costcenters.
s_cntr-low = it_costcenters-valfrom.
s_cntr-high = it_costcenters-valto.
s_cntr-sign = 'I'.
s_cntr-option = 'EQ'.
APPEND s_cntr.
CLEAR s_cntr.
ENDLOOP.
ENDIF.

ENDFORM. " get_cost_center
*&---------------------------------------------------------------------*
*& Form get_cost_element
*&---------------------------------------------------------------------*
* Getting the details of cost element
*----------------------------------------------------------------------*
FORM get_cost_element.
CALL FUNCTION 'BAPI_COSTELEMENTGRP_GETDETAIL'
EXPORTING
chartofaccounts = 'WWCA'
groupname = p_cstgp
TABLES
hierarchynodes = it_cstnodes
hierarchyvalues = it_costelements.

IF sy-subrc = 0.

LOOP AT it_costelements.
s_cstele-low = it_costelements-valfrom.
s_cstele-high = it_costelements-valto.
s_cstele-sign = 'I'.

s_cstele-option = 'BT'.
APPEND s_cstele.
CLEAR s_cstele.
ENDLOOP.

LOOP AT it_cstnodes.
IF it_cstnodes-hierlevel = 0.
it_node-highlevel1 = it_cstnodes-descript.
IF it_cstnodes-valcount EQ 0 .
CONTINUE.
ELSE.
PERFORM append_records_to_node.
ENDIF.
ENDIF.


IF it_cstnodes-hierlevel = 1.
it_node-highlevel2 = it_cstnodes-descript.
IF it_cstnodes-valcount EQ 0 .
CONTINUE.
ELSE.
PERFORM append_records_to_node.
ENDIF.

ENDIF.

IF it_cstnodes-hierlevel = 2.
it_node-highlevel3 = it_cstnodes-descript.
IF it_cstnodes-valcount EQ 0 .
CONTINUE.
ELSE.
PERFORM append_records_to_node.
ENDIF.

ENDIF.

IF it_cstnodes-hierlevel = 3.
it_node-highlevel4 = it_cstnodes-descript.
IF it_cstnodes-valcount EQ 0 .
CONTINUE.
ELSE.
PERFORM append_records_to_node.
ENDIF.

ENDIF.
ENDLOOP.

ENDIF.
ENDFORM. " get_cost_element
*&---------------------------------------------------------------------
*& Form get_obj_data
*&---------------------------------------------------------------------
* Getting the required data
*----------------------------------------------------------------------
FORM get_obj_data.
* Build the range for the period and the year
PERFORM build_the_range.

IF NOT s_skey[] IS INITIAL.
* Get the Headcount data
PERFORM get_the_headcount.
PERFORM add_headcount.
ENDIF.

*--Get the COSP data
PERFORM get_data_cosp.

* Get the Quarter totals for the respective years
PERFORM get_year_totals.

ENDFORM. " get_obj_data
*&---------------------------------------------------------------------
*& Form build_the_range
*&---------------------------------------------------------------------
* Builing the Quarters range
*----------------------------------------------------------------------
FORM build_the_range.
DATA : l_period LIKE coep-perio,
l_year LIKE cosp-gjahr.

* Build the range for the year
r_year-low = p_year.
r_year-sign = 'I'.
r_year-option = 'BT'.

l_period = p_toprd.
l_year = p_year.

DO 15 TIMES.
l_period = l_period + 1.
IF l_period > 12.
l_year = l_year + 1.
l_period = 1.
ENDIF.
ENDDO.

r_year-high = l_year.

APPEND r_year.
CLEAR r_year.
ENDFORM. " build_the_range
*&---------------------------------------------------------------------
*& Form get_the_headcount
*&---------------------------------------------------------------------
* Getting the headcount data
*----------------------------------------------------------------------
FORM get_the_headcount.
DATA : l_objnr LIKE cosr-objnr,
l_length TYPE i,
l_length1 TYPE i.

CLEAR v_toperiod.
REFRESH s_wrttp.
IF p_versn1 = '000' .
s_wrttp-low = '04'.
s_wrttp-option = 'EQ'.
s_wrttp-sign = 'I'.
APPEND s_wrttp.
ELSE .
REFRESH s_wrttp.
ENDIF.

*---Added
SELECT * FROM cosr
WHERE lednr = '00' AND
gjahr = p_year AND
wrttp IN s_wrttp AND
versn = p_versn1 AND
stagr IN s_skey.

CLEAR : v_qt2_tot, v_qt3_tot, v_qt4_tot, v_qt5_tot, v_qt6_tot, v_cnt
.
v_ncnt = v_toprd.
l_objnr = cosr-objnr.
l_length = strlen( l_objnr ).
l_length1 = l_length - 10.
v_times = p_toprd - p_frprd + 1.
v_ncnt = p_frprd.

* validation of objnr last four characters with respect to the
* selection screen cost centers
CHECK cosr-objnr+l_length1(10) IN s_cntr.

DO v_times TIMES.
v_cnt = v_cnt + 1.
CONCATENATE 'cosr-sme' v_ncnt INTO v_toperiod.
CONDENSE v_toperiod NO-GAPS.
ASSIGN (v_toperiod) TO <fs>.
IF v_cnt BETWEEN 1 AND 3.
v_qt1_tot = <fs>.
ELSEIF v_cnt BETWEEN 4 AND 6.
v_qt2_tot = <fs>.
ELSEIF v_cnt BETWEEN 7 AND 9.
v_qt3_tot = <fs>.
ELSEIF v_cnt BETWEEN 10 AND 12.
v_qt4_tot = <fs>.
ENDIF.
v_ncnt = v_ncnt + 1.
ENDDO.
READ TABLE it_output WITH KEY cst_ele = cosr-stagr
cost_ctr = cosr-objnr+l_length1(10)
BINARY SEARCH.
IF sy-subrc EQ 0 .
it_output-qt1_tot = it_output-qt1_tot + v_qt1_tot.
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
MODIFY it_output INDEX sy-tabix.
CLEAR it_output.
ELSE.
CLEAR tkt03.
SELECT SINGLE * FROM tkt03 WHERE kokrs EQ 'EGLS'
AND stagr EQ cosr-stagr.
it_output-descript = tkt03-bezei.
it_output-key_desc = tkt03-bezei.
it_output-cst_ele = cosr-stagr.
it_output-cost_ctr = cosr-objnr+l_length1(10).
it_output-qt1_tot = it_output-qt1_tot + v_qt1_tot.
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
it_output-sortord = 900.
it_output-sortord1 = 900.
APPEND it_output.
CLEAR it_output.
SORT it_output BY cst_ele cost_ctr.
ENDIF.
ENDSELECT.
*--End
SORT it_output BY cst_ele cost_ctr.
* Headcount for the other Quarters
PERFORM headcount_other_quarts.
LOOP AT it_output.
it_output-qt1_tot = it_output-qt1_tot * 1000.
it_output-qt2_tot = it_output-qt2_tot * 1000.
it_output-qt3_tot = it_output-qt3_tot * 1000.
it_output-qt4_tot = it_output-qt4_tot * 1000.
it_output-qt5_tot = it_output-qt5_tot * 1000.
it_output-qt6_tot = it_output-qt6_tot * 1000.
MODIFY it_output.
ENDLOOP.

ENDFORM. " get_the_headcount
*&---------------------------------------------------------------------
*& Form GET_DATA_COSP
*&---------------------------------------------------------------------
* Getting the cosp data
*----------------------------------------------------------------------
FORM get_data_cosp.
DATA : l_length TYPE i,
l_length1 TYPE i.

DATA : l_year LIKE cosr-gjahr.

REFRESH s_wrttp.
IF p_versn1 = '000' .
s_wrttp-low = '04'.
s_wrttp-option = 'EQ'.
s_wrttp-sign = 'I'.
APPEND s_wrttp.
ELSE.
REFRESH s_wrttp.
ENDIF.


SELECT * FROM cosp
WHERE lednr = '00' AND
gjahr = p_year AND
wrttp IN s_wrttp AND
versn = p_versn1 AND
kstar IN s_cstele.
*---Added
CLEAR: v_qt1_tot, v_qt2_tot, v_qt3_tot, v_qt4_tot, v_qt5_tot, v_qt6_tot
, v_cnt, it_output.

v_ncnt = p_frprd.
l_length = strlen( cosp-objnr ).
l_length1 = l_length - 10.
v_times = p_toprd - p_frprd + 1.
v_toprd = p_toprd.

CHECK cosp-objnr+l_length1(10) IN s_cntr.
DO v_times TIMES.
v_cnt = v_cnt + 1.
CONCATENATE 'cosp-wkg' v_ncnt INTO v_toperiod.
CONDENSE v_toperiod NO-GAPS.
ASSIGN (v_toperiod) TO <fs>.
IF v_cnt BETWEEN 1 AND 3.
v_qt1_tot = v_qt1_tot + <fs>.
ELSEIF v_cnt BETWEEN 4 AND 6.
v_qt2_tot = v_qt2_tot + <fs>.
ELSEIF v_cnt BETWEEN 7 AND 9.
v_qt3_tot = v_qt3_tot + <fs>.
ELSEIF v_cnt BETWEEN 10 AND 12.
v_qt4_tot = v_qt4_tot + <fs>.
ENDIF.
v_ncnt = v_ncnt + 1.
ENDDO.

READ TABLE it_output WITH KEY cst_ele = cosp-kstar
cost_ctr = cosp-objnr+l_length1(10)
BINARY SEARCH.
IF sy-subrc EQ 0 .
it_output-qt1_tot = it_output-qt1_tot + v_qt1_tot.
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
MODIFY it_output INDEX sy-tabix.
CLEAR it_output.
ELSE.

it_output-cost_ctr = cosp-objnr+l_length1(10).
it_output-cst_ele = cosp-kstar.
it_output-qt1_tot = it_output-qt1_tot + v_qt1_tot.
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
it_output-key_desc = space.
LOOP AT it_node WHERE valfrom LE cosp-kstar
AND valto GE cosp-kstar.
it_output-descript = it_node-descript.
it_output-sortord = sy-tabix.
it_output-sortord1 = it_node-sortord1.
it_output-highlevel1 = it_node-highlevel1.
it_output-highlevel2 = it_node-highlevel2.
it_output-highlevel3 = it_node-highlevel3.
it_output-highlevel4 = it_node-highlevel4.
ENDLOOP.

APPEND it_output.
CLEAR it_output.
ENDIF.
ENDSELECT.
*--End Added
SORT it_output BY cst_ele cost_ctr.

REFRESH s_wrttp.
IF p_versn2 = '000' .
s_wrttp-low = '04'.
s_wrttp-option = 'EQ'.
s_wrttp-sign = 'I'.
APPEND s_wrttp.
ELSE .
REFRESH s_wrttp.
ENDIF.

v_ver_start = v_times.
v_times = 18 - v_times."mmundhada 12/02

SELECT * FROM cosp
WHERE lednr = '00' AND
* gjahr = p_year and
wrttp IN s_wrttp AND
versn = p_versn2 AND
kstar IN s_cstele.
CLEAR : v_qt2_tot, v_qt3_tot, v_qt4_tot, v_qt5_tot, v_qt6_tot, v_cnt
.

* v_times = p_toprd - p_frprd + 1. "mmundhada 12/02
v_ncnt = v_toprd.
l_year = p_year.
l_length = strlen( cosp-objnr ).
l_length1 = l_length - 10.

CHECK cosp-objnr+l_length1(10) IN s_cntr.
v_cnt = v_ver_start .
DO v_times TIMES.
v_ncnt = v_ncnt + 1.
IF v_ncnt > 12.
l_year = l_year + 1.
v_ncnt = 1.
* v_cnt = 12. "mmundhada 12/02
PERFORM calculate_v_cnt.
ENDIF.
CHECK cosp-gjahr = l_year.
v_cnt = v_cnt + 1.
CONCATENATE 'cosp-wkg' v_ncnt INTO v_toperiod.
CONDENSE v_toperiod NO-GAPS.
ASSIGN (v_toperiod) TO <fs>.
IF v_cnt BETWEEN 4 AND 6.
v_qt2_tot = v_qt2_tot + <fs>.
ELSEIF v_cnt BETWEEN 7 AND 9.
v_qt3_tot = v_qt3_tot + <fs>.
ELSEIF v_cnt BETWEEN 10 AND 12.
v_qt4_tot = v_qt4_tot + <fs>.
ELSEIF v_cnt BETWEEN 13 AND 15.
v_qt5_tot = v_qt5_tot + <fs>.
ELSEIF v_cnt BETWEEN 16 AND 18.
v_qt6_tot = v_qt6_tot + <fs>.
ENDIF.
*v_toprd = v_toprd + 1.
ENDDO.

READ TABLE it_output WITH KEY cst_ele = cosp-kstar
cost_ctr = cosp-objnr+l_length1(10)
BINARY SEARCH.
IF sy-subrc EQ 0 .
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
it_output-qt5_tot = it_output-qt5_tot + v_qt5_tot.
it_output-qt6_tot = it_output-qt6_tot + v_qt6_tot.

MODIFY it_output INDEX sy-tabix.
CLEAR it_output.
*---Added mgm 10/07 mmundhada
ELSE.

it_output-cost_ctr = cosp-objnr+l_length1(10).
it_output-cst_ele = cosp-kstar.
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
it_output-qt5_tot = it_output-qt5_tot + v_qt5_tot.
it_output-qt6_tot = it_output-qt6_tot + v_qt6_tot.
it_output-key_desc = space.

LOOP AT it_node WHERE valfrom LE cosp-kstar
AND valto GE cosp-kstar.
it_output-descript = it_node-descript.
it_output-sortord = sy-tabix.
it_output-sortord1 = it_node-sortord1.
it_output-highlevel1 = it_node-highlevel1.
it_output-highlevel2 = it_node-highlevel2.
it_output-highlevel3 = it_node-highlevel3.
it_output-highlevel4 = it_node-highlevel4.
ENDLOOP.

APPEND it_output.
CLEAR it_output.
SORT it_output BY cst_ele cost_ctr.
*---End of Add 10/07
ENDIF.

ENDSELECT.
DELETE it_output WHERE qt1_tot = 0
AND qt2_tot = 0
AND qt3_tot = 0
AND qt4_tot = 0
AND qt5_tot = 0
AND qt6_tot = 0.

ENDFORM. " GET_DATA_COSP
*&---------------------------------------------------------------------
*& Form get_year_totals
*&---------------------------------------------------------------------
* Getting the respective year totals
*----------------------------------------------------------------------
FORM get_year_totals.
LOOP AT it_output.
IF p_frprd = 1.
it_output-yr_tot1 = it_output-qt1_tot + it_output-qt2_tot +
it_output-qt3_tot + it_output-qt4_tot.
it_output-yr_tot2 = it_output-qt5_tot + it_output-qt6_tot.
ELSEIF p_frprd = 4.
it_output-yr_tot1 = it_output-qt1_tot + it_output-qt2_tot +
it_output-qt3_tot.
it_output-yr_tot2 = it_output-qt4_tot + it_output-qt5_tot +
it_output-qt6_tot.
ELSEIF p_frprd = 7.
it_output-yr_tot1 = it_output-qt1_tot + it_output-qt2_tot.
it_output-yr_tot2 = it_output-qt3_tot + it_output-qt4_tot +
it_output-qt5_tot + it_output-qt6_tot.
ELSEIF p_frprd = 10.
it_output-yr_tot1 = it_output-qt1_tot.
it_output-yr_tot2 = it_output-qt2_tot + it_output-qt3_tot +
it_output-qt4_tot + it_output-qt5_tot.
it_output-yr_tot3 = it_output-qt6_tot.
ENDIF.
IF NOT it_output-key_desc IS INITIAL.
CLEAR : it_output-yr_tot1, it_output-yr_tot2,it_output-yr_tot3.
ENDIF.
MODIFY it_output INDEX sy-tabix.
CLEAR it_output.
ENDLOOP.
ENDFORM. " get_year_totals
*&---------------------------------------------------------------------
*& Form display_heading
*&---------------------------------------------------------------------
* Display column headings
*----------------------------------------------------------------------
FORM display_heading.
DATA l_tabix LIKE sy-tabix.
DATA : l_year2 LIKE cosr-gjahr,
l_year3 LIKE cosr-gjahr.
DATA : v_text1(35),
v_text2(35),
v_text3(35).

l_year2 = p_year + 1.
l_year3 = p_year + 2.

v_text1(4) = p_year.
v_text1+5(5) = 'Total'(011).


v_text2(4) = l_year2.
v_text2+5(5) = 'Total'(011).


v_text3(4) = l_year3.
v_text3+5(5) = 'Total'(011).

SKIP.
ULINE.
FORMAT COLOR COL_HEADING ON.

IF p_frprd = 10.
WRITE: / 'Description'(002),
45 sy-vline,
46 'Cst Ctr'(004),
61 sy-vline,
62(10) 'Q4',p_year,
72 sy-vline,
73(10) v_text1,
83 sy-vline,
84(10) 'Q1',l_year2,
94 sy-vline,
95(10) 'Q2',l_year2,
105 sy-vline,
106(10) 'Q3',l_year2,
116 sy-vline,
117(10) 'Q4',l_year2,
127 sy-vline,
128(10) v_text2,
138 sy-vline,
139(10) 'Q1',l_year3,
150 sy-vline,
151(10) v_text3,
161 sy-vline.

ELSEIF p_frprd = 7.
WRITE: / 'Description'(002),
45 sy-vline,
46 'Cst Ctr'(004),
61 sy-vline,
62(10) 'Q3',p_year,
72 sy-vline,
73(10) 'Q4',p_year,
83 sy-vline,
84(10) v_text1,
94 sy-vline,
95(10) 'Q1',l_year2,
105 sy-vline,
106(10) 'Q2',l_year2,
116 sy-vline,
117(10) 'Q3',l_year2,
127 sy-vline,
128(10) 'Q4',l_year2,
138 sy-vline,
139(10) v_text2,
150 sy-vline.
ELSEIF p_frprd = 4.
WRITE: / 'Description'(002),
45 sy-vline,
46 'Cst Ctr'(004),
61 sy-vline,
62(10) 'Q2',p_year,
72 sy-vline,
73(10) 'Q3',p_year,
83 sy-vline,
84(10) 'Q4',p_year,
94 sy-vline,
95(10) v_text1,
105 sy-vline,
106(10) 'Q1',l_year2,
116 sy-vline,
117(10) 'Q2',l_year2,
127 sy-vline,
128(10) 'Q3',l_year2,
138 sy-vline,
139(10) v_text2,
150 sy-vline.

ELSEIF p_frprd = 1.
WRITE: / 'Description'(002),
45 sy-vline,
46 'Cst Ctr'(004),
61 sy-vline,
62(10) 'Q1',p_year,
72 sy-vline,
73(10) 'Q2'(006),p_year,
83 sy-vline,
84(10) 'Q3'(007),p_year,
94 sy-vline,
95(10) 'Q4'(008),p_year,
105 sy-vline,
106(10) v_text1,
116 sy-vline,
117(10) 'Q1',l_year2,
127 sy-vline,
128(10) 'Q2',l_year2,
138 sy-vline,
139(10) v_text2,
150 sy-vline.

ENDIF.
FORMAT COLOR COL_HEADING OFF.
ULINE.
ENDFORM. " display_heading
*&---------------------------------------------------------------------
*& Form validate_period
*&---------------------------------------------------------------------
* Validate from period
*----------------------------------------------------------------------
FORM validate_period.
IF p_frprd = 1 OR
p_frprd = 4 OR
p_frprd = 7 OR
p_frprd = 10.
ELSE.
MESSAGE e005 WITH 'Enter a valid period'(012).
ENDIF.
ENDFORM. " validate_period
*&---------------------------------------------------------------------
*& Form validate_toperiod
*&---------------------------------------------------------------------
* Validate to period
*----------------------------------------------------------------------
FORM validate_toperiod.
IF p_toprd = 3 OR
p_toprd = 6 OR
p_toprd = 9 OR
p_toprd = 12.
ELSE.
MESSAGE e005 WITH 'Enter a valid period'(013).
ENDIF.

ENDFORM. " validate_toperiod
*&---------------------------------------------------------------------
*& Form validate_version1
*&---------------------------------------------------------------------
* Validate version1
*----------------------------------------------------------------------
FORM validate_version1.
* Local variable
DATA l_versn1 LIKE cosp-versn. " version1
CLEAR l_versn1.

SELECT versn
INTO l_versn1
FROM tka09 UP TO 1 ROWS
WHERE versn = p_versn1.
ENDSELECT.

IF sy-subrc NE 0.
MESSAGE e005 WITH 'Check the version1 entry'(014).
ENDIF.
ENDFORM. " validate_version1
*&---------------------------------------------------------------------
*& Form validate_version2
*&---------------------------------------------------------------------
* Validate version2
*----------------------------------------------------------------------
FORM validate_version2.
* Local variable
DATA l_versn2 LIKE cosp-versn. " version2
CLEAR l_versn2.

SELECT versn
INTO l_versn2
FROM tka09 UP TO 1 ROWS
WHERE versn = p_versn2.
ENDSELECT.

IF sy-subrc NE 0.
MESSAGE e005 WITH 'Check the version2 entry'(015).
ENDIF.
ENDFORM. " validate_version2
*&---------------------------------------------------------------------
*& Form validate_costcenter
*&---------------------------------------------------------------------
* Validate cost center
*----------------------------------------------------------------------
FORM validate_costcenter.
IF s_cntr-low IS INITIAL AND s_cntr-high IS INITIAL
AND p_cntrgp IS INITIAL.
MESSAGE e005 WITH 'Enter cost center or the cost center group'(016).
ENDIF.
IF NOT s_cntr-low IS INITIAL AND NOT p_cntrgp IS INITIAL.
MESSAGE e005 WITH 'Enter cost center or the cost center group'(016).
ENDIF.

ENDFORM. " validate_costcenter
*&---------------------------------------------------------------------
*& Form validate_costcentergp
*&---------------------------------------------------------------------
* Validate cost center group
*----------------------------------------------------------------------
FORM validate_costcentergp.
IF p_cntrgp IS INITIAL.
CLEAR it_idynpfields.
REFRESH it_idynpfields.
it_idynpfields-fieldname = 'S_CNTR-LOW'.
APPEND it_idynpfields.

CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-cprog
dynumb = '1000'
TABLES
dynpfields = it_idynpfields.
* exceptions
* invalid_abapworkarea = 1
* invalid_dynprofield = 2
* invalid_dynproname = 3
* invalid_dynpronummer = 4
* invalid_request = 5
* no_fielddescription = 6
* invalid_parameter = 7
* undefind_error = 8
* double_conversion = 9
* stepl_not_found = 10
* others = 11.

READ TABLE it_idynpfields.
IF it_idynpfields-fieldvalue = ' '.
MESSAGE e005 WITH 'Enter cost center or the cost center group'(016)
.
ENDIF.
ENDIF.
ENDFORM. " validate_costcentergp
*&---------------------------------------------------------------------
*& Form validate_costelement
*&---------------------------------------------------------------------
* Validate cost element
*----------------------------------------------------------------------
FORM validate_costelement.
IF s_cstele-low IS INITIAL AND p_cstgp IS INITIAL.
MESSAGE e005 WITH 'Enter cost element or the cost element group'(017)
.
ENDIF.
IF NOT s_cstele-low IS INITIAL AND NOT p_cstgp IS INITIAL.
MESSAGE e005 WITH 'Enter cost element or the cost element group'(017) .
ENDIF.

ENDFORM. " validate_costelement
*&---------------------------------------------------------------------
*& Form validate_costelementgp
*&---------------------------------------------------------------------
* Validate cost element group
*----------------------------------------------------------------------
FORM validate_costelementgp.
IF s_cstele-low IS INITIAL.
IF p_cstgp IS INITIAL.
MESSAGE e005 WITH 'Enter cost element or the cost element group'(017)
.
ENDIF.
ENDIF.

ENDFORM. " validate_costelementgp
*&---------------------------------------------------------------------
*& Form cost_cntr_gp_valuehelp
*&---------------------------------------------------------------------
* Search help for cost center group
*----------------------------------------------------------------------
FORM cost_cntr_gp_valuehelp.
CALL FUNCTION 'K_GROUP_SELECT'
EXPORTING
class = '0101'
field_name
='KOSTL'
table = 'CCSS'
IMPORTING
set_name = p_cntrgp
EXCEPTIONS
no_set_picked = 02.

CASE sy-subrc.
WHEN 1.
MESSAGE s005 WITH 'An appropriate object was not found'(018).
WHEN 2.
MESSAGE s005 WITH 'No object was selected'(019).
ENDCASE.

ENDFORM. " cost_cntr_gp_valuehelp
*&---------------------------------------------------------------------
*& Form cost_ele_gp_valuehelp
*&---------------------------------------------------------------------
* Search help for cost element group
*----------------------------------------------------------------------
FORM cost_ele_gp_valuehelp.
CALL FUNCTION 'K_GROUP_SELECT'
EXPORTING
class = '0102'
field_name = 'KSTAR'
table = 'CCSS'
IMPORTING
set_name = p_cstgp
EXCEPTIONS
no_set_picked = 02.


CASE sy-subrc.
WHEN 1.
MESSAGE s005 WITH 'An appropriate object was not found'(018).
WHEN 2.
MESSAGE s005 WITH 'No object was selected'(019).
ENDCASE.


ENDFORM. " cost_ele_gp_valuehelp
*&---------------------------------------------------------------------
*& Form headcount_other_quarts
*&---------------------------------------------------------------------
* Getting the head count data
*----------------------------------------------------------------------
FORM headcount_other_quarts.
DATA : l_objnr LIKE cosr-objnr,
l_year LIKE cosr-gjahr,
l_toprd LIKE coep-perio,
l_rec_cnt TYPE i,
l_length TYPE i,
l_length1 TYPE i.


CLEAR : v_toperiod,
v_toprd,
v_cnt,
l_objnr,
l_year,
l_length,
l_length1.
v_times = p_toprd - p_frprd + 1.

v_ver_start = v_times.
v_times = 18 - v_times.
v_toprd = p_toprd.
l_year = p_year.
CLEAR v_toperiod.

REFRESH s_wrttp.
IF p_versn2 = '000' .
s_wrttp-low = '04'.
s_wrttp-option = 'EQ'.
s_wrttp-sign = 'I'.
APPEND s_wrttp.
ELSE .
REFRESH s_wrttp.
ENDIF.



SELECT * FROM cosr
WHERE lednr = '00' AND
gjahr IN r_year AND
wrttp IN s_wrttp AND
versn = p_versn2 AND
stagr IN s_skey.
CLEAR : v_qt2_tot, v_qt3_tot, v_qt4_tot, v_qt5_tot, v_qt6_tot, v_cnt
.
v_ncnt = v_toprd.
l_year = p_year.
l_objnr = cosr-objnr.
l_length = strlen( l_objnr ).
l_length1 = l_length - 10.


* validation of objnr last four characters with respect to the
* selection screen cost centers
CHECK cosr-objnr+l_length1(10) IN s_cntr.
v_cnt = v_ver_start .
DO v_times TIMES.

v_ncnt = v_ncnt + 1.
IF v_ncnt > 12.
l_year = l_year + 1.
v_ncnt = 1.
* v_cnt = 12. "mmundhada 12/02
PERFORM calculate_v_cnt.
ENDIF.

CHECK cosr-gjahr = l_year.
v_cnt = v_cnt + 1.

CONCATENATE 'cosr-sme' v_ncnt INTO v_toperiod.
CONDENSE v_toperiod NO-GAPS.
ASSIGN (v_toperiod) TO <fs>.
IF v_cnt BETWEEN 4 AND 6.
v_qt2_tot = <fs>.
ELSEIF v_cnt BETWEEN 7 AND 9.
v_qt3_tot = <fs>.
ELSEIF v_cnt BETWEEN 10 AND 12.
v_qt4_tot = <fs>.
ELSEIF v_cnt BETWEEN 13 AND 15.
v_qt5_tot = <fs>.
ELSEIF v_cnt BETWEEN 16 AND 18.
v_qt6_tot = <fs>.
ENDIF.
ENDDO.

READ TABLE it_output WITH KEY cst_ele = cosr-stagr
cost_ctr = cosr-objnr+l_length1(10)
BINARY SEARCH.
IF sy-subrc EQ 0 .
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
it_output-qt5_tot = it_output-qt5_tot + v_qt5_tot.
it_output-qt6_tot = it_output-qt6_tot + v_qt6_tot.
MODIFY it_output INDEX sy-tabix.
CLEAR it_output.
ELSE.
CLEAR tkt03.
SELECT SINGLE * FROM tkt03 WHERE kokrs EQ 'EGLS'
AND stagr EQ cosr-stagr.
it_output-descript = tkt03-bezei.
it_output-key_desc = tkt03-bezei.
it_output-cst_ele = cosr-stagr.
it_output-cost_ctr = cosr-objnr+l_length1(10).
it_output-qt2_tot = it_output-qt2_tot + v_qt2_tot.
it_output-qt3_tot = it_output-qt3_tot + v_qt3_tot.
it_output-qt4_tot = it_output-qt4_tot + v_qt4_tot.
it_output-qt5_tot = it_output-qt5_tot + v_qt5_tot.
it_output-qt6_tot = it_output-qt6_tot + v_qt6_tot.
it_output-sortord = 900.
it_output-sortord1 = 900.
APPEND it_output.
CLEAR it_output.
SORT it_output BY cst_ele cost_ctr.
ENDIF.
CLEAR it_output.
ENDSELECT.
* clear it_output-cst_ele.
* modify it_output transporting cst_ele where cst_ele ne space.

ENDFORM. " headcount_other_quarts
*&---------------------------------------------------------------------
*& Form display_report
*&---------------------------------------------------------------------
* Display the report output
*----------------------------------------------------------------------
FORM display_report.
DATA : fg_gtotal, " flag for grand total display in case of
fg_nodesc VALUE 'X'.
" headcount data
DATA l_sytabix LIKE sy-tabix.
LOOP AT it_out.
l_sytabix = sy-tabix.
* Displaying the Grand total when there is headcount data
AT NEW highlevel1.

READ TABLE it_out INDEX l_sytabix.

IF it_out-highlevel1 IS INITIAL.

IF it_out-descript <> ' ' and L_SYTABIX <> 1.

IF fg_nodesc = 'X'.
ULINE.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
it_out-cost_ctr = ' '.
it_out-cst_ele = ' '.
IF p_frprd = 10.
PERFORM display_grand_total_4q.
ELSEIF p_frprd = 7.
PERFORM display_grand_total_3q.
ELSEIF p_frprd = 4.
PERFORM display_grand_total_2q.
ELSEIF p_frprd = 1.
PERFORM display_grand_total_1q.
ENDIF.
FORMAT COLOR COL_TOTAL OFF.
ULINE.

CLEAR fg_nodesc.
ENDIF.
ENDIF.

ENDIF.
ENDAT.


* Displaying the records corresponding to the cost element which have
* no description and the headcount data
IF it_out-highlevel1 IS INITIAL.
IF it_out-descript <> ' '.
fg_gtotal = 'X'.
* Displaying the grand total when there is headcount data
* and records having no description
IF fg_nodesc = 'X'.
ULINE.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
it_out-cost_ctr = ' '.
it_out-cst_ele = ' '.
IF p_frprd = 10.
PERFORM display_grand_total_4q.
ELSEIF p_frprd = 7.
PERFORM display_grand_total_3q.
ELSEIF p_frprd = 4.
PERFORM display_grand_total_2q.
ELSEIF p_frprd = 1.
PERFORM display_grand_total_1q.
ENDIF.
FORMAT COLOR COL_TOTAL OFF.
ULINE.
CLEAR fg_nodesc.
ENDIF.
ENDIF.
CLEAR : v_total1,
v_total2,
v_total3,
v_total4,
v_total5,
v_total6,
v_total7,
v_total8,
v_total9.

v_total1 = it_out-qt1_tot.
v_total2 = it_out-qt2_tot.
v_total3 = it_out-qt3_tot.
v_total4 = it_out-qt4_tot.
v_total5 = it_out-qt5_tot.
v_total6 = it_out-qt6_tot.
v_total7 = it_out-yr_tot1.
v_total8 = it_out-yr_tot2.
v_total9 = it_out-yr_tot3.

READ TABLE it_out INDEX l_sytabix.

* grand total when there is no headcount data and records corresponding
* to cost elements which have no description
IF it_out-descript = ' '.
v_gtotal1 = v_gtotal1 + v_total1.
v_gtotal2 = v_gtotal2 + v_total2.
v_gtotal3 = v_gtotal3 + v_total3.
v_gtotal4 = v_gtotal4 + v_total4.
v_gtotal5 = v_gtotal5 + v_total5.
v_gtotal6 = v_gtotal6 + v_total6.
v_gtotal7 = v_gtotal7 + v_total7.
v_gtotal8 = v_gtotal8 + v_total8.
v_gtotal9 = v_gtotal9 + v_total9.

ENDIF.

WRITE: / it_out-descript.
IF p_frprd = 10.
PERFORM write_output_for_4q.
ELSEIF p_frprd = 7.
PERFORM write_output_for_3q.
ELSEIF p_frprd = 4.
PERFORM write_output_for_2q.
ELSEIF p_frprd = 1.
PERFORM write_output_for_1q.

ENDIF.
ENDIF.


* Displaying the records for cost element data
AT END OF highlevel4.
IF NOT it_out-highlevel4 IS INITIAL.
CLEAR : v_total1,
v_total2,
v_total3,
v_total4,
v_total5,
v_total6,
v_total7,
v_total8,
v_total9.
SUM.
v_total1 = it_out-qt1_tot.
v_total2 = it_out-qt2_tot.
v_total3 = it_out-qt3_tot.
v_total4 = it_out-qt4_tot.
v_total5 = it_out-qt5_tot.
v_total6 = it_out-qt6_tot.
v_total7 = it_out-yr_tot1.
v_total8 = it_out-yr_tot2.
v_total9 = it_out-yr_tot3.

READ TABLE it_out INDEX l_sytabix.
WRITE: / it_out-highlevel4.

IF p_frprd = 10.
PERFORM write_output_for_4q.
ELSEIF p_frprd = 7.
PERFORM write_output_for_3q.
ELSEIF p_frprd = 4.
PERFORM write_output_for_2q.
ELSEIF p_frprd = 1.
PERFORM write_output_for_1q.

ENDIF.
ENDIF.
ENDAT.

AT END OF highlevel3.
IF NOT it_out-highlevel3 IS INITIAL.
CLEAR : v_total1,
v_total2,
v_total3,
v_total4,
v_total5,
v_total6,
v_total7,
v_total8,
v_total9.
SUM.
v_total1 = it_out-qt1_tot.
v_total2 = it_out-qt2_tot.
v_total3 = it_out-qt3_tot.
v_total4 = it_out-qt4_tot.
v_total5 = it_out-qt5_tot.
v_total6 = it_out-qt6_tot.
v_total7 = it_out-yr_tot1.
v_total8 = it_out-yr_tot2.
v_total9 = it_out-yr_tot3.

READ TABLE it_out INDEX l_sytabix.
IF NOT it_out-highlevel4 IS INITIAL.
ULINE.
FORMAT COLOR COL_POSITIVE ON.
it_out-cost_ctr = ' '.
it_out-cst_ele = ' '.
ENDIF.
WRITE: / it_out-highlevel3.

IF p_frprd = 10.
PERFORM write_output_for_4q.
ELSEIF p_frprd = 7.
PERFORM write_output_for_3q.
ELSEIF p_frprd = 4.
PERFORM write_output_for_2q.
ELSEIF p_frprd = 1.
PERFORM write_output_for_1q.

ENDIF.
IF NOT it_out-highlevel4 IS INITIAL.
FORMAT COLOR COL_POSITIVE OFF.
ULINE.
ENDIF.

ENDIF.
ENDAT.

AT END OF highlevel2.
IF NOT it_out-highlevel2 IS INITIAL.
CLEAR : v_total1,
v_total2,
v_total3,
v_total4,
v_total5,
v_total6,
v_total7,
v_total8,
v_total9.
SUM.
v_total1 = it_out-qt1_tot.
v_total2 = it_out-qt2_tot.
v_total3 = it_out-qt3_tot.
v_total4 = it_out-qt4_tot.
v_total5 = it_out-qt5_tot.
v_total6 = it_out-qt6_tot.
v_total7 = it_out-yr_tot1.
v_total8 = it_out-yr_tot2.
v_total9 = it_out-yr_tot3.

READ TABLE it_out INDEX l_sytabix.
IF NOT it_out-highlevel3 IS INITIAL.
ULINE.
FORMAT COLOR COL_GROUP ON.
it_out-cost_ctr = ' '.
it_out-cst_ele = ' '.
ENDIF.

WRITE: / it_out-highlevel2.

IF p_frprd = 10.
PERFORM write_output_for_4q.
ELSEIF p_frprd = 7.
PERFORM write_output_for_3q.
ELSEIF p_frprd = 4.
PERFORM write_output_for_2q.
ELSEIF p_frprd = 1.
PERFORM write_output_for_1q.

ENDIF.
IF NOT it_out-highlevel3 IS INITIAL.
FORMAT COLOR COL_GROUP OFF.
ULINE.
ENDIF.
ENDIF.
ENDAT.

AT END OF highlevel1.
IF NOT it_out-highlevel1 IS INITIAL.

CLEAR : v_total1,
v_total2,
v_total3,
v_total4,
v_total5,
v_total6,
v_total7,
v_total8,
v_total9.
SUM.
v_total1 = it_out-qt1_tot.
v_total2 = it_out-qt2_tot.
v_total3 = it_out-qt3_tot.
v_total4 = it_out-qt4_tot.
v_total5 = it_out-qt5_tot.
v_total6 = it_out-qt6_tot.
v_total7 = it_out-yr_tot1.
v_total8 = it_out-yr_tot2.
v_total9 = it_out-yr_tot3.

* Storing the Grand total
v_gtotal1 = v_gtotal1 + v_total1.
v_gtotal2 = v_gtotal2 + v_total2.
v_gtotal3 = v_gtotal3 + v_total3.
v_gtotal4 = v_gtotal4 + v_total4.
v_gtotal5 = v_gtotal5 + v_total5.
v_gtotal6 = v_gtotal6 + v_total6.
v_gtotal7 = v_gtotal7 + v_total7.
v_gtotal8 = v_gtotal8 + v_total8.
v_gtotal9 = v_gtotal9 + v_total9.


READ TABLE it_out INDEX l_sytabix.
IF NOT it_out-highlevel2 IS INITIAL.
ULINE.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
it_out-cost_ctr = ' '.
it_out-cst_ele = ' '.
ENDIF.
WRITE: / it_out-highlevel1.

IF p_frprd = 10.
PERFORM write_output_for_4q.
ELSEIF p_frprd = 7.
PERFORM write_output_for_3q.
ELSEIF p_frprd = 4.
PERFORM write_output_for_2q.
ELSEIF p_frprd = 1.
PERFORM write_output_for_1q.

ENDIF.
IF NOT it_out-highlevel2 IS INITIAL.
FORMAT COLOR COL_TOTAL OFF.
ULINE.
ENDIF.
ENDIF.
ENDAT.

* Displaying the Grand total when there is no headcount data and
* when there are cost element records which have no description
AT LAST.
IF fg_gtotal <> 'X'.
IF fg_nodesc = 'X'.
ULINE.
FORMAT COLOR COL_TOTAL INTENSIFIED ON.
it_out-cost_ctr = ' '.
it_out-cst_ele = ' '.
IF p_frprd = 10.
PERFORM display_grand_total_4q.
ELSEIF p_frprd = 7.
PERFORM display_grand_total_3q.
ELSEIF p_frprd = 4.
PERFORM display_grand_total_2q.
ELSEIF p_frprd = 1.
PERFORM display_grand_total_1q.
ENDIF.
FORMAT COLOR COL_TOTAL OFF.
ULINE.
CLEAR fg_nodesc.
ENDIF.
ELSE.
ULINE.
ENDIF.
ENDAT.

ENDLOOP.
ENDFORM. " display_report
*&---------------------------------------------------------------------

*& Form transfer_data
*&---------------------------------------------------------------------

* Transfer the output data to the final internal table
*----------------------------------------------------------------------
FORM transfer_data.
LOOP AT it_output.
MOVE-CORRESPONDING it_output TO it_out.
APPEND it_out.
CLEAR it_out.
ENDLOOP.

ENDFORM. " transfer_data
*&---------------------------------------------------------------------
*& Form write_output_for_1q
*&---------------------------------------------------------------------
* Display the output if the first quarter of the year entered
*----------------------------------------------------------------------
FORM write_output_for_1q.

WRITE : 45 sy-vline,
46 v_cstcenter NO-ZERO,
61 sy-vline,
62(10) v_total1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_total2 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_total3 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_total4 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_total7 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_total5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_total6 ROUND 3 NO-ZERO,
138 sy-vline,
139(10) v_total8 ROUND 3 NO-ZERO,
150 sy-vline.

ENDFORM. " write_output_for_1q
*&---------------------------------------------------------------------
*& Form display_grand_total_1q
*&---------------------------------------------------------------------
* Display the grand total if the first quarter of the year entered
*----------------------------------------------------------------------
FORM display_grand_total_1q.
WRITE: / 'Grand Total'(022),
45 sy-vline,
46 ' ',
61 sy-vline,
62(10) v_gtotal1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_gtotal2 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_gtotal3 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_gtotal4 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_gtotal7 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_gtotal5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_gtotal6 ROUND 3 NO-ZERO,
138 sy-vline,
139(10) v_gtotal8 ROUND 3 NO-ZERO,
150 sy-vline.


ENDFORM. " display_grand_total_1q
*&---------------------------------------------------------------------
*& Form write_output_for_4q
*&---------------------------------------------------------------------
* Display the output if the last quarter of the year entered
*----------------------------------------------------------------------
FORM write_output_for_4q.
WRITE : 45 sy-vline,
46 v_cstcenter NO-ZERO ,
61 sy-vline,
62(10) v_total1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_total7 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_total2 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_total3 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_total4 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_total5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_total8 ROUND 3 NO-ZERO,
138 sy-vline,
139(10) v_total6 ROUND 3 NO-ZERO,
150 sy-vline,
151(10) v_total9 ROUND 3 NO-ZERO,
161 sy-vline.

ENDFORM. " write_output_for_4q
*&---------------------------------------------------------------------
*& Form display_grand_total_4q
*&---------------------------------------------------------------------
* Display the grand total if the last quarter of the year entered
*----------------------------------------------------------------------
FORM display_grand_total_4q.
WRITE :/ 'Grand Total'(022),
45 sy-vline,
46 ' ',
61 sy-vline,
62(10) v_gtotal1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_gtotal7 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_gtotal2 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_gtotal3 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_gtotal4 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_gtotal5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_gtotal8 ROUND 3 NO-ZERO,
138 sy-vline,
139(10) v_gtotal6 ROUND 3 NO-ZERO,
150 sy-vline,
151(10) v_gtotal9 ROUND 3 NO-ZERO,
161 sy-vline.

ENDFORM. " display_grand_total_4q
*&---------------------------------------------------------------------*
*& Form append_records_to_node
*&---------------------------------------------------------------------*
* append the records to internal table it_node
*----------------------------------------------------------------------*
FORM append_records_to_node.
LOOP AT it_costelements.
MOVE it_costelements-valfrom TO it_node-valfrom.
MOVE it_costelements-valto TO it_node-valto.

it_node-descript = it_cstnodes-descript.
APPEND it_node.
it_cstnodes-valcount = it_cstnodes-valcount - 1.
DELETE it_costelements.
IF it_cstnodes-valcount EQ 0 .
EXIT.
ENDIF.
ENDLOOP.

ENDFORM. " append_records_to_node
*&---------------------------------------------------------------------*
*& Form display_grand_total_3q
*&---------------------------------------------------------------------*
* Display grand total if third quarter is entered on selection screen
*----------------------------------------------------------------------*
FORM display_grand_total_3q.
WRITE: / 'Grand Total'(022),
45 sy-vline,
46 ' ',
61 sy-vline,
62(10) v_gtotal1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_gtotal2 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_gtotal7 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_gtotal3 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_gtotal4 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_gtotal5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_gtotal6 ROUND 3 NO-ZERO,
138 sy-vline,
139(10) v_gtotal8 ROUND 3 NO-ZERO,
150 sy-vline.

ENDFORM. " display_grand_total_3q
*&---------------------------------------------------------------------*
*& Form display_grand_total_2q
*&---------------------------------------------------------------------*
* Display grand total if second quarter is entered on selection screen
*----------------------------------------------------------------------*
FORM display_grand_total_2q.
WRITE: / 'Grand Total'(022),
45 sy-vline,
46 ' ',
61 sy-vline,
62(10) v_gtotal1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_gtotal2 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_gtotal3 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_gtotal7 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_gtotal4 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_gtotal5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_gtotal6 ROUND 3 NO-ZERO,
138 sy-vline,
139(10) v_gtotal8 ROUND 3 NO-ZERO,
150 sy-vline.

ENDFORM. " display_grand_total_2q
*&---------------------------------------------------------------------*
*& Form write_output_for_3q
*&---------------------------------------------------------------------*
* Display output if third quarter is entered on selection screen
*----------------------------------------------------------------------*
FORM write_output_for_3q.
WRITE : 45 sy-vline,
46 v_cstcenter NO-ZERO ,
61 sy-vline,
62(10) v_total1 ROUND 3 NO-ZERO,
72 sy-vline,
73(10) v_total2 ROUND 3 NO-ZERO,
83 sy-vline,
84(10) v_total7 ROUND 3 NO-ZERO,
94 sy-vline,
95(10) v_total3 ROUND 3 NO-ZERO,
105 sy-vline,
106(10) v_total4 ROUND 3 NO-ZERO,
116 sy-vline,
117(10) v_total5 ROUND 3 NO-ZERO,
127 sy-vline,
128(10) v_total6
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> CO All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.