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: 

To get selected Listbox value

Former Member
0 Kudos

Hi SDN Gurus,

I am using listbox in screen '0100'. I am populating values thr program using 'VRM_SET_VALUES'. When i am trying to read the screen values using 'DYNP_VALUES_READ', all other field values are getting populated from the screen except listbox selected values. After coming back to the screen the selected value is getting cleared. pls tell me how this can be resolved.

My requirement is to give dropdown list to the user, and when the user selected the value i have to save it 'ztable'. Pls suggest any method which is simple & straight.

Thanks,

Krao.

8 REPLIES 8

MarcinPciak
Active Contributor
0 Kudos

Hi,

Please look at this code:


REPORT z_listbox NO STANDARD PAGE HEADING.

TYPE-POOLS vrm.
"screen field
DATA: listbox.

"value table
DATA: name TYPE  vrm_id,
      value_tab TYPE vrm_values WITH HEADER LINE.

CALL SCREEN 0900.

MODULE init_listbox OUTPUT.

  refresh value_tab.
  value_tab-key = '1'.
  value_tab-text = 'TRUE'.
  APPEND value_tab.
  value_tab-key = '0'.
  value_tab-text = 'FALSE'.
  APPEND value_tab.

  name = 'LISTBOX'.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = name
      values          = value_tab[]
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDMODULE.                    "init_listbox INPUT


MODULE user_command_0900 INPUT.
  IF sy-ucomm = 'FC_LIST'.  "list box function code
    MESSAGE listbox TYPE 'I'.
  ENDIF.
ENDMODULE.                    "user_command_0900 INPUT

MODULE user_exit input.
  IF sy-ucomm = 'FC_EXIT'. "exit function code
    LEAVE PROGRAM.
  ENDIF.
ENDMODULE.                    "user_exit INPUT

and screen flow logic for this


PROCESS BEFORE OUTPUT.
 MODULE init_listbox.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0900.
 MODULE user_exit AT EXIT-COMMAND.

Regards

Marcin

Edited by: Marcin Pciak on Jun 8, 2009 12:45 PM

0 Kudos

Hi Marcin,

Thanks for ur reply. As u gave i have initialised the listbox using 'vrm_set_values'. The values are getting displayed, but only after selecting the value, when i see the field its not having the selected value. I am using 'DYNP_VALUES_READ' to get the values selected from the screen, but its becoming blank and not having the selected value. Pls suggest how the selected value can be tracked from the screen.

Thanks,

Krao.

0 Kudos

Hi Krao,

You don't need to read values from dynpro. If you have assinged function code for listbox, it will automatically trigger PAI once you pick any value from it. In above example this value will be stored in listbox data object which is defined as listbox :


MODULE user_command_0900 INPUT.
  IF sy-ucomm = 'FC_LIST'.  "list box function code
      "LISTBOX data object stores selected value here
  ENDIF.
ENDMODULE.                    

Regards

Marcin

0 Kudos

Hi Marcin,

Can u pls expand what u told,bec even after assigned Function code, the listbox field doesn't had the value selected.

Also in addition to this, could u pls tell the other method, ie taking the selected the value from the screen using 'DYNP_VALUES_READ' bec other input fields i am able to read.

Thanks,

Krao.

0 Kudos

Ok, so let's do it step by step:

- create screen 0900

- place there an input field , select listbox in dropdown field

- call it MY_LISTBOX

- assign function code FC_LIST

- in screen flow logic write


PROCESS BEFORE OUTPUT.
 MODULE init_listbox.

PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0900.

- init_litbox is our module which we use to initialize possible value entry for listbox


DATA: name TYPE  vrm_id,
      value_tab TYPE vrm_values WITH HEADER LINE.

"define variable to change value with screen field
DATA: my_listbox(1) type c.  "name of out listbox 

MODULE init_listbox OUTPUT.
  refresh value_tab.
  value_tab-key = '1'.          "this is key field which will be returned once you selected TRUE value from listobx 
  value_tab-text = 'TRUE'.  "this text is displayed, but real value behind it is 1
  APPEND value_tab.
  value_tab-key = '0'.     "same here
  value_tab-text = 'FALSE'.   "and here
  APPEND value_tab.

  name = 'MY_LISTBOX'.   "give listobx name here

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = name
      values          = value_tab[]
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDMODULE.                    

- now, when you select one value from listbox sy-ucomm (or ok_field is assinged to screen) will store FC_LIST and my_listbox will hold 1 or 0 (key fields, not corresponding text fields TRUE or FALSE).


  IF sy-ucomm = 'FC_LIST'.
     "here MY_LISTBOX either has 0 or 1, if you want to get corresponding TEXT for that simply read table
     READ TABLE value_tab WITH KEY key = my_listbox.
     "key value is stored in MY_LISTBOX
     "text value for that key is stored in VALUE_TAB-TEXT, so you get your answer how to get selected value
  ENDIF.

As for fm 'DYNP_VALUES_READ it is mainly used for PROCESS ON-VALUE REQUEST (F4 - input help). It is used to get fields values on screen, because POV doens't trigger fields trasnport b/w screen field->variables in program. So unless you are using POV you don't need that fm.All screen fields values will be stored in they respecive data objects (variables) defined in program.

Hope now it is clear

Former Member
0 Kudos

hi

try this reference example

report ymylistbox.

type-pools : vrm.

data : name type vrm_id.

data : list type vrm_values.

data : value like line of list.

parameters : p1(10) as listbox visible length 10.

at selection-screen output.

name = 'P1'.

value-key = '1'.

value-text = 'suppu'.

append value to list.

value-key = '2'.

value-text = 'deepu'.

append value to list.

call function 'VRM_SET_VALUES'

exporting

id = name

values = list.

if sy-subrc <> 0.

endif.

start-of-selection.

write 😕 p1.

Regards

praveen_kumar194
Active Contributor
0 Kudos

hi i am trying to get selected value from list box. i am getting following error. any body help me please. i am posting entire my code.

REPORT zveeni.

TABLES zdetails.

TYPE-POOLS: vrm.

DATA: name TYPE vrm_id,

it_tab TYPE vrm_values WITH HEADER LINE,

it_details TYPE zdetails,

var TYPE i VALUE 1,

a TYPE zdetails-age.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS : age TYPE zdetails-age AS LISTBOX VISIBLE LENGTH 5 USER-COMMAND pra.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN OUTPUT.

name = 'age'.

SELECT * FROM zdetails INTO it_details.

it_tab-key = var.

it_tab-text = it_details-age.

APPEND it_tab.

var = var + 1.

ENDSELECT.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = name

values = it_tab[]

  • EXCEPTIONS

  • ID_ILLEGAL_NAME = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

AT SELECTION-SCREEN.

IF sy-ucomm = 'PRA'.

READ TABLE it_tab WITH TABLE KEY key = age.

a = it_tab-text.

ENDIF.

it is showing following error.

the declaration for the key field 'TEXT' is incomplete.

Former Member
0 Kudos

hi,

      step 1: create internal table how many values want in drop down in select-option.

                 for example:

DATA: it_values TYPE  vrm_values,

       wa_values LIKE LINE OF it_values,

       ld_field  TYPE vrm_id.

DATA: it_values1 TYPE  vrm_values,

       wa_values1 LIKE LINE OF it_values,

       ld_field1  TYPE vrm_id.

DATA: it_values2 TYPE  vrm_values,

       wa_values2 LIKE LINE OF it_values,

       ld_field2  TYPE vrm_id.


step 2: create the input parameters like this.

          

PARAMETERS p_type(20) TYPE AS LISTBOX VISIBLE LENGTH 20 DEFAULT  'Regular Order' OBLIGATORY LOWER CASE.

PARAMETERS p_shift(20) TYPE AS LISTBOX VISIBLE LENGTH 20 DEFAULT  'Morning' OBLIGATORY LOWER CASE.


step 3:  write the values in at selection-screen out.


AT SELECTION-SCREEN OUTPUT.

    CLEAR it_values.

    CLEAR it_values1.

    CLEAR it_values2.

   ld_field = 'P_BWART'.

   wa_values-key = '351'.

   wa_values-text = '351'.

   APPEND wa_values TO  it_values.

   ld_field1 = 'P_type'.

   wa_values1-key = 'Regular Order'.

   wa_values1-text = 'Regular Order'.

   APPEND wa_values1 TO  it_values1.

   CLEAR wa_values1.

   ld_field1 = 'P_type'.

   wa_values1-key = 'Party Order'.

   wa_values1-text = 'Party Order'.

   APPEND wa_values1 TO  it_values1.

   CLEAR wa_values1.

   ld_field2 = 'P_shift'.

   wa_values2-key = 'Morning'.

   wa_values2-text = 'Morning'.

   APPEND wa_values2 TO  it_values2.

   CLEAR wa_values2.

   ld_field2 = 'P_shift'.

   wa_values2-key = 'Evening'.

   wa_values2-text = 'Evening'.

   APPEND wa_values2 TO  it_values2.

   CLEAR wa_values2.

   ld_field2 = 'P_shift'.

   wa_values2-key = 'Running'.

   wa_values2-text = 'Running'.

   APPEND wa_values2 TO  it_values2.

   CLEAR wa_values2.


step 4: call the function module

           FM:  VRM_SET_VALUES


CALL FUNCTION 'VRM_SET_VALUES'

     EXPORTING

       id              = ld_field

       values          = it_values

     EXCEPTIONS

       id_illegal_name = 1

       OTHERS          = 2.

   CALL FUNCTION 'VRM_SET_VALUES'

     EXPORTING

       id              = ld_field1

       values          = it_values1

     EXCEPTIONS

       id_illegal_name = 1

       OTHERS          = 2.

   CALL FUNCTION 'VRM_SET_VALUES'

     EXPORTING

       id              = ld_field2

       values          = it_values2

     EXCEPTIONS

       id_illegal_name = 1

       OTHERS          = 2.

I hope will help full.