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: 

Elementary Search help with distinct values. Kindly help!

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

I have to create a search help for Plant field. The Plant field is in a custom table YPLANT_DET. Unfortunately the plant field in this table is not unique.

So the elementary search help will show duplicate plant entries.

How to customize the elementary search help so that I get only distict values on F4 help?

KIndly help!

Thanks

Gopal

8 REPLIES 8

Former Member
0 Kudos

Hi!

Do not use the yplant_det table for refenrence. In T001W, you can find the WERKS_D data element, use this on the field, where you wanted to use the search help. This will be unique.

Regards

Tamá

Former Member
0 Kudos

after creating the search help, u can write a select statement in the section where code can be written as select distinct plants.....

else u can use T001W table for ur search help as field werks_d.

Message was edited by:

Ramesh Babu Chirumamilla

0 Kudos

Hi Ramesh,

Where to write the code for selecting the distinct values? Are you saying that there is some option in elementary search help inself?

I am talking about the search help craeted via SE11 transaction.

kindly help!

Thanks

Gopal

0 Kudos

Hi Ramesh,

I cannot use T001W table as this I am using Xapps system where this table does not exist

Thanks

Gopal

0 Kudos

In SE11, inside search help create screen , there will be a field called "Search help exit". Basically in this field you can attach a function module that is copy of F4IF_SHLP_EXIT_EXAMPLE and write your code in that function module here to discard duplicate values for the plants.

Cheers.

RJv

ChandraMahajan
Active Contributor
0 Kudos

Hi,

You need to use Search help exit...

i am attaching below sample code..write the select query at appropriate location and pass the internal table to sub FM mentioned in the code..

Code Sample

-


BEGIN OF CODE SAMPLE -


-


BEGIN OF INCLUDE LZSHLPTOP -


FUNCTION-POOL zshlp. "MESSAGE-ID ..

TYPE-POOLS shlp.

TYPES:

BEGIN OF t_knvp,

kunnr TYPE kna1-kunnr,

name1 TYPE kna1-name1,

ort01 TYPE ort01_gp,

stras TYPE stras_gp,

kunn2 TYPE knvp-kunn2,

name1_2 TYPE kna1-name1,

END OF t_knvp.

DATA: i_knvp TYPE TABLE OF t_knvp,

wa_knvp TYPE t_knvp,

wa_selopt TYPE ddshselopt,

wa_fielddescr TYPE dfies.

DATA:

rc TYPE i,

v_tabix LIKE sy-tabix.

RANGES: r_ktokd FOR kna1-ktokd,

r_mcod1 FOR kna1-name1,

r_sortl FOR kna1-sortl,

r_kunnr FOR kna1-kunnr,

r_ort01 FOR kna1-ort01.

-


END OF INCLUDE LZSHLPTOP -


-


BEGIN OF FUNCTION MODULE Z_CUSTOM_SEARCH -


FUNCTION z_custom_search.

*"----


""Local interface:

*" TABLES

*" SHLP_TAB TYPE SHLP_DESCR_TAB_T

*" RECORD_TAB STRUCTURE SEAHLPRES

*" CHANGING

*" VALUE(SHLP) TYPE SHLP_DESCR_T

*" VALUE(CALLCONTROL) LIKE DDSHF4CTRL STRUCTURE DDSHF4CTRL

*"----


  • EXIT immediately, if you do not want to handle this step

CASE callcontrol-step.

*"----


  • STEP SELECT (Select values)

*"----


  • This step may be used to overtake the data selection completely.

  • To skip the standard seletion, you should return 'DISP' as following

  • step in CALLCONTROL-STEP.

  • Normally RECORD_TAB should be filled after this step.

WHEN 'SELECT'.

  • Change column header texts appearing on the search help hit list

LOOP AT shlp-fielddescr INTO wa_fielddescr.

v_tabix = sy-tabix.

CASE wa_fielddescr-fieldname.

WHEN 'KUNNR'.

wa_fielddescr-fieldtext = 'ShipToCustomer#'.

wa_fielddescr-reptext = 'ShipToCustomer#'.

wa_fielddescr-scrtext_s = 'ShipTo #'.

wa_fielddescr-scrtext_m = 'ShipToCustomer#'.

wa_fielddescr-scrtext_l = 'ShipToCustomer#'.

MODIFY shlp-fielddescr FROM wa_fielddescr

INDEX v_tabix TRANSPORTING fieldtext reptext scrtext_s

scrtext_m scrtext_l.

WHEN 'KUNN2'.

wa_fielddescr-reptext = 'BillToCustomer#'.

wa_fielddescr-fieldtext = 'BillToCustomer#'.

wa_fielddescr-scrtext_s = 'BillTo #'.

wa_fielddescr-scrtext_m = 'BillToCustomer #'.

