Application Development and Automation 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: 
Read only

Getting values back from a listbox.

Former Member
0 Likes
2,673

Hi Guys/Dolls

I have the following snippet of code (which was supplied by one of you gurus)

but can someone tell me how I can retrieve my selected listbox value into a variable so I can print it - sorry I'm new to ABAP. I've ran it through the debugger but just can't see it. can the answer be based on the following snippet of code as this is what I've coded up already.

Many thanks in advance.

Raj

TYPE-POOLS : vrm. "Value Request Manager

PARAMETERS: p_test AS LISTBOX VISIBLE LENGTH 20 OBLIGATORY.

INITIALIZATION.

PERFORM f4_value_request.

&----


*& Form f4_value_request

&----


  • text

----


FORM f4_value_request.

DATA: l_name TYPE vrm_id,

li_list TYPE vrm_values,

l_value LIKE LINE OF li_list.

l_value-key = '1'.

l_value-text = 'Value 1'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '2'.

l_value-text = 'Value 2'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '3'.

l_value-text = 'Value 3'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '4'.

l_value-text = 'Value 4'.

APPEND l_value TO li_list.

CLEAR l_value.

l_name = 'P_TEST'.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = l_name

values = li_list

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.

ENDFORM. " f4_value_request

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,589

hI...

Paste the following code... u will get the result...

REPORT YH642_TEST_F4_BETTER.

TYPE-POOLS : vrm. "Value Request Manager

DATa:

VALUES TYPE VRM_VALUES,

l_name TYPE vrm_id,

WA_VALUES LIKE LINE OF VALUES.

data:

w_text(20) type c.

PARAMETERS: p_test AS LISTBOX VISIBLE LENGTH 20 OBLIGATORY.

INITIALIZATION.

PERFORM f4_value_request.

start-of-selection.

READ TABLE VALUES WITH KEY P_TEST INTO WA_VALUES.

WRITE: WA_VALUES-TEXT.

&----


*& Form f4_value_request

&----


  • text

----


FORM f4_value_request.

DATA:

li_list TYPE vrm_values,

l_value LIKE LINE OF li_list.

l_value-key = '1'.

l_value-text = 'Value 1'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '2'.

l_value-text = 'Value 2'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '3'.

l_value-text = 'Value 3'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '4'.

l_value-text = 'Value 4'.

APPEND l_value TO li_list.

CLEAR l_value.

l_name = 'P_TEST'.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = l_name

values = li_list

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.

CALL FUNCTION 'VRM_GET_VALUES'

EXPORTING

id = l_name

IMPORTING

VALUES = VALUES

EXCEPTIONS

ID_NOT_FOUND = 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.

ENDFORM. " f4_value_request

11 REPLIES 11
Read only

Former Member
0 Likes
1,589

hi...

<b>( no need to do any thing separately here... the variable p_test contains the selected value )</b>

TYPE-POOLS : vrm. "Value Request Manager

PARAMETERS: p_test AS LISTBOX VISIBLE LENGTH 20 OBLIGATORY.

INITIALIZATION.

PERFORM f4_value_request.

<b>START-OF-SELECTION.

WRITE P_TEST.</b>

&----


*& Form f4_value_request

&----


  • text

----


FORM f4_value_request.

DATA: l_name TYPE vrm_id,

li_list TYPE vrm_values,

l_value LIKE LINE OF li_list.

l_value-key = '1'.

l_value-text = 'Value 1'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '2'.

l_value-text = 'Value 2'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '3'.

l_value-text = 'Value 3'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '4'.

l_value-text = 'Value 4'.

APPEND l_value TO li_list.

CLEAR l_value.

l_name = 'P_TEST'.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = l_name

values = li_list

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.

ENDFORM. " f4_value_request

reward if it helps u..

sai ramesh

Read only

Former Member
0 Likes
1,589

Hi Raj,

Another option is to use the function module F4IF_INT_TABLE_VALUE_REQUEST which is built for the exact purpose you need and you can see a lot of programs in its where used.

Also, a given program is DEMO_DROPDOWN_LIST_BOX which demos its usage.

Regards,

Aditya

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,589

Your selected value is in the paramater defined as a listbox.

You can use this value after PAI of screen 1000. (AT SELECTION-SCREEN and therafter)

Regards.

Read only

p291102
Active Contributor
0 Likes
1,589

Hi,

Actually your requirement is by giving the value u have to come some dynamic output in alv.

For your requirement i am sending the sample report. When executing this report put some number like example 53 and execute it. U can see the dyamic output in alv.

REPORT YMS_DYNAMICALV.

TYPE-POOLS: SLIS.

FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,

<DYN_WA>.

DATA: ALV_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,

