About->This document will provide the step by step process from uploading a pdf document from presentation server to application server and save the document from application server to presentation server.
- Target Users
- Business Requirement
- Screen Details
- Process to Upload the document in webdynpro pop up screen.
- Display the data from the POP up if required
- Download the PDF document from Application Server
1: Target Users :The target users of this document is those ABAPers working primarily in HR ABAP area and for them who were facing a situation of storing the document in application server and retrieve it rather than storing the data in a table .
2: Business Requirement
The business requirement is involved in two parts.
Part1–>This part is for the employees who have been allocated certain courses where they will finish the courses and upload the documents related to the courses completed by them.
Part2–>This part is for the Team who will validate those document and could able to download and view the documents attached by the employee, verify them and put their comments accordingly.
Part 1 Steps–>
The above screen show a highlighted button which will help the user to upload the document as he/she has already completed the course.
This screen will help the user to upload the document and once he/she hit the attach button it will save in the Application server.
Here I am not providing the details how to trigger the pop-up screen.
- Below code is about saving the document in application server
CONSTANTS path_name TYPE localfile VALUE ‘/usr/sap/HRD/Learning/’.
“Loop over attachment list for only new attachments
LOOP AT lt_attachment_list ASSIGNING <fs_attachment_list> .
* WHERE status = abap_false.” new attachment
MOVE-CORRESPONDING <fs_attachment_list> TO ls_data.
APPEND ls_data TO lt_data.
“get message manager
lo_api_controller ?= wd_this->wd_get_api( ).
” get message manager reference
CALL METHOD lo_api_controller->get_message_manager
message_manager = lo_msg_manager.
IF lt_data IS INITIAL.
” Attachement list is already saved
message_text = ‘Attachement list is already saved’ ).
* Save the data in application server
CONCATENATE path_name ls_data–file_name into file.
lv_filedata = ls_data–file_data.
OPEN DATASET file FOR OUTPUT IN BINARY MODE MESSAGE msg.
TRANSFER ls_data–file_data TO file.
IF sy–subrc = 0.
CLOSE DATASET file.
” Show success message
message_text = ‘Attachement list saved successfully !!!’ ).
Hit the attach button and the document saved successfully in the Application Server.
View the PDF File–>
To view the PDF document which user attached he has to click on the file name hyper link.
Code to View the PDF document–>
* For Upload Context Node
lo_nd_file_upload = wd_context->get_child_node( name = wd_this->wdctx_file_upload ).
* get element via lead selection
lo_el_file_upload = lo_nd_file_upload->get_element( ).
static_attributes = ls_input ).
if ls_input IS NOT INITIAL.
wd_comp_controller->GV_PDF = ls_input–file_contents.
* Select the data from the database table to view as the PDF *
LOOP AT lt_elements INTO lo_element.
static_attributes = ls_attach_list
“Check if record exists in table
MOVE-CORRESPONDING ls_attach_list TO ls_data.
APPEND ls_data TO lt_data.
wd_comp_controller->GV_PDF = ls_data–file_data.
Part 2 Steps–>
In this screen team can approve the request and can able to download the document.
- Below code is about downloading the data from Application Server
CALL FUNCTION ‘EPS2_GET_DIRECTORY_LISTING’
IV_DIR_NAME = dir_name
DIR_LIST = dir_list
INVALID_EPS_SUBDIR = 1
SAPGPARAM_FAILED = 2
BUILD_DIRECTORY_FAILED = 3
NO_AUTHORIZATION = 4
READ_DIRECTORY_FAILED = 5
TOO_MANY_READ_ERRORS = 6
EMPTY_DIRECTORY_LIST = 7
OTHERS = 8
IF SY–SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
LOOP AT lt_data INTO ls_data.
READ TABLE DIR_LIST INTO wa_list with key name = ls_data–file_name.
lv_filename = ls_data–file_name.
CALL METHOD cl_wd_runtime_services=>attach_file_to_response
i_filename = lv_filename
i_content = ls_data–file_data
i_mime_type = ‘pdf’.
Once hit the download button the document will download with download option.
Though I have not shared the whole code I believe this would helpful for those working in this kind of scenario.
Suggestion and comments is always welcome.