wa_fielddescr-scrtext_l = 'BillToCustomer #'.

MODIFY shlp-fielddescr FROM wa_fielddescr

INDEX v_tabix TRANSPORTING fieldtext reptext scrtext_s

scrtext_m scrtext_l.

WHEN 'NAME1'.

wa_fielddescr-fieldtext = 'ShipToCustomer Name'.

wa_fielddescr-reptext = 'ShipToCustomer Name'.

wa_fielddescr-scrtext_s = 'ShipTo Name'.

wa_fielddescr-scrtext_m = 'ShipToCustomer Name'.

wa_fielddescr-scrtext_l = 'ShipToCustomer Name'.

MODIFY shlp-fielddescr FROM wa_fielddescr

INDEX v_tabix TRANSPORTING fieldtext reptext scrtext_s

scrtext_m scrtext_l.

ENDCASE.

ENDLOOP.

  • Select the Bill to party customer based on the select options

FREE: r_ktokd, r_kunnr, r_sortl, r_mcod1, r_ort01, i_knvp.

LOOP AT shlp-selopt INTO wa_selopt.

  • Build a Range for the 5 selection options of the search help

CASE wa_selopt-shlpfield.

WHEN 'KTOKD'.

r_ktokd-sign = wa_selopt-sign.

r_ktokd-option = wa_selopt-option.

r_ktokd-low = wa_selopt-low.

r_ktokd-high = wa_selopt-high.

APPEND r_ktokd.

CLEAR r_ktokd.

WHEN 'KUNNR'.

r_kunnr-sign = wa_selopt-sign.

r_kunnr-option = wa_selopt-option.

r_kunnr-low = wa_selopt-low.

r_kunnr-high = wa_selopt-high.

APPEND r_kunnr.

CLEAR r_kunnr.

WHEN 'SORTL'.

r_sortl-sign = wa_selopt-sign.

r_sortl-option = wa_selopt-option.

r_sortl-low = wa_selopt-low.

r_sortl-high = wa_selopt-high.

APPEND r_sortl.

CLEAR r_sortl.

WHEN 'MCOD1'.

r_mcod1-sign = wa_selopt-sign.

r_mcod1-option = wa_selopt-option.

r_mcod1-low = wa_selopt-low.

r_mcod1-high = wa_selopt-high.

APPEND r_mcod1.

CLEAR r_mcod1.

WHEN 'ORT01'.

r_ort01-sign = wa_selopt-sign.

r_ort01-option = wa_selopt-option.

r_ort01-low = wa_selopt-low.

r_ort01-high = wa_selopt-high.

APPEND r_ort01.

CLEAR r_ort01.

ENDCASE.

ENDLOOP.

  • Retrieve data from KNVP table for the above selected ranges

  • Doing query to retrieve data for the search help

SELECT knvp~kunnr

kna1~name1

kna1~ort01

kna1~stras

knvp~kunn2

INTO TABLE i_knvp

FROM knvp

INNER JOIN kna1

ON knvpkunnr = kna1kunnr

WHERE

knvp~parvw = 'RE' AND " Bill to Party

knvp~kunnr IN r_kunnr AND

kna1~ktokd IN r_ktokd AND

kna1~sortl IN r_sortl AND

kna1~mcod1 IN r_mcod1 AND

kna1~ort01 IN r_ort01.

CHECK sy-subrc = 0.

DELETE ADJACENT DUPLICATES FROM i_knvp.

  • Select the short text for kunn2 from kna1.

  • Move all the selected records to Record_Tab

LOOP AT i_knvp INTO wa_knvp.

v_tabix = sy-tabix.

SELECT SINGLE name1 FROM kna1

INTO wa_knvp-name1_2

WHERE kunnr = wa_knvp-kunnr.

MOVE wa_knvp TO record_tab-string.

APPEND record_tab.

CLEAR record_tab.

MODIFY i_knvp FROM wa_knvp INDEX v_tabix.

CLEAR wa_knvp.

ENDLOOP.

rc = 0.

IF rc = 0.

callcontrol-step = 'DISP'.

ELSE.

callcontrol-step = 'EXIT'.

ENDIF.

EXIT. "Don't process STEP DISP additionally in this call.

WHEN 'PRESEL1'.

WHEN 'DISP'.

WHEN OTHERS.

ENDCASE.

ENDFUNCTION.

-


END OF FUNCTION MODULE Z_CUSTOM_SEARCH -


-


END OF CODE SAMPLE -


Save and activate at every step.

Regards,

Chandra

(Award points if helpful)

Andri
Explorer

Hello Gopal

There is an Search Help Exit called C140_DELETE_DUPLICATES which you can use directly to eliminate duplicate entries from your result list.

best regards,

Andri

Ruthiel
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for this tip!

Really helpful for me!