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: 

One select option depends on another

sergio_cifuentes
Participant
0 Kudos

i have two select options:

SELECT-OPTIONS so_cdr FOR zcmtt_cdr_rutas-cdr.

SELECT-OPTIONS so_ruta FOR zcmtt_cdr_rutas-ruta.

both are related in the table zcmtt_cdr_rutas what do i have to do to make so_ruta depends on the value of so_cdr, i mean if nothing is entered in so_cdr when i select so_ruta gave me all the values, if i select for example so_cdr = 1 then when i select so_ruta only displays me the values for so_cdr = 1 not all the list??

1 ACCEPTED SOLUTION

former_member589029
Active Contributor
0 Kudos

You can create a search help for the field 'ruta' and when calling it restrict the selection for the search help based on the value of cdr.

Here is what I did in a similar case:

flow logic:

PROCESS ON VALUE-REQUEST.

FIELD gs_pod_screen-ship_cond

MODULE f4_ship_cond.

code:

MODULE f4_ship_cond INPUT.

PERFORM f4_pod_shipping_conditions.

ENDMODULE. " f4_ship_cond INPUT

FORM f4_pod_shipping_conditions .

DATA: lt_return TYPE TABLE OF ddshretval,

ls_return TYPE ddshretval,

lv_line TYPE i,

lv_vendor TYPE bu_partner,

ls_shlp TYPE shlp_descr,

ls_selopt TYPE ddshselopt,

ls_if TYPE ddshiface,

lv_c(132) TYPE c.

  • where on the table control did we hit F4?

GET CURSOR LINE lv_line.

READ TABLE gt_pod_sales

INTO gs_pod_screen

INDEX lv_line

TRANSPORTING vendor.

CHECK NOT gs_pod_screen-vendor IS INITIAL.

  • the possible values always depend on the vendor => build it every time

  • get the search help parameters first

CALL FUNCTION 'F4IF_GET_SHLP_DESCR'

EXPORTING

shlpname = gc_shlp_shipcon

IMPORTING

shlp = ls_shlp.

  • now we have to set restrictions based on the vendor

CLEAR ls_selopt.

ls_selopt-shlpname = gc_shlp_shipcon. <= Search Help Name

ls_selopt-shlpfield = gc_name_vendor. <= Search Help Field for Restriction (cdr)

ls_selopt-sign = gc_i. <= 'I' for range

ls_selopt-option = gc_eq. <= 'EQ' for range

ls_selopt-low = gs_pod_screen-vendor. <= restriction value (cdr)

APPEND ls_selopt TO ls_shlp-selopt.

  • set the field for the output

READ TABLE ls_shlp-interface INTO ls_if

WITH KEY shlpfield = gc_name_ship_cond.

IF sy-subrc EQ 0.

ls_if-valfield = gc_field_shipcon.

MODIFY ls_shlp-interface FROM ls_if

INDEX sy-tabix TRANSPORTING valfield.

ENDIF.

  • pass in the base date and call the search help (this executes the search help but will just display values where cdr equals your restriction you put in earlier)

CALL FUNCTION 'F4IF_START_VALUE_REQUEST'

EXPORTING

shlp = ls_shlp

TABLES

return_values = lt_return.

READ TABLE lt_return INTO ls_return INDEX 1.

IF sy-subrc EQ 0.

gs_pod_screen-ship_cond = ls_return-fieldval.

ELSE.

CLEAR gs_pod_screen-ship_cond.

ENDIF.

  • transfer the value

MODIFY gt_pod_sales

FROM gs_pod_screen

INDEX lv_line

TRANSPORTING ship_cond.

ENDFORM. " f4_shipping_conditions

Hope that helps,

Michael

By the way, I did this for a field on a table control but you can attach this to any field.

For you the event would be:

AT SELECTION-SCREEN ON VALUE-REQUEST FOR ('RUTA').

Message was edited by: Michael Wackerbauer

3 REPLIES 3

former_member589029
Active Contributor
0 Kudos

You can create a search help for the field 'ruta' and when calling it restrict the selection for the search help based on the value of cdr.

Here is what I did in a similar case:

flow logic:

PROCESS ON VALUE-REQUEST.

FIELD gs_pod_screen-ship_cond

