07-26-2013 3:00 PM
How can i connect two list-box ?
I want the Second list-box's data will be populated according to the data selected in first list-box.
07-29-2013 10:58 AM
Hi Omkar,
I have two list boxes: Sales Organization and Sales Document Number in my scenario.
Based on the sales organization, the sales document numbers are displayed.
The AT SELECTION-SCREEN OUTPUT filters the values for the second list box based on the selected value of the first list box.
Here is the coding which satisfies your requirement:
*--------------------------------------------------------------------*
* Type-Pools
*--------------------------------------------------------------------*
TYPE-POOLS: vrm.
*--------------------------------------------------------------------*
* Types
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_vkorg,
vkorg TYPE vkorg,
END OF ty_vkorg,
BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
vkorg TYPE vkorg,
END OF ty_vbak.
*--------------------------------------------------------------------*
* Constants
*--------------------------------------------------------------------*
CONSTANTS: c_vkorg TYPE vrm_id VALUE 'P_VKORG',
c_vbeln TYPE vrm_id VALUE 'P_VBELN',
c_fcode TYPE char7 VALUE 'LISTING'.
*--------------------------------------------------------------------*
* Data
*--------------------------------------------------------------------*
DATA: gs_vbak TYPE ty_vbak,
gs_vkorg TYPE ty_vkorg,
gs_list TYPE vrm_value,
gt_list TYPE vrm_values,
gt_vbak TYPE STANDARD TABLE OF ty_vbak,
gt_vkorg TYPE STANDARD TABLE OF ty_vkorg.
*--------------------------------------------------------------------*
* Selection-Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-000.
PARAMETERS: p_vkorg TYPE vkorg AS LISTBOX VISIBLE LENGTH 20
USER-COMMAND listing,
p_vbeln TYPE vbeln_va AS LISTBOX VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK blk.
*--------------------------------------------------------------------*
* Initialization
*--------------------------------------------------------------------*
INITIALIZATION.
PERFORM get_sales_org.
*--------------------------------------------------------------------*
* Start-Of-Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM display_alv.
*--------------------------------------------------------------------*
* At Selection-Screen Output
*--------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
IF p_vkorg IS INITIAL.
LOOP AT gt_vkorg INTO gs_vkorg.
gs_list-key = gs_vkorg-vkorg.
gs_list-text = gs_vkorg-vkorg.
APPEND gs_list TO gt_list.
CLEAR: gs_list, gs_vkorg.
ENDLOOP.
PERFORM set_values_for_listbox USING c_vkorg.
ENDIF.
PERFORM get_sales_document.
LOOP AT gt_vbak INTO gs_vbak.
gs_list-key = gs_vbak-vbeln.
gs_list-text = gs_vbak-vbeln.
APPEND gs_list TO gt_list.
CLEAR: gs_list, gs_vbak.
ENDLOOP.
PERFORM set_values_for_listbox USING c_vbeln.
*&---------------------------------------------------------------------*
*& Form GET_SALES_ORG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales_org .
SELECT vkorg
FROM tvko
INTO TABLE gt_vkorg.
IF sy-subrc <> 0.
REFRESH: gt_vkorg.
ELSE.
SORT: gt_vkorg.
ENDIF.
ENDFORM. " GET_SALES_ORG
*&---------------------------------------------------------------------*
*& Form GET_SALES_DOCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales_document .
IF p_vkorg IS NOT INITIAL.
SELECT vbeln vkorg
FROM vbak
INTO TABLE gt_vbak
WHERE vkorg = p_vkorg.
IF sy-subrc = 0.
SORT gt_vbak BY vbeln.
ELSE.
REFRESH: gt_vbak.
ENDIF.
ENDIF.
ENDFORM. " GET_SALES_DOCUMENT
*&---------------------------------------------------------------------*
*& Form SET_VALUES_FOR_LISTBOX
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PA_ID text
*----------------------------------------------------------------------*
FORM set_values_for_listbox USING value(pa_id).
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = pa_id
values = gt_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.
REFRESH: gt_list.
ENDFORM. " SET_VALUES_FOR_LISTBOX
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv .
DATA: lo_alv TYPE REF TO cl_salv_table,
lo_exc TYPE REF TO cx_salv_msg,
lv_res TYPE string,
lt_vbak TYPE STANDARD TABLE OF ty_vbak.
IF gt_vbak IS NOT INITIAL.
READ TABLE gt_vbak INTO gs_vbak
WITH KEY vbeln = p_vbeln
vkorg = p_vkorg
BINARY SEARCH.
IF sy-subrc = 0.
APPEND gs_vbak TO lt_vbak.
ENDIF.
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = lt_vbak.
CATCH cx_salv_msg INTO lo_exc.
CALL METHOD lo_exc->get_text
RECEIVING
result = lv_res.
ENDTRY.
IF lo_alv IS BOUND.
CALL METHOD lo_alv->display.
ENDIF.
REFRESH: lt_vbak.
CLEAR: gs_vbak.
ENDFORM. " DISPLAY_ALV
Thanks & Regards,
T. Prasanna Kumar
07-29-2013 8:11 AM
Hello Omkar,
you requirement is event based. meaning once data in list box one is selected on click of second list box you need to write code for getting data.
Regards
Animesh Sundriyal
07-29-2013 8:15 AM
Hi Omkar,
You can refer to the standard program 'DEMO_DYNPRO_DROPDOWN_LISTBOX'.
This might be helpful for you.
Regards,
Santanu.
07-29-2013 8:18 AM
Hi,
Just check the link. It has the demo code.
http://help.sap.com/saphelp_470/helpdata/en/9f/dbabe435c111d1829f0000e829fbfe/content.htm
Cheers,
Arindam
07-29-2013 8:20 AM
Hello Omkar,
to add more to my previous answer. You exactly need to create a Process on value request for drop down 2 and then in the module you have to call function DYNP_VALUE_READ to read the first dropdown value and then write the logic to populate second.
Regards
Animesh Sundriyal
07-29-2013 8:23 AM
Hello Omkar,
You have to assign fcode to the two list box fields. When even one field is selected you can change the entries in another list box field in PROCESS ON VALUE-REQUEST by using VRM_SET_VALUES API.
07-29-2013 10:58 AM
Hi Omkar,
I have two list boxes: Sales Organization and Sales Document Number in my scenario.
Based on the sales organization, the sales document numbers are displayed.
The AT SELECTION-SCREEN OUTPUT filters the values for the second list box based on the selected value of the first list box.
Here is the coding which satisfies your requirement:
*--------------------------------------------------------------------*
* Type-Pools
*--------------------------------------------------------------------*
TYPE-POOLS: vrm.
*--------------------------------------------------------------------*
* Types
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_vkorg,
vkorg TYPE vkorg,
END OF ty_vkorg,
BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
vkorg TYPE vkorg,
END OF ty_vbak.
*--------------------------------------------------------------------*
* Constants
*--------------------------------------------------------------------*
CONSTANTS: c_vkorg TYPE vrm_id VALUE 'P_VKORG',
c_vbeln TYPE vrm_id VALUE 'P_VBELN',
c_fcode TYPE char7 VALUE 'LISTING'.
*--------------------------------------------------------------------*
* Data
*--------------------------------------------------------------------*
DATA: gs_vbak TYPE ty_vbak,
gs_vkorg TYPE ty_vkorg,
gs_list TYPE vrm_value,
gt_list TYPE vrm_values,
gt_vbak TYPE STANDARD TABLE OF ty_vbak,
gt_vkorg TYPE STANDARD TABLE OF ty_vkorg.
*--------------------------------------------------------------------*
* Selection-Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-000.
PARAMETERS: p_vkorg TYPE vkorg AS LISTBOX VISIBLE LENGTH 20
USER-COMMAND listing,
p_vbeln TYPE vbeln_va AS LISTBOX VISIBLE LENGTH 10.
SELECTION-SCREEN END OF BLOCK blk.
*--------------------------------------------------------------------*
* Initialization
*--------------------------------------------------------------------*
INITIALIZATION.
PERFORM get_sales_org.
*--------------------------------------------------------------------*
* Start-Of-Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM display_alv.
*--------------------------------------------------------------------*
* At Selection-Screen Output
*--------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
IF p_vkorg IS INITIAL.
LOOP AT gt_vkorg INTO gs_vkorg.
gs_list-key = gs_vkorg-vkorg.
gs_list-text = gs_vkorg-vkorg.
APPEND gs_list TO gt_list.
CLEAR: gs_list, gs_vkorg.
ENDLOOP.
PERFORM set_values_for_listbox USING c_vkorg.
ENDIF.
PERFORM get_sales_document.
LOOP AT gt_vbak INTO gs_vbak.
gs_list-key = gs_vbak-vbeln.
gs_list-text = gs_vbak-vbeln.
APPEND gs_list TO gt_list.
CLEAR: gs_list, gs_vbak.
ENDLOOP.
PERFORM set_values_for_listbox USING c_vbeln.
*&---------------------------------------------------------------------*
*& Form GET_SALES_ORG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales_org .
SELECT vkorg
FROM tvko
INTO TABLE gt_vkorg.
IF sy-subrc <> 0.
REFRESH: gt_vkorg.
ELSE.
SORT: gt_vkorg.
ENDIF.
ENDFORM. " GET_SALES_ORG
*&---------------------------------------------------------------------*
*& Form GET_SALES_DOCUMENT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_sales_document .
IF p_vkorg IS NOT INITIAL.
SELECT vbeln vkorg
FROM vbak
INTO TABLE gt_vbak
WHERE vkorg = p_vkorg.
IF sy-subrc = 0.
SORT gt_vbak BY vbeln.
ELSE.
REFRESH: gt_vbak.
ENDIF.
ENDIF.
ENDFORM. " GET_SALES_DOCUMENT
*&---------------------------------------------------------------------*
*& Form SET_VALUES_FOR_LISTBOX
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PA_ID text
*----------------------------------------------------------------------*
FORM set_values_for_listbox USING value(pa_id).
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = pa_id
values = gt_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.
REFRESH: gt_list.
ENDFORM. " SET_VALUES_FOR_LISTBOX
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv .
DATA: lo_alv TYPE REF TO cl_salv_table,
lo_exc TYPE REF TO cx_salv_msg,
lv_res TYPE string,
lt_vbak TYPE STANDARD TABLE OF ty_vbak.
IF gt_vbak IS NOT INITIAL.
READ TABLE gt_vbak INTO gs_vbak
WITH KEY vbeln = p_vbeln
vkorg = p_vkorg
BINARY SEARCH.
IF sy-subrc = 0.
APPEND gs_vbak TO lt_vbak.
ENDIF.
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = lt_vbak.
CATCH cx_salv_msg INTO lo_exc.
CALL METHOD lo_exc->get_text
RECEIVING
result = lv_res.
ENDTRY.
IF lo_alv IS BOUND.
CALL METHOD lo_alv->display.
ENDIF.
REFRESH: lt_vbak.
CLEAR: gs_vbak.
ENDFORM. " DISPLAY_ALV
Thanks & Regards,
T. Prasanna Kumar
07-29-2013 11:23 AM
Hi Omkar,
Refer this standard program DEMO_DYNPRO_DROPDOWN_LISTBOX.
Let me know if you want more help..
Regards,
Abdul
08-02-2013 7:11 PM
08-03-2013 3:24 AM