个人工作开发SAP/ABAP构件产量表

*&
*&-----------------------------------------------------------

----------*
*& 报表名称:构件产量报表
*& 报表类:PP
*& 开发人员:DONGSR
*& 日期:2006.5.28
*&
*&
*&
*&-----------------------------------------------------------

----------*

REPORT  ZDSR001

   MESSAGE-ID zlig.
*&-----------------------------------------------------------

----------*

*& TABLES:

*&-----------------------------------------------------------

----------*
TABLES:MSEG,        "物料凭证
       PRPS,
       PROJ,       "项目定义
       PRHI,        "项目指针
       MAKT,        "物料描述
       AUFK,        "制造订单长文本取数表
       AFKO,       "制造订单抬头表与MSEG
       MKPF,        "日期
       MARA.       "物料主数据

*&-----------------------------------------------------------

----------*

*& PROGRAM VARIABLES

*&-----------------------------------------------------------

----------*
TYPE-POOLS: slis.
DATA:BEGIN OF IT_MSEG OCCURS 0,
     MAT_PSPNR LIKE MSEG-MAT_PSPNR,"WBS 元素和PRHI-POSNR内容相


     WERKS LIKE MSEG-WERKS,  "工厂
     MBLNR LIKE MSEG-MBLNR,  "物料凭证
     BWART LIKE MSEG-BWART,  "移动类型
     MATNR LIKE MSEG-MATNR,  "构件号
     MENGE LIKE MSEG-MENGE,   "数量
     MEINS LIKE MSEG-MEINS,   "基本计量单位
     ZEILE LIKE MSEG-ZEILE,   "物料凭证中的项目
     aufnr like mseg-aufnr,
     END OF IT_MSEG.

DATA:BEGIN OF IT_MAKT OCCURS 0,
     MATNR LIKE MSEG-MATNR,
     MAKTX LIKE MAKT-MAKTX,   "物料描述
     END OF IT_MAKT.

*DATA:BEGIN OF IT_MARA OCCURS 0,
*     MATNR LIKE MSEG-MATNR,
*     MTART LIKE MARA-MTART,   "构件类型/物料类型
*     END OF IT_MARA.
DATA:BEGIN OF IT_MKPF OCCURS 0,
     BUDAT LIKE MKPF-BUDAT,   "日期
     MBLNR LIKE MSEG-MBLNR,   "物料凭证编号
     END OF IT_MKPF.
DATA:BEGIN OF IT_PRPS OCCURS 0,
     pspnr LIKE PRPS-pspnr,
     PSPHI LIKE PRPS-PSPHI,
     POST1 LIKE PRPS-POST1,
     END OF IT_PRPS.
DATA: BEGIN OF IT_PROJ OCCURS 0,
      PSPNR LIKE PROJ-PSPNR,
      PSPID LIKE PROJ-PSPID,
      POST1 LIKE PROJ-POST1,
      END OF IT_PROJ.

DATA: GJLB(18) TYPE C,
      DELB(16) TYPE C,            "定额类别
      DANZHONG(13) TYPE c,
      ZONGZL TYPE P,
      LEIBIE(16) TYPE c,
      DANWEI like MSEG-MEINS value 'KG',
      a type string,
      d(2) value 'kg',
      c(2) value  '  ',
      B(13) TYPE c,
      e type n.

DATA: begin of it_output occurs 0,
       BUDAT LIKE MKPF-BUDAT,
       MAT_PSPNR LIKE MSEG-MAT_PSPNR,
       WERKS LIKE MSEG-WERKS,
*     MTART LIKE MARA-MTART,
       MATNR LIKE MSEG-MATNR,
       maktx like makt-maktx,
       MENGE LIKE MSEG-MENGE,
       MEINS LIKE MSEG-MEINS,
       MBLNR LIKE MSEG-MBLNR,
       ZEILE LIKE MSEG-ZEILE,
       POST1 LIKE PRPS-POST1,     "WBS描述
       POST2 LIKE PROJ-POST1,    "项目描述
       PSPID LIKE PROJ-PSPID,     "项目定义
       aufnr like mseg-aufnr,
       LEIBIE(16) type c,
       DELB(16) TYPE C,            "定额类别
       DANZHONG(13) TYPE N,         "单重
       ZONGZL TYPE P,          "总重
       GJLB(18) TYPE C,
       DANWEI like MSEG-MEINS value 'KG', "定义重量单位
       psphi like prps-psphi,
       pspnr like prps-pspnr,
       GD TYPE C,
       END OF it_output.

 DATA:I_TEXT(80) TYPE C.
 DATA:TEXT_HEADER LIKE THEAD.
 DATA:TEXT_LINES LIKE TLINE OCCURS 0 WITH HEADER LINE.

**************************************************************

*****
DATA:  gs_layout           TYPE slis_layout_alv,
       gt_fieldcat         TYPE slis_t_fieldcat_alv with

