Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member206068
Discoverer

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.

Provide Project Details.


Create Entity Type with the required fields.


For Upload_Doc : Provide the following details.

Created Entity Type as shown below.

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


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

Insert field and check as key field (mandatory).

Click on Save

Now click on Generate button.

Then we will get below screen, click on continue

It displays generated OBJECTS SUCCESSFULLY.

And at that time it generates all classes automatically.

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

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.

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

Code:

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_STREAM.
DATA ls_documentdata    TYPE  bapi_doc_draw2,
       ls_DOCUMENTNUMBER 
TYPE  BAPI_DOC_AUX-DOCNUMBER,
       ls_DOCUMENTTYPE   
TYPE  BAPI_DOC_AUX-DOCTYPE,
       ls_DOCUMENTPART   
TYPE  BAPI_DOC_AUX-DOCPART,
       ls_DOCUMENTVERSION
TYPE  BAPI_DOC_AUX-DOCVERSION,
       ls_RETURN         
TYPE  BAPIRET2,
       lv_filename       
TYPE DBMSGORA-FILENAME,
       lv_PURE_FILENAME  
TYPE SDBAH-ACTID,
       lv_PURE_EXTENSION 
TYPE SDBAD-FUNCT.

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_documentdata
-wsapplication1 = 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_files
-originaltype       = '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_return-type CA 'EA'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

LS_DOC
-DOCNAME = 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

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

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

Now click on POST HTTP Method and Execute.

Service Response:


It will generate a document number as shown below.

Successfully uploaded document in DMS Server.


Result:

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

To open the file double click on it.

File got opened successfully as shown.

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

Thanks&Regards,

Prasanna Addula

6 Comments
Labels in this area