ZPPR014:Consolidate Material Receipt Value Report

38 篇文章 2 订阅

*&---------------------------------------------------------------------*
*& Progarm      :  ZPPR014                        Author : Jimmy Wong
*& Created      :  12 Oct 2012                    App    : PP
*& Title        :  Consolidate Material Receipt Value Report
*& Description  :  Consolidate Material Receipt Value Report
*&                 from Current Month Begin
*&---------------------------------------------------------------------*
*&  Version       Author      Date        description
*&                Jimmy       12 Oct 2012 the first version
*& M1             Jimmy       14 Dec 2012 Add selection PO / PR
*& M1             Jimmy       03 Jan 2013 Enhance
*&  the last update time  2013.01.03 10:00
*&---------------------------------------------------------------------*

report  zppr014 no standard page heading line-size 120.
*&---------------------------------------------------------------------*
* database table
*&---------------------------------------------------------------------*
tables : ekpo,tfkfsd,eket,eban.
*&---------------------------------------------------------------------*
* internal table & variables
*&---------------------------------------------------------------------*
data: begin of it_detail occurs 0,
      year_mm(7) type c,
      mm_flag type c,
      ptype(10)  type c,
      ebeln   like ekko-ebeln,
      ebelp   like ekpo-ebelp,
      werks   like ekpo-werks,
      matnr   like ekpo-matnr,
      matnr_c type c length 20,
      maktx   like makt-maktx,
      menge   like ekpo-menge,
      wemng like eket-wemng,
      netpr   like ekpo-netpr,
      peinh   like ekpo-peinh,
      netwr   like ekpo-netwr,
      lifnr   like ekko-lifnr,
      waers   like ekko-waers,
      frgke   like ekko-frgke,
      eindt   like eket-eindt,
      wkurs   like ekko-wkurs,
      end of it_detail.
data:it_po like it_detail occurs 0 with header line.
data:it_po_collect like it_detail occurs 0 with header line.
data:it_detail1 like it_detail occurs 0 with header line.
data:it_pr like it_detail occurs 0 with header line.
data:it_pr_collect like it_detail occurs 0 with header line.
field-symbols: <it_summ> type standard table,
               <wa_summ>,
               <wa_field>.
data: it_structure type lvc_t_fcat,
      wa_structure type lvc_s_fcat,
      it_summ type ref to data.
data:begin of it_plant occurs 0,
      werks like ekpo-werks,
     end of it_plant.
data: begin of it_field occurs 0,
      year_mm(7) type c,
      mm_flag type c,
      fieldname(10) type c,
      fielddesc(40) type c,
      end of it_field.
data: lv_i type i.
data:lv_first type sy-datum,
     lv_last type sy-datum,
     lv_from type sy-datum,
     lv_to type sy-datum,
     lv_low type c .
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
      wa_hier type slis_fieldcat_alv .
data:it_sort  type slis_t_sortinfo_alv,
     wa_sort  like line of  it_sort,
     wa_layout type slis_layout_alv,
     wa_events type slis_t_event.
data:begin of it_ekes occurs 0,
     ebeln    like ekes-ebeln,
     ebelp    like ekes-ebelp,
     etens    like ekes-etens,
     eindt    like ekes-eindt,
     menge    like ekes-menge,
     end of it_ekes.
data: it_ekes2 like it_ekes occurs 0 with header line  .
data:begin of it_eket occurs 0,
     ebeln    like ekes-ebeln,
     ebelp    like ekes-ebelp,
     etenr    like eket-etenr,
     eindt    like ekes-eindt,
     menge    like eket-menge,
     wemng    like eket-wemng,
     end of it_eket.
data:begin of it_eket_total occurs 0,
     ebeln    like ekes-ebeln,
     ebelp    like ekes-ebelp,
     menge    like eket-menge,
     wemng    like eket-wemng,
     end of it_eket_total.
data:begin of it_mbew occurs 0,
    matnr like mbew-matnr,
    bwkey like mbew-bwkey ,
    verpr like mbew-verpr ,
    stprs like mbew-stprs ,
    peinh like mbew-peinh ,
    end of it_mbew.
data:lv_total_line type i,
      lv_line type p decimals 3.
