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

Drop down according to rows in table control

Former Member
0 Likes
5,810

Hi Experts,

I have a table control on screen which has 2 columns out of which 1 column is dropdown.

Now,what i want is "depending on value in (row 1 column 1),the values in drop down box (row 1 column 2) should change.Similarly,depending on alues in (row 2 column1),the values in (row 2 column 2) should change"...

How can we do this??

Kindly reply...

1 ACCEPTED SOLUTION
Read only

Former Member
3,697

Hi Abdul,

The challenge here in populating the drop down dynamically is to trigger the PAI when you click on the drop down list.

As you must have already seen, the drop down list has a function code associated with it, but this will be triggered only on selection of a value in the list.

I have created a program which will update the drop down values according to the value of first column of the selected row. But here is the loop-hole, I have created a button (Like a refresh button) in each row to trigger the PAI and update the drop down list dynamically. This button has to be clicked to refresh the drop down box.

If you get some other way to trigger the PAI before selecting value, then replace it with the push button logic.

Here is my code.

REPORT  ZTEST_DROPDOWN_TC.

  type-pools : vrm.

controls tc type TABLEVIEW USING SCREEN 0100.

data : cols like LINE OF tc-cols.

Data : tc_lines like sy-loopc.
DATA: tc_cur_line LIKE sy-loopc.
data ok_code like sy-ucomm.

types : Begin of tc_type ,
    
  COL1(10) type c,
       COL2(10) type c,

     end of tc_type.

data : tc_tab type TABLE OF tc_type,
           tc_wa like line of tc_tab.

tc_wa-col1 = 'FRUITS'.
append tc_wa to tc_tab.

tc_wa-col1 = 'FLOWERS'.
append tc_wa to tc_tab.

tc_wa-col1 = 'VEGETABLES'.
append tc_wa to tc_tab.


call screen 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
   SET PF-STATUS 'PF100'.
   SET TITLEBAR 'Table Control'.
*  perform f4_value_col2.

ENDMODULE.                 " STATUS_0100  OUTPUT

         
*&---------------------------------------------------------------------*
*&      Module  F4_VALUE_COL2  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form F4_VALUE_COL2 .

    data: lv_name type vrm_id,
         lt_list type vrm_values,
         ls_value like line of lt_list.

    refresh lt_list.
    clear lt_list.
    case tc_wa-col1.

    when 'FRUITS'.

      ls_value-key = '01'.
      ls_value-text = 'Apple'.
      append ls_value to lt_list.

      ls_value-key = '02'.
      ls_value-text = 'Orange'.
      append ls_value to lt_list.

      ls_value-key = '03'.
      ls_value-text = 'Banana'.
      append ls_value to lt_list.

   when 'FLOWERS'.

      ls_value-key = '04'.
      ls_value-text = 'Rose'.
      append ls_value to lt_list.

      ls_value-key = '05'.
      ls_value-text = 'Lily'.
      append ls_value to lt_list.

      ls_value-key = '06'.
      ls_value-text = 'Daisy'.
      append ls_value to lt_list.

   when 'VEGETABLES'.

      ls_value-key = '07'.
      ls_value-text = 'Carrot'.
      append ls_value to lt_list.

      ls_value-key = '08'.
      ls_value-text = 'Beetroot'.
      append ls_value to lt_list.

      ls_value-key = '09'.
      ls_value-text = 'Cabbage'.
      append ls_value to lt_list.

ENDCASE.

      lv_name = 'TC_WA-COL2'.

   call function 'VRM_SET_VALUES'
     exporting
       id     = lv_name
       values = lt_list.
*   modify tc_tab from tc_wa.

ENDform.                 " F4_VALUE_COL2  OUTPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
  case OK_CODE.

    when 'LIST'.
        GET CURSOR LINE tc_cur_line.
       read table tc_tab into tc_wa index tc_cur_line.
       perform f4_value_col2.
    when 'BACK'.
       leave PROGRAM.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

SE51 Screen Flow Logic

Notice the push button in each row. I have given the function code LIST to it.


PROCESS BEFORE OUTPUT.

  loop at tc_tab into tc_wa
     with control tc cursor tc-current_line.

  endloop.
  MODULE STATUS_0100.
*