header line,
       g_repid             LIKE sy-repid,
       fieldcatalog        like gt_fieldcat,
       sortable            type SLIS_T_SORTINFO_ALV,
       ls_sort             TYPE slis_sortinfo_alv.
**************************************************************

**********
DATA:   CURRK LIKE BSID-PSWSL.
CONSTANTS: C_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME
                                  VALUE 'TOP_OF_PAGE'.

*&-----------------------------------------------------------

----------*

*& SELECTION-SCREEN

*&-----------------------------------------------------------

----------*
selection-screen begin of block chanliang with frame title

text-w02.

 

 SELECT-OPTIONS :  s_ps for PROJ-PSPID NO INTERVALS
                                         NO-EXTENSION.
 PARAMETERS :  P_WERKS LIKE MSEG-WERKS obligatory,
               P_bwart LIKE mseg-bwart obligatory.
 SELECT-OPTIONS :
* s_DELB for delb  NO INTERVALS
*                                   NO-EXTENSION,"构件定额类别
                  s_budat for mkpf-budat obligatory,  "构件日


                  S_matnr FOR mseg-matnr. "构件
*                  S_gjlb FOR gjlb NO INTERVALS
*                                         NO-EXTENSION. "物料

类型

selection-screen end of block chanliang.

PARAMETERS :
huizong radiobutton group DSR default 'X',
chaxun radiobutton group DSR.

 SELECTION-SCREEN BEGIN OF LINE.
 SELECTION-SCREEN COMMENT 1(31) TEXT-X03.
 PARAMETERS: s_delb AS CHECKBOX DEFAULT ' '.
 SELECTION-SCREEN COMMENT 40(10) TEXT-X01 FOR FIELD s_delb.
 PARAMETERS: s_gjlb AS CHECKBOX DEFAULT ' '.
 SELECTION-SCREEN COMMENT 60(10) TEXT-X02 FOR FIELD s_gjlb.
 SELECTION-SCREEN END OF LINE.

AT SELECTION-SCREEN.
  if s_delb <> ''
  and s_gjlb <> ''.
    message e001.
  endif.

**************************************************************

********

*

* TOP-OF-PAGE
**************************************************************

********

*
TOP-OF-PAGE.

**************************************************************

********

*

* END-OF-PAGE
**************************************************************

********

*
END-OF-PAGE.

**************************************************************

********

*

* START-OF-SELECTION
**************************************************************

********

*
START-OF-SELECTION.
IF huizong = 'X'.
perform data_retrieval.
perform display_alv_report1.

else.
if chaxun = 'X'.
perform data_retrieval.
perform display_alv_report2.
endif.
endif.

 

**&----------------------------------------------------------

---------

**
**&      Form  z_table
**&----------------------------------------------------------

---------

**
**       text
**-----------------------------------------------------------

---------

**
**  -->  p1        text
**  <--  p2        text
**-----------------------------------------------------------

---------

*&-----------------------------------------------------------

---------

*
*&      Form  build_fieldcatalog1
*&-----------------------------------------------------------

---------


form build_fieldcatalog1.
    fieldcatalog-fieldname   = 'BUDAT'.
    fieldcatalog-seltext_m   = '日期'.
    fieldcatalog-col_pos     = 0.
    fieldcatalog-datatype    = 'CURR'.
    append fieldcatalog to gt_fieldcat.
    clear  fieldcatalog.

     fieldcatalog-fieldname   = 'PSPID'.
     fieldcatalog-seltext_m   = '项目编号'.
     fieldcatalog-col_pos     = 1.
     fieldcatalog-outputlen   = 15.
     append fieldcatalog to gt_fieldcat.
     clear  fieldcatalog.

     fieldcatalog-fieldname   = 'POST2'.
     fieldcatalog-seltext_m   = '项目描述'.
     fieldcatalog-col_pos     = 2.
     fieldcatalog-outputlen   = 10.
     append fieldcatalog to gt_fieldcat.
     clear  fieldcatalog.

  fieldcatalog-fieldname   = 'WERKS'.
  fieldcatalog-seltext_m   = '工厂'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'LEIBIE'.
  fieldcatalog-seltext_m   = '类别'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'ZONGZL'.
  fieldcatalog-seltext_m   = '重量'.
  fieldcatalog-col_pos     = 5.
  fieldcatalog-do_sum      = 'X'.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'DANWEI'.
  fieldcatalog-seltext_m   = '单位'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.
  endform.
*&-----------------------------------------------------------

---------

*
*&      Form  build_fieldcatalog2
*&-----------------------------------------------------------

---------

*

form build_fieldcatalog2.

  fieldcatalog-fieldname   = 'MAT_PSPNR'.
  fieldcatalog-seltext_m   = '项目编码'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 15.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'POST1'.
  fieldcatalog-seltext_m   = '项目描述'.
  fieldcatalog-col_pos     = 1.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'WERKS'.
  fieldcatalog-seltext_m   = '工厂'.
  fieldcatalog-col_pos     = 2.
  fieldcatalog-datatype    = 'CURR'.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'DELB'.
  fieldcatalog-seltext_m   = '定额类别'.
  fieldcatalog-col_pos     = 3.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'GJLB'.
  fieldcatalog-seltext_m   = '构件类别'.
  fieldcatalog-col_pos     = 4.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'BUDAT'.
  fieldcatalog-seltext_m   = '日期'.
    fieldcatalog-col_pos     = 5.
    fieldcatalog-datatype    = 'CURR'.
    append fieldcatalog to gt_fieldcat.
    clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = '构件代码'.
  fieldcatalog-col_pos     = 6.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MAKTX'.
  fieldcatalog-seltext_m   = '构件描述'.
  fieldcatalog-col_pos     = 7.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   =  'MENGE'.
  fieldcatalog-seltext_m   = '数量'.
  fieldcatalog-col_pos     = 8.
  fieldcatalog-do_sum      = 'X'.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   =  'MEINS'.
  fieldcatalog-seltext_m   = '数量单位'.
  fieldcatalog-col_pos     = 9.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

 fieldcatalog-fieldname   = 'DANZHONG'.
  fieldcatalog-seltext_m   = '单重'.
  fieldcatalog-col_pos     = 10.
  fieldcatalog-do_sum      = 'X'.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'ZONGZL'.
  fieldcatalog-seltext_m   = '总重'.
  fieldcatalog-col_pos     = 11.
  fieldcatalog-do_sum      = 'X'.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'DANWEI'.
  fieldcatalog-seltext_m   = '单位'.
  fieldcatalog-col_pos     = 12.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MBLNR'.
  fieldcatalog-seltext_m   = '物料凭证'.
  fieldcatalog-col_pos     = 13.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

 fieldcatalog-fieldname   = 'ZEILE'.
  fieldcatalog-seltext_m   = '物料凭证项目'.
  fieldcatalog-col_pos     = 14.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

 fieldcatalog-fieldname   = 'AUFNR'.
  fieldcatalog-seltext_m   = '相关生产订单'.
  fieldcatalog-col_pos     = 15.
  append fieldcatalog to gt_fieldcat.
  clear  fieldcatalog.

endform.                    " BUILD_FIELDCATALOG

***&---------------------------------------------------------

---------
*
**
***&      Form  DATA_RETRIEVAL
***&---------------------------------------------------------

---------

form data_retrieval.

select MAT_PSPNR
         werks
         mblnr
         bwart
         matnr
         menge
         meins
         zeile
         aufnr
    from mseg
    into corresponding fields of table it_mseg
     where  werks = p_werks
      and matnr in s_matnr
      and bwart = P_bwart.

if not it_mseg[] is initial.
endif.
select psphi
       pspnr
       post1
   from prps
   into corresponding fields of table it_prps
   for all entries in it_mseg
   where pspnr = it_mseg-mat_pspnr.
*
select pspnr
       pspid
       post1
    from proj
    into corresponding fields of table it_proj
     for all entries in it_prps
    where pspnr = it_prps-psphi
         and pspid in s_ps.


select   mblnr
         budat
    from mkpf
    into corresponding fields of table it_mkpf
      for all entries in it_mseg
      where mblnr = it_mseg-mblnr
        and budat in s_budat.


loop at it_mseg.
    it_output-MAT_PSPNR = it_mseg-MAT_PSPNR.
    it_output-werks = it_mseg-werks.
    it_output-mblnr = it_mseg-mblnr.
    it_output-matnr = it_mseg-matnr.
    it_output-menge = it_mseg-menge.
    it_output-meins = it_mseg-meins.
    it_output-ZEILE = IT_MSEG-ZEILE.
    it_output-aufnr = it_mseg-aufnr.
    it_output-danwei = 'KG'.

 

read table it_prps with key pspnr = it_mseg-MAT_PSPNR.
it_output-post1 = it_prps-post1.
it_output-pspnr = it_prps-pspnr.


loop at it_proj where pspnr = it_prps-psphi.
it_output-pspid = it_proj-pspid.
it_output-post2 = it_proj-post1.
endloop.

read table it_mkpf with key mblnr = it_output-mblnr.
    it_output-budat = it_mkpf-budat.


select single maktx
      from makt
      into it_output-maktx
      where matnr = it_mseg-matnr
      and spras = sy-langu.

 

TEXT_HEADER-TDID ='KOPF'.              "长文本ID段
 TEXT_HEADER-TDOBJECT = 'AUFK'.        "生产订单表
 TEXT_HEADER-TDSPRAS = 1.              "系统语言
 CONCATENATE SY-MANDT it_output-aufnr INTO a."client和订单相联

