Chinaunix首页 | 论坛 | 博客
  • 博客访问: 203402
  • 博文数量: 54
  • 博客积分: 2056
  • 博客等级: 大尉
  • 技术积分: 568
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-25 12:07
文章分类

全部博文(54)

文章存档

2014年(1)

2013年(1)

2012年(1)

2011年(2)

2010年(1)

2009年(11)

2008年(28)

2007年(9)

我的朋友

分类:

2007-08-28 23:13:27

*&---------------------------------------------------------------------*
*& Report  Z14841_WORKFLOW_DOWNLOADER
*&
*----------------------------------------------------------------------*
*       ABAP Code WebViewer Beta Version - Date - 08.05.2005
*----------------------------------------------------------------------*
*       Written By: Ram Manohar Tiwari     
*----------------------------------------------------------------------*
*       Presented By:
*----------------------------------------------------------------------*
*  This utility tool retrives workflow data, converts it into a flat
*  file and downloads it on the chosen directory of your PC.
*-----------------------------------------------------------------------
*  This utility is developed on MiniSAP and should be compatible with
*  SAP4.7 version. Though with slight modifications to remove
*  the value added aspects will make it compatible with any versions of
*  SAP.
*-----------------------------------------------------------------------
* SELECTION SCREEN
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_wfid    TYPE swd_header-wfd_id  OBLIGATORY,
             p_vers    TYPE swd_header-version OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1 .
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_outdir LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b2.
*----------------------------------------------------------------------*
* Table declaration
*----------------------------------------------------------------------*
*-----------------------------------------------------------------------
DATA : gv_directory LIKE rlgrap-filename,
       gv_file_name TYPE string,
       gv_workflow_file_name TYPE trdir-name.
DATA : BEGIN OF gt_workflow OCCURS 0,
        rec(1000) TYPE c,
       END OF gt_workflow.
DATA : gv_workflow_wa        LIKE LINE OF gt_workflow.
DATA : gv_append TYPE c VALUE ' '.
*----------------------------------------------------------------------*
* Type declaration
*----------------------------------------------------------------------*
* Type for report
*----------------------------------------------------------------------*
* CONSTANTS                                                            *
*----------------------------------------------------------------------*
CONSTANTS : gc_false(1)     TYPE c VALUE ' ',
            gc_true(1)      TYPE c VALUE 'X',
            gc_quotes1(1)   TYPE c VALUE '''',
            gc_asterik(1)   TYPE c VALUE '*',
            gc_comma(1)     TYPE c VALUE ',',
            gc_quotes(1)    TYPE c VALUE '"',
            gc_percent(1)   TYPE c VALUE '%'.
*----------------------------------------------------------------------*
* Data declaration
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_progf.
*  PERFORM get_report_name USING    'P_VERS'
*                          CHANGING  p_vers.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_outdir.
  PERFORM get_directory_name USING    'P_OUTDIR'
                             CHANGING p_outdir.
AT SELECTION-SCREEN.
  PERFORM selection_screen_validations.
START-OF-SELECTION.
  PERFORM prepare_file_name   USING   p_outdir
                                      gv_workflow_file_name
                           CHANGING   gv_file_name.
* Read workflow tables and convert for download
  PERFORM get_workflow_data    TABLES  gt_workflow.

  PERFORM show_workflow_file USING gv_file_name.
 
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  get_report_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
*FORM get_report_name using    x_report_field_name
*                     changing y_report_name.
*
*
*  PERFORM read_screen_values USING    x_report_field_name
*                             CHANGING y_report_name.
*
*  IF x_report_field_name eq 'P_PROG'.
*
*    CALL FUNCTION 'REPOSITORY_INFO_SYSTEM_F4'
*      EXPORTING
*        object_type           = 'PROG'
*        object_name           = y_report_name
*        suppress_selection    = 'X'
*        without_personal_list = ' '
*      IMPORTING
*        object_name_selected  = p_prog
*      EXCEPTIONS
*        cancel                = 01.
*
*  ELSEIF x_report_field_name eq 'P_PROGF'.
*    CALL FUNCTION 'REPOSITORY_INFO_SYSTEM_F4'
*      EXPORTING
*        object_type           = 'FUNC'
*        object_name           = y_report_name
*        suppress_selection    = ' '
*        without_personal_list = 'X'
*      IMPORTING
*        object_name_selected  = p_progf
*      EXCEPTIONS
*        cancel                = 01.
*  ENDIF.
*
*ENDFORM.                    " get_directory_name
*&---------------------------------------------------------------------*
*&      Form  get_file_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_directory_name USING    x_file_field_name
                     CHANGING    y_directory_name.
  CLASS cl_gui_frontend_services DEFINITION LOAD.
  DATA : lv_file_path TYPE rlgrap-filename,
         lv_file_name TYPE rlgrap-filename,
         lv_outdir    TYPE string,
         lv_directory TYPE string.
  CONSTANTS : lc_window_title TYPE string
                        VALUE 'Select workflow download folder'.
  PERFORM read_screen_values USING    x_file_field_name
                             CHANGING y_directory_name.
  lv_directory = y_directory_name.
  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title         = lc_window_title
      initial_folder       = lv_directory
    CHANGING
      selected_folder      = lv_outdir
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3.
 
  IF sy-subrc EQ 0.
    p_outdir = lv_outdir.
  ENDIF.
ENDFORM.                    " get_directory_name
*&--------------------------------------------------------------------*
*&      Form  read_screen_values
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->P_FIELD    text
*      -->P_VALUE    text
*---------------------------------------------------------------------*
FORM read_screen_values USING    x_field
                        CHANGING y_value.
  DATA: lv_dynpname LIKE d020s-prog,
        lv_dynpnumb LIKE d020s-dnum.
  DATA: BEGIN OF lt_dynpvaluetab OCCURS 1.
          INCLUDE STRUCTURE dynpread.
  DATA: END   OF lt_dynpvaluetab.
  lv_dynpname = sy-repid.
  lv_dynpnumb = sy-dynnr.
  REFRESH lt_dynpvaluetab.
  lt_dynpvaluetab-fieldname = x_field.
  APPEND lt_dynpvaluetab.
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = lv_dynpname
      dynumb               = lv_dynpnumb
    TABLES
      dynpfields           = lt_dynpvaluetab
    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
      OTHERS               = 10.
  IF sy-subrc = 0.
    READ TABLE lt_dynpvaluetab INDEX 1.
    MOVE: lt_dynpvaluetab-fieldvalue TO y_value.
  ENDIF.
ENDFORM.                    " read_screen_values
*&---------------------------------------------------------------------*
*&      Form  selection_screen_validations
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM selection_screen_validations .
*      MESSAGE e001(AQ) WITH
*     'This Report does not exist'.
  CONCATENATE p_wfid '.txt' INTO gv_workflow_file_name.
ENDFORM.                    " selection_screen_validations
*&--------------------------------------------------------------------*
*&      Form  prepare_file_name
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->x_directory    text
*      -->x_program_name text
*      -->y_file_name    text
*---------------------------------------------------------------------*
FORM prepare_file_name USING x_directory
                             x_file
                    CHANGING y_file_name.
  CONCATENATE x_directory '\' x_file INTO y_file_name.
 
ENDFORM.                    " prepare_file_name
*&---------------------------------------------------------------------*
*&      Form  download_workflow_file_on_pc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM download_workflow_file_on_pc TABLES   xt_download
                                           xt_header_table
                                  USING    x_outfile TYPE string.

* Use gui_download if file is located on the local PC.
* WS_download only works in foreground
  IF sy-batch EQ 'X'.
    MESSAGE e001(aq) WITH
   'This program cannot be executed in background'.
*   ERROR: Unable to download locally stored files when running in
*   background
  ELSE.

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = x_outfile
        filetype                = 'ASC'
        append                  = gv_append
        write_field_separator   = 'X'
      TABLES
        data_tab                = xt_header_table
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
* Status of download
    CASE sy-subrc.
      WHEN 0.
*        MESSAGE I002(AQ) WITH
*        'Workflow downloaded as ' x_outfile.
        gv_append = 'X'.
      WHEN OTHERS.
*        Upload unsuccessful - error message
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDCASE.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = x_outfile
        filetype                = 'ASC'
        append                  = gv_append
        write_field_separator   = 'X'
      TABLES
        data_tab                = xt_download
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
* Status of download
    CASE sy-subrc.
      WHEN 0.
*        MESSAGE I002(AQ) WITH
*        'Workflow downloaded as ' x_outfile.
        gv_append = 'X'.
      WHEN OTHERS.
*        Upload unsuccessful - error message
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDCASE.
  ENDIF.
ENDFORM.                    " download_workflow_file_on_pc
*&---------------------------------------------------------------------*
*&      Form  get_workflow_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_workflow  text
*----------------------------------------------------------------------*
FORM get_workflow_data  TABLES  yt_workflow.
  DATA : lv_task     TYPE  swd_ahead-task,
         lv_wfdkey   TYPE  swd_wfdkey,
         lv_obj_ext  TYPE  rhobjects-object.
  DATA : ls_header     TYPE swd_ahead,
         ls_global     TYPE swdiglobal,
         ls_container  TYPE REF TO  if_swf_cnt_container.
  TYPES: BEGIN OF ty_header_table,
           header TYPE char100,
         END OF ty_header_table.
  DATA :lt_header     TYPE STANDARD TABLE OF swd_ahead
                           WITH HEADER LINE,
        lt_global     TYPE STANDARD TABLE OF swdiglobal
                           WITH HEADER LINE,
        lt_container  TYPE STANDARD TABLE OF REF TO
if_swf_cnt_container WITH HEADER LINE.

  DATA : lt_text     TYPE STANDARD TABLE OF swd_text   WITH HEADER LINE,
         lt_binding  TYPE STANDARD TABLE OF swd_bindef WITH HEADER LINE,
         lt_steps    TYPE STANDARD TABLE OF swd_astep  WITH HEADER LINE,
         lt_lines    TYPE STANDARD TABLE OF swd_alines WITH HEADER LINE,
         lt_method   TYPE STANDARD TABLE OF swd_imethd WITH HEADER LINE,
        lt_condition TYPE STANDARD TABLE OF swd_condef WITH HEADER LINE,
         lt_templates TYPE STANDARD TABLE OF swuoprop  WITH HEADER LINE,
         lt_forms     TYPE STANDARD TABLE OF swdiforms WITH HEADER LINE,
        lt_tasks     TYPE STANDARD TABLE OF swd_itasks WITH HEADER LINE,
        lt_events    TYPE STANDARD TABLE OF swd_ievnts WITH HEADER LINE,
        lt_context   TYPE STANDARD TABLE OF swd_wfctxt WITH HEADER LINE.

  lv_wfdkey-wfd_id   = p_wfid.
  lv_wfdkey-version  = p_vers.
  lv_wfdkey-exetyp   = 'S'.
  lv_obj_ext = p_wfid.
  CALL FUNCTION 'SWD_GET_WORKFLOW_DEFINITION'
    EXPORTING
      act_wfdkey         = lv_wfdkey
      act_object_ext     = lv_obj_ext
    IMPORTING
      wfd_header         = ls_header
      wfd_global         = ls_global
      wfd_container      = ls_container
    TABLES
      wfd_text           = lt_text
      wfd_binding        = lt_binding
      wfd_steps          = lt_steps
      wfd_lines          = lt_lines
      wfd_method         = lt_method
      wfd_condition      = lt_condition
      wfd_templates      = lt_templates
      wfd_forms          = lt_forms
      wfd_tasks          = lt_tasks
*      wfd_events         = lt_events
      wfd_conttext       = lt_context
    EXCEPTIONS
      internal_not_found = 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.

  DATA : lt_header_table TYPE STANDARD TABLE OF ty_header_table
                              WITH HEADER LINE.

  APPEND ls_header TO lt_header.
  APPEND ls_global TO lt_global.
  APPEND ls_container TO lt_container.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_HEADER'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_header
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_GLOBAL'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_global
                                               lt_header_table
                                      USING    gv_file_name.
*    lt_header_table = 'LT_CONTAINER'.
*    append lt_header_table.
*    clear lt_header_table.
*    PERFORM download_workflow_file_on_pc tables  lt_container
*                                                 lt_header_table
*                                        using    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_TEXT'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_text
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_BINDING'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_binding
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_STEPS'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_steps
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_LINES'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_lines
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_CONDITION'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_condition
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_TEMPLATES'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_templates
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_FORMS'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_forms
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_TASKS'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_tasks
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_EVENTS'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_events
                                               lt_header_table
                                      USING    gv_file_name.
  CLEAR : lt_header_table[].
  lt_header_table = 'LT_CONTEXT'.
  APPEND lt_header_table.
  CLEAR lt_header_table.
  PERFORM download_workflow_file_on_pc TABLES  lt_context
                                               lt_header_table
                                      USING    gv_file_name.
 
ENDFORM.                    " get_workflow_data
*&---------------------------------------------------------------------*
*&      Form  show_workflow_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->X_FILE_NAME  text
*----------------------------------------------------------------------*
FORM show_workflow_file  USING    x_file_name.
  DATA : lv_url(200) TYPE c.
  lv_url = x_file_name.
  CALL FUNCTION 'CALL_BROWSER'
    EXPORTING
      url = lv_url.

ENDFORM.                    " show_workflow_file
 
 
************************
示例:
P_WFID          =                WS96000079
P_VERS          =                0000

C:\Documents and Settings\Gong huiwen\桌面
阅读(878) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~