Continues……
Pre-requisite: ( Please go through the below link before you continue )
Attach files with save, retrieve and delete functionality in Web Dynpro ABAP – Part 1
Step 7:
Create a table ui element TBL_LIST and bind it to the context node ATTACHMENT_LIST as below
Note: choose editor for FILE_NAME attribute as FILE DOWNLOAD (ui element )
Step 8:
Go the column editor TBL_LIST_FILE_NAME_EDITOR and bind the properties as show below
Step 9:
Create a tool bar to the table TBL_LIST and add a button BTN_SAVE and attach an action as show below
Add the below code (Save functionality) in event handler method ONACTIONSAVE
ONACTIONSAVE |
---|
METHOD onactionsave . FIELD-SYMBOLS <fs_attachment_list> LIKE LINE OF lt_attachment_list. lo_nd_attachment_list = lo_nd_attachment_list->get_static_attributes_table( DATA lt_data TYPE TABLE OF ytr_attach_files. “========================================================== LOOP AT lt_attachment_list ASSIGNING <fs_attachment_list> ” set status CLEAR ls_data. ENDLOOP. “get message manager IF lt_data[] IS INITIAL. RETURN. “========================================================== ” Show success message ENDMETHOD. |
Step 10:
Create another button BTN_DELETE (to delete files ) and attach the action DELETE_ATTACHMENT as shown below
Add the below code in (Delete functionality) in event handler method ONACTIONDELETE_ATTACHMENT
ONACTIONDELETE_ATTACHMENT |
---|
METHOD onactiondelete_attachment . “========================================================== lt_elements = IF lt_elements[] IS INITIAL. lo_msg_manager->report_error_message( RETURN. DATA lt_data TYPE TABLE OF ytr_attach_files. CLEAR lt_data. “========================================================== “Check if record exists in table APPEND ls_data TO lt_data. ENDIF. “========================================================== |
Step 11:
Go to method WDDOINIT( ) of view and add the below code ( Retrieve functionality )
WDDOINIT |
---|
METHOD wddoinit . DATA lo_nd_attachment_list TYPE REF TO if_wd_context_node. FIELD-SYMBOLS: <ls_data> LIKE LINE OF lt_data. CLEAR lt_attachment_list. “========================================================== lo_nd_attachment_list->bind_table( new_items = lt_attachment_list ENDMETHOD. |
Save the component and active it
Step 12:
Create WDA application as below
Now, we are ready to see some output and the save, retrieve & delete functionality while attaching files
Output:
Click on BROWSE button as shown below
The choose file to upload wizard appears & choose a file and click on OPEN button as below
Click on attach button as shown below
Now, file is attached into table but it is not yet saved into database table ( see the highlighted cell )
Click on Save attachments button as show below (Now, the attachment is saved into data base .. see the highlighted cell )
The data is stored into data base table YTR_ATTACH_FILES as below
Again, browse another file and attach ( see the second row – for newly added file )
To delete an attachment, we need to select a row & click on “Delete attachment” button as show below
Note: on click delete attachment button, it deletes the attachment from data base as well ( if file is already stored )
Error messages:
If user clicks on save attachment button and no fresh attachment to save, then user will be notified with the below error message
If user clicks on Delete attachment button and no row has been selected (chosen), then user will be notified with below error message
—————————————————
Hope this document helps for those who are looking for uploading files and storing in table and retrieving 🙂
I appreciate if any comments/feedback from you 🙂 🙂 🙂
Good One. Thanks Rama
Thanks Vimal… 🙂 hope this helps you…
Thanks for sharing.
Thank you Sahir 🙂
Hi Rama,
In step no. 8,You have binded Data property to which attribute of node Attachment_List. ?
Thanks,
Vimal
Hi Vimal,
Sorry, the image was not clear. I have updated new image at step 8.
Please check now.
Regards,
Rama
Brilliant Blog Ramakrishna.
Thanks,
Syam
Thank you Syam 🙂
I am glad if its useful
Hi Rama,
I am able to design this application successfully.But i have a question,Now suppose ABAPer’s want to access this file,So how can they access it in same format.
ABAPer’s want to save this attached file to some standard TCODE. How can they do this ?
We have simply used select statements and binded the data and we are able to download the file.But how the same thing is possible in ABAP.is there any FM ?
Can you help on this?
Hi Vimal,
Thats good, you are able to create this application successfully 🙂
There are many scn threads available to attach files in abap.
Please refer the methods in the class CL_GUI_FRONTEND_SERVICES.
Here you can use methods to read files/content and you can save into table as we did here.
Hope this helps you.
Regards,
Rama
Nice and clear document. I am working on similar requirement , here I need to attach .Txt/.msg/.xls/.docx too . In one of your screenshots above, .txt is in false state.
any work around?
Hi Mohinder,
We can attach all types of files with this application.
The status ” false” indicates that the file is not yet saved into database table ( just attached but not pressed SAVE button 🙂 ).
Please refer the below snap shot – where all types of files have been attached and saved into data base.
Hi Rama,
Indeed a nice explanation of document, very neatly done. I tried approach mentioned abovve, however CL_SYSTEM_UUID doesnt exist in below EHP6.
Thanks
Mohinder
Hi Mohinder,
Thank you 🙂 : I appreciate your ratings for this document 😎
The class CL_SYSTEM_UUID is used just to create a unique key.
You can create GUID by using FM: GUID_CREATE.
Use GUID22 from this FM.
Regards,
Rama
Hi Rama,
Thanks for clarification. I followed exactly same steps , but when I click to link I get below
pop-up. Whats wrong I am doing here? This happened when I tried earlier also, then thought of following your code but same error.
Hi Mohinder,
This dialog box is asking the user for options to choose while downloading a file.
If you don’t want to see again, please un-check the check box “Always ask before opening this type of file”.
Regards,
Rama
Hi Rama,
Thanks for the info,however I understand this pop up I can disable anytime but if you see ~wd_key.htm , is the name of folder and it wouldnt open any documents, this document is in .htm format and doesnt open any files. Only PDFs, .PNG opens any ways thanks for help.
Thanks
Mohinder
Hi Mohinder,
Please bind following properties on UI element File Download
i) Data
ii)File Name
iii)File Type
and your file will be able to get downloaded in any format.
Thanks,
Vimal Sharma
Thank you Katrice 🙂 .. I am happy if its useful.
Your feedback and ratings motive me ,,, to go ahead 🙂
Hi Rama,
One of the most useful doc.
Thanks for sharing 🙂
But can u explain me how to view the attached document.
In your screen you have kept the file name as link to action. By clicking on it will it open the attached file???
Pls let me know how to view the attached file?
Thanks,
Nalla B.
Hi Nalla,
Thank you 🙂 I appreciate your feedback and ratings on this document.
Let me answer your question :
Here, I have used FileDownload ui element in the table. Hence you are able to see the link under file name. As we all know, on click on fileDownload ui element, we can either see or save the files.
Regards,
Rama
Hi Rama,
Could you pls share the code for the file download options used in this application.
It will be very much useful. 🙂
Thanks
Nalla B.
Hi Nalla,
I haven’t written any code to download the files. Its the feature of FileDownload ui element that, as you click on link, user is allowd to open or save file.
Regards,
Rama
Hi Rama
Very useful thanks for sharing…
Thank you Shanthan 🙂
Hi Ramakrishnappa,
thank you for sharing. The way you exaplained is good. Keep it up 🙂
Best regards,
Rao.
Thanks a lot Rao 🙂 I am glad if its useful.
Regards,
Rama
Hi,
Good Tutorial on File Attachments.
Any Possibility integration of Document Server.
Best Regards,
Priyesh Shah
Thank you Priyesh 🙂
Yes, we can attach files to GOS instead of custom table with the amendment in the updation / ratrieving logic.
Regards,
Rama
Hi Ramakrishna,
You mean to say in WebDynpro ABAP we can use GOS objects.
How?
Best Regards
Priyesh Shah
Yes we can attach files to GOS in WDA.
Please refer the below document
Attach files to GOS with Save, Retrieve, Delete functionality in SAP Web Dynpro ABAP – Part 1
Regards,
Rama
Thank you very much Rama for sharing.
I started to work in Webdynpro. It is very helpful for me 🙂
Thank you Sangeetha 🙂 I appreciate your feedback and I am glad that it is helpful for you 😎
Welcome to WD world … keep exploring the documents under this section and all the best !!!
Regards,
Rama
Hi Ramakrishnaappa,
This is very useful information.
Thanks for sharing.
Regards,
Siva kumar.
Thank you Siva 🙂
Regards,
Rama
Hi Rama,
I have done the same and got the things working but I am not getting the colour in column. I guess the colour coding is missing here. kindly help on the same.
Hi,
Thanks for following the document in detail 🙂
Ooops, that is missed,
To set color to column—>
Select the table column and set the cell design property as required.
Regards,
Rama
Hi Rama,
Havent tried yet, but content is definitely useful(gonna use when oppoprtunity comes) .. Thanks for sharing.
Regards,
Tashi
Thank you Tashi 🙂
Regards,
Rama
Hi Rama!
I like the work done here!
A simple idea : you could provide the save/retrieve/delete methods as interface so that the component could be used by anyone and the files stored in everyone own personnal data storage (like SAP BDS or PM attached doc or else…) just by implementing this interface.
Then with sap link (for example) provide a nice tool for the community! 🙂
Kind regards,
(if you need help for this do not hesitate! 😉 )
Hi Giraud,
Thank you for your comments 🙂
I too liked your Idea but here in this document I have written the business logic inside component ( to minimize the documentation steps 😉 ) just for DEMO purpose. It should be separated into a class/interface implementation.
Any way I will try to provide component & class using sap link program ASAP.
Regards,
Rama
Hi Rama,
Great effort in writing the blog. To be honest i have not seen a customer asking to store documents in DB when there are better solutions available like kM, content server. DMS. Such solutions have better file management and archiving mechanisms rather than storing the files in traditional DB.
Integration with KM, content server, and DMS are all available. This woud be my last solution.
Ashish
“ To be honest i have not seen a customer asking to store documents in DB”
Been there!!
That’s why the interface solution can enable user case free adaptation of the component as suggested in a previous comment ^^
Hi Ashish,
Thanks for your comments 🙂
May be you have not come across such customers 😉 … just kidding.
Agree with you that to suggest the customers for km, content server, dms etc. But here, I just explained possible option with DB, may be its useful if customers insists for this kind of approach.
Please refer my other document, which explains about attaching documents to GOS.
Attach files to GOS with Save, Retrieve, Delete functionality in SAP Web Dynpro ABAP – Part 1
Regards,
Rama
Hi Rama,
the thread is so useful and clearly explained,Kudos for the thread.It helped me in solving the uploading of the attachments but I am unable to download the uploaded file using Download UI element in table.As no text is displaying in that column. As earlier you said that there is an issue with 7.30 the same i am facing but I solved the issue of binding the file download UI element and i am unable to bind the data source of the table to the Raw string of the table.Can u please help me in this.
1.Error while binding the file
2.File Name is not displaying once uploaded
Hi Rohith,
Thank you for your feedback.
To resolve your issue, follow the below steps
Hope this solves your issue.
Regards,
Rama
Thank You Rama,
Issue Resolved.Thanks for your Quick response.
Hello Rama,
I know that this a very old thread. Yet I am writing in this thread with a hope that I would get some help. 🙂
My requirment here is a bit different.
For my Web dynpro application I have created a transaction.
User is using this transaction in which now they want this FILE_UPLOAD functionality.
This functionality works in browser but when executed using transaction, Browse is not working
Request your help here. How can I fix this? It’s really very important requirement for us.
Regards,
Ruta