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: 

return listbox key in table control when value selected in listbx(dropdown)

Former Member
0 Kudos

Hi Gurus,

Need your help,

I have a table control ( TABC) whose fields are from internal table( IT_DSTRUCT) with work area (WA_DSTRUCT).

field WA_DSTRUCT-SITE's attribute are

I/O field

LISTBOX WITH KEY .

In my PBO, I have written below code:

SELECT werks name1 FROM t001w INTO CORRESPONDING FIELDS OF TABLE it_t001w2 WHERE regio = va_region.

SORT it_t001w2 by werks name1.

field_id = 'WA_DSTRUCT-WERKS'.

CLEAR: value,values.

REFRESH values.

LOOP AT it_t001w2 INTO wa_t001w2.

value-KEY = wa_t001w2-werks.

value-TEXT = wa_t001w2-name1.

APPEND value TO VALUES.

ENDLOOP.

SORT values.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = field_id

values = values[].

Now, when I execute my program, text is getting populated instead of 'key'

example:

hy01 - hyderabad location 01

hy02 - hyderabad location 02

what I want to be returned onto screen is 'hy01' but I am getting 'hyderabad location 01' instead.

Edited by: DeepakNandikanti on Jul 22, 2010 12:04 PM

6 REPLIES 6

former_member1245113
Active Contributor
0 Kudos

hi

Change your code as follows

have a table control ( TABC) whose fields are from internal table( IT_DSTRUCT) with work area (WA_DSTRUCT).

LOOP AT it_t001w2 INTO wa_t001w2.

" Just Change the Order as mentioned below
*   value-KEY = wa_t001w2-werks.
value-KEY = wa_t001w2-name1 " Change  WERKS to NAME1 here
*  value-TEXT = wa_t001w2-name1.
value-TEXT = wa_t001w2-werks.. " Change  NAME1 to WERKS here
APPEND value TO VALUES.
ENDLOOP.
SORT values.

CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = field_id
values = values[].

Now, when I execute my program, text is getting populated instead of 'key'
example: 

hy01 - hyderabad location 01 " I have checked your code and am getting correct displayed as you want it to be
hy02 - hyderabad location 02

Cheerz

Ram

0 Kudos

Thanks for your reply Ram,

I have tried as you have suggested but I am not getting the 'Key', the code is always returning

'text' of values

value-key

value-text

0 Kudos

Hi!

You might try out this one:

IF value-key IS INITIAL.

MOVE value-text(4) to value-key.

ENDIF.

Not very beautiful solution, but will work for sure.

Regards

Tamá

0 Kudos

Dear Tamas,

where shall I insert above code lines??

Edited by: DeepakNandikanti on Jul 22, 2010 2:13 PM

0 Kudos

Thank You Tamas,

I used your suggestion for my alrternate solution.

I am closing thread.

--Dep

Former Member
0 Kudos

Hi Gurus,

I am getting the value-key onto the screen but just before I display it on the screen(100)

it is displaying name1( prob from value-text).

I am able to see the drop down list on my screen column

when I select a value from dropdown all corresponding values are getting selected correctly.

for example:

hyderbad region 01 | hyderabad region 01 | 35 | AP | India

hyderbad region 02 | hyderabad region 02 | 36 | AP | India

hyderbad region 03 | hyderabad region 03 | 37 | AP | India

but*I need

hy 01 | hyderabad region 01 | 35 | AP | India

hy 02 | hyderabad region 02 | 36 | AP | India

hy 03 | hyderabad region 03 | 37 | AP | India