define alv_field.
  clear:wa_hier.
  wa_hier-fieldname = &1.
  wa_hier-seltext_m = &2.
  wa_hier-seltext_l = &3.
  wa_hier-outputlen = &4.
  wa_hier-just = &5.
  wa_hier-do_sum = &6.
  wa_hier-ref_tabname = &7 .
  wa_hier-ref_fieldname = &8 .

  append wa_hier to fc_hier.
end-of-definition.
*----------------------------------------------------------------------*
*  Parameter & Select-Options                                          *
*----------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-001.
select-options: s_matnr for ekpo-matnr.
select-options: s_werks for ekpo-werks.
selection-screen begin of line.
selection-screen position 1.
parameters:  p_po as checkbox default 'X'.
selection-screen comment 3(12) com1.
selection-screen position 30.
select-options: s_ebeln for ekpo-ebeln.
selection-screen end of line.
selection-screen begin of line.
selection-screen position 1.
parameters:  p_pr as checkbox default 'X'.
selection-screen comment 3(12) com2.
selection-screen position 30.
select-options: s_banfn for eban-banfn.                     "M1 Add
selection-screen end of line.

parameters: p_eindt like eket-eindt default sy-datum  no-display.
parameters: s_num  type  tfkfsd-length   default '1' no-display.
select-options: s_eindt for eket-eindt  . "no-display.
parameters:p_summ radiobutton group gr1 ,
           p_detail radiobutton group gr1.
selection-screen end of block 1.

initialization.
  com1 = 'PO No'.
  com2 = 'PR No'.
  s_eindt-sign = 'I'.
  s_eindt-option = 'BT'.
  concatenate  sy-datum+0(4) sy-datum+4(2) '01' into s_eindt-low.
  perform get_last_day using s_eindt-low  changing  s_eindt-high.
  append s_eindt.

*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
  if s_eindt-high is initial.
    message 'Please input Delivery Date To' type 'I'.
    exit.
  endif.
  perform get_date.
  perform get_data.

  if it_detail[] is initial and it_detail1[] is initial .
    message 'No Record Found' type 'I'.
    exit.
  endif.
  if not it_detail[] is initial.
    perform process_po_data.
  endif.
  if not it_detail1[] is initial.
    perform process_pr_data.
  endif.

  if p_detail = 'X'.
    perform dispaly_detail_data.
  endif.
  if p_summ = 'X'.
    perform get_date_fieldname.
    perform create_structure.
    perform create_dynamic_table.  " 按照定义的内表结构,产生一个内表
    perform get_summ_data.
    perform dispaly_suumary_data.
  endif.

end-of-selection.
*&---------------------------------------------------------------------*
*&      Form  GET_DATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_date .
  data:lv_year(4) type c,
       lv_current type sy-datum.
  concatenate  sy-datum+0(4) sy-datum+4(2) '01' into lv_current.
  if s_num is initial.
    s_num = 1.
  endif.

  clear: lv_low.
  if s_eindt-low is not initial.
    concatenate s_eindt-low+0(4) s_eindt-low+4(2) '01' into lv_first.
    lv_from = lv_first.
    perform get_last_day using s_eindt-high  changing  lv_last.
    lv_last = lv_last + 1.
    lv_to = lv_last .
    lv_low = 'X'.
  else.
    if s_eindt-high >= lv_current.
      lv_first = lv_current.
      lv_from = '00000000'.
      perform get_last_day using s_eindt-high  changing  lv_last.
      lv_last = lv_last + 1.
      lv_to = lv_last .
    else.
      lv_from = '00000000'.
      perform get_last_day using s_eindt-high  changing  lv_last.
      lv_last = lv_last + 1.
      lv_to = lv_last .
      lv_year  = lv_last+0(4) - s_num .
      concatenate lv_year+0(4) lv_last+4(2) '01' into lv_first.
      perform get_last_month using  lv_first 0 changing  lv_first.
      concatenate lv_first+0(4) lv_first+4(2) '01' into lv_first.
    endif.
  endif.
  refresh s_eindt.
  s_eindt-sign = 'I'.
  s_eindt-option = 'BT'.
  s_eindt-low =  lv_from.
  s_eindt-high = lv_to  - 1.
  append s_eindt.

*  s_eindt-sign = 'I'.
*  s_eindt-option = 'BT'.
*  concatenate p_eindt+0(4) p_eindt+4(2) '01' into s_eindt-low.
*  lv_first = s_eindt-low.
*  lv_year  = p_eindt+0(4) + s_num .
*  concatenate lv_year+0(4) p_eindt+4(2) '01' into s_eindt-high.
*  lv_last = s_eindt-high.
*  s_eindt-high = s_eindt-high - 1.
*  append s_eindt.