IT_FLDCAT TYPE LVC_T_FCAT.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_FLDS(5) TYPE C.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

  • build the dynamic internal table

PERFORM BUILD_DYN_ITAB.

  • write 5 records to the alv grid

DO 5 TIMES.

PERFORM BUILD_REPORT.

ENDDO.

  • call the alv grid.

PERFORM CALL_ALV.

************************************************************************

  • Build_dyn_itab

************************************************************************

FORM BUILD_DYN_ITAB.

DATA: NEW_TABLE TYPE REF TO DATA,

NEW_LINE TYPE REF TO DATA,

WA_IT_FLDCAT TYPE LVC_S_FCAT.

  • Create fields .

DO P_FLDS TIMES.

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = SY-INDEX.

WA_IT_FLDCAT-DATATYPE = 'CHAR'.

WA_IT_FLDCAT-INTLEN = 5.

APPEND WA_IT_FLDCAT TO IT_FLDCAT .

ENDDO.

  • Create dynamic internal table and assign to FS

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_FLDCAT

IMPORTING

EP_TABLE = NEW_TABLE.

ASSIGN NEW_TABLE->* TO <DYN_TABLE>.

  • Create dynamic work area and assign to FS

CREATE DATA NEW_LINE LIKE LINE OF <DYN_TABLE>.

ASSIGN NEW_LINE->* TO <DYN_WA>.

ENDFORM. "build_dyn_itab

*********************************************************************

  • Form build_report

*********************************************************************

FORM BUILD_REPORT.

DATA: FIELDNAME(20) TYPE C.

DATA: FIELDVALUE(5) TYPE C.

DATA: INDEX(3) TYPE C.

FIELD-SYMBOLS: <FS1>.

DO P_FLDS TIMES.

INDEX = SY-INDEX.

  • Set up fieldvalue

CONCATENATE 'FLD' INDEX INTO

FIELDVALUE.

CONDENSE FIELDVALUE NO-GAPS.

  • <b> assign component index of structure <dyn_wa> to <fs1>.

  • <fs1> = fieldvalue.</b>

ENDDO.

  • Append to the dynamic internal table

APPEND <DYN_WA> TO <DYN_TABLE>.

ENDFORM. "build_report

************************************************************************

  • CALL_ALV

************************************************************************

FORM CALL_ALV.

DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.

DO P_FLDS TIMES.

CLEAR WA_CAT.

WA_CAT-FIELDNAME = SY-INDEX.

WA_CAT-SELTEXT_S = SY-INDEX.

WA_CAT-OUTPUTLEN = '5'.

APPEND WA_CAT TO ALV_FLDCAT.

ENDDO.

  • Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IT_FIELDCAT = ALV_FLDCAT

TABLES

T_OUTTAB = <DYN_TABLE>.

ENDFORM. "call_alv

Thanks,

Sankar M

Read only

Former Member
0 Likes
1,589

Hi,

I think your listbox value are in p_test parameter.

Because you set p_test as ID.



l_name = 'P_TEST'.

CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
<b>id = l_name</b>
values = li_list
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.

But the value of P_Test is your value key (1, 2, 3.. ),

since you set at this code:


l_value-key = '1'.
l_value-key = '2'.
etc..

Regards,

Read only

Former Member
0 Likes
1,589

Yes - I see it now I was interrogating the value in the initialization section.

This give me the index value how do I get the actual textual value? or would I have to do a case statement or can I get it via another method?

Sorry to be a pain.

Raj

Read only

0 Likes
1,589

Hi,

Yes, you can use Case statement.

Regards,

Read only

p291102
Active Contributor
0 Likes
1,589

Hi,

Actually your requirement is by giving the value u have to come some dynamic output in alv. For your requirement i am sending the sample report. When executing this report put some number like example 53 and execute it. U can see the dyamic output in alv.

REPORT YMS_DYNAMICALV.

TYPE-POOLS: SLIS.

FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,

<DYN_WA>.

DATA: ALV_FLDCAT TYPE SLIS_T_FIELDCAT_ALV,

IT_FLDCAT TYPE LVC_T_FCAT.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_FLDS(5) TYPE C.

SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

  • build the dynamic internal table

PERFORM BUILD_DYN_ITAB.

  • write 5 records to the alv grid

DO 5 TIMES.

PERFORM BUILD_REPORT.

ENDDO.

  • call the alv grid.

PERFORM CALL_ALV.

************************************************************************

  • Build_dyn_itab

************************************************************************

FORM BUILD_DYN_ITAB.

DATA: NEW_TABLE TYPE REF TO DATA,

NEW_LINE TYPE REF TO DATA,

WA_IT_FLDCAT TYPE LVC_S_FCAT.

  • Create fields .

DO P_FLDS TIMES.

CLEAR WA_IT_FLDCAT.

