Chinaunix首页 | 论坛 | 博客
  • 博客访问: 34042
  • 博文数量: 17
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 190
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 16:20
文章分类
文章存档

2011年(1)

2010年(2)

2009年(3)

2008年(11)

我的朋友

分类:

2008-10-13 16:55:09

*----------------------------------------------------------------------*
*   Program Name:                                                      *
*   Option: Report                                                     *
*   Module:                                                            *
*   Author:                                                            *
*   Create date :                                                      *
*   Function:                                                          *
*----------------------------------------------------------------------*
REPORT Zprogram NO STANDARD PAGE HEADING     "输入程序名称
                   LINE-SIZE  252
                   LINE-COUNT 65
                   MESSAGE-ID ZX.        "输入消息ID
TYPE-POOLS : SLIS .
*程序中使用的表格
TABLES: VBAK,VBAP.
*定义内表
DATA: BEGIN OF INTAB OCCURS 0 ,
   VBELN  LIKE VBAK-VBELN,
   POSNR  LIKE VBAP-POSNR,
    END OF INTAB.
DATA: BEGIN OF MDTBX OCCURS 0.
        INCLUDE STRUCTURE MDTB.
DATA: END   OF MDTBX.
DATA :FIELDCAT           TYPE SLIS_T_FIELDCAT_ALV,
      HEADING            TYPE SLIS_T_LISTHEADER,
      LAYOUT             TYPE SLIS_LAYOUT_ALV,
      EVENTS             TYPE SLIS_T_EVENT,
      SORT               TYPE SLIS_T_SORTINFO_ALV.
DATA :I_DISP_FINAL       LIKE INTAB OCCURS 0 WITH HEADER LINE.
DATA :I_DISP_FINAL_TEMP  LIKE INTAB OCCURS 0 WITH HEADER LINE.
DATA :V_REPID            LIKE SY-REPID,
      T_FLD              TYPE SLIS_FIELDCAT_ALV,
      V_FILE(100)        TYPE C,
      C_DIR_NAME1        LIKE EPSF-EPSDIRNAM VALUE '/usr/tmp/srm/po',
      V_TEXT(2000)       TYPE C.
DATA:
  I_FIELDCAT_ALV  TYPE SLIS_T_FIELDCAT_ALV,
  I_EVENTS        TYPE SLIS_T_EVENT,
  I_EVENT_EXIT    TYPE SLIS_T_EVENT_EXIT,
  I_LIST_COMMENTS TYPE SLIS_T_LISTHEADER,
  I_EXCLUDING     TYPE SLIS_T_EXTAB,
  I_HEADER        TYPE SLIS_T_LISTHEADER.
DATA:
  W_VARIANT          LIKE DISVARIANT,  "显示变式结构
  WX_VARIANT         LIKE DISVARIANT,
  W_VARIANT_SAVE(1)  TYPE C,
  W_EXIT(1)          TYPE C,
  W_REPID            LIKE SY-REPID,  "abap程序,当前主程序
  W_USER_SPECIFIC(1) TYPE C,
  W_CALLBACK_UCOMM   TYPE SLIS_FORMNAME,   "字符型
  W_PRINT            TYPE SLIS_PRINT_ALV,  "类型组
  W_LAYOUT           TYPE SLIS_LAYOUT_ALV, "类型组
  W_HTML_TOP_OF_PAGE TYPE  SLIS_FORMNAME,  "字符型
  W_FIELDCAT_ALV     LIKE LINE OF I_FIELDCAT_ALV,
  W_EXCLUDING        LIKE LINE OF I_EXCLUDING,
  W_EVENTS           LIKE LINE OF I_EVENTS,
  W_EVENT_EXIT       LIKE LINE OF I_EVENT_EXIT,
  W_LIST_COMMENTS    LIKE LINE OF I_LIST_COMMENTS,
  W_VBELN LIKE VBFA-VBELN,
  W_ERDAT LIKE VBFA-ERDAT,
  W_VBELN1 LIKE VBFA-VBELN,
  W_ERDAT1 LIKE VBFA-ERDAT,
  W_POSNN LIKE VBFA-POSNN,
  IT_VBFA LIKE VBFA  OCCURS 0 WITH HEADER LINE,
  W_IVNO             TYPE I.
