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

Restricting values in Table Control

Former Member
0 Likes
1,303

Hi Friends,

I have a requirement where in table control there some 5 columns. One of the columns has data elements has some 4 fixed values.

Like for example Truck, Train, Ship, Flight.

My requirement is to restrict the each of the value to a particular row.

End user should not be enter the same value in the row 2. i.e. for example truck should not be repeated in 2 rows of the table control.

How can i restrict this. Help me out on this issue.

With Regards,

Kishan Raj. K

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,181

Hi Kishan,

This is how I implemented your requirement.

Few adjustments that need to be taken care of.

1. The value for key and text must be the same for the drop down menu.

2. The key for the drop down menu must be given in caps.

These are the steps.

1. In screen painter, give function code for drop down. (Col2 in the table control is a drop down)

2. Declare a range table for key values of drop down.

     data: lv_name type vrm_id,
          lt_list type vrm_values,
          ls_value like line of lt_list.
  ranges : key_range for ls_value-key.

In the PBO.


MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'PF100'.
    SET TITLEBAR 'Table Control'.
    refresh lt_list.
     clear lt_list.
     perform f4_value_col2.
ENDMODULE.                 " STATUS_0100  OUTPUT

form F4_VALUE_COL2 .

       ls_value-key = 'FRUITS'.
       ls_value-text = 'FRUITS'.
       append ls_value to lt_list.
       ls_value-key = 'FLOWERS'.
       ls_value-text = 'FLOWERS'.
       append ls_value to lt_list.
       ls_value-key = 'VEGETABLES'.
       ls_value-text = 'VEGETABLES'.
       append ls_value to lt_list.
        if not key_range is INITIAL.
             delete lt_list where key in key_range.
        endif.
     lv_name = 'TC_WA-COL2'.
    call function 'VRM_SET_VALUES'
      exporting
        id     = lv_name
        values = lt_list.
*
ENDform.

In the PAI, clear key_range to reset the values each time.


MODULE USER_COMMAND_0100 INPUT.

   clear key_range[].
   case OK_CODE.
     when 'BACK'.
         leave PROGRAM.

   ENDCASE.
ENDMODULE.    

In the screen,

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 USER_COMMAND_0100.
     loop at tc_tab.
      chain.
        field tc_wa-col1.
        field tc_wa-col2.
        field tc_wa-col3.
        module update_table  .
       endchain.
     endloop.

In the update table module, populate teh range table.

MODULE UPDATE_TABLE INPUT.

   key_range-sign = 'I'.
   key_range-option = 'EQ'.
   key_range-low = tc_wa-col2.
   append key_range.
 
ENDMODULE.

Check the output and let me know.

6 REPLIES 6
Read only

Former Member
0 Likes
1,182

Hi Kishan,

This is how I implemented your requirement.

Few adjustments that need to be taken care of.

1. The value for key and text must be the same for the drop down menu.

2. The key for the drop down menu must be given in caps.

These are the steps.

1. In screen painter, give function code for drop down. (Col2 in the table control is a drop down)

2. Declare a range table for key values of drop down.

     data: lv_name type vrm_id,
          lt_list type vrm_values,
          ls_value like line of lt_list.
  ranges : key_range for ls_value-key.

In the PBO.


MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'PF100'.
    SET TITLEBAR 'Table Control'.
    refresh lt_list.
     clear lt_list.
     perform f4_value_col2.
ENDMODULE.                 " STATUS_0100  OUTPUT

form F4_VALUE_COL2 .

       ls_value-key = 'FRUITS'.
       ls_value-text = 'FRUITS'.
       append ls_value to lt_list.
       ls_value-key = 'FLOWERS'.
       ls_value-text = 'FLOWERS'.
       append ls_value to lt_list.
       ls_value-key = 'VEGETABLES'.
       ls_value-text = 'VEGETABLES'.
       append ls_value to lt_list.
        if not key_range is INITIAL.
             delete lt_list where key in key_range.
        endif.
     lv_name = 'TC_WA-COL2'.
    call function 'VRM_SET_VALUES'
      exporting
        id     = lv_name
        values = lt_list.
*
ENDform.

In the PAI, clear key_range to reset the values each time.


MODULE USER_COMMAND_0100 INPUT.

   clear key_range[].
   case OK_CODE.
     when 'BACK'.
         leave PROGRAM.

   ENDCASE.
ENDMODULE.    

In the screen,

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 USER_COMMAND_0100.
     loop at tc_tab.
      chain.
        field tc_wa-col1.
        field tc_wa-col2.
        field tc_wa-col3.
        module update_table  .
       endchain.
     endloop.

In the update table module, populate teh range table.

MODULE UPDATE_TABLE INPUT.

   key_range-sign = 'I'.
   key_range-option = 'EQ'.
   key_range-low = tc_wa-col2.
   append key_range.
 
ENDMODULE.

Check the output and let me know.

Read only

0 Likes
1,181

Hi Susmitha,

Thanks for your help, this is solution what i was expecting.

But if the end user gives the data wrong. he might want it to change later to some other line or row.

The code you gave is perfect. I just want to know whether the above problem can be solved with small changes.

With Regards,

Kishan Raj

Read only

0 Likes
1,181

Yes, that was the purpose of clear key_range[] statement.

If the end user inputted a wrong value, he can change it to null value in the drop down. The old value will be brought back to the drop down menu.

Hope that was what you wanted.

Read only

0 Likes
1,181

Hi Susmitha,

Thanks, I got the issue solved i did not try it making the values null.

Thanks for your effort. I got my requirement satisfied.

With Regards,

Kishan Raj. K


Read only

Former Member
0 Likes
1,181

hi kishan ,

       consider t_screen is the internal table storing table control values .

                    

                    vehicle is the attribute name .

         At  PAI  .

        

        chain .

          fields x_screen-vehicle .

          Module check_repeating on chain-request .

        endchain .

module check_repeating .

  

         read table t_screen into x_screen with vehicle = x_screen-vehicle .

              

                 if sy-subrc = 0   .

                    

                  message e001 . "entered vehicle already exists

end module .

Change the internal table and structure name with your table control table and structure name ..

With regards ,

Juneed k Manha

Read only

Former Member
0 Likes
1,181

Hi Friends,

Thanks For your help and efforts. I got my requirement satisfied.

With Thanks and Regards,

Kishan Raj