Scenario:

Why and when we use DMS?


DMS is used to read the content of storage documents (external data server but not SAP content server).Here I am going to explain one of mine client requirement to upload the document after/while creating the Purchase requisition in item level. So in order to achieve the functionality we need to upload the file from non-SAP server into DMS (CV01N) using Gateway.

By Using this Blog, you can upload a wide range of documents like Word Documents,Excel Sheets, PDF, Text Files and Images and many more through Gateway service.

Procedure:

Goto SEGW TCode and Create Project as shown below.

/wp-content/uploads/2016/08/1_1020282.png

Provide Project Details.

/wp-content/uploads/2016/08/2_1020283.png


Create Entity Type with the required fields.

/wp-content/uploads/2016/08/3_1020314.png


For Upload_Doc : Provide the following details.

/wp-content/uploads/2016/08/4_1020315.png

Created Entity Type as shown below.

Double click on Entity Type created and put tick mark on Media type check box (mandatory).

/wp-content/uploads/2016/08/5_1020316.png

/wp-content/uploads/2016/08/6_1020317.png


Double click on Properties and Click on Insert Row to add fields.

/wp-content/uploads/2016/08/7_1020318.png

Insert field and check as key field (mandatory).

/wp-content/uploads/2016/08/8_1020319.png

Click on Save

/wp-content/uploads/2016/08/9_1020320.png

Now click on Generate button.

/wp-content/uploads/2016/08/10_1020321.png

Then we will get below screen, click on continue

/wp-content/uploads/2016/08/11_1020322.png

It displays generated OBJECTS SUCCESSFULLY.

/wp-content/uploads/2016/08/12_1020326.png

And at that time it generates all classes automatically.

/wp-content/uploads/2016/08/13_1020327.png

Then Redefine the DEFINE method in the *MPC_EXT Class and add the below logic.

/wp-content/uploads/2016/08/14_1020328.png

Method DEFINE.

super->DEFINE( ).
 

DATA: lo_entity     type REF TO  /IWBEP/IF_MGW_ODATA_ENTITY_TYP,

lo_property type REF TO  /IWBEP/IF_MGW_ODATA_PROPERTY.

lo_entity = model->GET_ENTITY_TYPE( IV_ENTITY_NAME = ‘ Upload_Doc’ ).”Entity Name

IF lo_entity is BOUND.

lo_property = lo_entity->GET_PROPERTY( IV_PROPERTY_NAME = ‘DocName’ ).”Key Value(SLUG)

lo_property->SET_AS_CONTENT_TYPE( ).


ENDIF.

Endmethod.

Right Click on ZCL_ZUPLOAD_DOC_DMS_DPC_EXT class and select Go to ABAP Workbench.

/wp-content/uploads/2016/08/15_1020329.png

Redefine CREATE_STREAM Method and implement the below logic to upload document into the DMS Server from ODATA Service.

/wp-content/uploads/2016/08/16_1020330.png

Code:

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
DATA ls_documentdata    TYPE  bapi_doc_draw2,
       ls_DOCUMENTNUMBER 
TYPE  BAPI_DOC_AUXDOCNUMBER,
       ls_DOCUMENTTYPE   
TYPE  BAPI_DOC_AUXDOCTYPE,
       ls_DOCUMENTPART   
TYPE  BAPI_DOC_AUXDOCPART,
       ls_DOCUMENTVERSION
TYPE  BAPI_DOC_AUXDOCVERSION,
       ls_RETURN         
TYPE  BAPIRET2,
       lv_filename       
TYPE DBMSGORAFILENAME,
       lv_PURE_FILENAME  
TYPE SDBAHACTID,
       lv_PURE_EXTENSION 
TYPE SDBADFUNCT.

DATAlt_files           TYPE TABLE OF BAPI_DOC_FILES2,
       ls_files          
TYPE          BAPI_DOC_FILES2,
* Short Texts
       lt_drat           
TYPE TABLE OF bapi_doc_drat,
* Object links
       lt_drad           
TYPE TABLE OF bapi_doc_drad,
       LS_DOC            
TYPE ZCL_ZUPLOAD_DOC_DMS_MPC=>TS_UPLOAD_DOC.
* Pass SLUG value


lv_filename
= IV_SLUG.


* Function Module to split and get file name and extension


CALL FUNCTION ‘SPLIT_FILENAME’
EXPORTING
long_filename       
= lv_filename
IMPORTING
PURE_FILENAME       
lv_PURE_FILENAME
PURE_EXTENSION      
lv_PURE_EXTENSION.

* Allocate document data
ls_documentdata
documenttype    = ‘DOC’.
ls_documentdata
documentversion = ‘000’.
ls_documentdata
documentpart    = ’00’.

ls_documentdatawsapplication1 = lv_PURE_EXTENSION.
ls_documentdata
wsapplication2 = lv_PURE_EXTENSION.

* Check original 1 into the SAP data base at the same time
REFRESH lt_files.
CLEAR lt_files.

ls_filesoriginaltype       = ‘1’.
ls_files
WSAPPLICATION      = lv_PURE_EXTENSION.
ls_files
SOURCEDATACARRIER  = ‘SAP-SYSTEM’.
ls_files
docfile            = IV_SLUG.
APPEND ls_files to lt_files.

* BAPI to Upload document into DMS Server
CALL FUNCTION ‘BAPI_DOCUMENT_CREATE2’
EXPORTING
DOCUMENTDATA              
= ls_documentdata
IMPORTING
DOCUMENTTYPE              
= ls_DOCUMENTTYPE
DOCUMENTNUMBER            
= ls_DOCUMENTNUMBER
DOCUMENTPART              
= ls_DOCUMENTPART
DOCUMENTVERSION           
= ls_DOCUMENTVERSION
RETURN                     = ls_RETURN
TABLES
DOCUMENTDESCRIPTIONS      
= lt_drat
OBJECTLINKS               
= lt_drad
DOCUMENTFILES             
= lt_files.
IF ls_returntype CA ‘EA’.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

ELSE.

CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.

LS_DOCDOCNAME = ls_DOCUMENTNUMBER.

copy_data_to_ref(
EXPORTING
is_data
LS_DOC
CHANGING
cr_data
= er_entity ).
ENDIF.

endmethod.


All input Values we have to get into the SLUG parameter from the UI Side. If you have multiple input parameter values then concatenate multiple parameter values with delimiter we have to get the values in SLUG parameter.


Testing Our Service:

Now we will test our service in Gateway Client transaction /IWFND/MAINT_SERVICE

/wp-content/uploads/2016/08/17_1020332.png

Select the entityset and Upload a file through add file button which is on left side corner as shown in the below screen shot.

/wp-content/uploads/2016/08/18_1020333.png

Pass SLUG values(mandatory) file name as shown in the below screen shot.

/wp-content/uploads/2016/08/19_1020334.png

Now click on POST HTTP Method and Execute.

/wp-content/uploads/2016/08/20_1020338.png

Service Response:


It will generate a document number as shown below.

/wp-content/uploads/2016/08/21_1020339.png

Successfully uploaded document in DMS Server.


Result:

Go to CV03N Transaction and provide document number and document type and click enter as shown below.

/wp-content/uploads/2016/08/22_1020340.png

To open the file double click on it.

/wp-content/uploads/2016/08/23_1020341.png

File got opened successfully as shown.

/wp-content/uploads/2016/08/24_1020342.png

In the same way we can upload any type of document into DMS.

Thanks&Regards,

Prasanna Addula

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply