Chinaunix首页 | 论坛 | 博客
  • 博客访问: 285138
  • 博文数量: 62
  • 博客积分: 2966
  • 博客等级: 少校
  • 技术积分: 615
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-07 23:16
个人简介

Be a simple man

文章分类

全部博文(62)

文章存档

2012年(6)

2011年(15)

2010年(6)

2009年(3)

2008年(5)

2007年(27)

我的朋友

分类:

2008-01-09 20:32:21

*&---------------------------------------------------------------------
*& Program Name     : ZTEST_CO1                                        *
*& Title            :                                                  *
*& Module Name      : CO                                               *
*& Sub-Module       :                                                  *
*& Author           : Jason Zhang (SAP)                                *
*& Create Date      : 2008/01/05                                       *
*& Logical DB       : Nothing                                          *
*& Selection Screen : Default                                          *
*& Program Type     : Report                                           *
*& SAP Release      : 620                                              *
*&---------------------------------------------------------------------*
*& REVISION LOG                                                        *
*& LOG#     DATE         AUTHOR        DESCRIPTION                     *
*& ----     ----       ----------      -----------                     *
*& 0000   2008/01/07    Jason Zhang       Initial Implementation       *
*&                                                                     *
*&---------------------------------------------------------------------*
report  ztest_co1   .
type-pools: slis.
*----------------------------------------------------------------------*
* 声明引用数据表
*----------------------------------------------------------------------*
tables: coep,cobk,afko.
*----------------------------------------------------------------------*
* 变量定义
*----------------------------------------------------------------------*
data: begin of gt_table occurs 0,
      khd(2), "考核点
      cxbh(20) ,  "产线编号
      bcbh(20) , "班次编号
      matnr like coep-matnr, "物料编号
      uspob like coep-uspob,  "成本中心
      aufnr like afko-aufnr,  "生产订单编号
      kstar like coep-kstar,  "成本要素 
      orgvg like cobk-orgvg,  "业务交易
      txt   like tj01t-txt,   "业务交易文本
      megbtr like coep-megbtr, "数量
      meinb  like coep-meinb,  "单位
      wogbtr like coep-wogbtr, "金额
      end of gt_table.
types: begin of typ_data,
      khd(2), "考核点
      cxbh(20) ,  "产线编号
      bcbh(20) , "班次编号
      matnr like coep-matnr, "物料编号
      uspob like coep-uspob,  "成本中心
      aufnr like afko-aufnr,  "生产订单编号
      kstar like coep-kstar,  "成本要素 
      orgvg like cobk-orgvg,  "业务交易
      txt   like tj01t-txt,   "业务交易文本
      megbtr like coep-megbtr, "数量
      wogbtr like coep-wogbtr, "金额
*      meinb  LIKE coep-meinb, "单位
      unit   type lvc_quan,
     end of typ_data.
data gt_outtab   type table of typ_data with header line.
data gt_fieldcat type slis_t_fieldcat_alv.
data gt_sort     type slis_t_sortinfo_alv.
data gs_variant  type disvariant.
data: sla type slis_layout_alv.
*----------------------------------------------------------------------*
* 屏幕查询条件定义
*----------------------------------------------------------------------*
selection-screen begin of block bl_1 with frame title text-001.
parameters: p_kokrs like coep-kokrs obligatory,
            p_bukrs like coep-bukrs obligatory,
            p_gjahr like coep-gjahr obligatory,
            p_perio like coep-perio obligatory.
select-options: p_aufnr for afko-aufnr,
                p_plnbez for afko-plnbez obligatory,
                p_khd for coep-sgtxt.
selection-screen end of block bl_1.
*--------------------------------------------------------------------
* Program constructor.
*--------------------------------------------------------------------
load-of-program.
** For Display Variant
  gs_variant-report = sy-repid.
  perform layout_sort_build changing gt_sort.
  perform prepare_field_catalog changing gt_fieldcat.
*--------------------------------------------------------------------
* s t a r t - o f - s e l e c t i o n.
*--------------------------------------------------------------------
start-of-selection.
  perform getdata.
  perform alvdata.
*&---------------------------------------------------------------------*
*&      Form  getdata
*&---------------------------------------------------------------------*
form getdata .
  data: begin of t_afko occurs 0,
        plnbez like afko-plnbez, "物料编号
        aufnr like afko-aufnr,  "生产订单编号
        objnr like coep-objnr,
        end of t_afko.
  data: begin of t_coep occurs 0,
        belnr like coep-belnr,
        kokrs like coep-kokrs,
*        perio LIKE coep-perio,
        aufnr like afko-aufnr,  "生产订单编号
        matnr like coep-matnr,  "coep物料编号
        uspob like coep-uspob,  "成本中心
        objnr like coep-objnr,  "对象编号
        kstar like coep-kstar,  "成本要素
        megbtr like coep-megbtr, "数量
        meinb  like coep-meinb,  "单位
        wogbtr like coep-wogbtr, "金额
        sgtxt like coep-sgtxt,   "借用字段
        orgvg like cobk-orgvg,
        txt like tj01t-txt,
        end of t_coep.
  data: begin of t_coep2 occurs 0,
        aufnr like afko-aufnr,
        kokrs like coep-kokrs,
        matnr like coep-matnr,  "coep物料编号
        uspob like coep-uspob,  "成本中心
        objnr like coep-objnr,  "对象编号
        kstar like coep-kstar,  "成本要素
        megbtr like coep-megbtr, "数量
        meinb  like coep-meinb,  "单位
        wogbtr like coep-wogbtr, "金额
        sgtxt like coep-sgtxt,   "借用字段
        orgvg like cobk-orgvg,
        txt like tj01t-txt,
        end of t_coep2.
  data: begin of t_cobk occurs 0,
        belnr like cobk-belnr,
        kokrs like cobk-kokrs,
        orgvg like cobk-orgvg,
        txt like tj01t-txt,
        end of t_cobk.
*根据成品物料号得到订单号码和对象号码
  select plnbez aufnr from afko
  into corresponding fields of table t_afko
  where plnbez in p_plnbez and
        aufnr in p_aufnr.
  loop at t_afko.
    concatenate 'OR' t_afko-aufnr into t_afko-objnr.
    modify t_afko.
  endloop.
  sort t_afko.
  delete adjacent duplicates from t_afko.
  if not t_afko[] is initial.
*根据对象编号取得COEP相关字段
    select coep~kokrs coep~belnr coep~matnr coep~uspob coep~objnr
           coep~kstar coep~megbtr coep~meinb coep~wogbtr coep~sgtxt
    from coep
    into corresponding fields of table t_coep
    for all entries in t_afko
    where coep~objnr = t_afko-objnr and
          coep~gjahr = p_gjahr and
          coep~kokrs = p_kokrs and
          coep~perio = p_perio and
          coep~lednr = '00'.  "一般情况下为 00 ********.
  endif.
* COBK~ORGVR,tj01t~tx
  select cobk~orgvg tj01t~txt cobk~kokrs cobk~belnr
  from cobk inner join tj01t
  on cobk~orgvg = tj01t~vrgng
  into corresponding fields of table t_cobk
  where tj01t~spras = sy-langu.
* 将ORGVG,TXT写入T_COEP
  loop at t_coep.
  read table t_cobk with key belnr = t_coep-belnr  kokrs = t_coep-kokrs
  binary search.
    if sy-subrc = 0.
      t_coep-orgvg = t_cobk-orgvg.
      t_coep-txt = t_cobk-txt.
      modify t_coep .
    endif.
  endloop.
*如果为重估类型 人工写入
  loop at t_coep where orgvg = ''.
    select single tj01t~txt into t_coep-txt
    from tj01t
    where vrgng = 'RKLN'.
    t_coep-orgvg = 'RKLN'.
    modify t_coep.
  endloop.
*将订单编号写入T_COEP
  loop at t_coep.
    read table t_afko with key objnr = t_coep-objnr binary search.
    if sy-subrc = 0.
      t_coep-aufnr = t_afko-aufnr.
      modify t_coep.
    endif.
  endloop.
  data: h1 like coep-sgtxt,
        h2 like coep-sgtxt,
        h3 like coep-sgtxt.
*非差异数据分解SGTXT字段为KHD,CXBH,BCBH,写入GT_TABLE
  loop at t_coep.
    if t_coep-matnr = '' and t_coep-uspob = ''.
    else.
      if t_coep-sgtxt <> ''.
        split t_coep-sgtxt at ';' into h1 h2.
        split h2 at ';' into h2 h3.
        gt_table-khd = h1.
        gt_table-cxbh = h2.
        gt_table-bcbh = h3.
      endif.
    endif.
    move-corresponding t_coep to gt_table.
    append gt_table.
  endloop.

  if not p_khd[] is initial.
    loop at gt_table.
      if gt_table not in p_khd[].
        delete gt_table.
      endif.
    endloop.
  endif.
  loop at gt_table.
    gt_outtab-unit = gt_table-meinb.
    move-corresponding gt_table to gt_outtab.
    append gt_outtab.
  endloop.