endform.                    " GET_DATE


*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_data .

  clear:it_detail,it_detail[] ,it_detail1,it_detail1[],it_po,it_po[],it_pr,it_pr[].
  "PO data
  if p_po = 'X'.
    select distinct b~ebeln b~ebelp b~werks b~matnr b~menge b~netpr b~peinh b~netwr
          a~lifnr a~waers a~frgke a~wkurs c~maktx
        into corresponding fields of table it_detail
        from  ekko as a
              inner join ekpo as b on a~ebeln = b~ebeln
              inner join eket as d on a~ebeln = d~ebeln and b~ebelp = d~ebelp
              left join makt as c on b~matnr = c~matnr and c~spras = sy-langu
        where b~ebeln in s_ebeln                            "M1 Add
          and b~matnr in s_matnr
          and b~werks in s_werks
          and b~loekz = space   "no delete
          and d~eindt in s_eindt.
  endif.
  "PR Data
  if p_pr = 'X'.
    select b~banfn as ebeln b~bnfpo as ebelp b~werks b~matnr b~menge b~bsmng as wemng
          b~lfdat as eindt b~frgkz as frgke c~maktx
        into corresponding fields of table it_detail1
        from eban as b
            left join makt as c on b~matnr = c~matnr and c~spras = sy-langu
        where b~banfn in s_banfn                            "M1 Add
          and b~matnr in s_matnr
          and b~werks in s_werks
          and b~lfdat in s_eindt
          and b~loekz = space . "no delete
  endif.
endform.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form process_po_data .
  data:lv_menge like ekpo-menge.

  call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      text = 'Processing PO Data........'.
  sort it_detail by ebeln ebelp.


  select  ebeln ebelp etenr menge wemng eindt
   into corresponding fields of table it_eket
   from eket
   for all entries in it_detail
   where ebeln = it_detail-ebeln
       and ebelp = it_detail-ebelp
       and eindt in s_eindt.
  sort it_eket by ebeln ebelp.
  loop at it_eket .
    move-corresponding it_eket to it_eket_total.
    collect it_eket_total.
    clear:it_eket_total.
  endloop.
  sort it_eket_total by ebeln ebelp.


  select ebeln ebelp etens eindt  menge
      into corresponding fields of table it_ekes2
    from ekes
    for all entries in it_detail
      where ebeln = it_detail-ebeln
          and ebelp = it_detail-ebelp
          and eindt in s_eindt
          and ebtyp = 'OA'.
  delete it_ekes2 where eindt eq '00000000' .
  sort it_ekes2 by ebeln ebelp.

  describe table it_detail lines lv_total_line.
  loop at it_detail.
    lv_line =  sy-tabix  / lv_total_line * 100.
    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        percentage = lv_line
        text       = 'Processing PO Data........'.
    move-corresponding it_detail to it_po.

    read table it_eket_total with  key ebeln = it_po-ebeln  ebelp = it_po-ebelp binary search.
    if sy-subrc eq 0.

      it_po-wemng =  it_eket_total-wemng.
      it_po-menge = it_po-menge - it_po-wemng  .   " Open Qty

      check it_po-menge ne 0.

      read table it_ekes2 with   key ebeln = it_po-ebeln ebelp = it_po-ebelp.
      if sy-subrc ne 0.
        read table it_eket_total with  key ebeln = it_po-ebeln  ebelp = it_po-ebelp binary search.
        if sy-subrc eq 0.
          loop at  it_eket where  ebeln = it_po-ebeln and ebelp = it_po-ebelp.
            move-corresponding it_eket to it_ekes.
            append it_ekes.
            clear it_ekes.
          endloop.
        endif.
      else.
        loop at  it_ekes2 where  ebeln = it_po-ebeln and ebelp = it_po-ebelp.
          move-corresponding it_ekes2  to it_ekes.
          append it_ekes.
          clear it_ekes.
        endloop.
      endif.

      check not it_ekes[] is initial.

      perform check_po_pr_type using it_po-frgke
                                    'PO'
                             changing it_po-ptype.

      if it_po-waers <> 'HKD'.
        perform tranfer_amount using it_po-waers
                               changing it_po-wkurs
                                        it_po-netpr.
      endif.

      lv_menge = it_po-menge.
      sort it_ekes by eindt descending.
      loop at it_ekes.
        if lv_menge >= it_ekes-menge.
          it_po-menge = it_ekes-menge.
        else.
          it_po-menge = lv_menge.
        endif.
        lv_menge = lv_menge - it_ekes-menge.
        it_po-eindt = it_ekes-eindt.

        if it_po-peinh ne 0.
          it_po-netwr = it_po-netpr * it_po-menge / it_po-peinh.
        else.
          it_po-netwr = 0.
        endif.
        perform tranfer_year_month using it_po-eindt
                                  changing it_po-year_mm
                                           it_po-mm_flag.
        append it_po.

        it_plant-werks = it_po-werks.
        collect it_plant.

        if p_summ = 'X'.  " sum
          it_po_collect-year_mm = it_po-year_mm .
          it_po_collect-mm_flag = it_po-mm_flag.
          it_po_collect-ptype = it_po-ptype.
          it_po_collect-werks = it_po-werks .
          it_po_collect-netwr = it_po-netwr .
          collect it_po_collect.
          clear it_po_collect.
        endif.
        if lv_menge <= 0.
          exit.
        endif.
      endloop.
    endif.
    clear:it_po,it_ekes,it_ekes[].
  endloop.
  free : it_ekes,it_ekes2,it_eket,it_detail,it_eket_total.
