<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Function Module in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680209#M619387</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most likely reasons (without watching it in debug) are that you have KUNNR in the wrong format... or name1 doesn't match... try the following (not syntax checked):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data:
  ls_kna1               like kna1,
  l_kunnr               like kna1-kunnr.

  call function 'CONVERSION_EXIT_ALPHA_INPUT' 
    exporting
      input = kunnr
    exporting 
      output = l_kunnr. "ensure leading zeros

  select single * into ls_kna1
     from kna1
     where kunnr = l_kunnr. "unique key
*
* "  and   name1 = name1. " leave this out for now...
*
  if sy-subrc is initial.
    gt_kna1 = ls_kna1-land1.
  else.
    raise invalid_data.
  endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your naming conventions confuse me a bit too... how about having something more like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*"  IMPORTING
*"     VALUE(I_KUNNR) LIKE  KNA1-KUNNR
*"     VALUE(I_NAME1) LIKE  KNA1-NAME1
*"  EXPORTING
*"     REFERENCE(O_LAND1) LIKE  KNA1-LAND1
*"  EXCEPTIONS
*"      INVALID_DATA
*"      NAME_MISMATCH&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;note that I've added an extra exception... and then have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data:
  ls_kna1               like kna1,
  l_kunnr               like kna1-kunnr.

  clear: o_land1. "reset outputs

  call function 'CONVERSION_EXIT_ALPHA_INPUT' 
    exporting
      input = i_kuunr
    exporting 
      output = l_kunnr. "ensure leading zeros

  select single * into ls_kna1
     from kna1
     where kunnr = l_kunnr. "unique key

  if sy-subrc is initial.
    if ls_kna1-name = i_name1.
      o_land1 = ls_kna1-land1.
    else.
      raise name_mismatch.  "found customer, different name
    endif.
  else.
    raise invalid_data.
  endif.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Aug 2007 00:47:33 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-08-12T00:47:33Z</dc:date>
    <item>
      <title>Function Module</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680207#M619385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I developing a sample function module.&lt;/P&gt;&lt;P&gt;Here is the source code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(KUNNR) LIKE  KNA1-KUNNR
*"     VALUE(NAME1) LIKE  KNA1-NAME1
*"  EXPORTING
*"     REFERENCE(GT_KNA1) LIKE  KNA1-LAND1
*"  EXCEPTIONS
*"      INVALID_DATA
*"----------------------------------------------------------------------


  select single * into wa_kna1
         from kna1
         where kunnr = kunnr
         and   name1 = name1.

  if sy-subrc eq 0.
    gt_kna1 = wa_kna1-land1.
  else.
    raise invalid_data.
  endif.

endfunction.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what in the global data .&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
tables: spfli,
        kna1.

data: wa_spfli like spfli.

data: wa_kna1 like kna1.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When i am testing the function module i am getting a exception raised every time ...&lt;/P&gt;&lt;P&gt;let me know to fix this one...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2007 22:46:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680207#M619385</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-11T22:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Function Module</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680208#M619386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alexander,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For sure you are not passing correct entries to the FM so the select query is failing. Just pass the correct values so that value should be fetched from KNA1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Atish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Aug 2007 00:06:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680208#M619386</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-12T00:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: Function Module</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680209#M619387</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most likely reasons (without watching it in debug) are that you have KUNNR in the wrong format... or name1 doesn't match... try the following (not syntax checked):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
data:
  ls_kna1               like kna1,
  l_kunnr               like kna1-kunnr.

  call function 'CONVERSION_EXIT_ALPHA_INPUT' 
    exporting
      input = kunnr
    exporting 
      output = l_kunnr. "ensure leading zeros

  select single * into ls_kna1
     from kna1
     where kunnr = l_kunnr. "unique key
*
* "  and   name1 = name1. " leave this out for now...
*
  if sy-subrc is initial.
    gt_kna1 = ls_kna1-land1.
  else.
    raise invalid_data.
  endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your naming conventions confuse me a bit too... how about having something more like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*"  IMPORTING
*"     VALUE(I_KUNNR) LIKE  KNA1-KUNNR
*"     VALUE(I_NAME1) LIKE  KNA1-NAME1
*"  EXPORTING
*"     REFERENCE(O_LAND1) LIKE  KNA1-LAND1
*"  EXCEPTIONS
*"      INVALID_DATA
*"      NAME_MISMATCH&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;note that I've added an extra exception... and then have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data:
  ls_kna1               like kna1,
  l_kunnr               like kna1-kunnr.

  clear: o_land1. "reset outputs

  call function 'CONVERSION_EXIT_ALPHA_INPUT' 
    exporting
      input = i_kuunr
    exporting 
      output = l_kunnr. "ensure leading zeros

  select single * into ls_kna1
     from kna1
     where kunnr = l_kunnr. "unique key

  if sy-subrc is initial.
    if ls_kna1-name = i_name1.
      o_land1 = ls_kna1-land1.
    else.
      raise name_mismatch.  "found customer, different name
    endif.
  else.
    raise invalid_data.
  endif.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Aug 2007 00:47:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/function-module/m-p/2680209#M619387</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-08-12T00:47:33Z</dc:date>
    </item>
  </channel>
</rss>

