Copyright 2021 - BV TallVision IT

Selection screens are generated from (abap) coding and generally sometimes need a little tweeking to make it do what you need it to do. This article is about such tweek: fetch information that has been typed on the screen, but the user has not pressed "enter" yet. 

A classic example is processing you're own F4 logic: the user fills in a value like ABC*, then presses F4 and your logic is started. You'll find that the actual screen parameter doesn't have value "ABC*" just yet. Pick it up with function module DYNP_VALUES_READ !

  DATA: gt_DYNPVALUETAB type standard table of DYNPREAD. 

            DYNAME             = SY-REPID
            DYNUMB             = SY-DYNNR
            DYNPFIELDS         = gt_DYNPFIELDS.

The field or fields for which a value is required, will need to be specified on the gt_DYNPFIELD table before you call the function module. It operates as a work instruction list and it does not return all field values of the whole dynpro. Make sure you fill in gt_DYNPFIELD first !

There is also a DYNP_VALUES_UPDATE which is very useful to confuse the end user - e.g. by finishing what he/she is typing. Best left alone.

Method screen reader

To capture this logic in a method, this is my solution:.

In the definition (static method):

  screen_reader importing fieldname type any returning value(fieldvalue) type string.

The actual method

  METHOD screen_reader.
    data: lt_DYNPREAD type standard table of DYNPREAD,
          lw_DYNPREAD type DYNPREAD.

    clear: lt_dynpread[], lw_dynpread.
    lw_dynpread-fieldname = fieldname.
    append lw_dynpread to lt_dynpread.

        DYNAME     = sy-repid
        DYNUMB     = sy-dynnr
        DYNPFIELDS = lt_dynpread
        OTHERS     = 4.
    if sy-subrc = 0.
      read table lt_dynpread into lw_dynpread index 1.
      fieldvalue = lw_dynpread-FIELDVALUE.


An implementation example:

MODULE choose_matnr_01 INPUT.

  gw_materials_2200-MATNR01 = lcl_BlueBox=>screen_reader( 'GW_MATERIALS_2200-MATNR01' ).
  lcl_BlueBox=>choose_material( changing material = gw_materials_2200-MATNR01 ).