이글은 아래 링크의 원본 글에 대한 한글 번역 입니다
https://blogs.sap.com/2013/11/25/how-to-close-ovs-popup-window/

How to Close OVS Popup window

November 25, 2013

 

소개

이글은 웹딘프로아밥에서 OVS 팝업 윈도우를 닫는 코드에 대해 설명합니다.

 

요구사항은 다음 글에서 시작되었습니다: https://scn.sap.com/thread/3456054 - OVS에서 검색 결과가 없을때 새 팝업을 열고 OVS는 닫는 방법을 알고 싶습니다.

 

준비물

OVS 서치 헬프  작성법.

 

이 글에서는 OVS 서치 헬프 작성법을 설명하지 않겠습니다. 이미 인터넷에 비슷한 글이 많이 있습니다. OVS 작성법을 먼저 공부하려면 대표적으로 Amy King의 다음 글을 참고하세요: https://scn.sap.com/docs/DOC-32690.

 

단계별 진행

OVS를 만들었다면 다음 단계를 따라가세요. 목표는 OVS에서 검색결과가 없을때 새 팝업을 열고 자동으로 OVS 윈도우를 닫는 것입니다.

 

주의: 지금 설명하는 방법은 여러 해결방법중 한가지를 보여주는 것으로 유일한 해결책은 아닙니다.

 

 

뷰의 어트리뷰트 탭으로 이동하여 어트리뷰트 GR_HANDLE 을 타입 TYPE REF TO IF_WDR_OVS_LISTENER 으로 만듭니다.

/wp-content/uploads/2013/11/1_331155.jpg

 

이제 아래 코드를 ON_OVS 메소드(OVS의 이벤트 핸들러)에 입력합니다.

 

ON_OVS
METHOD onovs .
* declare data structures for the fields to be displayed and
* for the table columns of the selection list, if necessary
   TYPES:
     BEGIN OF lty_stru_input,
*   add fields for the display of your search input here
       carrid TYPE string,
     END OF lty_stru_input.
   TYPES:
     BEGIN OF lty_stru_list,
*   add fields for the selection list here
       carrid TYPE string,
     END OF lty_stru_list.


   DATA: ls_search_input  TYPE lty_stru_input,
         lt_select_list   TYPE STANDARD TABLE OF lty_stru_list,
         ls_text          TYPE wdr_name_value,
         lt_label_texts   TYPE wdr_name_value_list,
         lt_column_texts  TYPE wdr_name_value_list,
         lv_window_title  TYPE string,
         lv_group_header  TYPE string,
         lv_table_header  TYPE string.


   DATA: lo_window_manager TYPE REF TO if_wd_window_manager,
         lr_view_controller TYPE REF TO if_wd_view_controller,
         lo_api_component  TYPE REF TO if_wd_component,
         lo_window         TYPE REF TO if_wd_window,
         l_text            TYPE string_table.


   FIELD-SYMBOLS: <ls_query_params> TYPE lty_stru_input,
                  <ls_selection>    TYPE lty_stru_list.


   CASE ovs_callback_object->phase_indicator.


     WHEN if_wd_ovs=>co_phase_0.  "configuration phase, may be omitted
*   in this phase you have the possibility to define the texts,
*   if you do not want to use the defaults (DDIC-texts)


       ls_textname = `CARRID`.  "must match a field name of search
       ls_textvalue = `Airline`. "wd_assist->get_text( `001` ).
       INSERT ls_text INTO TABLE lt_label_texts.


       ls_textname = `CARRID`"must match a field in list structure
       ls_textvalue = `Airline`. "wd_assist->get_text( `002` ).
       INSERT ls_text INTO TABLE lt_column_texts.


*      lv_window_title = wd_assist->get_text( `003` ).
*      lv_group_header = wd_assist->get_text( `004` ).
*      lv_table_header = wd_assist->get_text( `005` ).


       ovs_callback_object->set_configuration(
                 label_texts  = lt_label_texts
                 column_texts = lt_column_texts
                 group_header = lv_group_header
                 window_title = lv_window_title
                 table_header = lv_table_header
                 col_count    = 2
                 row_count    = 20 ).




     WHEN if_wd_ovs=>co_phase_1"set search structure and defaults
*   In this phase you can set the structure and default values
*   of the search structure. If this phase is omitted, the search
*   fields will not be displayed, but the selection table is
*   displayed directly.
*   Read values of the original context (not necessary, but you
*   may set these as the defaults). A reference to the context
*   element is available in the callback object.


       ovs_callback_object->context_element->get_static_attributes(
           IMPORTING static_attributes = ls_search_input ).
