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

Retrives workflow data and show in HTML



 
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:41 pm    Post subject: Retrives workflow data and show in HTML Reply with quote

Code:
REPORT  Z_RMTIWARI_WORKFLOW_WEBVIEWER            .

*----------------------------------------------------------------------*
*       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 and prepares a graphical
*  representation in HTML.
*-----------------------------------------------------------------------
*  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.

*----------------------------------------------------------------------*
* Type declaration
*----------------------------------------------------------------------*
* Type for report

TYPES : BEGIN OF TY_MATRIX,
          X1(20),
          X2(20),
          X3(20),
          X4(20),
          X5(20),
          X6(20),
          X7(20),
          X8(20),
          X9(20),
          X10(20),
          X11(20),
          X12(20),
          X13(20),
        END OF TY_MATRIX.


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

data : GV_DIRECTORY LIKE rlgrap-filename,
       GV_FILE_NAME TYPE STRING,
       GV_WORKFLOW_FILE_NAME TYPE trdir-name.
DATA : BEGIN OF GT_HTML OCCURS 0,
        REC(1000) TYPE c,
       END OF GT_HTML.

DATA : GV_APPEND TYPE C value ' '.

DATA : GT_MATRIX type table of TY_MATRIX with HEADER line.

*----------------------------------------------------------------------*
* 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_MATRIX.

  PERFORM CONVERT_TABLE_TO_HTML  TABLES GT_MATRIX
                                        GT_HTML.



  PERFORM DOWNLOAD_WORKFLOW_FILE_ON_PC tables  GT_HTML
                                        using  GV_FILE_NAME.


  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 '.html' 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
                                  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                  = ' '
        WRITE_FIELD_SEPARATOR   = ' '
      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.

      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_MATRIX.

  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_MATRIX type standard table of TY_MATRIX with HEADER line.

DATA : LV_COUNTER type i,
       LV_OLD_NODE type swd_lines-pred_node.

    CLEAR LT_MATRIX.
    READ TABLE LT_LINES index 1.
    LT_MATRIX-x7 = LT_LINES-PRED_NODE.
    APPEND LT_MATRIX.


    LV_COUNTER = 1.
*    SORT lt_lines BY PRED_NODE.
*    LOOP AT lt_lines.
*
*     IF lv_old_node ne lt_lines-PRED_NODE.
*       if sy-tabix ne 1.
*         APPEND lt_matrix.
*       endif.
*       CLEAR  lt_matrix.
*       CLEAR  lv_counter.
*       lt_matrix-x7 = lt_lines-PRED_NODE.
*       lv_counter = 1.
*
*     ELSE.
       LV_COUNTER = lv_counter + 1.
       CASE LV_COUNTER.
         WHEN 1.
             LT_MATRIX-x6 = LT_LINES-SUCC_NODE.
         WHEN 2.
             LT_MATRIX-x6 = LT_LINES-SUCC_NODE.

         WHEN 3.
            LT_MATRIX-x8 = LT_LINES-SUCC_NODE.
         WHEN 4.
            LT_MATRIX-x5 = LT_LINES-SUCC_NODE.

         WHEN 5.
            LT_MATRIX-x9 = LT_LINES-SUCC_NODE.

         WHEN 6.
            LT_MATRIX-x4 = LT_LINES-SUCC_NODE.

         WHEN 7.
            LT_MATRIX-x10 = LT_LINES-SUCC_NODE.
         WHEN 8.
            LT_MATRIX-x3 = LT_LINES-SUCC_NODE.

         WHEN 9.
            LT_MATRIX-x11 = LT_LINES-SUCC_NODE.
         WHEN 10.
           LT_MATRIX-x2 = LT_LINES-SUCC_NODE.

         WHEN 11.
           LT_MATRIX-x12 = LT_LINES-SUCC_NODE.
         WHEN 12.
           LT_MATRIX-x1 = LT_LINES-SUCC_NODE.

         WHEN 13.
           LT_MATRIX-x13 = LT_LINES-SUCC_NODE.

         ENDCASE.
*       ENDIF.

          LV_OLD_NODE = LT_LINES-PRED_NODE.



*       ENDLOOP.

    APPEND  LT_MATRIX.

    YT_MATRIX[] = LT_MATRIX[].

ENDFORM.                    " get_workflow_data

*&---------------------------------------------------------------------*
*&      Form  convert_table_to_html
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GT_REP_TABLE  text
*      -->P_GT_HTML  text
*----------------------------------------------------------------------*
 
FORM convert_table_to_html  TABLES XT_MATRIX
                                  YT_HTML.

  DEFINE add_html.
    YT_HTML = &1.
    APPEND YT_HTML.

  END-OF-DEFINITION.


* Add Header to HTML
  add_html '<HTML>'.
  add_html '<head>'.
  add_html '<title>'.
  add_html 'ABAP Code WebViewer by www.rmtiwari.com'.
  add_html ' View :'.
*  add_html gv_prog_name.
  add_html '</title>'.
  add_html ' '.
  add_html '<meta name="description"'.
  add_html ' content="'.
*  add_html P_DESC.
  add_html '">'.
  add_html '<meta name="keywords"'.
  add_html 'content="' .
  add_html 'www.rmtiwari.com,ABAP Code WebViewer,ABAP Code,'.
*  add_html P_WFID .
  add_html '">'.

  add_html '<link type="text/css">'.
  add_html '</head>'.
  add_html '<BODY>'.
  add_html '<PRE>'.

  add_html '<TABLE>'.
  data : LV_TABLE_FIELD(15) type c.
  FIELD-SYMBOLS : <fs_table_value> TYPE ANY.
  data : LV_FIELD_NO        type i.
  LOOP AT XT_MATRIX.
    add_html '<TR>'.
    LV_FIELD_NO = 0.
    DO 13 times.
      LV_FIELD_NO = lv_field_no + 1.
      add_html '<TD>'.
*      concatenate 'XT_MATRIX-X' lv_field_no into lv_table_field.
*      MOVE  (lv_table_field) TO lv_table_value.

       ASSIGN COMPONENT LV_FIELD_NO of structure XT_MATRIX to
<fs_table_value>.
      add_html <fs_table_value>.
      add_html '</TD>'.
    ENDDO.
    add_html '</TR>'.
  ENDLOOP.

  add_html '</TABLE>'.
* Close HTML Tags
  add_html '</PRE>'.
  add_html '</BODY>'.
  add_html '</HTML>'.

ENDFORM.
*&---------------------------------------------------------------------*
*&      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

 
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.