Skip to Content
avatar image
Former Member

closing pop-up box error

Hello,

Im getting a frustrating problem' Access via 'NULL' object reference not possible ' when I try to close the popup box , I am assuming its something to do with either setting up my nodes or attributes, unfortunately i tried everything I could but nothing worked.

this is the part of the code action to generate a popup box, subscribe and assign the OK button an action

method ONACTIONADD_NAME .

Data: context_node type ref to if_wd_context_node.

data lv_action_view TYPE REF TO if_wd_view_controller.

DATA lv_title TYPE string.

DATA lo_nd_add_name TYPE REF TO if_wd_context_node.

DATA lo_el_add_name TYPE REF TO if_wd_context_element.

DATA ls_add_name TYPE wd_this->element_add_name.

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.

  • generate a popup box

lo_api_component = wd_comp_controller->wd_get_api( ).

lo_window_manager = lo_api_component->get_window_manager( ).

lo_window = lo_window_manager->create_window(

window_name = 'W_ADD_NAME'

title = 'Add a Tester'

close_in_any_case = abap_false

message_display_mode = if_wd_window=>co_msg_display_mode_selected

close_button = abap_true

button_kind = if_wd_window=>co_buttons_okcancel

message_type = if_wd_window=>co_msg_type_none

default_button = if_wd_window=>co_button_ok

).

  • Subscribe the action handler methods to the popup ok and cancel buttons

lv_action_view = wd_this->wd_get_api( ).

lo_window->subscribe_to_button_event(

button = if_wd_window=>co_button_ok

action_name = 'ON_OK_ADD_NAME'

action_view = lv_action_view

).

lo_window->open( ).

endmethod.

and this is the action where I have the issue of closing the popup box

DATA lo_nd_ui_manipulation TYPE REF TO if_wd_context_node.

DATA lo_nd_add_name TYPE REF TO if_wd_context_node.

DATA lo_el_add_name TYPE REF TO if_wd_context_element.

DATA lo_nd_sname TYPE REF TO if_wd_context_node.

DATA ls_add_name TYPE wd_this->element_add_name.

DATA lo_nd_sname_copy TYPE REF TO if_wd_context_node.

DATA lt_sname_copy TYPE wd_this->elements_sname_copy.

DATA lv_msg_text TYPE string.

DATA lv_param1 TYPE symsgv.

DATA lv_param2 TYPE symsgv.

DATA lv_param3 TYPE symsgv.

DATA lv_elements_count TYPE i.

data lo_window type ref to if_wd_window.

  • get message manager

data lo_api_controller type ref to if_wd_controller.

data lo_message_manager type ref to if_wd_message_manager.

  • Read the values user entered in add name popup

lo_nd_add_name = wd_context->get_child_node( name = wd_this->wdctx_add_name ).

lo_el_add_name = lo_nd_add_name->get_element( ).

lo_el_add_name->get_static_attributes(

IMPORTING

static_attributes = ls_add_name ).

IF ls_add_name IS INITIAL OR ls_add_name-first_name IS INITIAL.

  • display messages fill in the required field in the pop-up windows

lo_api_controller ?= wd_This->Wd_Get_Api( ).

CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER

RECEIVING

MESSAGE_MANAGER = lo_message_manager.

CALL METHOD lo_message_manager->REPORT_T100_MESSAGE

EXPORTING

MSGID = '00'

MSGNO = 055

MSGTY = 'E' .

ELSE.

  • Check if the name is already present

lo_nd_sname_copy = wd_context->get_child_node( name = wd_this->wdctx_sname_copy ).

CHECK NOT lo_nd_sname_copy IS INITIAL.

CALL METHOD lo_nd_sname_copy->get_static_attributes_table

IMPORTING

table = lt_sname_copy.

READ TABLE lt_sname_copy WITH KEY first_name = ls_add_name-first_name TRANSPORTING NO FIELDS.

IF sy-subrc EQ 0.

  • If a same name exist, raise error message

lv_msg_text = 'name exist, please enter a different name'.

lo_api_controller ?= wd_This->Wd_Get_Api( ).

CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER

RECEIVING

MESSAGE_MANAGER = lo_message_manager.

CALL METHOD lo_message_manager->REPORT_ERROR_MESSAGE

EXPORTING

MESSAGE_TEXT = lv_msg_text.

ELSE.

  • if the name doesnt exist