*初始化
INITIALIZATION.
  V_REPID = SY-REPID.
  DATA : G_FIRST_DAY LIKE SY-DATUM,
         G_LAST_DAY LIKE SY-DATUM,
         G_YEAR LIKE MKPF-MJAHR,
         G_MONTH LIKE MBEW-LFMON,
         G_PERIOD LIKE S012-SPBUP.

  SELECTION-SCREEN BEGIN OF BLOCK FILE  WITH FRAME TITLE TEXT-001.
  SELECT-OPTIONS: P_MAKTX FOR MAKT-MAKTX.
  PARAMETERS:    P_VBELN LIKE VBAK-VBELN.
  SELECTION-SCREEN END OF BLOCK FILE.
  SELECTION-SCREEN BEGIN OF BLOCK FILE1  WITH FRAME TITLE TEXT-002.
  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS B1  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN COMMENT 3(20) TEXT-B01.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS B2  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN COMMENT 3(20) TEXT-B02.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS B3  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN COMMENT 3(20) TEXT-B03.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS B4  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN COMMENT 3(20) TEXT-B04.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS B5  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN COMMENT 3(20) TEXT-B05.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE.
  PARAMETERS B6  AS CHECKBOX DEFAULT 'X'.
  SELECTION-SCREEN COMMENT 3(20) TEXT-B06.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN END OF BLOCK FILE1.
************************************************************
*FILE1結束
************************************************************
*显示/下载到PC/下载到服务器
  SELECTION-SCREEN BEGIN OF BLOCK RADIO WITH FRAME TITLE TEXT-003.
  PARAMETERS R1 RADIOBUTTON GROUP GR1.                "ALV显示
  PARAMETERS R2 RADIOBUTTON GROUP GR1.                "download to pc
  PARAMETERS R3 RADIOBUTTON GROUP GR1 DEFAULT 'X'.    "download to unix
  SELECTION-SCREEN END OF BLOCK RADIO.
START-OF-SELECTION.
  PERFORM GET_DATA.
  IF R1 EQ 'X'.
* ALV 显示 
    PERFORM DISP.
  ELSEIF R2 EQ 'X'.
* DOWNLOAD TO PC
    CONCATENATE 'D:\SRM-POWO' P_WERKS SY-DATUM SY-UZEIT '.TXT' INTO V_FILE.
    PERFORM DOWNLOAD_DATA_TO_PC TABLES I_MM
                                USING    V_FILE.
  ELSE.
* DOWNLOAD TO UNIX 
    CONCATENATE C_DIR_NAME1 '/' 'srm_powo' P_WERKS SY-DATUM SY-UZEIT '.txt' INTO V_FILE.
    PERFORM DOWNLOAD_DATA_TO_UNIX TABLES I_MM
                                USING    V_FILE.
  ENDIF.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  call_alv_function
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM CALL_ALV_FUNCTION .
  SORT  I_DISP_FINAL_TEMP.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = V_REPID
      I_STRUCTURE_NAME   = 'I_DISP_FINAL_TEMP'
*      is_layout          = layout
      IT_FIELDCAT        = FIELDCAT
*      I_CALLBACK_TOP_OF_PAGE      = 'TOP_OF_PAGE'
      IT_SORT            = SORT
      I_DEFAULT                   = 'X'
      I_SAVE                      = 'A'
      IS_VARIANT                  = W_VARIANT
      IS_LAYOUT                   = W_LAYOUT
*      I_CALLBACK_PF_STATUS_SET    = 'MENU_SET'
      I_CALLBACK_USER_COMMAND     = 'MY_COMMAND'
      IT_EVENTS                   = I_EVENTS[]
*      IT_EVENT_EXIT               = I_EVENT_EXIT
*      IT_EXCLUDING                = I_EXCLUDING
      IS_PRINT                    = W_PRINT
    TABLES
      T_OUTTAB           = I_DISP_FINAL_TEMP.
  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.                    " CALL_ALV_FUNCTION
*&---------------------------------------------------------------------*
*&      Form  fill_layout_structure
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FILL_LAYOUT_STRUCTURE .
  DATA : I_EVENTS TYPE SLIS_ALV_EVENT.
  DATA : LINE TYPE SLIS_LISTHEADER.
  DATA : H_SYDATE LIKE SY-DATUM.
  CLEAR LAYOUT.
  LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
*  LAYOUT-F2CODE            = '&ETA'.
*  LAYOUT-ZEBRA = 'X'.
  LAYOUT-INFO_FIELDNAME = 'COLOR'.
