2023 Jun 01 9:31 AM
Hi Experts,
I have a requirement to Create Document with attached files(txt, pdf, jpeg Etc) through through custom BAPI, can you please share the BAPI code if any one having.
Thanks ,
Satheesh Kumar.
2023 Jun 02 4:18 AM
Certainly! Here's an example of a custom BAPI code snippet that creates a document with attached files in SAP:
DATA: lv_document_type TYPE dokar,
lv_document_number TYPE doknr,
lv_file_name TYPE string,
lt_attachment TYPE TABLE OF solisti1,
lt_return TYPE TABLE OF bapiret2.
" Set the document type
lv_document_type = 'DR'.
" Set the document number (if known in advance)
lv_document_number = '000000001'.
" Populate the attachment table
CLEAR lt_attachment.
lv_file_name = 'file1.txt'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file_name
TABLES
data_tab = lt_attachment.
APPEND LINES OF lt_attachment TO lt_attachment.
CLEAR lt_attachment.
lv_file_name = 'file2.pdf'.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file_name
TABLES
data_tab = lt_attachment.
APPEND LINES OF lt_attachment TO lt_attachment.
" Create the document with attachments using the BAPI
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
documenttype = lv_document_type
documentnumber = lv_document_number
TABLES
attachments = lt_attachment
EXCEPTIONS
OTHERS = 4.
" Check for any errors or return messages
IF sy-subrc <> 0.
" Handle the error or display the return messages
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
Please note that this is a basic example, and you may need to adapt it to your specific requirements. Ensure that you provide the appropriate document type, document number (if known in advance), and populate the `lt_attachment` table with the actual file data using the `GUI_UPLOAD` function module or other suitable methods.
Also, remember to handle any errors and process the return messages appropriately based on your specific needs.
Please consult the SAP documentation for more details on the `BAPI_DOCUMENT_CREATE2` function module and its parameters to customize the code according to your specific scenario and requirements.
2023 Jun 02 8:45 AM
Hi Aman,
With above code I am not able to create Document with attached file in DMS server, can you please give me the exact custom BAPI code (with Import parameters, Export parameters, return parameters Etc).
Note: I want to create document with input as Base64 data either it is text or pdf or jpeg etc. for that can you please provide the custom BAPI code if you have .
Thanks,
Satheesh.