endform.                    " PROCESS_DATA
*&---------------------------------------------------------------------*
*&      Form  PROCESS_PR_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form process_pr_data .

  call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      text = 'Processing PR Data........'.
  sort it_detail1 by ebeln ebelp.

  select matnr bwkey verpr stprs peinh
      into corresponding fields of table it_mbew
      from mbew
      for all entries in it_detail1
      where matnr = it_detail1-matnr
        and bwkey = it_detail1-werks.
  sort it_mbew by matnr bwkey.

  describe table it_detail1 lines lv_total_line.
  loop at it_detail1.
    lv_line =  sy-tabix  / lv_total_line * 100.
    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        percentage = lv_line
        text       = 'Processing PR Data........'.
    move-corresponding it_detail1 to it_pr.
    if not it_pr-eindt is initial.

      it_pr-menge = it_pr-menge - it_pr-wemng.
      check  it_pr-menge ne 0.

      read table it_mbew with  key matnr = it_pr-matnr  bwkey = it_pr-werks binary search.
      if sy-subrc eq 0.
        it_pr-peinh =  it_mbew-peinh.
        it_pr-netpr =  it_mbew-verpr.
        if it_pr-peinh ne 0.
          it_pr-netwr = it_pr-netpr * it_pr-menge / it_pr-peinh.
        endif.
      endif.


      perform check_po_pr_type using it_pr-frgke
                                    'PR'
                             changing it_pr-ptype.


      perform tranfer_year_month using it_pr-eindt
                                changing it_pr-year_mm
                                         it_pr-mm_flag.
      append it_pr.
      it_plant-werks = it_pr-werks.
      collect it_plant.

      if p_summ = 'X'.
        it_pr_collect-year_mm = it_pr-year_mm .
        it_pr_collect-mm_flag = it_pr-mm_flag.
        it_pr_collect-ptype = it_pr-ptype.
        it_pr_collect-werks = it_pr-werks .
        it_pr_collect-netwr = it_pr-netwr .
        collect it_pr_collect.
        clear it_pr_collect.
      endif.
    endif.
    clear:it_pr.
  endloop.
  free : it_mbew,it_detail1.
endform.                    " PROCESS_PR_DATA
*&---------------------------------------------------------------------*
*&      Form  TRANFER_AMOUNT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_PO_WAERS  text
*      -->P_IT_PO_NETPR  text
*      <--P_IT_PO_NETPR  text
*----------------------------------------------------------------------*
form tranfer_amount  using    p_waers
                     changing p_wkurs
                              p_netpr type ekpo-netpr.
  data: curr_ex like bapicurr-bapicurr .
  data: fa like vbrp-kursk.
  data: fn like bapiacitemo-net_amount.
  if not p_waers is initial.
    curr_ex  = p_wkurs .
    call function 'BAPI_CURRENCY_CONV_TO_INTERNAL'
      exporting
        currency             = p_waers
        amount_external      = curr_ex
        max_number_of_digits = 13
      importing
        amount_internal      = fa.
    p_wkurs = fa.
    clear:curr_ex .
    curr_ex  = p_netpr .
    call function 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
      exporting
        currency        = p_waers
        amount_internal = curr_ex
      importing
        amount_external = fn.
    p_netpr = fn.
    p_netpr = p_netpr * p_wkurs.
  endif.
endform.                    " TRANFER_AMOUNT
*&---------------------------------------------------------------------*
*&      Form  TRANFER_YEAR_MONTH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_PO_EINDT  text
*      <--P_IT_PO_YEAR_MM  text
*----------------------------------------------------------------------*
form tranfer_year_month  using    p_eindt
                         changing p_year_mm
                                  p_mm_flag.
  data:lv_year(4) type c,
       lv_mm(2) type c,
       lv_mid type sy-datum,
       lv_tmpdate type sy-datum.
  if lv_low = 'X'.
    lv_tmpdate = p_eindt.
  else.
    if p_eindt < lv_first.
      lv_tmpdate = lv_first.
    else.
      lv_tmpdate = p_eindt.
    endif   .
  endif.
  lv_year = lv_tmpdate+0(4).
  lv_mm = lv_tmpdate+4(2).
  concatenate lv_year lv_mm  '15' into lv_mid .
  concatenate lv_year '/' lv_mm   into p_year_mm .
  if p_eindt <= lv_mid .
    p_mm_flag = 'A'.
  else.
    p_mm_flag = 'B'.
  endif.
endform.                    " TRANFER_YEAR_MONTH
*&---------------------------------------------------------------------*
*&      Form  CHECK_PO_PR_TYPE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_PO_FRGKE  text
*      <--P_IT_PO_PTYPE  text
*----------------------------------------------------------------------*
form check_po_pr_type  using    p_frgke
                                p_popr
                       changing p_ptype.

  if p_popr = 'PO'.
    if p_frgke = 'R'.
      p_ptype = 'PO(Rel)'.
    else.
      p_ptype = 'PO(No-Rel)'.
    endif.
  elseif p_popr = 'PR'.
    if p_frgke = '2'.
      p_ptype = 'PR(Rel)'.
    else.
      p_ptype = 'PR(No-Rel)'.
    endif.
  endif.
endform.                    " CHECK_PO_PR_TYPE
*&---------------------------------------------------------------------*
*&      Form  CREATE_STRUCTURE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_structure .

  wa_structure-fieldname = 'WERKS'.  " 第一列列名
  wa_structure-col_pos   = 1.       " 表示第一列 --- 可心省略,默认情况下,第一行对应到生产内表的第一列,如果指定,则按指定的列顺序生成内表
  wa_structure-inttype = 'C'.       " 数据类型
  wa_structure-intlen = 4.          " 长度
  append wa_structure to it_structure.

  wa_structure-fieldname = 'PTYPE'.
  wa_structure-col_pos   = 2.
  wa_structure-inttype = 'C'.
  wa_structure-intlen = 10.
  append wa_structure to it_structure.

  lv_i = 3.
  loop at it_field.
    wa_structure-fieldname = it_field-fieldname.
    wa_structure-col_pos   =  lv_i.
    wa_structure-datatype =  'DEC' .
    wa_structure-inttype = 'P'."ekpo-netwr .
    wa_structure-intlen = 20.
    wa_structure-decimals = 2.
    append wa_structure to it_structure.

    lv_i = lv_i + 1.
  endloop.

endform.                    " CREATE_STRUCTURE
*&---------------------------------------------------------------------*
*&      Form  GET_DATE_FIELDNAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_date_fieldname .
  data:lv_date type sy-datum,
       lv_lastdate type sy-datum ,
       lv_year(4) type c,
       lv_month(2) type c,
       lv_en_month(3) type c,
       lv_day(5) type c.

  lv_date = lv_first.
  clear:it_field,it_field[].
  while lv_date < lv_last.
    call function 'RP_LAST_DAY_OF_MONTHS'
      exporting
        day_in            = lv_date
      importing
        last_day_of_month = lv_lastdate.

    lv_year = lv_date+0(4).
    lv_month = lv_date+4(2) .
    lv_day  = lv_lastdate+6(2) .

    concatenate lv_year  '/' lv_month  into it_field-year_mm .
    it_field-mm_flag = 'A'.
    concatenate lv_year  lv_month it_field-mm_flag  into it_field-fieldname .
    translate it_field-fieldname to upper case.
    perform get_en_month using lv_month
                         changing lv_en_month.
    concatenate lv_year  lv_en_month '1-15'  into it_field-fielddesc separated by space.
    append it_field.

    it_field-mm_flag = 'B'.
    concatenate lv_year lv_month it_field-mm_flag  into it_field-fieldname .
    translate it_field-fieldname to upper case.
    concatenate '16-' lv_day  into lv_day .
    concatenate lv_year  lv_en_month  lv_day  into it_field-fielddesc separated by space .
    append it_field.

    perform get_last_month using  lv_date 1 changing  lv_date.
  endwhile.

