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

Column based search (Push button) in table control

0 Likes
1,835

Hi Experts,

I have a requirement that user should able to do a column based search which means he can select any column and for that particular column, search will be performed and if any value is found out then those cells will be highlighed with different color.

Though I have already design a simple protocol to highlight rows when user have not chosen any column but I am not sure how to achieve the search functionality when user chooses any column. I have added search push button on the table control for this functionality.

I tried to explore threads but unfortunately nothing has helped me.

Please help me with the above requirement.

Regards,

Jatan

1 ACCEPTED SOLUTION
Read only

arivazhagan_sivasamy
Active Contributor
0 Likes
1,442

Hi,

Use syntax

GET CURSOR { {FIELD <field> [field_properties]}
           | {LINE line [line_properties]} }.

Now you will get column name in <field>  and also you can get the line no, from that you can define the search.

Arivazhagan S

6 REPLIES 6
Read only

AndyS
Explorer
0 Likes
1,442

Hi Jatan,

Instead of using a table-control I would prefer to use a ALV-Grid or the newer SAP List Viewer.


There is a method GET_SELECTIONS? For details see SAPHelp.

Or have I misunderstood your issue?

Wishes

Andreas

Read only

0 Likes
1,442

Hi Andreas,

This is the new requirement from the customer to add search button in 12 year old table control logic so I can not use ALV Grid for this purpose.

Regards,

Jatan

Read only

Former Member
0 Likes
1,442

Hi,

If the table control is created using wizard you can write the code in the module user command.

Use FM POPUP_GET_VALUES to create a popup for the selection value. Now after getting the search value Read the internal table for all the line containing that value and pass the value in 'X' in the field MARK ( field name may be different for your program) which is used for selection in the Table control.

Let me know if you need sample code for the same.

Hope this helps,

Read only

0 Likes
1,442

Hi Gaurav,


Thanks for your reply.

A code may be useful as I am still not sure how search will be done based on column? Open question is which parameter get set when I choose any column and during search how that parameter can be used.

Thanks & Regards,

Jatan

Read only

Former Member
0 Likes
1,442

Hi,

Lets say you have a button the screen (where Table Control is defined) having Function code as GOTO.

FORM f_code_tc_goto_lines  USING   i_tc_name    TYPE any  " Table Control Name

                                    i_table_name TYPE any. " Internal Table name

*** Code to scroll the table control to the
*** Line item number mentioned in the popup
*** after pressing the GOTO button
   DATA: lv_table_name    LIKE feld-name,
         lt_fields        TYPE STANDARD TABLE OF sval WITH HEADER LINE,
         lv_return        TYPE string,
         lv_item          TYPE posnr,
         lv_key TYPE char50.

   FIELD-SYMBOLS <t_tc>         TYPE cxtab_control.
   FIELD-SYMBOLS <t_table>      TYPE STANDARD TABLE.

   ASSIGN (i_tc_name) TO <t_tc>.

   CONCATENATE i_table_name '[]' INTO lv_table_name.   "table body
   ASSIGN (lv_table_name) TO <t_table>.                "not headerline
   lv_key       = text-057.

   CLEAR lt_fields.
   lt_fields-tabname    = 'VBAP'.   " Here you can giv any table name which has a text field
   lt_fields-fieldname  = 'POSNR'. " Text field
   lt_fields-field_attr = ' '.
   lt_fields-field_obl  = 'X'.
   APPEND lt_fields.
*** To present a poopup to enter item number
   CALL FUNCTION 'POPUP_GET_VALUES'
     EXPORTING
       popup_title     = lv_key
       start_column    = '26'
       start_row       = '5'
     IMPORTING
       returncode      = lv_return
     TABLES
       fields          = lt_fields
     EXCEPTIONS
       error_in_fields = 1
       OTHERS          = 2.
   IF sy-subrc <> 0.
     MESSAGE text-041 TYPE 'W'.
   ENDIF.
   IF lv_return IS INITIAL.
     CONDENSE lt_fields-value.
     lv_item = lt_fields-value.
     READ TABLE gt_item WITH KEY posnr = lv_item TRANSPORTING NO FIELDS.
     IF sy-subrc EQ 0.
       <t_tc>-top_line = sy-tabix.        "Scrolling the Table Control to mentioned index
       <t_tc>-current_line = sy-tabix.
       SET CURSOR FIELD 'GS_ITEM-MATNR' LINE <t_tc>-current_line.
     ELSE.
       MESSAGE text-041 TYPE 'W'.
     ENDIF.
   ENDIF.

ENDFORM.                    " FCODE_TC_GOTO_LINES

Read only

arivazhagan_sivasamy
Active Contributor
0 Likes
1,443

Hi,

Use syntax

GET CURSOR { {FIELD <field> [field_properties]}
           | {LINE line [line_properties]} }.

Now you will get column name in <field>  and also you can get the line no, from that you can define the search.

Arivazhagan S