Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Reg:Display data using ALV

Former Member
0 Kudos

Hi all,

In my Requirent i want to Display data like this Using ALV.

Please help me how to display data using alv like this.

From: Plant. Order nr : Po.Number

To: Vendor Number

Date: System Date Doc. Currency : EUR

Ship To: Ship to Address Invoice To: Invoice Address.

4 REPLIES 4

former_member598013
Active Contributor
0 Kudos

Hi Venkar,

Check out the Sample code for your reference.


***********************************************************************
* 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 <> 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 <> 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 round 3 no-zero,
            138 sy-vline,
            139(10) v_total8 round 3 no-zero,
            150 sy-vline.

endform.                    " write_output_for_3q
*&---------------------------------------------------------------------*
*&      Form  write_output_for_2q
*&---------------------------------------------------------------------*
*    Display output if second quarter is entered on selection screen
*----------------------------------------------------------------------*
form write_output_for_2q.
  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_total7 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 round 3 no-zero,
            138 sy-vline,
            139(10) v_total8 round 3 no-zero,
            150 sy-vline.

endform.                    " write_output_for_2q
*&---------------------------------------------------------------------*
*&      Form  display_cst_element
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_cst_element.
data v_lines like sy-index.
describe table s_cstele lines v_lines.

clear: v_cost_element.
if not p_cstgp is initial.
  clear v_cost_element.
elseif s_cstele-high is initial and v_lines le 1.
 v_cost_element = s_cstele-low.
else.
 clear v_cost_element.
endif.


describe table s_cstele lines v_lines.

clear: v_cstcenter.
if not p_cntrgp is initial.
 v_cstcenter = p_cntrgp.
elseif s_cntr-high is initial and v_lines le 1.
 v_cstcenter = s_cntr-low.
else.
 clear v_cstcenter.
endif.


ENDFORM.                    " display_cst_element
*&---------------------------------------------------------------------*
*&      Form  add_headcount
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM add_headcount.

it_output1[] = it_output[].
refresh it_output.
clear it_output.

loop at it_output1.
clear it_output1-cost_ctr.
move-corresponding it_output1 to it_output.
collect it_output.
endloop.

ENDFORM.                    " add_headcount
*&---------------------------------------------------------------------*
*&      Form  calculate_v_cnt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM calculate_v_cnt.
if p_frprd eq 1.
 v_cnt  = 12.
elseif p_frprd = 4.
 v_cnt = 09.
elseif p_frprd = 7.
 v_cnt = 6.
elseif p_frprd = 10.
 v_cnt = 3.
endif.
ENDFORM.                    " calculate_v_cnt

Thanks,

Chidanand

Former Member
0 Kudos

Use Function module REUSE_ALV_GRID_DISPLAY and pass your internal table to it. Also use TOP_OF_PAGE event for getting the page header as you desire.

I presume the data fetching logic you would have already taken care of.

Alternately you can also use method set_table_for_first_display of class CL_GUI_ALV_GRID to display ALV grid.

Regards,

Former Member
0 Kudos

hi,

go throu the following link,it will give brief idea of how ALV works:

[http://saptechnical.com/Tutorials/ALV/Interactive/demo.htm]

Former Member
0 Kudos

Pls gothrough with these example programs you will get an idea of doing ALV programs.

BALVSD02_GRID

BALVST02_GRID

BALVST03_GRID

BCALV_GRID_01

BCALV_GRID_02

BCALV_GRID_03

BCALV_GRID_04

BCALV_GRID_05

BCALV_GRID_06

BCALV_GRID_07

BCALV_GRID_08

BCALV_GRID_09

BCALV_GRID_10

BCALV_GRID_11

++++++++++++++

BALVBT01

BALVBT02

BALVHD01

BALVHD01_GROUP

BALVHM10

BALVHM12

BALVHT01

BALVSD01

BALVSD03

BALVSD04

BALVSD11

BALVSM03

BALVSM04

BALVSM11

BALVST01

BALVST02

BALVST02_GRID

BALVST03_GRID

BCALV_EDIT_06

BCALV_EDIT_07

BCALV_GRID_02

BCALV_GRID_03

BCALV_GRID_10

Regards,

Ramesh.