Attach files to GOS with Save, Retrieve, Delete functionality in SAP Web Dynpro ABAP – Part 1
Purpose:
Application for attaching files to GOS with save, retrieve & delete functionality in Webdynpro ABAP
Scenario:
I would like to explain the functionality of how to save,retrieve & delete files / Notes during attachments to GOS in Webdynpro ABAP application.
Please refer the below link for more info on GOS
GOS ( Generic Object Services )
Here I would consider the scenario of SAP FSRI module, and attach files / notes against a policy number.
Class: CL_GOS_API
Provides access to the GOS attachment list for applications. In the first step, the application must create an instance of the class CL_GOS_API and then register its unique application object at the same time. Currently, application objects of the categories BOR Object and Persistent Classes are supported. The attachment list can then be read, and the content of individual attachments can be read, modified, deleted, or created.
Pre-requisite:
Basic knowledge of Webdynpro ABAP,& OO ABAP
Step by Step Process:
Step 1:
Go t-code SE11 and create a custom structure YST_GOS_ATTACH_LIST as below
i.e. add a field ICON and include structure GOS_S_ATTA as below
Step 2:
Go to t-code SE80 and create a web dynpro component as below
Step 3:
Go to context tab of component controller and create a node ATTACHMENTS by using structure YST_GOS_ATTACH_LIST and set the properties as below
Step 4:
Create another node “ATTACHMENT_CONTENTS” by using structure GOS_S_ATTCONT as below
Step 5:
Go to attributes tab of component controller and create the global attributes GO_GOS & GV_USER_ACTION as below
Step 5A:
Create methods in component controller as below
Now, the write the code as below
Method: DO_ON_CREATE
DO_ON_CREATE |
---|
METHOD do_on_create . ” Set user action ” Refresh attachment list ctx lo_node = wd_context->get_child_node( lo_node->invalidate( ). ” Show respective popup window ENDMETHOD. |
Method: DO_SAVE
DO_SAVE |
---|
METHOD do_save . DATA: ls_attacont TYPE gos_s_attcont, ” Read notes detail context lo_node->get_element( )->get_static_attributes( ls_attacont-atta_cat = cl_gos_api=>c_msg. IF wd_this->gv_user_action EQ 1.”Create wd_this->go_gos->insert_al_item( ELSEIF wd_this->gv_user_action EQ 2.”Change MOVE-CORRESPONDING ls_attacont TO ls_atta_key. lv_commit = CATCH cx_gos_api. “#EC NO_HANDLER IF lv_commit EQ abap_true. “=============================== |
Method: LOAD_ATTACHMENT_CONTENTS
LOAD_ATTACHMENT_CONTENTS |
---|
METHOD load_attachment_contents . DATA: ls_atta_key TYPE gos_s_attkey, “get attachment content “set data to context lo_node = wd_context->get_child_node( lo_element = lo_node->get_element( ). lo_element->set_static_attributes( static_attributes = ls_attacont ). ” Based on content, show popup window IF ls_attacont-content_x IS INITIAL. ENDIF. wd_this->show_popup( |
Method: LOAD_ATTACHMENT_LIST
LOAD_ATTACHMENT_LIST |
---|
METHOD load_attachment_list . DATA: lt_atta TYPE TABLE OF gos_s_atta, FIELD-SYMBOLS: <ls_atta> LIKE LINE OF lt_atta. TRY. CLEAR lt_attachment_list. LOOP AT lt_atta ASSIGNING <ls_atta>. CONDENSE ls_attachment_list-tech_type. IF ls_attachment_list-tech_type EQ ‘TXT’ OR “=========================== lo_node = wd_context->get_child_node( lo_node->bind_table( ENDMETHOD. |
Method: SHOW_POPUP
SHOW_POPUP |
---|
method SHOW_POPUP . “—————————————————- lo_window_manager = lo_api_component->get_window_manager( ). “creat a pop up window IF lo_window IS BOUND. IF id_action1 IS NOT INITIAL. IF id_action2 IS NOT INITIAL. |
Step 6:
Go to view V_MAIN and create context attribute POLICY_ID under node CONTEXT as below
Step 7:
Map the context node ATTACHMENTS from component controller to V_MAIN view’s controller as below
Step 8:
Create an input field and bind the value to context attribute POLICY_ID as below
Step 9:
Create a button “BTN_GET_LIST” and create an action “GET_LIST” and bind it to the event of button as below
Step 9 A:
Write the below code in event handler method ONACTIONGET_LIST as below
Here, we are creating an instance to GOS for the given policy number.
ONACTIONGET_LIST |
---|
METHOD onactionget_list . “========================== “============================ CLEAR ls_object. TRY. “============================ |
Step 10:
Create a table ui element TBL and bind the data source property to node ATTACHMENTS as below
Step 11:
Create the columns and bind to the context attributes as shown below
Step 12:
Create an extra column called “ACTIONS” for display, change, delete actions with SelectedCellVariant “KEY” as below
Step 13:
Right click on column ACTIONS and choose “Insert Cell Variant” as below
Step 14:
Set the variantKey “KEY” to TableMultiCellEditor as shown below
Step 15 :
Create a button for display and bind it to the action DO_ACTION as below
Step 16 :
Create a button for change and bind it to the action DO_ACTION as below
Step 17 :
Create a button for delete and bind it to the action DO_ACTION as below
Step 17A:
Write the below code in event handler method ONACTIONDO_ACTION
ONACTIONDO_ACTION |
---|
METHOD onactiondo_action . CASE id. “get the current row data “========================= CALL METHOD wd_comp_controller->load_attachment_contents |
Step 17B:
Go to actions tab of view V_MAIN and create an action SAVE for save action on popup window for attaching notes or files. i.e. we have subscribed the button “OK” of popup window to SAVE action on view V_MAIN
Write the below code in event handler method ONACTIONSAVE.
ONACTIONSAVE |
---|
” Save attachements wd_comp_controller->do_save( ). |
Hello
Can you add the implementation code for method LOAD_ATTACHMENT_LIST ?
And also code to implement for events DO_ACTION and GET_LIST ?
Thx
Xavier
Hi Xavier,
Thanks a lot for going through the document in details 🙂 ... I appreciate your findings.. yah! missed to include the implementation of those methods 😕 ..
I have added the implementation code of those methods 🙂
Regards,
Rama
We need to find out the minimum Netweaver Enhancement Pack level that is required for CL_GOS_API - so we can get this to work in our webdynpro development.
Hi,
As for as I know, the class CL_GOS_API is available from NW 7.31.
Hi,
Class CL_GOS_API and structure GOS_S_ATTA does not exist in our system ECC 6.0,.
What to do? do we need to activate object or patch update?
Hi John,
AFAIK,the class CL_GOS_API is available from NW 7.31. I think you might need to upgrade your system to EHP6.
Dear Ramakrishnappa Gangappa,
Thanks for u r Sharing the Good Document regarding GOS In WebDynpro. I'm Getting the all that u r shared but after upload then i want to see the attachments like(PDF,PNG,JPEG,doc..) files are converted as a raw string data type data, I'm unable to get the exact output that i have uploaded. while click on download button it's path changed like C:/FAKEPATH/KOLA.jpg. Please help me regarding this.
Thanks & Regards,
Suresh Reddy.
Hi Suresh,
Thank you for your feedback.
Please have look at the below thread:
File path defaulted to 'C:\fakepath' when attaching
Hope this helps you.
Regards,
Rama
Dear Ramakrishnapppa,
Thanks for your feedback i'm getting the exact output in internet Explorer Browser with your Suggestion but in the google chrome browser and also it's work for .PDF Files. Suppose if i upload the file formats like .PNG,.DOC,.JPEG and Excel then it woks like Pdf file viewing on the Browser. If is not possible what is alternative solution for this.
Thanks & Regards,
Suresh Reddy.
Hi
I am trying to do the same, But i am getting the Error:
500 SAP Internal Server Error
ERROR: Could not find attribute ATTACHMENTS (termination: RABAX_STATE)
please help me, I am new for WD.