Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Upload file from application server(AL11) to DMS

madan_c
Explorer
0 Kudos
5,290

Hi Everyone,

I have PDF file exist in AL11 and want to upload same file in DMS system using BAPI: BAPI_DOCUMENT_CHANGE2 . Created DMS document number first using BAPI: BAPI_DOCUMENT_CREATE , then calling change BAPI to attach document from application server by giving application server path and file name. Please guys, it's bit urgent, have been trying from past 2 days, but couldn't achieve this.

Could you pls suggest me, is it possible to upload file from Al11 into DMS ? It seems, it's possible, but couldn't find a way.

Followed link: https://blogs.sap.com/2013/11/25/create-an-sap-dms-document-attaching-a-file-from-the-application-se...

But i'm unable to attach document in DMS. Please look into below mentioned code and suggest me, am i missing anything.

*******--- Code ----------------------

***---- Create DMS Document

CLEAR ls_documentdata.
ls_documentdata-documenttype = dms_key-dokar. "'ZRM'.
ls_documentdata-description = lv_dartxt. "'Testing DMS-Ecratum'.
ls_documentdata-username = sy-uname.
ls_documentdata-statusextern = 'RE'.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE'
EXPORTING
documentdata = ls_documentdata
IMPORTING
doctype = dms_key-dokar
docnumber = dms_key-doknr
docpart = dms_key-doktl
docversion = dms_key-dokvr
return = ls_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true
IMPORTING
return = ls_return.

*****---- Attach document by getting file from application server

TYPES: BEGIN OF ts_document_hdr,
type TYPE dokar,
number TYPE doknr,
part TYPE doktl_d,
version TYPE dokvr,
END OF ts_document_hdr.

DATA: ls_document_hdr TYPE ts_document_hdr,
" ls_documentdata TYPE bapi_doc_draw2,
ls_documentdatax TYPE bapi_doc_drawx2.

* Document Header
ls_document_hdr-type = dms_key-dokar.
ls_document_hdr-number = dms_key-doknr.
ls_document_hdr-part = dms_key-doktl.
ls_document_hdr-version = dms_key-dokvr.

* Document Data
ls_documentdata1-wsapplication2 = 'PDF'."p_filty.
ls_documentdatax-wsapplication2 = abap_true.
ls_documentdata1-docfile2 = '/usr/sap/trans/FlowChart.pdf'. "p_path && p_filnm.
ls_documentdatax-docfile2 = abap_true.

* Document Files
ls_files-documenttype = ls_document_hdr-type.
ls_files-documentnumber = ls_document_hdr-number.
ls_files-documentpart = ls_document_hdr-part.
ls_files-documentversion = ls_document_hdr-version.
ls_files-docpath = '/usr/sap/trans/'. "p_path.
ls_files-docfile = 'FlowChart.pdf'. "p_filnm.
ls_files-description = 'Filename' && '/usr/sap/trans/' && 'FlowChart.pdf'.
ls_files-wsapplication = 'PDF'. "p_filty.
* ls_files-sourcedatacarrier = 'DV-1' . "p_datcar.
ls_files-originaltype = '1'.
ls_files-storagecategory = 'DMS_C1_ST'. " Here tried with "SAP-SYSTEM"
APPEND ls_files TO lt_files.

* Attach file to the Document.
CALL FUNCTION 'BAPI_DOCUMENT_CHANGE2'
EXPORTING
documenttype = ls_document_hdr-type
documentnumber = ls_document_hdr-number
documentpart = ls_document_hdr-part
documentversion = ls_document_hdr-version
documentdata = ls_documentdata1
documentdatax = ls_documentdatax
IMPORTING
return = ls_return
TABLES
documentfiles = lt_files.

IF ls_return-type NE 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
MESSAGE s000(zz) WITH 'Success'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
MESSAGE ID ls_return-id TYPE ls_return-type NUMBER ls_return-number
WITH ls_return-message_v1 ls_return-message_v2 ls_return-message_v3 ls_return-message_v4.
ENDIF.

After running above code, am getting below error.

As requested, pls it's very urgent.please do needful

Regards

Madan Chandragiri

20 REPLIES 20

former_member370623
Active Participant
0 Kudos
2,898

Check the authorization object 'S_GUI' id 'ACTVT' field '60'.

0 Kudos
2,898

Hi Ibrahim,

Have mentioned auth and value as shown below. Any other suggestion.

FYI... I have SAP_ALL

2,898

to check authorization use ST01

0 Kudos
2,898