endform.                    " GET_DATE_FIELDNAME
*&---------------------------------------------------------------------*
*&      Form  GET_EN_MONTH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LV_MONTH  text
*----------------------------------------------------------------------*
form get_en_month  using    p_month
                   changing p_en_month.
  case p_month.
    when '01'.
      p_en_month = 'Jan'.
    when '02'.
      p_en_month = 'Feb'.
    when '03'.
      p_en_month = 'Mar'.
    when '04'.
      p_en_month = 'Apr'.
    when '05'.
      p_en_month = 'May'.
    when '06'.
      p_en_month = 'Jun'.
    when '07'.
      p_en_month = 'Jul'.
    when '08'.
      p_en_month = 'Aug'.
    when '09'.
      p_en_month = 'Sep'.
    when '10'.
      p_en_month = 'Oct'.
    when '11'.
      p_en_month = 'Nov'.
    when '12'.
      p_en_month = 'Dec'.
  endcase.
endform.                    " GET_EN_MONTH
*&---------------------------------------------------------------------*
*&      Form  CREATE_DYNAMIC_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_dynamic_table .
  call method cl_alv_table_create=>create_dynamic_table
    exporting
      it_fieldcatalog = it_structure
    importing
      ep_table        = it_summ.

  assign it_summ->* to <it_summ>.
endform.                    " CREATE_DYNAMIC_TABLE
*&---------------------------------------------------------------------*
*&      Form  GET_SUMM_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_summ_data .

  data:wa_new_line type ref to data,
       lv_ptype(10)  type c.
  create data wa_new_line like line of <it_summ>." 建立一个与动态内表结构相同的数据对象,且数据对象为是一个结构
  assign wa_new_line->* to <wa_summ>.

  sort it_pr_collect by year_mm mm_flag ptype werks.
  sort it_po_collect by year_mm mm_flag ptype werks.
  sort it_field by fieldname.
  loop at it_plant.
    lv_i = 4.
    while lv_i > 0.
      case lv_i.
        when 4.
          lv_ptype = 'PR(No-Rel)'.
        when 3.
          lv_ptype = 'PR(Rel)'.
        when 2.
          lv_ptype = 'PO(Rel)'.
        when 1.
          lv_ptype = 'PO(No-Rel)'.
      endcase.
      loop at it_structure into wa_structure.
        assign component wa_structure-fieldname of structure <wa_summ> to <wa_field>. " 用指针 <wa_field>指向工作区<wa_summ>中的一个字段,字段名为wa_structure-fieldname.
        if wa_structure-fieldname ='WERKS' .
          <wa_field>  = it_plant-werks .
        elseif wa_structure-fieldname ='PTYPE' .
          <wa_field>  = lv_ptype.
        else.
          read table it_field with key fieldname = wa_structure-fieldname  binary search.
          if lv_i = 4 or lv_i = 3.
            read table it_pr_collect with key year_mm = it_field-year_mm
                                              mm_flag = it_field-mm_flag
                                              ptype = lv_ptype
                                              werks = it_plant-werks  binary search.
            if sy-subrc eq 0.
              <wa_field>  =  it_pr_collect-netwr. " 给指针指向的字段赋值
            else.
              <wa_field>  =  0.
            endif.
          else.
            read table it_po_collect with key year_mm = it_field-year_mm
                                              mm_flag = it_field-mm_flag
                                              ptype = lv_ptype
                                              werks = it_plant-werks  binary search.
            if sy-subrc eq 0.
              <wa_field>  =  it_po_collect-netwr.
            else.
              <wa_field>  =  0.
            endif.
          endif.
        endif.
      endloop.
      append <wa_summ> to <it_summ>.
      lv_i  = lv_i  - 1.
    endwhile.
  endloop.
endform.                    " GET_SUMM_DATA

