Quantcast
Channel: SCN : All Content - Web Dynpro ABAP
Viewing all articles
Browse latest Browse all 3667

Attach files with save, retrieve and delete functionality in Web Dynpro ABAP - Part 1

$
0
0

Purpose:

Application for attaching files with save, retrieve & delete functionality in Webdynpro ABAP

 

Scenario:

I would like to explain the functionality of how to save,retrieve & delete files during attachments in Webdynpro ABAP application. It stores attached files in custom data base table.

 

Pre-requisite:

Basic knowledge of Webdynpro ABAP,& OO ABAP

 

Step by step Process


The process is divided as below

  • Create a custom table YTR_ATTACH_FILES to store files
  • Create a WDA component with save, retrieve & delete function

 

Note:
In this document, just for demo purpose the business logic of saving & retrieving data from data base table has written in WDA component.

 

Strictly the business logic should be separated from WDA component by using a model i.e. class, function module, etc.

(Refer MVC architecture in Architecture of Webdynpro for ABAP)

 

Create a transparent table YTR_ATTACH_FILES

 

Step 1.

Go to transaction code SE11 and enter database table name YTR_ATTACH_FILES as below

table0.PNG

 

 

Step 2:

Set the delivery & maintenance settings as below

 

table1.PNG

 

 

Step 3:

Go to technical settings and maintain the entries as below 

table2.PNG

 

 

Step 4:

Create the fields in table as below

table3.PNG

 

 

 

Create a Webdynpro ABAP component

 

Step1:

  Go to transaction code SE80 and create the Webdynpro ABAP component as below with a view V_MAIN as below

1.PNG

 

 

Step 2:

Go to the view context of view V_MAIN and create a node INPUT by using table name YTR_ATTACH_FILES as below

v1.PNG

 

 

Step3:

Create a node ATTACHMENT_LIST by using table name YTR_ATTACH_FILES as below

v2.PNG

 

 

Step 4:

Create the layout by using context nodes INPUT & OUTPUT as below

v3.PNG


Choose the editors for table columns as suggested below

Technical_data_of_table.jpg

 

Step 5:

Create a ui element FILE_UPLOAD and bind the properties as shown below

v4.PNG

 

 

 

Step 6:

  Create a button BTN_ATTACH and attach an action ATTACH as below

v5.PNG

Add the below code into event handler method ONACTIONATTACH   (to attach a file into table)

ONACTIONATTACH

METHOD onactionattach .
  DATA lo_nd_input            TYPE REF TO if_wd_context_node.
  DATA lo_el_input            TYPE REF TO if_wd_context_element.
  DATA ls_input               TYPE wd_this->element_input.
  DATA lo_nd_attachment_list  TYPE REF TO if_wd_context_node.
  DATA lt_attachment_list     TYPE wd_this->elements_attachment_list.
  DATA ls_attachment_list     LIKE LINE OF lt_attachment_list.
  DATA lv_temp                TYPE string.

  "==========================================================
  " Read the details of file chosen for attachment
  "==========================================================
  lo_nd_input =
  wd_context->get_child_node( name = wd_this->wdctx_input ).

* get element via lead selection
  lo_el_input = lo_nd_input->get_element( ).

* get all declared attributes
  lo_el_input->get_static_attributes(
    IMPORTING
      static_attributes = ls_input ).

  " return if nothing to do
  IF ls_input-file_data is INITIAL.
    " Notify the user, please choose a file
    RETURN.
  ENDIF.

  "==========================================================
  " Read the attachment list
  "==========================================================
* navigate from <CONTEXT> to <ATTACHMENT_LIST> via lead selection
  lo_nd_attachment_list =
    wd_context->get_child_node( name = wd_this->wdctx_attachment_list ).


  lo_nd_attachment_list->get_static_attributes_table(
  IMPORTING table = lt_attachment_list ).

  "==========================================================
  " Prepare data to save
  "==========================================================
  CLEAR ls_attachment_list.
  ls_attachment_list-mandt = sy-mandt.
  ls_attachment_list-uname = sy-uname.
  " Generate Unique identifier
  TRY.
    ls_attachment_list-guid = cl_system_uuid=>create_uuid_c22_static( ).
    CATCH cx_uuid_error.  " Error Class for UUID Processing Errors.
  ENDTRY.

  ls_attachment_list-file_data = ls_input-file_data.

  " get file name from path
  WHILE ls_input-file_name CA '\'.
    SPLIT ls_input-file_name AT '\'
    INTO lv_temp ls_input-file_name.
  ENDWHILE.
  ls_attachment_list-file_name = ls_input-file_name.

  ls_attachment_list-file_type = ls_input-file_type.
  ls_attachment_list-erdat = sy-datum.
  ls_attachment_list-erzet = sy-timlo.
  ls_attachment_list-status = abap_false."attachment is new

  APPEND ls_attachment_list TO lt_attachment_list.

  "==========================================================
  " Bind data to context
  "==========================================================
  lo_nd_attachment_list->bind_table(
    EXPORTING
      new_items            =    lt_attachment_list
  ).

ENDMETHOD.

 

--------------------------------------------

Continued...........

 

Attach files with save, retrieve and delete functionality in Web Dynpro ABAP - Part 2


Viewing all articles
Browse latest Browse all 3667

Trending Articles



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