Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Clearing a field whilst in 'ON-VALUE-REQUEST' for another screen field

Former Member
0 Kudos
106

Hi,

I have two screen fields which are linked in a hierarchy, i.e. the 2nd field values are dependant on the 1st.

I have put the following code into the ON-VALUE-REQUEST module of the first field:


* Read value of FIELD2
  CLEAR: field_value, dynpro_values.
  field_value-fieldname = 'FIELD2'.
  APPEND field_value TO dynpro_values.

  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname             = sy-repid
      dynumb             = sy-dynnr
      translate_to_upper = 'X'
    TABLES
      dynpfields         = dynpro_values.

  READ TABLE dynpro_values INDEX 1 INTO field_value.
  l_field2 = field_value-fieldvalue.

* Search help for FIELD1
  CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
      tabname                   = 'FIELD1TAB'
      fieldname                 = 'FIELD1NAME'
     searchhelp                =  'FIELD1SEARCHHELP'
*   SHLPPARAM                 = ' '
     dynpprog                  = sy-repid
     dynpnr                    = sy-dynnr
     dynprofield               = 'FIELD1'
* IMPORTING
*   USER_RESET                =
   TABLES
     return_tab                = lt_return
   EXCEPTIONS
     field_not_found           = 1
     no_help_for_field         = 2
     inconsistent_help         = 3
     no_values_found           = 4
     OTHERS                    = 5.

  READ TABLE lt_return INTO wa_return INDEX 1.
  l_field1 = wa_return-fieldval.

* See if FIELD2 value is still valid after FIELD1 has changed
  IF NOT l_field1 IS INITIAL AND NOT l_field2 IS INITIAL.
    SELECT SINGLE *
      FROM field2_table
      WHERE field1 EQ l_field1
        AND field2 EQ l_field2.
    IF sy-subrc NE 0.
*     FIELD2 value is not valid, clear it
      CLEAR: field_value, dynpro_values.
      field_value-fieldname = 'FIELD2'.
      CLEAR field_value-fieldvalue.
      field_value-fieldinp = 'X'.
      APPEND field_value TO dynpro_values.
      CALL FUNCTION 'DYNP_VALUES_UPDATE'
        EXPORTING
          dyname     = sy-repid
          dynumb     = sy-dynnr
        TABLES
          dynpfields = dynpro_values.
    ENDIF.
  ENDIF.

The problem I'm having is that FIELD1 is not updating from the value selected from the search help. I've tried commenting all the code after the search help function out and found that it all worked until DYNP_VALUES_UPDATE was inserted. This is somehow stopping the update to FIELD1 which should happen automatically when the user selects a value from the search help.

Can anyone tell me what I've done wrong or if there is an easier way of clearing FIELD2 based on whether it's value is still valid after FIELD1 has changed?

Thanks,

Gill

2 REPLIES 2

Former Member
0 Kudos
48

I've solved this myself, I wasn't refreshing table dynpro_values inbetween the calls to FM DYNP_VALUES_UPDATE.

0 Kudos
48

Hi Mr. Gill Ackroyd,

I need the solution for this case if you can send me the whole code.

Best regards,