*&---------------------------------------------------------------------*
*&      Form  DISPALY_DETAIL_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form dispaly_detail_data .
  clear:it_detail,it_detail[].
  append lines of it_po to it_detail.
  append lines of it_pr to it_detail.
  sort it_detail by year_mm ebeln ebelp.

  free: it_po ,it_pr.

  refresh: fc_hier,it_sort.

  alv_field  'YEAR_MM' '' 'Month/Year' ''  'L' '' '' ''.
  alv_field  'EBELN' 'PO/PR' '' '' 'L' '' '' ''.
  alv_field  'EBELP' 'Item' '' '' 'R' '' '' ''.
  alv_field  'WERKS' '' 'Plant' '' 'L' '' '' ''.
  alv_field  'MATNR' '' 'Material' '20' 'L' '' 'MARA' 'MATNR'.
  alv_field  'MAKTX' 'Desc.' '' '20' 'L' '' '' ''.
  alv_field  'MENGE' 'Qty' '' '' 'R' 'X' '' ''.
  alv_field  'NETPR' 'Net Price' '' '' 'R' '' '' ''.
  alv_field  'PEINH' 'Price Unit' '' '' 'R' '' '' ''.
  alv_field  'NETWR' '' 'Amount' '' 'R' 'X' '' ''.
  alv_field  'EINDT' '' 'Deliv. Date' '10' 'L' '' '' ''.
  alv_field  'LIFNR' 'Vendor' '' '' 'L' '' 'LFA1' 'LIFNR'.

  add 1 to wa_sort-spos.
  wa_sort-fieldname = 'YEAR_MM'.
  wa_sort-up = 'X'.
  wa_sort-subtot = 'X'.
  append wa_sort to it_sort.


  wa_layout-zebra = 'X'.
  wa_layout-f2code = '&ETA'.
  wa_layout-colwidth_optimize = 'X'.

  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat             = fc_hier[]
      i_save                  = 'A'
      it_sort                 = it_sort
      i_callback_program      = sy-repid
      is_layout               = wa_layout
      it_events               = wa_events
*     i_callback_user_command = 'ALV_USER_COMMAND'
    tables
      t_outtab                = it_detail[]
    exceptions
      program_error           = 1
      others                  = 2.
endform.                    " DISPALY_DETAIL_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPALY_SUUMARY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form dispaly_suumary_data .

  free: it_po ,it_pr,it_po_collect,it_pr_collect.

  refresh: fc_hier,it_sort.
  alv_field  'WERKS' '' 'Plant' '' 'L' ''  '' ''.
  alv_field  'PTYPE' 'Type' '' '' 'L' ''  '' ''.

  loop at it_field.
    alv_field  it_field-fieldname '' it_field-fielddesc '15' 'R' 'X'  '' ''.
  endloop.

  add 1 to wa_sort-spos.
  wa_sort-fieldname = 'WERKS'.
  wa_sort-up = 'X'.
  wa_sort-subtot = 'X'.
  append wa_sort to it_sort.

  wa_layout-zebra = 'X'.
  wa_layout-f2code = '&ETA'.
  wa_layout-colwidth_optimize = 'X'.

  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat        = fc_hier[]
      it_sort            = it_sort
      is_layout          = wa_layout
      it_events          = wa_events
      i_save             = 'A'
      i_callback_program = sy-repid
    tables
      t_outtab           = <it_summ>
    exceptions
      program_error      = 1
      others             = 2.
endform.                    " DISPALY_SUUMARY_DATA
*&---------------------------------------------------------------------*
*&      Form  get_last_day
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FROM     text
*      -->P_TO       text
*----------------------------------------------------------------------*
form get_last_day using p_from
                  changing p_to.
  call function 'LAST_DAY_OF_MONTHS'
    exporting
      day_in            = p_from
    importing
      last_day_of_month = p_to
    exceptions
      day_in_no_date    = 1
      others            = 2.
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.

endform.                    "get_last_day
*&---------------------------------------------------------------------*
*&      Form  get_last_day
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_FROM     text
*      -->P_TO       text
*----------------------------------------------------------------------*
form get_last_month using p_from
                          p_month
                  changing p_to.
  call function 'HR_PSD_DATES_ADD_MONTHS'
    exporting
      v_date       = p_from
      v_months     = p_month
    importing
      e_date       = p_to
    exceptions
      not_positive = 1
      others       = 2.
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.

endform.                    "get_last_day

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值