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 catch value from Listbox in ABAP using VRM_SET_VALUES

0 Kudos

I made Listbox on screen using function `VRM_SET_VALUES`. It works normal, but I can't choose field from the list. Artibute is `DATA gs_screen1100-db_flight(40) TYPE c`. Have I forgotten something?

MODULE init_listbox OUTPUT.
  DATA:
    ls_value  TYPE vrm_value,
    lt_values TYPE vrm_values.

  SELECT carrid, connid
    FROM sflight
    WHERE carrid = 'LH'
    INTO TABLE @DATA(lt_sflight).

  CLEAR lt_values.
  LOOP AT lt_sflight ASSIGNING FIELD-SYMBOL(<fs_sflight>).
    ls_value-key = <fs_sflight>-carrid.
    ls_value-text = <fs_sflight>-connid.
    APPEND ls_value TO lt_values.
  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'GS_SCREEN1100-DB_FLIGHT'
      values = lt_values.
ENDMODULE.
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

The error is due to how you fill the list of values, KEY should be unique.

    ls_value-key = <fs_sflight>-carrid.
    ls_value-text = <fs_sflight>-connid.

For your information, the selected value will make its KEY stored in the target screen field (as you can see in debug).

If you select "LH 0401", it will store "LH" in the screen field and "LH" represents many entries, the first one is shown.

You may simply define the key as being the concatenation of CARRID and CONNID to make it unique.

Minimal reproducible program:

PARAMETERS db_fligh(40) TYPE c AS LISTBOX VISIBLE LENGTH 40.
AT SELECTION-SCREEN OUTPUT.
  DATA:
    ls_value  TYPE vrm_value,
    lt_values TYPE vrm_values.
  SELECT DISTINCT carrid, connid
    FROM sflight
    WHERE carrid = 'LH'
    INTO TABLE @DATA(lt_sflight).
  CLEAR lt_values.
  LOOP AT lt_sflight ASSIGNING FIELD-SYMBOL(<fs_sflight>).
    ls_value-key = <fs_sflight>-carrid && <fs_sflight>-connid.
    ls_value-text = <fs_sflight>-carrid && ` ` && <fs_sflight>-connid.
    APPEND ls_value TO lt_values.
  ENDLOOP.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'DB_FLIGH'
      values = lt_values.
6 REPLIES 6

venkateswaran_k
Active Contributor
0 Kudos

Hi

Please check with option VISIBLE LENGTH <len> with SEELCT-OPTIONS and/ or PARAMETERS commands.

specifically the ID parameter

CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'GS_SCREEN1100-DB_FLIGHT'    <======== this parameter field
      values = lt_values.

0 Kudos

I have to do this in Screen Painter.

Sandra_Rossi
Active Contributor
0 Kudos

I don't think it's related to your question but you should never declare with a dash/hyphen:

DATA gs_screen1100-db_flight(40) TYPE c.

you should declare:

DATA: BEGIN OF gs_screen1100,
        db_flight(40) TYPE c,
      END OF gs_screen1100.

NB: did you debug your program to make sure your module is called? Do you have one line in LT_VALUES? What are the attributes of your screen field?

0 Kudos

I have like this:

TYPES: BEGIN OF gty_fields_screen1100,
         ch_price      TYPE flag,
         ch_currency   TYPE flag,
         ch_planetype  TYPE flag,
         ch_seatsmax   TYPE flag,

         rb1_yes       TYPE flag,
         rb1_no        TYPE flag,
         rb2_yes       TYPE flag,
         rb2_no        TYPE flag,
         p_name(40)    TYPE c,
         db_flight(40) TYPE c,
         db_lines(60)  TYPE c,
       END OF gty_fields_screen1100.

DATA:
  gs_screen1100 TYPE gty_fields_screen1100.

In LT_VALUES I have a table with rows from SFLIGHT with two columns. I see in dropbox list, but I can't choose value. Always is LH 0454.

Sandra_Rossi
Active Contributor

The error is due to how you fill the list of values, KEY should be unique.

    ls_value-key = <fs_sflight>-carrid.
    ls_value-text = <fs_sflight>-connid.

For your information, the selected value will make its KEY stored in the target screen field (as you can see in debug).

If you select "LH 0401", it will store "LH" in the screen field and "LH" represents many entries, the first one is shown.

You may simply define the key as being the concatenation of CARRID and CONNID to make it unique.

Minimal reproducible program:

PARAMETERS db_fligh(40) TYPE c AS LISTBOX VISIBLE LENGTH 40.
AT SELECTION-SCREEN OUTPUT.
  DATA:
    ls_value  TYPE vrm_value,
    lt_values TYPE vrm_values.
  SELECT DISTINCT carrid, connid
    FROM sflight
    WHERE carrid = 'LH'
    INTO TABLE @DATA(lt_sflight).
  CLEAR lt_values.
  LOOP AT lt_sflight ASSIGNING FIELD-SYMBOL(<fs_sflight>).
    ls_value-key = <fs_sflight>-carrid && <fs_sflight>-connid.
    ls_value-text = <fs_sflight>-carrid && ` ` && <fs_sflight>-connid.
    APPEND ls_value TO lt_values.
  ENDLOOP.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'DB_FLIGH'
      values = lt_values.

0 Kudos

Thank you!