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: 

How to capture the user change in an input field on a selection screen?

Former Member
0 Kudos

I am coding a selection screen in which there are two input fields. The first field takes a Unix directory from the user input. Based on the input value, the second field will be populated with a the name of a file under the corresponding directory.

My question is how I can make the program capture the user input without having to make the user press ENTER after they enter the value in the first field?

Any help will be greatly appreciated.

5 REPLIES 5

Former Member
0 Kudos

If your list of directory names is restricted, then you could consider prepopulating a list with these values and implementing a listbox on that field (if you're not sure how to do that search for 'listbox vrm' in Google)... with the listbox define a user-command in it so that a change of value can be picked up in your logic and the list of corresponding files generated into the second field (this could even be a listbox too).

Jonathan

venkat_o
Active Contributor
0 Kudos

Hi Ning Hu , The following sample program is suitable for ur requirement. You have to use function module DYNP_VALUES_UPDATE to update automatically. Execute and check the program once.

REPORT zvenkat_head MESSAGE-ID zmsg .
*&---------------------------------------------------------------------*
" Declaration part
*&---------------------------------------------------------------------*
TYPES:
   BEGIN OF t_t001w,
     werks       TYPE t001w-werks,
     name1       TYPE t001w-name1,
   END OF t_t001w,
   t_return_tab  TYPE ddshretval.
DATA:
    w_t001w      TYPE t_t001w,
    w_return_tab TYPE t_return_tab.
DATA:
    i_t001w      TYPE STANDARD TABLE OF t_t001w,
    i_return_tab TYPE STANDARD TABLE OF t_return_tab.
*&---------------------------------------------------------------------*
"SELECTION-SCREEN
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS :p_werks TYPE t001w-werks,
            p_name1 TYPE t001w-name1.
SELECTION-SCREEN END OF BLOCK b1.

*&---------------------------------------------------------------------*
" AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_werks
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_werks.
  PERFORM f4_help_for_palant.

*&---------------------------------------------------------------------*
*&      Form  f4_help_for_palant
*&---------------------------------------------------------------------*
FORM f4_help_for_palant.

  DATA:
      w_dynpfields TYPE dynpread,
      i_dynpfields LIKE STANDARD TABLE OF dynpread.

  IF i_t001w[] IS INITIAL.
    SELECT werks name1
    FROM t001w
    INTO TABLE i_t001w.
  ENDIF.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
*   DDIC_STRUCTURE         = ' '
    retfield               = 'WERKS'
*   PVALKEY                = ' '
    dynpprog               = sy-repid
    dynpnr                 = sy-dynnr
    dynprofield            = 'P_WERKS'
*   STEPL                  = 0
*   WINDOW_TITLE           =
*   VALUE                  = ' '
   value_org              = 'S'
*   MULTIPLE_CHOICE        = ' '
*   DISPLAY                = ' '
*   CALLBACK_PROGRAM       = ' '
*   CALLBACK_FORM          = ' '
*   MARK_TAB               =
* IMPORTING
*   USER_RESET             =
    TABLES
      value_tab              = i_t001w
*   FIELD_TAB              =
    return_tab             = i_return_tab
*   DYNPFLD_MAPPING        =
* EXCEPTIONS
*   PARAMETER_ERROR        = 1
*   NO_VALUES_FOUND        = 2
*   OTHERS                 = 3
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  READ TABLE i_return_tab INTO w_return_tab INDEX 1.
  p_werks = w_return_tab-fieldval.
  READ TABLE i_t001w INTO w_t001w WITH KEY werks = p_werks.
  IF sy-subrc = 0.

    w_dynpfields-fieldname    = 'P_NAME1'.
    w_dynpfields-fieldvalue   = w_t001w-name1.
    APPEND w_dynpfields TO i_dynpfields.
    CLEAR w_dynpfields.

    CALL FUNCTION 'DYNP_VALUES_UPDATE'
      EXPORTING
        dyname               = sy-repid
        dynumb               = sy-dynnr
      TABLES
        dynpfields           = i_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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


  ENDIF.


ENDFORM.                    " f4_help_for_palant
I hope that it solves ur problem. Regards, Venkat.O

Former Member
0 Kudos

Thanks, Jonathan. The directory choices may not be a predefined list. Otherwise you method would be a perfect solution.

Former Member
0 Kudos

Venkat,

Thanks for taking time to answer my question. I tested the function module you mentioned. However, what it does is to update the screen field value dynamically without undergoing the PBO. Actually I need a function module to automatically detect user input in the screen fields. For example, if the user changes the directory, the program will immediately know that. Next when the user clicks the file open dialog to select a file name, the dialog will open in the new directory. It is similar to the role of an ActionListener in Java. Do you know if this is possible to be implemented in ABAP?

Former Member
0 Kudos

Venkat,

Actually you led me to the real solution! It's the function module DYNP_VALUES_READ that does the trick for me. This function enables the program to capture dynamic user changes without recourse to PAI. Please refer to the code below:


REPORT   zreiabsintf MESSAGE-ID zreiabsintfmc.

*<HGDC------------------------------------------------------------------
*  Selection screen for the conversion program
*HGDC>------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK input WITH FRAME TITLE text-001.
PARAMETERS: p_indir   LIKE epsf-epsdirnam OBLIGATORY,                   " Inbound file directory
            p_infile  LIKE epsf-epsfilnam DEFAULT gc_infile OBLIGATORY, " Inbound file name
SELECTION-SCREEN END OF BLOCK input.

*<HGDC------------------------------------------------------------------
*   Displays a file-open dialog when the user clicks the search
*   help button next to the inbound file text field. The user
*   can select the inbound file visually.
*HGDC>------------------------------------------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
* Capture any user change to the directory.
  PERFORM check_dir_change.
* Display the file open dialog
  PERFORM file_open_dialog CHANGING p_infile.

*<HGDC------------------------------------------------------------------
* Global constants
*HGDC>------------------------------------------------------------------
CONSTANTS:
    gc_indir  LIKE epsf-epsdirnam
              VALUE '/interfaces/<SID>/inbound/',      " Default inbound directory template
    gc_infile LIKE epsf-epsfilnam VALUE 'input'.       " Default inbound file name

*<HGDC------------------------------------------------------------------
* Global data
*HGDC>------------------------------------------------------------------
DATA:
    gs_dynpfields   TYPE dynpread,                        " Fields of the current screen
     gt_dynpfields   LIKE STANDARD TABLE OF gs_dynpfields. " Table of the screen fields

*&---------------------------------------------------------------------*
*&      Form  file_open_dialog
*&---------------------------------------------------------------------*
*       Opens a dialog window for the user to choose a file in
*       the specified Unix directory.
*----------------------------------------------------------------------*
*      <--P_FILE is the file to be selected.
*----------------------------------------------------------------------*
FORM file_open_dialog  CHANGING p_file.

* Validate the directory.
  OPEN DATASET p_indir FOR INPUT IN BINARY MODE.

  IF sy-subrc NE 0.
    MESSAGE i001(zreiabsintfmc) WITH p_indir.    " Unable to open the given directory
    EXIT.
  ENDIF.

  CLOSE DATASET p_indir.

* Call the dialog window to open a file in the directory.
  CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
    EXPORTING
      directory        = p_indir
    IMPORTING
      serverfile       = p_file
    EXCEPTIONS
      canceled_by_user = 1
      OTHERS           = 2.
  IF sy-subrc NE 0.
    MESSAGE i002(zreiabsintfmc).                 " Failed to open the file.
    EXIT.
  ENDIF.

ENDFORM.                    " file_open_dialog

*&---------------------------------------------------------------------*
*&      Form  check_dir_change
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM check_dir_change .
  CLEAR gs_dynpfields.
  CLEAR gt_dynpfields.

  gs_dynpfields-fieldname = 'P_INDIR'.
  gs_dynpfields-fieldvalue = p_indir.
  APPEND gs_dynpfields TO gt_dynpfields.


  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      dyname               = sy-repid
      dynumb               = sy-dynnr
    TABLES
      dynpfields           = gt_dynpfields
    EXCEPTIONS
      invalid_abapworkarea = 1
      invalid_dynprofield  = 2
      invalid_dynproname   = 3
      invalid_dynpronummer = 4
      invalid_request      = 5
      no_fielddescription  = 6
      invalid_parameter    = 7
      undefind_error       = 8
      double_conversion    = 9
      stepl_not_found      = 10
      OTHERS               = 11.
  IF sy-subrc  NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE gt_dynpfields INTO gs_dynpfields INDEX 1.
  p_indir = gs_dynpfields-fieldvalue.

ENDFORM.                    " check_dir_change

Thanks for all your answers! The problem is now solved.

Edited by: Ning Hu on Apr 9, 2008 11:32 AM

Edited by: Ning Hu on Apr 9, 2008 11:34 AM