madan.c I removed the image because it included usernames, which I thought might be personal identifying information. (Please see rules of engagement: https://community.sap.com/resources/rules-of-engagement.) You're welcome to add the image back or upload a new one as long as you're certain that you aren't including any personal information that would violate our rules of engagement.

--Jerry

Make sure to subscribe to What's New!

FredericGirod
Active Contributor
2,898

In the blog you refer to, there are two parameters not use in your code.

 
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
  EXPORTING
    documentdata    = ls_documentdata
    pf_ftp_dest     = 'SAPFTPA'      <----
    pf_http_dest    = 'SAPHTTPA'     <---- 

0 Kudos
2,898

Hi...

Though i passed these 2 parameters initially, got same message. So i changed calling change bapi instead of create2 bapi.

0 Kudos
2,898

When you check the error message Where-used, this is always used to real local file (from sapgui). So I think the key of this blog is to use this SAPFTPA or SAPHTTA to simulate reading local file.

If you read the comments behind the blog, some people have issue with this blog and do another way.

0 Kudos
2,898

Hi Frederic,

As said, though i used SAPFTPA or SAPHTTA, i got same error message. My requirement is clear that, want to attach file in DMS by creating DMS document number from application server.

As per blog: https://blogs.sap.com/2013/11/25/create-an-sap-dms-document-attaching-a-file-from-the-application-se...

it's possible to attch document in DMS by providing application server path and file name. But i'm not able to achieve this.

Can anyone pls provide working code, if you have already or suggest me at least what else i need to follow.

Regards

Madan Chandragiri

2,898

As said by Frederic, use SAPFTPA/SAPHTTPA.

Are you sure that the file exists on your application server (double check the name and path, pay attention to lower case and upper case). Eventually,

Are you sure you have FTP and file system authorization (transaction ST01)?

If you never used SAPFTPA before, try to regenerate it by calling the program RSFTP005.

Eventually do an RFC trace on SAPFTPA via SM59 and run program RSRFCTRC (I don't know what it will trace). BE CAREFUL: deactivate the trace after you have used it.

0 Kudos
2,898

Hi Sandra,

Yea. The PDF file exist in application server that should be uploaded in DMS. As you suggested, cross checked application server path and file name, everything seems ok, and called program: RSFTP005, and checked the Trace as well in ST01. Frankly speaking, didn;t get any trace.

Tried again by passing SAPFTPA/SAPHTTPA using BAPI:BAPI_DOCUMENT_CREATE2, am still getting same error. Any other suggestions to work it out or any working code .

Regards

Madan Chandragiri

Sandra_Rossi
Active Contributor
0 Kudos
2,898

I'm sorry but people won't help you faster because it's "very urgent". You know, People only care of their own colleagues/friends... 😉

Sandra_Rossi
Active Contributor
0 Kudos
2,898

In your screenshot, there is the variable LS_RET, but your code doesn't contain it (I only see LS_RETURN). Can you explain?

madan_c
Explorer
0 Kudos
2,898

Hi Sandra,

Please find below code.

CLEAR ls_documentdata.
ls_documentdata-documenttype = dms_key-dokar. "'ZRM'.
ls_documentdata-description = lv_dartxt. "'Testing DMS-Ecratum'.
ls_documentdata-username = sy-uname.
ls_documentdata-statusextern = 'RE'.

ls_drat-language = 'EN'.
ls_drat-description = 'Test file'.
APPEND ls_drat TO lt_drat.

CLEAR ls_files.
ls_files-originaltype = '1'.
ls_files-storagecategory = 'SAP-SYSTEM'.
ls_files-docpath = '/usr/sap/trans/'.
ls_files-docfile = 'example.pdf'.
ls_files-description = 'Testing file.pdf'.
ls_files-wsapplication = 'PDF'.
ls_files-language = sy-langu.
APPEND ls_files TO lt_files.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
documentdata = ls_documentdata
pf_ftp_dest = 'SAPFTPA'
pf_http_dest = 'SAPHTTPA'
IMPORTING
documenttype = lv_docty
documentnumber = lv_docnr
documentpart = lv_docpr
documentversion = lv_docvr
return = ls_ret
TABLES
documentfiles = lt_files

documentdescriptions = lt_drat.

IF ls_ret-type NE 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
ENDIF.

Getting below error while running

Sandra_Rossi
Active Contributor
0 Kudos
2,898

Eventually look at the code I have posted here.

madan_c
Explorer
0 Kudos
2,898

Hi Sandra,

Thank you very much for provided code, but still i'm getting sam error. Created dummp program and run in background as well. But no luck. Any other suggestion pls....

Regards

Madan Chandrgairi

0 Kudos
2,751

Dear Sandra ,

The link is expired please can you repost again.

keremkoseoglu
Contributor
0 Kudos
2,898

0 Kudos
2,898

Hi All,

I have a small question on DMS.

While creating the document via FM ‘BAPI_DOCUMENT_CREATE2’ its goes into error “document category and documetn discpline required, we have customize the DMS as these two are always to be put as manadtory , how to handle this in progrm.

Please suggest.

Thanks & Regards,

Raj Singh

durgaprasad_sharma2
Participant
0 Kudos
2,756

Dear MADAN , 

Have you got any solution for this i am still stuck in my case document number is getting generated but the file path provided of al11 bapi is picking the file name but data is stored as zero kb in DMS docs. please help if you found any root cause for same.

0 Kudos
1,613

Hi Durgaprasad,

Have you got the solution, I'm also facing the same issue.

Thank you in Advance.