Posted: Sun Oct 14, 2007 9:39 pm Post subject: Workflow data upload/download
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 , 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.
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
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.