08-11-2007 11:46 PM
I developing a sample function module.
Here is the source code.
*"----------------------------------------------------------------------
*"*"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.
Here is what in the global data .
tables: spfli,
kna1.
data: wa_spfli like spfli.
data: wa_kna1 like kna1.
When i am testing the function module i am getting a exception raised every time ...
let me know to fix this one...
08-12-2007 1:06 AM
Hi Alexander,
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.
Regards,
Atish
08-12-2007 1:47 AM
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):
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.
Your naming conventions confuse me a bit too... how about having something more like:
*" 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
note that I've added an extra exception... and then have:
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.