endform.                    " getdata
*&---------------------------------------------------------------------*
*&      Form  alvdata
*&---------------------------------------------------------------------*
form alvdata .
  perform setlayout.
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      i_callback_program = gs_variant-report
      it_fieldcat        = gt_fieldcat[]
      it_sort            = gt_sort[]
      is_variant         = gs_variant
      is_layout          = sla
    tables
      t_outtab           = gt_outtab[]
    exceptions
      program_error      = 1
      others             = 2.
endform.                    " alvdata
*---------------------------------------------------------------------*
*       FORM LAYOUT_SORT_BUILD                                        *
*---------------------------------------------------------------------*
*       Sorting                                                       *
*---------------------------------------------------------------------*
*  -->  LT_SORT                                                       *
*---------------------------------------------------------------------*
form layout_sort_build changing lt_sort type slis_t_sortinfo_alv.
  data ls_sort type slis_sortinfo_alv.
* Key
  clear ls_sort.
  ls_sort-fieldname = 'KHD'.
  ls_sort-spos      = 1.
  ls_sort-up        = 'X'.
  ls_sort-subtot    = 'X'.
  append ls_sort to lt_sort.
  clear ls_sort.
  ls_sort-fieldname = 'MATNR'.
  ls_sort-spos      = 1.
  ls_sort-up        = 'X'.
  ls_sort-subtot    = 'X'.
  append ls_sort to lt_sort.
  clear ls_sort.
  ls_sort-fieldname = 'USPOB'.
  ls_sort-spos      = 1.
  ls_sort-up        = 'X'.
  ls_sort-subtot    = 'X'.
  append ls_sort to lt_sort.
  clear ls_sort.
  ls_sort-fieldname = 'TXT'.
  ls_sort-spos      = 1.
  ls_sort-up        = 'X'.
  ls_sort-subtot    = 'X'.
  append ls_sort to lt_sort.
endform.  " LAYOUT_sort_build
*&---------------------------------------------------------------------*
*&      Form  prepare_field_catalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form prepare_field_catalog changing lt_fieldcat type slis_t_fieldcat_alv
.
  data ls_fieldcat type slis_fieldcat_alv.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'KHD'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '考核点'.
  ls_fieldcat-outputlen    = 10.
  ls_fieldcat-no_sum       = 'X'.
  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'CXBH'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '产线编号'.
  ls_fieldcat-outputlen    = 10.
  ls_fieldcat-no_sum       = 'X'.
*  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'BCBH'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '班次编号'.
  ls_fieldcat-outputlen    = 10.
  ls_fieldcat-no_sum       = 'X'.
*  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'MATNR'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '物料编号'.
  ls_fieldcat-outputlen    = 10.
  ls_fieldcat-no_sum       = 'X'.
  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'USPOB'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '成本中心'.
  ls_fieldcat-outputlen    = 20.
  ls_fieldcat-no_sum       = 'X'.
  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'AUFNR'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '生产订单编号'.
  ls_fieldcat-outputlen    = 10.
  ls_fieldcat-no_sum       = 'X'.
*  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'KSTAR'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '成本要素'.
  ls_fieldcat-outputlen    = 10.
  ls_fieldcat-no_sum       = 'X'.
*  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'TXT'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '交易业务'.
  ls_fieldcat-outputlen    = 20.
  ls_fieldcat-no_sum       = 'X'.
  ls_fieldcat-key          = 'X'.
  append ls_fieldcat to lt_fieldcat.
* Num
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'MEGBTR'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '数量'.
  ls_fieldcat-outputlen    = 10.
*  ls_fieldcat-do_sum       = 'X'.
  ls_fieldcat-no_sum       = 'X'.
  append ls_fieldcat to lt_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'WOGBTR'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '金额'.
  ls_fieldcat-outputlen    = 10 .
  ls_fieldcat-do_sum       = 'X'.
  append ls_fieldcat to lt_fieldcat.
* UNIT
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = 'UNIT'.
  ls_fieldcat-tabname      = 'gt_outtab'.
  ls_fieldcat-reptext_ddic = '单位'.
  ls_fieldcat-outputlen    = 10.
*  ls_fieldcat-do_sum       = 'X'.
  append ls_fieldcat to lt_fieldcat.
endform.                    "prepare_field_catalog
*&---------------------------------------------------------------------*
*&      Form  setlayout
*&---------------------------------------------------------------------*
form setlayout .
  sla-colwidth_optimize = 'X'.
  sla-zebra             = 'X'.
endform.                    " setlayout
阅读(8116) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~