*     pass the values to the OVS component
       ovs_callback_object->set_input_structure(
           input = ls_search_input ).




     WHEN if_wd_ovs=>co_phase_2.
*   If phase 1 is implemented, use the field input for the
*   selection of the table.
*   If phase 1 is omitted, use values from your own context.


       IF ovs_callback_object->query_parameters IS NOT BOUND.
******** TODO exception handling
       ENDIF.
       ASSIGN ovs_callback_object->query_parameters->*
                               TO <ls_query_params>.
       IF NOT <ls_query_params> IS ASSIGNED.
******** TODO exception handling
       ENDIF.


*     call business logic for a table of possible values
       SELECT carrid FROM sflight INTO TABLE lt_select_list.
       ovs_callback_object->set_output_table( output = lt_select_list ).
 
       IF lt_select_list IS INITIAL.     
*     Open a popup if no entries found 
         lo_api_component  = wd_comp_controller->wd_get_api( ).
         lo_window_manager = lo_api_component->get_window_manager( ).
 
         INSERT `No Entries Found! Do you want to create new entries?` INTO TABLE l_text.
 
         lo_window   = lo_window_manager->create_popup_to_confirm(
                           text = l_text
                           button_kind = if_wd_window=>co_buttons_yesno
                           message_type = if_wd_window=>co_msg_type_question
                           window_position = if_wd_window=>co_center
                            ).
 
*     Get View Controller Reference
         lr_view_controller = wd_this->wd_get_api( ).
 
*     Subscribe to No button Event
         lo_window->subscribe_to_button_event(
               button = if_wd_window=>co_button_no
               action_name = ‘CLOSE_OVS’           ” Create this Action
               action_view = lr_view_controller
               is_default_button = abap_false ).
 
         lo_window->open( ).
 
*     Store OVS Listener instance globally
         wd_this->gr_handle ?= ovs_callback_object.
       ENDIF.


     WHEN if_wd_ovs=>co_phase_3.
*   apply result


       IF ovs_callback_object->selection IS NOT BOUND.
******** TODO exception handling
       ENDIF.


       ASSIGN ovs_callback_object->selection->* TO <ls_selection>.
       IF <ls_selection> IS ASSIGNED.
         ovs_callback_object->context_element->set_attribute(
                                name  = `VAL`   ” Context Attribute Name
                                value = <ls_selection>carrid ).


       ENDIF.
   ENDCASE.


ENDMETHOD.

 

 

다음은 뷰의 액션 탭으로 이동하여 액션 CLOSE_OVS를 만듭니다.

 

/wp-content/uploads/2013/11/2_331180.jpg

 

 

아래 코드를 ONACTIONCLOSE_OVS 메소드에 입력합니다.

 

ONACTIONCLOSE_OVS
METHOD onactionclose_ovs .
* Work around to close the OVS search help window
   wd_this->gr_handle->on_cancel( ).


ENDMETHOD.

 

컴포넌트를 저장하고 활성화 합니다.

 

실행 결과

웹딘프로 어플리케이션을 테스트하겠습니다.

 

입력 필드에서 F4 헬프를 선택합니다.

 

/wp-content/uploads/2013/11/3_331186.jpg

검색 버튼을 누릅니다. ( co_phase_1 이 생략 된 경우 안눌러도 됩니다 ).

 

/wp-content/uploads/2013/11/4_331193.jpg

 

만약 검색 결과가 없다면 팝업이 열린 것을 볼 수 있습니다!

/wp-content/uploads/2013/11/5_331194.jpg

( 테스트로 팝업을 보기 위해 디버거로 테이블을 비웠습니다 ).

 

No 버튼에 대해서만 OVS를 닫는 이벤트 처리를 해두었습니다. No 를 클릭하면 OVS 윈도우도 자동으로 닫히는 것을 볼 수 있습니다.

 

/wp-content/uploads/2013/11/6_331195.jpg

 

 

 

결론

 

이번 데모에서는 No 버튼만 OVS를 닫는 이벤트 처리를 했지만, 비슷하게 Yes 버튼에도 신규 항목을 작성하는 화면으로 이동하도록 이벤트 처리를 할 수 있습니다. 이글이 비슷한 문제로 어려움을 겪는 분들에게 도움이 되었으면 좋겠습니다.   

 

 

 

이글은 아래 링크의 원본 글에 대한 한글 번역 입니다
https://blogs.sap.com/2013/11/25/how-to-close-ovs-popup-window/

+ Recent posts