Skip to Content
Former Member
Nov 04, 2014 at 08:24 PM

Search help exit goes awry...


For a search help exit, I have the following code where I am trying to find a distinct email address with the customer number (from a view):

DATA: ls_fielddescr TYPE dfies, "loc str for shlp-fielddescr
           ls_selopt TYPE ddshselopt.  "loc str for shlp-selopt

 *Local structure for itab record_tab
   DATA: BEGIN OF ls_record.
           INCLUDE STRUCTURE seahlpres.
   DATA: END OF ls_record.

   DATA: ls_kunnr TYPE kunnr,
         ls_start TYPE string,
         ls_end TYPE string,
         v_smtp TYPE AD_SMTPADR.

 *Internal table to store Customer Name
   DATA: BEGIN OF gt_email OCCURS 0,
          smtp LIKE adr6-smtp_addr,
          kunnr LIKE kna1-kunnr,
         END OF gt_email.
   RANGES: lr_smtp FOR adr6-smtp_addr.  "Ranges for customer number
   CHECK callcontrol-step = 'DISP'.
   LOOP AT shlp-fielddescr INTO ls_fielddescr.
     CASE ls_fielddescr-fieldname.
       WHEN 'SMTP_ADDR'.
         ls_fielddescr-intlen = ls_fielddescr-outputlen = 241.
         MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
       WHEN 'KUNNR'.
         ls_fielddescr-offset = 251.
         MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.

 *Build range for customer number
   LOOP AT shlp-selopt INTO ls_selopt WHERE shlpfield = 'SMTP_ADDR'.
     lr_smtp-sign = ls_selopt-sign.
     lr_smtp-option = ls_selopt-option.
     lr_smtp-low = ls_selopt-low.
     lr_smtp-high = ls_selopt-high.
     APPEND lr_smtp.
     CLEAR: lr_smtp.

 *Select Customer name
   SELECT DISTINCT a~smtp_addr b~kunnr
     INTO TABLE gt_email
     FROM adr6 AS a INNER JOIN kna1 AS b
     ON a~addrnumber = b~adrnr
     WHERE a~smtp_addr IN lr_smtp.

 *Modify record_tab to append Customer name to customer number
   LOOP AT record_tab INTO ls_record.
     v_smtp = ls_record-string+231(10).
     READ TABLE gt_email WITH KEY smtp = v_smtp.
     IF sy-subrc = 0.
       ls_start = ls_record-string+0(241).
       ls_end = ls_record-string+241(*).
       CLEAR: ls_record-string.
       ls_record-string+0(241) = ls_start.
       ls_record-string+242(10) = ' '.
       ls_record-string+252(10) = gt_email-kunnr.
       ls_record-string+262(*) = ls_end.
       MODIFY record_tab FROM ls_record.
       CLEAR: ls_record,ls_start,ls_end,gt_email,v_smtp.

Once I run my custom customer search using email using tcode XD03, I get the following error:

When I run my search help without the exit, I get plenty of records (mainly duplicates which would be correct for our system) so I know it's not the view itself causing the error. Any thoughts on why this is happening or any other information you need to help me solve this problem?