MODULE f4_ship_cond.

code:

MODULE f4_ship_cond INPUT.

PERFORM f4_pod_shipping_conditions.

ENDMODULE. " f4_ship_cond INPUT

FORM f4_pod_shipping_conditions .

DATA: lt_return TYPE TABLE OF ddshretval,

ls_return TYPE ddshretval,

lv_line TYPE i,

lv_vendor TYPE bu_partner,

ls_shlp TYPE shlp_descr,

ls_selopt TYPE ddshselopt,

ls_if TYPE ddshiface,

lv_c(132) TYPE c.

  • where on the table control did we hit F4?

GET CURSOR LINE lv_line.

READ TABLE gt_pod_sales

INTO gs_pod_screen

INDEX lv_line

TRANSPORTING vendor.

CHECK NOT gs_pod_screen-vendor IS INITIAL.

  • the possible values always depend on the vendor => build it every time

  • get the search help parameters first

CALL FUNCTION 'F4IF_GET_SHLP_DESCR'

EXPORTING

shlpname = gc_shlp_shipcon

IMPORTING

shlp = ls_shlp.

  • now we have to set restrictions based on the vendor

CLEAR ls_selopt.

ls_selopt-shlpname = gc_shlp_shipcon. <= Search Help Name

ls_selopt-shlpfield = gc_name_vendor. <= Search Help Field for Restriction (cdr)

ls_selopt-sign = gc_i. <= 'I' for range

ls_selopt-option = gc_eq. <= 'EQ' for range

ls_selopt-low = gs_pod_screen-vendor. <= restriction value (cdr)

APPEND ls_selopt TO ls_shlp-selopt.

  • set the field for the output

READ TABLE ls_shlp-interface INTO ls_if

WITH KEY shlpfield = gc_name_ship_cond.

IF sy-subrc EQ 0.

ls_if-valfield = gc_field_shipcon.

MODIFY ls_shlp-interface FROM ls_if

INDEX sy-tabix TRANSPORTING valfield.

ENDIF.

  • pass in the base date and call the search help (this executes the search help but will just display values where cdr equals your restriction you put in earlier)

CALL FUNCTION 'F4IF_START_VALUE_REQUEST'

EXPORTING

shlp = ls_shlp

TABLES

return_values = lt_return.

READ TABLE lt_return INTO ls_return INDEX 1.

IF sy-subrc EQ 0.

gs_pod_screen-ship_cond = ls_return-fieldval.

ELSE.

CLEAR gs_pod_screen-ship_cond.

ENDIF.

  • transfer the value

MODIFY gt_pod_sales

FROM gs_pod_screen

INDEX lv_line

TRANSPORTING ship_cond.

ENDFORM. " f4_shipping_conditions

Hope that helps,

Michael

By the way, I did this for a field on a table control but you can attach this to any field.

For you the event would be:

AT SELECTION-SCREEN ON VALUE-REQUEST FOR ('RUTA').

Message was edited by: Michael Wackerbauer

0 Kudos

Thanks Mike, how do i restrict the values of a select option to the values showed in the list??

0 Kudos

In my case I basically had a z-table with field1 and field2.

When I click F4 for field1, I get all the values from my z-table for field1.

In the coding I just have one value e.g. 'VENDOR1'

Which means when I click on F4 for field2 I get only those values from the z-table where field1 = 'VENDOR1'

If the table looks like:

field1 field2

VENDOR1 value1

VENDOR1 value2

VENDOR1 value3

VENDOR2 valuea

VENDOR2 valueb

I would get value1, value2, value3 from the search help for field2

The restriction would be

ls_selopt-sign = 'I'.

ls_selopt-option = 'EQ'.

ls_selopt-low = 'VENDOR1'.

append ls_selopt to lt_selopt.

If you want to restrict by more than one value, just keep adding entries to your lt_selopt table

ls_selopt-sign = 'I'.

ls_selopt-option = 'EQ'.

ls_selopt-low = 'VENDOR2'.

append ls_selopt to lt_selopt.

or

ls_selopt-sign = 'I'.

ls_selopt-option = 'BT.

ls_selopt-low = 'VENDOR1'.

ls_selopt-high = 'VENDOR4'.

append ls_selopt to lt_selopt.

Regards,

Michael