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->get_static_attributes_table(
"========================================================== 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
|
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.
"========================================================== 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 :smile:
I appreciate if any comments/feedback from you :smile: :smile: :smile:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
9 | |
7 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 |