PROCESS AFTER INPUT.
*    module tc_action_user_command.
    MODULE USER_COMMAND_0100.
    loop at tc_tab.
     chain.
       field tc_wa-col1.
       field tc_wa-col2.
     endchain.
   endloop.

Output



Note - The refresh button has to be clicked each time.

(Also, you can achieve your purpose if its just getting the F4 help. It is more feasible to get the F4 values for the field dynamically. On clicking F4, perform your code in ON VALUE-REQUEST FOR field to populate with the values according to value in column 1. The user can select from the list and proceed. It will still serve the purpose, I guess. )

Another way to trigger PAI

IN Menu painter -  Assign a function code say 'CS' to function key F2.

Include the following in PAI.

MODULE USER_COMMAND_0100 INPUT.
  case OK_CODE.

     when 'CS'.
        GET CURSOR LINE tc_cur_line.
       read table tc_tab into tc_wa index tc_cur_line.
       perform f4_value_col2.

This will also update the list box. You click on the field and hit F2. The  values in drop down box will be refreshed.

Hi Experts,

I have a table control on screen which has 2 columns out of which 1 column is dropdown.

Now,what i want is "depending on value in (row 1 column 1),the values in drop down box (row 1 column 2) should change.Similarly,depending on alues in (row 2 column1),the values in (row 2 column 2) should change"...

How can we do this??

Kindly reply...

10 REPLIES 10
Read only

Former Member
0 Likes
3,697

Hi Abdul,

Your requirement is to have dynamic F4 help.

Its explained nicely here - http://wiki.sdn.sap.com/wiki/display/Snippets/F4+help+of+one+field+depends+on+other+field

If not clear, ask further.

BR.

Read only

0 Likes
3,697

Hi Ankit,

Thank you for your reply....But i dont want F4 help.The second column is drop down (List box).

My query is how can i get the required values in drop down box.

Read only

0 Likes
3,697

Hi,

The link you have given suggest changing drop down values depending on values entered in first drop down but here we want change in drop down values depending on values coming from1st column which is not drop down and 1st column is read only.

Values for 1st column came from select query.More over this is table control in module pool

Read only

0 Likes
3,697

Hi Abdul,

The link i gave gives you idea and not the exact solution. The link has dynamic values for column 1 which is bit tricky than your case of static value for column 1. So you need to read the link, understand the FMs used and modify as per your need.

BR.

Read only

former_member219762
Contributor
0 Likes
3,697

Hi,

   Trigger PAI when user enter data by FIELD <coloumn1> MODULE <mod>  ON REQUEST,get current  line using get cursor line,form that get the value of column 1 in that module and using this value set list value by VRM_SET_VALUE in PBO

Regards,

Sreenivas.

Read only

0 Likes
3,697

Hi Sreenivasa,

thank you for your reply.But,User is not going to enter into column1.

I am displaying column1 from some select query.

And this is table control in which first column is read only.We can not edit it.

It might possible ,values in each row of column1 have different value.So value in second column(drop down) will also be different...Pls tell me how can we achieve this??

Read only

0 Likes
3,697

Hi,

     Then use FIELD <coloum2> MODULE <mod >AT CURSOR-SELECTION.In that module Get the cursor line,coloum1 value from that we can set list value in PBO.

Regards,

Sreenivas.

Read only

0 Likes
3,697

Hi,

I have tried using at cursor selection.

When we click on drop down,it displays blank drop down(ie drop down with blank field).And when we click on that blank field of drop down it triggers the required module and shows the output.

Do you know how can we trigger the same without clicking on blank field of drop down.??

I have written AT CURSOR SELECTION event in PAI of screen.

Read only

Former Member
3,698

Hi Abdul,

The challenge here in populating the drop down dynamically is to trigger the PAI when you click on the drop down list.

As you must have already seen, the drop down list has a function code associated with it, but this will be triggered only on selection of a value in the list.

I have created a program which will update the drop down values according to the value of first column of the selected row. But here is the loop-hole, I have created a button (Like a refresh button) in each row to trigger the PAI and update the drop down list dynamically. This button has to be clicked to refresh the drop down box.

If you get some other way to trigger the PAI before selecting value, then replace it with the push button logic.

Here is my code.