WA_IT_FLDCAT-FIELDNAME = SY-INDEX.

WA_IT_FLDCAT-DATATYPE = 'CHAR'.

WA_IT_FLDCAT-INTLEN = 5.

APPEND WA_IT_FLDCAT TO IT_FLDCAT .

ENDDO.

  • Create dynamic internal table and assign to FS

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = IT_FLDCAT

IMPORTING

EP_TABLE = NEW_TABLE.

ASSIGN NEW_TABLE->* TO <DYN_TABLE>.

  • Create dynamic work area and assign to FS

CREATE DATA NEW_LINE LIKE LINE OF <DYN_TABLE>.

ASSIGN NEW_LINE->* TO <DYN_WA>.

ENDFORM. "build_dyn_itab

*********************************************************************

  • Form build_report

*********************************************************************

FORM BUILD_REPORT.

DATA: FIELDNAME(20) TYPE C.

DATA: FIELDVALUE(5) TYPE C.

DATA: INDEX(3) TYPE C.

FIELD-SYMBOLS: <FS1>.

DO P_FLDS TIMES.

INDEX = SY-INDEX.

  • Set up fieldvalue

CONCATENATE 'FLD' INDEX INTO

FIELDVALUE.

CONDENSE FIELDVALUE NO-GAPS.

  • <b> assign component index of structure <dyn_wa> to <fs1>.

  • <fs1> = fieldvalue.</b>

ENDDO.

  • Append to the dynamic internal table

APPEND <DYN_WA> TO <DYN_TABLE>.

ENDFORM. "build_report

************************************************************************

  • CALL_ALV

************************************************************************

FORM CALL_ALV.

DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.

DO P_FLDS TIMES.

CLEAR WA_CAT.

WA_CAT-FIELDNAME = SY-INDEX.

WA_CAT-SELTEXT_S = SY-INDEX.

WA_CAT-OUTPUTLEN = '5'.

APPEND WA_CAT TO ALV_FLDCAT.

ENDDO.

  • Call ABAP List Viewer (ALV)

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

IT_FIELDCAT = ALV_FLDCAT

TABLES

T_OUTTAB = <DYN_TABLE>.

ENDFORM. "call_alv

Thanks,

Sankar M

Read only

Former Member
0 Likes
1,589

Hi...use

" VRM_GET_VALUES" FUNCTION MODULE...

Read only

Former Member
0 Likes
1,589

Hi Raj

here is a suggestion.wat all the code you have pasted is under initialization event.

now you want to get the value from the list box into a variable,as the list box is on the selection screen,put an event called AT SELECTION_SCREEN after initialization event as this.

TYPE-POOLS : vrm. "Value Request Manager

<b>DATA : V(80) TYPE C.</b>

PARAMETERS: p_test AS LISTBOX VISIBLE LENGTH 20 OBLIGATORY.

INITIALIZATION.

PERFORM HELP_REQUEST.

<b>AT SELECTION-SCREEN.

V = P_TEST.

START-OF-SELECTION.

WRITE 😕 'The selected paramter value is ',V.</b>

I hope this should be of help to you.

Kindly reward points if helpful.

Regards

Zarina

Read only

Former Member
0 Likes
1,590

hI...

Paste the following code... u will get the result...

REPORT YH642_TEST_F4_BETTER.

TYPE-POOLS : vrm. "Value Request Manager

DATa:

VALUES TYPE VRM_VALUES,

l_name TYPE vrm_id,

WA_VALUES LIKE LINE OF VALUES.

data:

w_text(20) type c.

PARAMETERS: p_test AS LISTBOX VISIBLE LENGTH 20 OBLIGATORY.

INITIALIZATION.

PERFORM f4_value_request.

start-of-selection.

READ TABLE VALUES WITH KEY P_TEST INTO WA_VALUES.

WRITE: WA_VALUES-TEXT.

&----


*& Form f4_value_request

&----


  • text

----


FORM f4_value_request.

DATA:

li_list TYPE vrm_values,

l_value LIKE LINE OF li_list.

l_value-key = '1'.

l_value-text = 'Value 1'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '2'.

l_value-text = 'Value 2'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '3'.

l_value-text = 'Value 3'.

APPEND l_value TO li_list.

CLEAR l_value.

l_value-key = '4'.

l_value-text = 'Value 4'.

APPEND l_value TO li_list.

CLEAR l_value.

l_name = 'P_TEST'.

CALL FUNCTION 'VRM_SET_VALUES'

EXPORTING

id = l_name

values = li_list

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.

CALL FUNCTION 'VRM_GET_VALUES'

EXPORTING

id = l_name

IMPORTING

VALUES = VALUES

EXCEPTIONS

ID_NOT_FOUND = 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.

ENDFORM. " f4_value_request