系赋给A
 TEXT_HEADER-TDNAME = a.

 

CALL FUNCTION 'READ_TEXT'
      EXPORTING
           ID        = TEXT_HEADER-TDID
           LANGUAGE  = TEXT_HEADER-TDSPRAS
           NAME      = TEXT_HEADER-TDNAME
           OBJECT    = TEXT_HEADER-TDOBJECT
      IMPORTING
           HEADER    = TEXT_HEADER
      TABLES
           LINES     = text_lines
      EXCEPTIONS
           NOT_FOUND = 1.


READ TABLE TEXT_LINES INDEX 3.
    IF sy-subrc = 0.
      danzhong = TEXT_LINES-TDLINE.
      condense danzhong no-gaps.
      SHIFT danzhong BY 5 PLACES LEFT.
condense danzhong no-gaps.
      replace d with c into danzhong.
      condense danzhong no-gaps.
    endif.

READ TABLE TEXT_LINES INDEX 5.
  IF sy-subrc = 0.
  DELB = TEXT_LINES-TDLINE.
SHIFT DELB BY 9 PLACES LEFT.
*  delb = s_delb.
endif.


b = danzhong.
b = b * it_output-menge.
    condense b no-gaps.
    zongzl = b.
    it_output-zongzl = zongzl.

if it_output-menge = 0.
it_output-ZONGZL = 0.
endif.

it_output-danzhong = danzhong.
it_output-zongzl = zongzl.

it_output-delb = delb.
it_output-gjlb = it_output-matnr+1(1).

if s_gjlb = '' and s_delb = ''.
leibie = ''.

endif.

if s_gjlb <> '' and s_delb = ''.

leibie = it_output-gjlb.
endif.

if s_gjlb = '' and s_delb <> ''.
leibie = it_output-delb.
endif.
it_output-leibie = leibie.

if not it_output-budat is initial.
if not it_output-aufnr is initial.
if not it_output-MAT_PSPNR is initial.
if not it_output-pspid is initial.

append it_output.
*    danzhong = 0.
*    zongzl = 0.
*    b = 0.
  clear it_output.
  endif.
  endif.
  endif.
  endif.

endloop.

endform.

*&-----------------------------------------------------------

---------

*
*&      Form  display_alv_report1
*&-----------------------------------------------------------

---------

FORM display_alv_report1.
  perform build_fieldcatalog1.

  gs_layout-colwidth_optimize = 'X'.
  gs_layout-info_fieldname       = 'LINE_COL'.

  g_repid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM     = G_REPID
      IS_LAYOUT              = gs_layout
      i_callback_top_of_page = 'TOP-OF-PAGE1'
      IT_FIELDCAT            = gt_fieldcat[]
      IT_SORT                = SORTABLE[]
      I_SAVE                 = 'A'
    TABLES
      T_OUTTAB               = IT_OUTPUT
    EXCEPTIONS
      PROGRAM_ERROR          = 1
      OTHERS                 = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " display_alv_report


*&-----------------------------------------------------------

---------

*
*&      Form  display_alv_report2
*&-----------------------------------------------------------

---------

  FORM display_alv_report2 .
  perform build_fieldcatalog2.

  gs_layout-colwidth_optimize = 'X'.
  gs_layout-info_fieldname       = 'LINE_COL'.

  g_repid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM     = G_REPID
      IS_LAYOUT              = gs_layout
      i_callback_top_of_page = 'TOP-OF-PAGE2'
      IT_FIELDCAT            = gt_fieldcat[]
      IT_SORT                = SORTABLE[]
      I_SAVE                 = 'A'
    TABLES
      T_OUTTAB               = IT_OUTPUT
    EXCEPTIONS
      PROGRAM_ERROR          = 1
      OTHERS                 = 2.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " display_alv_report

*------------------------------------------------------------

-------*
* ALV Report Header                                           

     *
*------------------------------------------------------------

-------*
Form top-of-page1.
*ALV Header declarations
  data: t_header type slis_t_listheader,
        wa_header type slis_listheader,
        t_line like wa_header-info,
        ld_lines type i,
        ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = '发货分类汇总报表'.
  append wa_header to t_header.
  clear wa_header.


  call function 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.


endform.                    "top-of-page


*------------------------------------------------------------

-------*
* ALV Report Header                                           

     *
*------------------------------------------------------------

-------*
Form TOP-OF-PAGE2.
*ALV Header declarations
  data: t_header type slis_t_listheader,
        wa_header type slis_listheader,
        t_line like wa_header-info,
        ld_lines type i,
        ld_linesc(10) type c.


* Title
  wa_header-typ  = 'H'.
  wa_header-info = '构件发货细节查询'.
  append wa_header to t_header.
  clear wa_header.


call function 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.                    "top-of-page

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值