Select particular listbox value on start of Dynpro?

732 views Asked by At

I have a custom dialog dynpro including an input field named DYN_MATNR as listbox for which I have included a list of particular materials as selection.

How can I set a specific material (of that list) as selected when the dialog dynpro is opened?

PBO of dialog dynpro:

  data lt_values type vrm_values.

  select  matnr,
          maktx
    into  table @data(lt_materials)
    from  makt
    where matnr in @so_matnr
      and spras = 'D'
    order by matnr.

  loop at lt_materials assigning field-symbol(<material>).
    append initial line to lt_values assigning field-symbol(<value>).
    <value>-key  = <material>-matnr.
    <value>-text = <material>-maktx.
  endloop.

  call function 'VRM_SET_VALUES'
    exporting
      id              = 'DYN_MATNR'
      values          = lt_values
    exceptions
      id_illegal_name = 1
      others          = 2.
  if sy-subrc <> 0.
    " ...
  endif.

This works and it shows the list of materials as listbox values. To select a particular material I have included the FM DYNP_VALUES_UPDATE afterwards and also in PBO but this did not work:

  data lv_stepl type syst-stepl.

  call function 'DYNP_GET_STEPL'
    importing
      povstepl        = lv_stepl
    exceptions
      stepl_not_found = 1
      others          = 2.
  if sy-subrc <> 0.
    " ...
  endif.

  data(lt_dynpfields) = value dynpread_tabtype(
   ( fieldname  = 'DYN_MATNR'
     stepl      = lv_stepl
     fieldvalue = gcl_helper->get_matnr( ) " matnr which should be selected is stored here
     fieldinp   = space )
  ).

  call function 'DYNP_VALUES_UPDATE'
    exporting
      dyname               = sy-repid
      dynumb               = sy-dynnr
    tables
      dynpfields           = lt_dynpfields
    exceptions
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      undefind_error       = 7
      others               = 8.
  if sy-subrc <> 0.
    " ...
  endif.

I am also not able to directly set DYN_MATNR as it is not available in PBO.

Any hints?

1

There are 1 answers

1
tar On BEST ANSWER

Got it:

You need to additionally define a global(!) variable with the name and (wished) type of the input field (e.g. in the top include of the report or in a separate include of the dynpro logic):

data dyn_matnr type matnr.

Then you can set the initial value of the dynpro field in PBO directly:

dyn_matnr = gcl_helper->get_matnr( ).

As this becomes rather irritating when using various dialog dynpros I recommend including the dynpro number in those variables and input fields.