lo_nd_sname_copy = wd_context->get_child_node( name = wd_this->wdctx_sname_copy ).

CHECK NOT lo_nd_sname_copy IS INITIAL.

CALL METHOD lo_nd_sname_copy->get_static_attributes_table

IMPORTING

table = lt_sname_copy.

READ TABLE lt_sname_copy WITH KEY first_name = ls_add_name-first_name TRANSPORTING NO FIELDS.

  • IF the name doesnt exist , add name

lo_nd_sname = wd_context->get_child_node( name = wd_this->wdctx_sname ).

CHECK NOT lo_nd_sname IS INITIAL.

lo_nd_sname->bind_structure( new_item = ls_add_name set_initial_elements = abap_false ).

CLEAR lt_sname_copy.

CALL METHOD lo_nd_sname->get_static_attributes_table

IMPORTING

table = lt_sname_copy.

  • add the name to the local context

lo_nd_sname_copy->bind_table( lt_sname_copy ).

  • add the name to the shared data name context

lo_nd_sname->bind_table( lt_sname_copy ).

  • set the table's visible row property in order to show the added record

lv_elements_count = lo_nd_sname_copy->get_element_count( ).

lo_nd_ui_manipulation = wd_context->get_child_node( name = wd_this->wdctx_ui_manipulation ).

lo_nd_ui_manipulation->set_attribute( name = `VISIBLEROW` value = lv_elements_count ).

lv_param1 = ls_add_name-first_name.

lv_param2 = ls_add_name-last_name.

lv_param3 = ls_add_name-c_num.

  • display a successfull message

lo_api_controller ?= wd_This->Wd_Get_Api( ).

CALL METHOD lo_api_controller->GET_MESSAGE_MANAGER

RECEIVING

MESSAGE_MANAGER = lo_message_manager

.

  • report message

CALL METHOD lo_message_manager->REPORT_SUCCESS

EXPORTING

MESSAGE_TEXT = 'succesfully added'.

  • Enable/disable delete button based on lead selection

CALL METHOD wd_comp_controller->manage_delete_button .

  • Save the last action in the context, this data will be shown in the idr

CLEAR lv_msg_text.

lv_msg_text = wd_assist->if_wd_component_assistance~get_text( key = '014' ).

CONCATENATE lv_msg_text ls_add_name-first_name INTO lv_msg_text SEPARATED BY space.

lo_nd_ui_manipulation = wd_context->get_child_node( name = wd_this->wdctx_ui_manipulation ).

lo_nd_ui_manipulation->set_attribute( name = `IDR_LAST_ACTION` value = lv_msg_text ).

lo_window->close( ).

every time I add the lo_window->close( ). I get the Null error.

Thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Mar 05, 2009 at 05:06 PM

    Thanks guys, I followed Anzy's way of creating a pop up and it worked fine.

    does anyone know how can I insert the data into my table after I saved them in my local context??

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Abdul,

      I guess that you want the user to be able to modify the data in the table & then have the changes made saved to database. Right? SAP recommends using a BAPI for doing the same. (Using a [Service Call|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/9cb5d345-0801-0010-6a8e-fc57c23fd600] you can call a BAPI from within your component & get the desired functionality.) If you however intend to just try out a sample example in your IDES then you can directly try using the normal ABAP MODIFY statement on the database table. Try check the sample code snippet below.

      Regards,

      Uday

      data:
            node_sflight           type ref to if_wd_context_node,
            elem_sflight           type ref to if_wd_context_element,
            lt_elements            type WDR_CONTEXT_ELEMENT_SET,
            stru_sflight           type if_main=>element_sflight_node,
            it_flights             type if_main=>elements_sflight_node.
       
      "   navigate from <CONTEXT> to <SFLIGHT_NODE> via lead selection
          node_sflight_node = wd_context->get_child_node( name = if_main=>wdctx_sflight_node ).
       
      "   get element via lead selection
      "    elem_sflight_node = node_sflight_node->get_element(  ).
           lt_elements = node_sflight->get_elements( ). 
           
      "   get all declared attributes
          loop at lt_elements into elem_sflight.
          elem_sflight->get_static_attributes(
            importing
              static_attributes = stru_sflight ).
              
          append stru_sflight to it_flights.
          endloop.
          
          modify ZSFLIGHT99 from table it_flights.
          if sy-subrc eq 0.
          
          endif.

  • avatar image
    Former Member
    Mar 05, 2009 at 02:22 PM

    Reading your code as is the , lo_window is not initialized, when call is made to the method

    lo_window->Close( ) .

    conceptually you will need to get the Reference to the POP-up window you created in your first method, put this reference to point to lo_window.

    and then call lo_window->close( ).

    Greetings

    Prashant

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 05, 2009 at 03:49 AM

    Hi Abdul,

    Try passing the view name in the close statement.

    Refer:

    lo_window->close( '<view name>'  ). " give the pop up view name here
    

    I hope it helps.

    Regards

    Arjun

    Edited by: Arjun on Mar 5, 2009 9:19 AM

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 05, 2009 at 05:51 AM

    Hi Abdul,

    Go through this [excellent blog by Anzy|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6707] [original link is broken] [original link is broken] [original link is broken]; where he explains how you can close popup windows. (The blog is titled as external windows but it does actually refer to popup windows.)

    Below is another workaround for the same. You must be callinng a popup by using the code wizard. Within this code at 1 place you would have something like lo_window_manager->create_window( ) which would be returning the reference to this popup window. You can create an attribute of type ref to IF_WD_WINDOW & ave this reference into it. So map this context node even to your popups view. When you want to close this popup just read the context attribute value in your view and call the close( ) method on this reference variable.

    Just go through the code snippets below:

    To call the popup and save the window reference into a component controller level attribute:

    METHOD onactiondisplay_popup .
      DATA: lv_node  TYPE REF TO if_wd_context_node,
            lv_kunnr TYPE ig_componentcontroller=>element_kna1-kunnr,
            lt_vbak  TYPE ig_componentcontroller=>elements_vbak.
    
    
    *   get message manager
      DATA lo_api_controller     TYPE REF TO if_wd_controller.
      DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
    
      lo_api_controller ?= wd_this->wd_get_api( ).
    
      CALL METHOD lo_api_controller->get_message_manager
        RECEIVING
          message_manager = lo_message_manager.
    
    
      lv_node = wd_context->get_child_node( name = 'KNA1' ).
    
      CALL METHOD lv_node->get_attribute
        EXPORTING
          name  = 'KUNNR'
        IMPORTING
          value = lv_kunnr.
    
      SELECT * FROM vbak INTO TABLE lt_vbak WHERE kunnr = lv_kunnr.
    
    " If no sales orders exist for the customer then display an error message quoting the same
      IF sy-subrc NE 0.
    
    *   report message
        CALL METHOD lo_message_manager->report_error_message
          EXPORTING
            message_text = 'No sales orders exist for this customer!'.
    " If sales orders exist for the customer then display the orders within a popup
      ELSE.
        lv_node = wd_context->get_child_node( name = 'VBAK' ).
        lv_node->bind_table( new_items = lt_vbak ).
    
        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.
    
        lo_api_component  = wd_comp_controller->wd_get_api( ).
        lo_window_manager = lo_api_component->get_window_manager( ).
        lo_window         = lo_window_manager->create_window(
                            window_name            = 'POPUP_WINDOW'
                            title                  = 'Working with modal windows in webdynpro!'
                            CLOSE_IN_ANY_CASE      = ABAP_TRUE ).
    
        lv_node = wd_context->get_child_node( name = 'WINDOW_REFERENCE' ).
    
        CALL METHOD lv_node->set_attribute
          EXPORTING
            value  = lo_window
            name   = 'REFERENCE'.
    
        lo_window->open( ).
      ENDIF.
    ENDMETHOD.                    "onactiondisplay_popup

    To close the popup window:

    lv_node = wd_context->get_child_node( name = 'WINDOW_REFERENCE' ).
      CALL METHOD lv_node->get_attribute
        EXPORTING
          name   = 'REFERENCE'
        IMPORTING
          value  = lv_pop_window_ref.
      lv_pop_window_ref->close( ).

    Regards,

    Uday

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 05, 2009 at 09:50 AM

    Hi ,

    First debug your application & try to find where your getting error, The reason your getting this error some this is not correct in your application / something does not hold any data. So i suggest just check your view/window/ui element/static names. if in case using context, change the cordinality to 0..1

    anylise error output in ST22

    Try above all

    Regards

    Ravi

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 09, 2009 at 07:13 PM

    Hi Uday Gubbala

    i did use BAPI in my action, adn my program works perfectly now

    thanks man

    Add comment
    10|10000 characters needed characters exceeded