Webdynpro Abap for File Upload

March 29, 2018 | Author: Rahul Oberoi | Category: Filename, Double Click, String (Computer Science), Information Technology Management, Data


Comments



Description

Upload and Download Files in Webdynpro ABAPby Nagendran R, Enteg Infotech, Bangalore, India Go to T-Code- SE80, Create a Web Dynpro Component(Zfile_upload in this example) Double click on the view MAIN -> choose Context tab -> right-click on the topmost context and choose Create> Node. Create two Nodes Node1: N_UPLOAD Cardinality 1.1 Attributes FILE_NAME FILE_TYPE FILE_SIZE Type STRING STRING STRING n Attributes Type FILE_NAME STRING FILE_TYPE STRING FILE_SIZE STRING FILE_CONTENTS XSTRING .FILE_CONTENTS XSTRING Node2: N_FILE_DOWNLOAD Cardinality is 0. . . 1. Now go to Layout tab of MAIN view. Create the element FileUpload. 2.After creating the two Nodes. Create a group. . . . Create a BUTTON UI element with text property as Upload and action property as UPLOAD.After adding the File Upload UI element. . . Create a group and inside group create a UI element TABLE.Afrer creating Button. . . Click on Context and choose the Node N_FILE_DOWNLOAD. . Create binding as below.After creating the table right-click on the table UI element and choose Create Binding. and in the TEXT property BIND the attribute FILE_NAME OF NODE N_FILE_DOWNLOAD.Now. in the Table columns choose the column File contents. . . . the table look like the table in the below screen shot. .After Binding. Filename. .Now. Choose the UI element FILE_UPLOAD and create binding for the property data. mimetype. . . Create a z-table to store all the attachments that has been uploaded. so that the files can be downloaded later.After Binding the UI element FILE UPLOAD. The z-table fields and types are mentioned below. Go to the methods tab and double-click on ONACTIONUPLOADA(action property for UPLOAD button) and place the below code: . DATA lo_nd_n_upload TYPE REF TO if_wd_context_node. DATA ls_n_upload TYPE wd_this->element_n_upload. DATA lo_nd_n_file_download TYPE REF TO if_wd_context_node. . * * navigate from <CONTEXT> to <N_UPLOAD> via lead selection lo_nd_n_upload = wd_context->get_child_node( name = wd_this->wdctx_n_upload ). navigate from <CONTEXT> to <N_FILE_DOWNLOAD> via lead selection lo_nd_n_file_download = wd_context->get_child_node( name = wd_this>wdctx_n_file_download ).method ONACTIONUPLOAD . data ls_file_upload TYPE ZFILE_UPLOAD1. DATA lt_n_file_download TYPE wd_this->elements_n_file_download. DATA lo_el_n_upload TYPE REF TO if_wd_context_element. ls_file_upload-FILE_TYPE = ls_n_upload-FILE_TYPE.* get element via lead selection lo_el_n_upload = lo_nd_n_upload->get_element( ). * ls_n_upload will contain the File name file type and file contents * ls_n_upload-file_size = xstrlen( ls_n_upload-file_contents ). endif. endmethod. ENDIF. lo_nd_n_file_download>bind_table( new_items = lt_n_file_download set_initial_elements = abap_true ). insert zfile_upload1 from ls_file_upload. ls_file_upload-FILE_CONTENTS = ls_n_upload-FILE_CONTENTS. * get all declared attributes lo_el_n_upload->get_static_attributes( IMPORTING static_attributes = ls_n_upload ). select file_name file_type file_size file_contents from zfile_upload1 into TABLE lt_n_file_download. . ls_file_upload-FILE_SIZE = ls_n_upload-FILE_SIZE. if sy-subrc = 0. * @TODO handle not set lead selection IF lo_el_n_upload IS not INITIAL. ls_file_upload-FILE_NAME = ls_n_upload-FILE_NAME. Create a Web Ddynpro Application and test it. The Output Will be. .Activate all the Web Dynpro components . . file details can be seen in the Table and a Link to Download will be availablle.Click on Browse -> Choose a file for Upload -> Click on Upload. Click on the Link to download the Uploaded file. After Uploading. . The Download file can be viewed in a Pop-up window. .
Copyright © 2024 DOKUMEN.SITE Inc.