*  LAYOUT-COLTAB_FIELDNAME = 'COLOR'.
*  LAYOUT-DETAIL_POPUP      = 'X'.
*   LAYOUT-GET_SELINFOS = 'X'.
*   LAYOUT-DETAIL_POPUP = 'X'.
*  CLEAR I_EVENTS.
*  i_events-form = 'TOP_OF_PAGE'.
*  i_events-name = 'TOP_OF_PAGE'.
*  APPEND i_events TO events.
*  CLEAR I_EVENTS.
*  i_events-name = 'END_OF_LIST'.
*  i_events-form = 'END_OF_PAGE'.
*  APPEND i_events TO events.
*  CLEAR LINE.
*  LINE-TYP  = 'H'.
*  MOVE : '                            JOHNSON HEALTH TECH.CO.LTD ' TO  LINE-INFO .
*  MOVE : '             BOM明細表 ' TO  LINE-INFO.
*  APPEND LINE TO HEADING.
*  CLEAR line.
*  line-typ  = 'S'.
*  MOVE : p_budat TO h_sydate.
*  CONCATENATE  '日期: ' p_budat INTO line-info SEPARATED BY space .
*  APPEND line TO heading.
*  CLEAR LINE.
*  LINE-TYP  = 'S'.
*  CONCATENATE  '報表名稱:     ' SY-REPID INTO  LINE-INFO
*  SEPARATED      BY SPACE.
*  APPEND LINE TO HEADING.
*  CLEAR LINE.
*  LINE-TYP = 'S'.
*  CONCATENATE '製表日期   : ' SY-DATUM INTO  LINE-INFO
*  SEPARATED BY  SPACE.
*  APPEND LINE   TO   HEADING.
*  CLEAR LINE.
*  LINE-TYP = 'S'.
*  CONCATENATE '製表人員    : ' SY-UNAME INTO  LINE-INFO
*  SEPARATED BY  SPACE.
*  APPEND LINE   TO   HEADING.
*   CLEAR LINE.
*   LINE-TYP = 'S'.
*   CONCATENATE 'Page No  : ' SY-PAGNO INTO  LINE-INFO
*   SEPARATED BY  SPACE.
*   APPEND LINE   TO   HEADING.
ENDFORM.                    " FILL_LAYOUT_STRUCTURE
*&---------------------------------------------------------------------*
*&      Form  fill_field_catalog_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->F          text
*      -->T          text
*      -->O          text
*      -->D          text
*      -->H          text
*      -->TL         text
*----------------------------------------------------------------------*
FORM FILL_FIELD_CATALOG_TABLE  USING  F T O D H TL .
  DATA L_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  CLEAR L_FIELDCAT.
  STATICS POS LIKE SY-INDEX VALUE 20.
  POS = POS + 1.
  CLEAR T_FLD.
  MOVE 1 TO T_FLD-ROW_POS.
  MOVE POS TO T_FLD-COL_POS.
  MOVE F  TO L_FIELDCAT-FIELDNAME.
  MOVE T  TO L_FIELDCAT-TABNAME.
  MOVE O  TO L_FIELDCAT-OUTPUTLEN.
  MOVE D  TO L_FIELDCAT-SELTEXT_M.
  MOVE H  TO L_FIELDCAT-HOTSPOT.
  MOVE TL TO L_FIELDCAT-DO_SUM.
  APPEND L_FIELDCAT TO FIELDCAT.
ENDFORM.                    " FILL_FIELD_CATALOG_TABLE
*&---------------------------------------------------------------------*
*&      Form  DISP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM DISP.
  LOOP AT INTAB.
    MOVE-CORRESPONDING INTAB TO I_DISP_FINAL_TEMP.
    APPEND I_DISP_FINAL_TEMP.
    CLEAR I_DISP_FINAL_TEMP.
  ENDLOOP.
  PERFORM DISPLAY_DATA.    " Display the Final Data
ENDFORM.                    "OUT-PUT
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_DATA_TO_UNIX
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ITAB     text
*      -->P_FILE     text
*----------------------------------------------------------------------*
*DOWNLOAD TO PC.
FORM DOWNLOAD_DATA_TO_PC TABLES   P_ITAB
                           USING    P_FILE.
  DATA : W_FILE LIKE RLGRAP-FILENAME,
         W_TYPE LIKE RLGRAP-FILETYPE VALUE 'DAT'.
* Download file in SAP Application Server (Unix)
  CLEAR : W_FILE.
  MOVE P_FILE TO W_FILE.
  CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      FILENAME                = W_FILE
      FILETYPE                = W_TYPE
    TABLES
      DATA_TAB                = P_ITAB
    EXCEPTIONS
      FILE_OPEN_ERROR         = 1
      FILE_WRITE_ERROR        = 2
      INVALID_FILESIZE        = 3
      INVALID_TYPE            = 4
      NO_BATCH                = 5
      UNKNOWN_ERROR           = 6
      INVALID_TABLE_WIDTH     = 7
      GUI_REFUSE_FILETRANSFER = 8
      CUSTOMER_ERROR          = 9
      NO_AUTHORITY            = 10.
