Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

Upload document into DMS Server using Net Weaver Gateway

$
0
0

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

 

1.png

Provide Project Details.

2.png


Create Entity Type with the required fields.

3.png


For Upload_Doc : Provide the following details.

4.png

Created Entity Type as shown below.

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

5.png

6.png


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

7.png

Insert field and check as key field (mandatory).

8.png

Click on Save

9.png

Now click on Generate button.

10.png

 

Then we will get below screen, click on continue

11.png

It displays generated OBJECTS SUCCESSFULLY.

12.png

And at that time it generates all classes automatically.

13.png

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

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

15.png

 

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

16.png

 

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

 

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

18.png

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

 

19.png

 

 

Now click on POST HTTP Methodand Execute.

20.png

 

Service Response:


It will generate a document number as shown below.

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

22.png

 

To open the file double click on it.

23.png

File got opened successfully as shown.

24.png

 

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

 

Thanks&Regards,

Prasanna Addula


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>