SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Workflow data upload/download



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Business Workflow
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sun Oct 14, 2007 9:39 pm    Post subject: Workflow data upload/download Reply with quote

Workflow data upload/download ( Incomplete - upload does not work)

Requirement:
Was trying to create a utility that can download workflow data into a flat file which can further be used to upload workflow data or to show the workflow in an HTML. Good idea Smile, but I was not able to complete it ..

Processing:
These programs can be useful as an example for :
Download / Upload of several itabs into one file.
Use of Workflow data related function modules.

Code:

REPORT  Z_RMTIWARI_WORKFLOW_DOWNLOADER            .

*----------------------------------------------------------------------*
*       ABAP Code WebViewer Beta Version - Date - 08.05.2005
*----------------------------------------------------------------------*
*       Written By: Ram Manohar Tiwari             
*----------------------------------------------------------------------*
*       Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*
*  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


Code:

REPORT  Z_RMTIWARI_WORKFLOW_UPLOADER            .

*----------------------------------------------------------------------*
*       ABAP Code WebViewer Beta Version - Date - 08.05.2005
*----------------------------------------------------------------------*
*       Written By: Ram Manohar Tiwari             
*----------------------------------------------------------------------*
*       Presented By: http://www.rmtiwari.com
*----------------------------------------------------------------------*
*  This utility tool uploads workflow data downloaded using download
*  utility.
*-----------------------------------------------------------------------
*  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_INFILE 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(3000) 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 '%',
            GC_TAB          TYPE X VALUE '09'.

*----------------------------------------------------------------------*
* 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_INFILE.
  PERFORM GET_FILE_NAME USING   'P_INFILE'
                        CHANGING P_INFILE.

AT SELECTION-SCREEN.
  PERFORM SELECTION_SCREEN_VALIDATIONS.

START-OF-SELECTION.
  GV_FILE_NAME = P_INFILE.

* Upload File and get workflow data
  PERFORM GET_WORKFLOW_DATA    TABLES  GT_WORKFLOW.

END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  get_file_name
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
 
FORM get_file_name using         X_FILE_FIELD_NAME
                     changing    Y_FILE_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_FILE      type string,
         LV_RC        type I.

  data : LT_FILE_TABLE type standard table of FILE_TABLE.
  data : LV_FILE_TABLE_WA type FILE_NAME.

  CONSTANTS : LC_WINDOW_TITLE type string
                        value 'Select workflow download folder'.

  PERFORM READ_SCREEN_VALUES USING    X_FILE_FIELD_NAME
                             CHANGING Y_FILE_NAME.

  LV_FILE = Y_FILE_NAME.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
    EXPORTING
      WINDOW_TITLE            = LC_WINDOW_TITLE
      DEFAULT_EXTENSION       = '.txt'
      INITIAL_DIRECTORY       = LV_FILE
    CHANGING
      FILE_TABLE              = LT_FILE_TABLE
      RC                      = LV_RC
    EXCEPTIONS
      FILE_OPEN_DIALOG_FAILED = 1
      CNTL_ERROR              = 2
      ERROR_NO_GUI            = 3
      NOT_SUPPORTED_BY_GUI    = 4
      others                  = 5
          .

  if SY-subrc eq 0.
    READ TABLE LT_FILE_TABLE into LV_FILE_TABLE_WA index 1.
    P_INFILE = LV_FILE_TABLE_WA.
  endif.
ENDFORM.                    " get_file_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  upload_workflow_file_from_pc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM upload_workflow_file_from_pc tables   YT_UPLOAD
                                  using    X_INFILE.

* 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_UPLOAD'
      EXPORTING
        FILENAME                = X_INFILE
        FILETYPE                = 'ASC'
*        HAS_FIELD_SEPARATOR     = 'X'
      TABLES
        DATA_TAB                = YT_UPLOAD
      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.

      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.

DATA : LV_CURR_DATA(20)  TYPE C.
TYPES : BEGIN OF TY_SPLIT_LINE,
         REC(3000) TYPE C,
       END OF TY_SPLIT_LINE.

DATA : LT_SPLIT_LINE TYPE standard table of TY_SPLIT_LINE
                          with HEADER line.

FIELD-SYMBOLS: <fs1>,
               <fs2>.

DATA: LV_NEW_WFD_ID  LIKE swd_header-wfd_id,
        LV_TARGET_TASK LIKE swd_ahead-task,
        LV_TASK_ID     TYPE SWD_STEP_T,
        LV_NEW_OBJID   TYPE HRSOBJECT-OBJID.

    PERFORM UPLOAD_WORKFLOW_FILE_FROM_PC tables  GT_WORKFLOW
                                        using    GV_FILE_NAME.

    CALL FUNCTION 'RH_HRSOBJECT_COPY'
      EXPORTING
        REF_OTYPE                          = 'WS'
        REF_OBJID                          = '90000001'
*       ACT_LANGU                          = SY-LANGU
*        ACT_STEXT                          = 'Uploaded by Ram'
*        ACT_SHORT                          = 'Uploaded by Ram'
        NO_DIALOG                          = 'X'
     IMPORTING
*       COPY_OTYPE                         =
       COPY_OBJID                         = LV_NEW_OBJID
*       COPY_SHORT                         =
*       COPY_STEXT                         =
     EXCEPTIONS
       OBJECT_NOT_COPIED                  = 1
       NO_CLIENT_INDEP_MAIN_ALLOWED       = 2
       NO_CORR_NUMBER                     = 3
       OTHERS                             = 4
              .
    IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    CONCATENATE 'WS' LV_NEW_OBJID into LV_TARGET_TASK.

    LOOP AT GT_WORKFLOW.

      IF GT_WORKFLOW-rec = 'LT_HEADER'.
         LV_CURR_DATA  = 'LT_HEADER'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_GLOBAL'.
         LV_CURR_DATA  = 'LT_GLOBAL'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_TEXT'.
         LV_CURR_DATA  = 'LT_TEXT'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_BINDING'.
         LV_CURR_DATA  = 'LT_BINDING'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_STEPS'.
         LV_CURR_DATA  = 'LT_STEPS'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_LINES'.
         LV_CURR_DATA  = 'LT_LINES'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_METHOD'.
         LV_CURR_DATA  = 'LT_METHOD'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_CONDITION'.
         LV_CURR_DATA  = 'LT_CONDITION'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_TEMPLATES'.
         LV_CURR_DATA  = 'LT_CONDITION'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_FORMS'.
         LV_CURR_DATA  = 'LT_FORMS'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_TASKS'.
         LV_CURR_DATA  = 'LT_TASKS'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_EVENTS'.
         LV_CURR_DATA  = 'LT_EVENTS'.
         CONTINUE.
      ELSEIF GT_WORKFLOW-rec = 'LT_CONTEXT'.
         LV_CURR_DATA  = 'LT_CONTEXT'.
         CONTINUE.
      ENDIF.

      IF not LS_HEADER-wfd_id is initial.
        REPLACE ALL OCCURRENCES OF LS_HEADER-wfd_id in
                    GT_WORKFLOW with LV_TARGET_TASK .
      ENDIF.


      SPLIT GT_WORKFLOW at GC_TAB into table LT_SPLIT_LINE.
      LOOP AT LT_SPLIT_LINE.
        ASSIGN (lv_curr_data) to <fs2>.
        ASSIGN COMPONENT SY-tabix of STRUCTURE <fs2> to .
        <fs1> = LT_SPLIT_LINE-rec.

      ENDLOOP.
      IF LV_CURR_DATA = 'LT_HEADER'.
         LS_HEADER-OBJID = LV_TARGET_TASK.
         LS_HEADER = LT_HEADER.

         APPEND LT_HEADER.
      ELSEIF LV_CURR_DATA = 'LT_GLOBAL'.
         LS_GLOBAL = LT_GLOBAL.
         APPEND LT_GLOBAL.
      ELSEIF LV_CURR_DATA = 'LT_TEXT'.
         APPEND LT_TEXT.
      ELSEIF LV_CURR_DATA = 'LT_BINDING'.
         APPEND LT_BINDING.
      ELSEIF LV_CURR_DATA = 'LT_STEPS'.
         APPEND LT_STEPS.
      ELSEIF LV_CURR_DATA = 'LT_LINES'.
         APPEND LT_LINES.
      ELSEIF LV_CURR_DATA = 'LT_METHOD'.
         APPEND LT_METHOD.
      ELSEIF LV_CURR_DATA = 'LT_CONDITION'.
         APPEND LT_CONDITION.
      ELSEIF LV_CURR_DATA = 'LT_TEMPLATES'.
         APPEND LT_CONDITION.
      ELSEIF LV_CURR_DATA = 'LT_FORMS'.
         APPEND LT_FORMS.
      ELSEIF LV_CURR_DATA = 'LT_TASKS'.
         APPEND LT_TASKS.
      ELSEIF LV_CURR_DATA = 'LT_EVENTS'.
         APPEND LT_EVENTS.
      ELSEIF LV_CURR_DATA = 'LT_CONTEXT'.
         APPEND LT_CONTEXT.
      ENDIF.

.
    ENDLOOP.



