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 "====================================== wd_this->gv_user_action = 1."Create " Refresh attachment list ctx "============================================= DATA lo_node TYPE REF TO if_wd_context_node. lo_node = wd_context->get_child_node( name = wd_this->wdctx_attachment_contents ). lo_node->invalidate( ). " Show respective popup window "============================= wd_this->show_popup( EXPORTING io_view_ctrl = io_view_ctrl id_button_kind = 3 id_action1 = 'SAVE' id_window_name = id_window_name ). ENDMETHOD. |
Method: DO_SAVE
DO_SAVE |
---|
METHOD do_save . DATA: ls_attacont TYPE gos_s_attcont, ls_atta_key TYPE gos_s_attkey, lv_roltype TYPE oblroltype, lv_commit TYPE flag, lo_node TYPE REF TO if_wd_context_node, lo_element TYPE REF TO if_wd_context_element. " Read notes detail context "==================================== lo_node = wd_context->get_child_node( name = wd_this->wdctx_attachment_contents ). lo_node->get_element( )->get_static_attributes( IMPORTING static_attributes = ls_attacont ). " Attach notes "======================================= TRY. ls_attacont-atta_cat = cl_gos_api=>c_msg. " Check if attachment documents IF ls_attacont-content_x IS INITIAL. ls_attacont-tech_type = 'TXT'. lv_roltype = cl_gos_api=>c_annotation. ELSE. lv_roltype = cl_gos_api=>c_attachment. ENDIF. IF wd_this->gv_user_action EQ 1."Create wd_this->go_gos->insert_al_item( EXPORTING is_attcont = ls_attacont iv_roltype = lv_roltype RECEIVING rv_commit = lv_commit ). ELSEIF wd_this->gv_user_action EQ 2."Change lv_commit = wd_this->go_gos->update_al_item( is_attcont = ls_attacont ). ELSE."delete
MOVE-CORRESPONDING ls_attacont TO ls_atta_key. lv_commit = wd_this->go_gos->delete_al_item( is_atta_key = ls_atta_key ). * CATCH cx_gos_api. " GOS API: Exception ENDIF. CATCH cx_gos_api. "#EC NO_HANDLER ENDTRY. IF lv_commit EQ abap_true. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = abap_true. ENDIF. "=============================== " Reload the context "=============================== wd_this->load_attachment_list( ). ENDMETHOD.
|
Method: LOAD_ATTACHMENT_CONTENTS
LOAD_ATTACHMENT_CONTENTS |
---|
METHOD load_attachment_contents . DATA: ls_atta_key TYPE gos_s_attkey, ls_attacont TYPE gos_s_attcont, lv_window_name TYPE string, lv_title TYPE string, lv_text TYPE string, lv_button_kind TYPE wdr_popup_button_kind. " Prepare key MOVE-CORRESPONDING is_atta TO ls_atta_key. "get attachment content TRY. ls_attacont = wd_this->go_gos->get_al_item( is_atta_key = ls_atta_key ). CATCH cx_gos_api. "#EC NO_HANDLER ENDTRY. "set data to context DATA lo_node TYPE REF TO if_wd_context_node. DATA lo_element TYPE REF TO if_wd_context_element. lo_node = wd_context->get_child_node( name = wd_this->wdctx_attachment_contents ). lo_element = lo_node->get_element( ). lo_element->set_static_attributes( static_attributes = ls_attacont ). " Based on content, show popup window "============================ CLEAR lv_button_kind. IF wd_this->gv_user_action EQ 2. lv_title = 'Change'. lv_button_kind = 3. ELSEIF wd_this->gv_user_action EQ 3. lv_title = 'Display'. ELSEIF wd_this->gv_user_action EQ 4. lv_title = 'Delete'. lv_button_kind = 3. ENDIF. IF ls_attacont-content_x IS INITIAL. lv_window_name = 'W_ATTACH_NOTES'. lv_text = 'Notes'. CONCATENATE lv_title lv_text INTO lv_title SEPARATED BY space. ELSE. lv_window_name = 'W_ATTACH_FILES'. lv_text = 'File'. CONCATENATE lv_title lv_text INTO lv_title SEPARATED BY space. ENDIF. wd_this->show_popup( EXPORTING io_view_ctrl = io_view_ctrl id_button_kind = lv_button_kind id_title = lv_title id_action1 = 'SAVE' id_window_name = lv_window_name ). ENDMETHOD. |
Method: LOAD_ATTACHMENT_LIST
LOAD_ATTACHMENT_LIST |
---|
METHOD load_attachment_list . "=================================== DATA: lt_atta TYPE TABLE OF gos_s_atta, lt_attachment_list TYPE wd_this->elements_attachments, ls_attachment_list LIKE LINE OF lt_attachment_list. FIELD-SYMBOLS: <ls_atta> LIKE LINE OF lt_atta. TRY. lt_atta = wd_this->go_gos->get_atta_list( ). CATCH cx_gos_api. "#EC NO_HANDLER ENDTRY. CLEAR lt_attachment_list.
LOOP AT lt_atta ASSIGNING <ls_atta>. CLEAR ls_attachment_list. MOVE-CORRESPONDING <ls_atta> TO ls_attachment_list. CONDENSE ls_attachment_list-tech_type. IF ls_attachment_list-tech_type EQ 'TXT' OR ls_attachment_list-tech_type IS INITIAL. ls_attachment_list-icon = 'ICON_ANNOTATION'. ELSE. ls_attachment_list-icon = 'ICON_ATTACHMENT'. ENDIF. APPEND ls_attachment_list TO lt_attachment_list. ENDLOOP. "=========================== " Set data to context node "=========================== DATA lo_node TYPE REF TO if_wd_context_node.
lo_node = wd_context->get_child_node( name = wd_this->wdctx_attachments ). lo_node->bind_table( EXPORTING new_items = lt_attachment_list ). ENDMETHOD.
|
Method: SHOW_POPUP
SHOW_POPUP |
---|
method SHOW_POPUP . "Purpose: Display popup window of More CoB "------------------------------------------------ "Data declarations "------------------------------------------------ DATA lo_window_manager TYPE REF TO if_wd_window_manager. DATA lo_api_component TYPE REF TO if_wd_component. DATA lo_window TYPE REF TO if_wd_window. DATA lv_title TYPE string. "---------------------------------------------------- "get view contoller, window manager lo_api_component = wd_this->wd_get_api( ). lo_window_manager = lo_api_component->get_window_manager( ). * "---------------------------------------------------- lv_title = id_title. IF lv_title IS INITIAL. lv_title = 'Create Attachments'. ENDIF. "creat a pop up window CALL METHOD lo_window_manager->create_window EXPORTING * modal = ABAP_TRUE window_name = id_window_name title = lv_title * close_button = ABAP_TRUE button_kind = id_button_kind * message_type = IF_WD_WINDOW=>CO_MSG_TYPE_NONE * close_in_any_case = ABAP_TRUE * message_display_mode = * default_button = is_resizable = abap_false RECEIVING window = lo_window. IF lo_window IS BOUND. IF id_button_kind EQ 3. IF id_action1 IS NOT INITIAL. CALL METHOD lo_window->subscribe_to_button_event EXPORTING button = 4 button_text = id_action1_text * tooltip = action_name = id_action1 action_view = io_view_ctrl is_default_button = abap_true. ENDIF. IF id_action2 IS NOT INITIAL. CALL METHOD lo_window->subscribe_to_button_event EXPORTING button = 6 * button_text = * tooltip = action_name = id_action2 action_view = io_view_ctrl is_default_button = abap_false. ENDIF. ENDIF. lo_window->open( ). ENDIF. "---------------------------------------------------- "------------------------------------------------ endmethod.
|
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 . " Data declarations DATA lv_pol_id TYPE /msg/h_pol_id. "========================== "read policy number "========================== wd_context->get_attribute( EXPORTING name = 'POLICY_ID' IMPORTING value = lv_pol_id ). "============================ "Create an instance of GOS "============================ DATA ls_object TYPE gos_s_obj.
CLEAR ls_object. ls_object-instid = lv_pol_id. " Policy Number ls_object-typeid = '/MSG/HRISK'. ls_object-catid = 'BO'. TRY. wd_comp_controller->go_gos = cl_gos_api=>create_instance( is_object = ls_object ). CATCH cx_gos_api. "#EC NO_HANDLER ENDTRY. "============================ "Load attachment list "============================ wd_comp_controller->load_attachment_list( ). ENDMETHOD. |
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 . DATA ls_attachments TYPE wd_this->element_attachments. DATA lo_view_ctrl TYPE REF TO if_wd_view_controller. CASE id. WHEN 'BTN_CHANGE'. wd_comp_controller->gv_user_action = 2."Change WHEN 'BTN_DISPLAY'. wd_comp_controller->gv_user_action = 3."Display WHEN 'BTN_DELETE'. wd_comp_controller->gv_user_action = 4."Delete WHEN OTHERS. ENDCASE.
"get the current row data CALL METHOD context_element->get_static_attributes IMPORTING static_attributes = ls_attachments. "========================= "Load attachment content "========================= lo_view_ctrl ?= wd_this->wd_get_api( ). CALL METHOD wd_comp_controller->load_attachment_contents EXPORTING is_atta = ls_attachments io_view_ctrl = lo_view_ctrl. ENDMETHOD. |
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( ). |
Continued......