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: 

Search help exit goes awry...

Former Member
0 Kudos

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.

     ENDCASE.

   ENDLOOP.

*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.

   ENDLOOP.

*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.

     ENDIF.

   ENDLOOP.

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?

3 REPLIES 3

pavelduchac
Participant
0 Kudos

Hi Michael, It's a type cast error.

You are trying to assign value into a field symbol of type t (time field), which has a different type or length or is structure/table etc...

Click on "Debugger' button, put a breakpoint on line 935 of include LSDH4F02 and run it to find out what you are trying to assign to the field symbol <fs>.

Based on that information you can change offset in the exit so that correct variable is passed through into the record_tab.

0 Kudos

Thank Pavel for your reply,

I do know it's a type-cast error, I just don't understand why. Line 935-936 reads the following way:


ASSIGN LOCAL COPY OF <hstring> (type_info-intlen)

               TO <input> TYPE type_info-inttype.

It crashes when it tries at line 02 in the example above. I guess I don't understand OFFSETs that well. I had thought with AD_SMTPADDR type being 241 characters long and KUNNR being 10 characters long and having a single character between them, I had the OFFSET covered. I edited the code to the following with the same results:


LOOP AT record_tab INTO ls_record.

     v_smtp = ls_record-string+241(11).

     READ TABLE gt_email WITH KEY smtp = v_smtp.

     IF sy-subrc = 0.

       ls_start = ls_record-string+0(252).

       ls_end = ls_record-string+252(*).

       CLEAR: ls_record-string.

       ls_record-string+0(241) = ls_start.

       ls_record-string+241(1) = ' '.


0 Kudos

Hi Michael,

I would suggest to put a breakpoint on line


MODIFY record_tab FROM ls_record.

and then during runtime copy the string ls_record to a notepad or text editor.

Compare the string you have produced with the output structure of the search help (filed by field based on the length)

i.e. 123456789XYZ9876543210

123456789 - field 1 (length 9)

XYZ - field 2 (length 3)

9876543210 - field 3 (length 10)

It seems you moved the output string by 11 chars to the right, but search help output remained the same structure?!?

Therefore the length doesn't match.

Put a second breakpoint at this line and check what is being assigned where. I think that structures won't match.


ASSIGN LOCAL COPY OF <hstring> (type_info-intlen)

               TO <input> TYPE type_info-inttype.