*      clear : ls_header-wfd_id.

      CALL FUNCTION 'SWD_GET_NEXT_WFDID'
        EXPORTING
          act_task        = LV_TARGET_TASK
        IMPORTING
          next_free_objid = LV_NEW_WFD_ID.


   LV_WFDKEY-WFD_ID   = LV_NEW_WFD_ID.
   LV_WFDKEY-VERSION  = '0000'.
   LV_WFDKEY-EXETYP   = 'S'.

   LS_HEADER-WFD_ID   = LV_NEW_WFD_ID.
   LS_HEADER-VERSION  = '0000'.
   LS_HEADER-EXETYP   = 'S'.
   LS_HEADER-OBJID    = lv_new_wfd_id+2(8).
   LS_HEADER-LANGUAGE = SY-langu.
   LS_HEADER-TASK     = LV_NEW_WFD_ID.
   LS_HEADER-TASK_STEXT = 'Test By RMT'.
   LS_HEADER-LONGTEXT   = 'Test By RMT'.

   LS_HEADER-CHANGED_BY = SY-uname.
   LS_HEADER-CHANGED_ON = SY-datum.
   LS_HEADER-CHANGED_AT = SY-uzeit.



*
*   concatenate  'WS' lv_new_wfd_id into lv_target_task.
   LV_TARGET_TASK = LV_NEW_WFD_ID.
   LV_TASK_ID = LV_TARGET_TASK.


* get container
  TRY.
      CALL METHOD cl_swf_cnt_factory=>create_swd_task_container
        EXPORTING
          im_task_id        = LV_TARGET_TASK
          im_wfdkey         = LV_WFDKEY
        IMPORTING
          ex_task_container = LS_CONTAINER.
    CATCH cx_root.
  ENDTRY.

*
  LOOP AT LT_STEPS.
    LT_STEPS-CREATED_BY = SY-uname.
    LT_STEPS-CREATED_ON = SY-datum.
    LT_STEPS-CREATED_AT = SY-uzeit.
    MODIFY LT_STEPS.
  ENDLOOP.


* set buffer
  CALL FUNCTION 'SWD_INTERN_SET_BUFFER'
    EXPORTING
      wfd_header    = LS_HEADER
      wfd_global    = LS_GLOBAL
      wfd_container = LS_CONTAINER
    TABLES
      wfd_events    = LT_EVENTS
      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_forms     = LT_FORMS
      wfd_tasks     = LT_TASKS
      wfd_templates = LT_TEMPLATES.


CALL FUNCTION 'SWD_WF_GRAPHIC_START'
* EXPORTING
*   FOCUS_NODEID          =
* EXCEPTIONS
*   ERROR_IN_GRAFIK       = 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.


*
* CALL FUNCTION 'SWD_WORKFLOW_STORE'
*   EXPORTING
*     IM_TASK                       = lv_target_task
*    IM_WFDKEY                     = lv_wfdkey
*    IM_OKCODE                     = 'COPY'
*  IMPORTING
*    EX_TASK                       = lv_target_task
*    EX_WFDKEY                     = lv_wfdkey
*  EXCEPTIONS
*    INTERNAL_DATABASE_ERROR       = 1
*    INTERNAL_NO_DEFINITION        = 2
*    ACTION_CANCELED               = 3
*    OTHERS                        = 4
*           .
*  IF sy-subrc ne 0.
*    MESSAGE E004(wd) WITH lv_target_task.
*
*  ELSE.
*
*      MESSAGE I002(AQ) WITH
*     'Workflow Downloaded ' lv_wfdkey-WFD_ID.
*
*      commit work.
*  ENDIF.

*
*
*
*
** store new workflow
*  CALL FUNCTION 'SWD_STORE'
*    EXPORTING
*      act_task    = lv_target_task
*      act_wfdkey  = lv_wfdkey
*      dialog_flag = 'X'
*      act_okcode  = 'SAVE'
*      commit_flag = ' '
*    EXCEPTIONS
*      INTERNAL_DATABASE_ERROR = 01
*      INTERNAL_NO_DEFINITION  = 02
*      OTHERS      = 03.
*  IF sy-subrc ne 0.
*    MESSAGE E004(wd) WITH lv_target_task.
*
*  ELSE.
*
*      MESSAGE I002(AQ) WITH
*     'Workflow Downloaded ' lv_wfdkey-WFD_ID.
*
*      commit work.
*  ENDIF.

* activation

    CALL FUNCTION 'SWD_ACTIVATE_WORKFLOW'
      EXPORTING
        act_task                = LV_TARGET_TASK
        act_wfdkey              = LV_WFDKEY
      EXCEPTIONS
        internal_database_error = 01.
    IF SY-subrc ne 0.
      MESSAGE I250(wd) WITH LV_TARGET_TASK.
    ENDIF.


ENDFORM.                    " get_workflow_data
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Business Workflow All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.