Sunday, March 6, 2011

SAP DMS Upload program

Program to upload documents in DMS

*&---------------------------------------------------------------------*
*& Report ZBAPI_DMS_CV01N
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zbapi_dms_cv01n.

TYPES: BEGIN OF t_record,
gv_descripcion(40), " Description
documentversion(2), " Documet version
documentpart(3), " Document part
created_by(12), " Creator
wsapplication(3), " Document type
docfile(255), " File path
charname(30), " Characteristic Name
charvalue(30) , " Plant maintenance Document
doctyp(3), " Document Type
END OF t_record.

DATA: record TYPE STANDARD TABLE OF t_record WITH HEADER LINE.

DATA: gv_documento LIKE draw-doknr,
* gv_clase LIKE draw-dokar VALUE 'PMD',
gv_version LIKE draw-dokvr VALUE '00',
gv_part LIKE draw-doktl VALUE '000',
gv_descripcion LIKE drat-dktxt,
gv_return LIKE bapiret2,
gv_ruta LIKE bapi_doc_files2-docfile.

DATA: gs_documentdata LIKE bapi_doc_draw2,
gt_characteristicvalues LIKE bapi_characteristic_values OCCURS 0 WITH HEADER LINE,
gt_classallocations LIKE bapi_class_allocation OCCURS 0 WITH HEADER LINE,
gt_documentfiles LIKE bapi_doc_files2 OCCURS 0 WITH HEADER LINE.

DATA : l_path TYPE string,
length TYPE i.
*--->>> selection Screen
SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-002.
PARAMETERS: pa_fname LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK rad1.

*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_fname.
*&---------------------------------------------------------------------*

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = ',*.TXT,*.TXT.'
mode = 'O'
IMPORTING
filename = pa_fname
EXCEPTIONS
inv_winsys = 01
no_batch = 02
selection_cancel = 03
selection_error = 04.

START-OF-SELECTION.

l_path = pa_fname.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_path
* FILETYPE = 'ASC'
has_field_separator = 'X'
IMPORTING
filelength = length
TABLES
data_tab = record
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.

IF sy-subrc <> 0.
MESSAGE i016(pg) WITH 'Invalid file. Please check again'.
STOP.
ENDIF.

LOOP AT record.

CLEAR: gs_documentdata.

gs_documentdata-documenttype = record-doctyp.
gs_documentdata-documentnumber = gv_documento.
gs_documentdata-documentversion = record-documentversion.
gs_documentdata-documentpart = record-documentpart.
gs_documentdata-description = record-gv_descripcion.

CLEAR: gt_characteristicvalues, gt_characteristicvalues[].
gt_characteristicvalues-classtype = '017'.
gt_characteristicvalues-classname = 'PM_DOCUMENT'.
gt_characteristicvalues-charname = record-charname.
gt_characteristicvalues-charvalue = record-charvalue.
APPEND gt_characteristicvalues.

CLEAR: gt_classallocations, gt_classallocations[].
gt_classallocations-classtype = '017'.
gt_classallocations-classname = 'PM_DOCUMENT'.
APPEND gt_classallocations.

CLEAR: gt_documentfiles, gt_documentfiles[].
gt_documentfiles-wsapplication = record-wsapplication."'XLS'.
*--->>>
* CONCATENATE record-docfile '.' record-wsapplication INTO record-docfile.
* CONDENSE record-docfile.
*--->>>
gt_documentfiles-docfile = record-docfile. " file path
gt_documentfiles-created_by = gt_documentfiles-created_by.
gt_documentfiles-storagecategory = 'Z5'.
gt_documentfiles-checkedin = 'X'.
APPEND gt_documentfiles.

*--->>>
CLEAR: gv_return.
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
documentdata = gs_documentdata
IMPORTING
return = gv_return
TABLES
characteristicvalues = gt_characteristicvalues
classallocations = gt_classallocations
documentfiles = gt_documentfiles.
IF gv_return-type CA 'AE'.
* WRITE gv_return-message.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
CLEAR: gs_documentdata, gv_return, gt_characteristicvalues[], gt_classallocations[], gt_documentfiles[].
ENDLOOP.

************************************************************************************
Data Uploading Format







Description Documet version Document partCreatorDocument typeFile pathCharacteristic NamePlant maintenance DocumentDocument Type
Description test00000developer1PPT\\172.17.9.151\DMS-Upload\Mobile SafetyMACHINEDRAWINGSPLANNING & RELIABILITYPMD


Permitted document types



















Doc TypeText
DOCMicrosoft Word file
DOXMS word 2007
DRWAutocad files
HTMHTML Files
IMGScanned Files (Image)
JPGScanned Files
MPPMS Project
PDFAcrobat Reader
PPTMicrosoft Powerpoint
PPXMicrosoft Powerpoint
SIMSAP Tutor Application
TXTText Files
VSDMicrosoft Visio files
WWIWinword 6.0
XLSMicrosoft EXCEL
XLXMS excel 2007
ZTFTIFF formatt - Scanned Files

SAP Dynamic Action

This Link is very good

http://wiki.sdn.sap.com/wiki/display/Snippets/Dynamic+Action