REPORT  ZTEST_DROPDOWN_TC.

  type-pools : vrm.

controls tc type TABLEVIEW USING SCREEN 0100.

data : cols like LINE OF tc-cols.

Data : tc_lines like sy-loopc.
DATA: tc_cur_line LIKE sy-loopc.
data ok_code like sy-ucomm.

types : Begin of tc_type ,
    
  COL1(10) type c,
       COL2(10) type c,

     end of tc_type.

data : tc_tab type TABLE OF tc_type,
           tc_wa like line of tc_tab.

tc_wa-col1 = 'FRUITS'.
append tc_wa to tc_tab.

tc_wa-col1 = 'FLOWERS'.
append tc_wa to tc_tab.

tc_wa-col1 = 'VEGETABLES'.
append tc_wa to tc_tab.


call screen 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
   SET PF-STATUS 'PF100'.
   SET TITLEBAR 'Table Control'.
*  perform f4_value_col2.

ENDMODULE.                 " STATUS_0100  OUTPUT

         
*&---------------------------------------------------------------------*
*&      Module  F4_VALUE_COL2  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form F4_VALUE_COL2 .

    data: lv_name type vrm_id,
         lt_list type vrm_values,
         ls_value like line of lt_list.

    refresh lt_list.
    clear lt_list.
    case tc_wa-col1.

    when 'FRUITS'.

      ls_value-key = '01'.
      ls_value-text = 'Apple'.
      append ls_value to lt_list.

      ls_value-key = '02'.
      ls_value-text = 'Orange'.
      append ls_value to lt_list.

      ls_value-key = '03'.
      ls_value-text = 'Banana'.
      append ls_value to lt_list.

   when 'FLOWERS'.

      ls_value-key = '04'.
      ls_value-text = 'Rose'.
      append ls_value to lt_list.

      ls_value-key = '05'.
      ls_value-text = 'Lily'.
      append ls_value to lt_list.

      ls_value-key = '06'.
      ls_value-text = 'Daisy'.
      append ls_value to lt_list.

   when 'VEGETABLES'.

      ls_value-key = '07'.
      ls_value-text = 'Carrot'.
      append ls_value to lt_list.

      ls_value-key = '08'.
      ls_value-text = 'Beetroot'.
      append ls_value to lt_list.

      ls_value-key = '09'.
      ls_value-text = 'Cabbage'.
      append ls_value to lt_list.

ENDCASE.

      lv_name = 'TC_WA-COL2'.

   call function 'VRM_SET_VALUES'
     exporting
       id     = lv_name
       values = lt_list.
*   modify tc_tab from tc_wa.

ENDform.                 " F4_VALUE_COL2  OUTPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
  case OK_CODE.

    when 'LIST'.
        GET CURSOR LINE tc_cur_line.
       read table tc_tab into tc_wa index tc_cur_line.
       perform f4_value_col2.
    when 'BACK'.
       leave PROGRAM.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

SE51 Screen Flow Logic

Notice the push button in each row. I have given the function code LIST to it.


PROCESS BEFORE OUTPUT.

  loop at tc_tab into tc_wa
     with control tc cursor tc-current_line.

  endloop.
  MODULE STATUS_0100.
*

PROCESS AFTER INPUT.
*    module tc_action_user_command.
    MODULE USER_COMMAND_0100.
    loop at tc_tab.
     chain.
       field tc_wa-col1.
       field tc_wa-col2.
     endchain.
   endloop.

Output



Note - The refresh button has to be clicked each time.

(Also, you can achieve your purpose if its just getting the F4 help. It is more feasible to get the F4 values for the field dynamically. On clicking F4, perform your code in ON VALUE-REQUEST FOR field to populate with the values according to value in column 1. The user can select from the list and proceed. It will still serve the purpose, I guess. )

Another way to trigger PAI

IN Menu painter -  Assign a function code say 'CS' to function key F2.

Include the following in PAI.

MODULE USER_COMMAND_0100 INPUT.
  case OK_CODE.

     when 'CS'.
        GET CURSOR LINE tc_cur_line.
       read table tc_tab into tc_wa index tc_cur_line.
       perform f4_value_col2.

This will also update the list box. You click on the field and hit F2. The  values in drop down box will be refreshed.