ABAP Webdynpro - 如何使用用户自定义的value help

For input attribute totally five input help mode could be selected. In most of time we would always like to leverage the existing dictionary search help defined in DDIC. However if existing one could not fulfill our requirement, we have to develop our own value help by ourselves.

I have used a simple example to demonstrate how to use “Freely Programmed” input help mode.

I have one consumer component ZCONSUMER, and one component ZUSER_HELP.
ZCONSUMER just have one input field for post ID and post description. When click value help of Post ID, the view of ZUSER_HELP will be opened and there is a SQL select to fetch the description according to post ID from database table.

(1) in ZUSER_HELP, create the context node with attribute ID for post id, and description for post description. Since I use external mapping for data transfer from consumer component to value help provider component, so I mark the flag “Input Element(Ext.)”. Define the node as interface node.

(2) Implement the standard component interface IWD_VALUE_HELP. Redefine the method SET_VALUE_HELP_LISTENER. Also include your own value help view into the interface view WD_VALUE_HELP.

In the method SET_VALUE_HELP_LISTENER, I select the post description from database table and store it to attribute DESCRIPTION.
The listener reference is also stored into member variable of component controller for later usage.

method SET_VALUE_HELP_LISTENER .
   data: lv_id type socialdata-internal_id,
         lv_text type socialdata-socialposttext.
   wd_this->mr_listener = listener.
   data(lo_node) = wd_context->get_child_node( IF_COMPONENTCONTROLLER=>wdctx_post ).
   CHECK lo_node IS NOT INITIAL.
   lo_node->get_attribute( EXPORTING name = 'ID' IMPORTING value = lv_id ).
   SELECT SINGLE socialposttext INTO lv_text from socialdata where internal_id = lv_id.
   CHECK sy-subrc = 0.
   lo_node->set_attribute( name = 'DESCRIPTION' value = lv_text ).
endmethod.

(3) Draw a button in value help view to close the value help popup window once clicked. Just use the reference stored in step2 to close window.

method ONACTIONCLOSE .
  wd_comp_controller->mr_listener->close_window( ).
endmethod.

(4) in consumer component ZCONSUMER, create component usage to ZUSER_HELP, and create context node POST. Choose Input help mode Freely Programmed and choose component usage ZUSER_DEFINE_HELP from value help.

Create an interface controller usage on component usage ZUSER_DEFINE_HELP and finish the context node mapping, or else you will meet with runtime error
“External mapping of Node ZUSER_HELP#COMPONENTCONTROLLER.CONTEXT.POST is Not Completed yet”.

Now once clicked the value help icon of input field Post ID, the value help window provided by component ZUSER_HELP will pop up automatically.

And once close button is clicked, the description field of consumer component will be filled.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":


你可能感兴趣的:(ABAP Webdynpro - 如何使用用户自定义的value help)