ENDFORM.                    "DOWNLOAD_DATA_TO_PC
*&---------------------------------------------------------------------*
*&      Form  DOWNLOAD_DATA_TO_UNIX
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ITAB     text
*      -->P_FILE     text
*----------------------------------------------------------------------*
FORM DOWNLOAD_DATA_TO_UNIX TABLES   P_ITAB
                           USING    P_FILE.
  DATA : W_FILE LIKE RLGRAP-FILENAME,
         W_TYPE LIKE RLGRAP-FILETYPE VALUE 'DAT'.
* Download file in SAP Application Server (Unix)
  OPEN DATASET P_FILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
  IF SY-SUBRC NE 0.
    EXIT.
  ENDIF.
  LOOP AT P_ITAB INTO V_TEXT.
    TRANSFER V_TEXT TO P_FILE.
  ENDLOOP.
  CLOSE DATASET P_FILE.
ENDFORM.                    "DOWNLOAD_DATA_TO_UNIX
*&---------------------------------------------------------------------*
*&      Form  EVENTS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT_EVENTS  text
*----------------------------------------------------------------------*
FORM EVENTS USING  IT_EVENTS TYPE SLIS_T_EVENT.
  DATA : WA_EVENT TYPE SLIS_ALV_EVENT.
  CLEAR WA_EVENT.
  WA_EVENT-NAME = 'TOP-OF-PAGE'.
  WA_EVENT-FORM = 'TOP_OF_PAGE'.
  APPEND WA_EVENT TO I_EVENTS.
ENDFORM.                    " f4000_event
*&---------------------------------------------------------------------*
*&      Form  ALV_HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_HEADER   text
*----------------------------------------------------------------------*
FORM ALV_HEADER USING I_HEADER TYPE SLIS_T_LISTHEADER.
  DATA: WA_LINE TYPE SLIS_LISTHEADER.
  CLEAR WA_LINE.
  WA_LINE-TYP = 'H'.
*  WA_LINE-INFO = 'Johnson Co.Ltd'.
  WA_LINE-INFO = '                                 xx科技有限公司'.
  APPEND WA_LINE TO I_HEADER.
ENDFORM.                    "ALV_HEADER
*&---------------------------------------------------------------------*
*&      Form  top-of-page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM TOP_OF_PAGE.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      IT_LIST_COMMENTARY = I_HEADER.
*      I_LOGO             = 'ENJOYSAP_LOGO'.
 
ENDFORM.                    "top-of-page
*&--------------------------------------------------------------------*
*&      Form  MY_COMMAND
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->UCOMM      text
*      -->SELFIELD   text
*---------------------------------------------------------------------*
FORM MY_COMMAND USING UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
  READ TABLE I_DISP_FINAL_TEMP INDEX SELFIELD-TABINDEX.
  CHECK SY-SUBRC = 0.
  CASE UCOMM.
    WHEN '&IC1'.
      CASE SELFIELD-SEL_TAB_FIELD.
        WHEN  'I_DISP_FINAL_TEMP-VBELN'.
          SET  PARAMETER  ID  'AUN'  FIELD  I_DISP_FINAL_TEMP-VBELN.
          CALL  TRANSACTION  'VA03'  AND  SKIP  FIRST  SCREEN.
        WHEN  'I_DISP_FINAL_TEMP-MATNR'.
          SET  PARAMETER  ID  'MAT'  FIELD  I_DISP_FINAL_TEMP-MATNR.
          CALL  TRANSACTION  'MM03'  AND  SKIP  FIRST  SCREEN.
      ENDCASE.
  ENDCASE.
ENDFORM.                    "MY_COMMAND

*&--------------------------------------------------------------------*
*&      Form  menu_set
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->RT_EXTAB   text
*---------------------------------------------------------------------*
FORM MENU_SET USING RT_EXTAB TYPE SLIS_T_EXTAB..
  SET PF-STATUS '9100'.   "定义屏幕状态,然后在里面定义自己的按钮
ENDFORM.                    "menu_set
阅读(872) | 评论(0) | 转发(0) |
0

上一篇:我的bolg之家

下一篇:abap入门之道

给主人留下些什么吧!~~