08-04-2009 6:20 PM
Hi,
I'm trying to understand if it's possible to use a foreign key integrity check in an ABAP reports. I have understood that this kind of check is deactivated for performance reasons, is it right?
In this case I'd like to know if it is possible to activate the foreign key check "on demand", or just for a particular table.
As an example, I'd like to use the foreign key defined on attribute AKONT of table KNB1, that points on the related attribute of table SKB1.
Thanks,
Gabriele
08-04-2009 6:46 PM
Welcome on SCN!
I'm trying to understand if it's possible to use a foreign key integrity check in an ABAP reports. I have understood that this kind of check is deactivated for performance reasons, is it right?
Most likely yes. Integrity is turned OFF for Open SQL statements but is turned ON for screen fields.
If you just create screen parameter like
parameters pa_akont type knb1-akont.
...then input help for that field will be automatically provided. This means that you will not be able to pick or enter value different that this allowed from SKB1 table (foreign key relationship will be checked).
You can explicitly assign different input help or search help for certain screen field independently of type it is refering i.e by means of fm F4IF_FIELD_VALUE_REQUEST .
This however still relates only to screen fields, not fields used directly in ABAP statement.
Regards
Marcin
08-04-2009 6:46 PM
Welcome on SCN!
I'm trying to understand if it's possible to use a foreign key integrity check in an ABAP reports. I have understood that this kind of check is deactivated for performance reasons, is it right?
Most likely yes. Integrity is turned OFF for Open SQL statements but is turned ON for screen fields.
If you just create screen parameter like
parameters pa_akont type knb1-akont.
...then input help for that field will be automatically provided. This means that you will not be able to pick or enter value different that this allowed from SKB1 table (foreign key relationship will be checked).
You can explicitly assign different input help or search help for certain screen field independently of type it is refering i.e by means of fm F4IF_FIELD_VALUE_REQUEST .
This however still relates only to screen fields, not fields used directly in ABAP statement.
Regards
Marcin
08-04-2009 7:06 PM
Ok,
so I can't do anything in order to use automatically the foreign key integrity check. Not so good according to me.
I was serching for something in the help documentation and I read there are some function modules that allow foreign key check; does anybody know which one I have to use for my business case (KNB1-AKONT)?
Thanks again,
Gabriele
08-04-2009 7:16 PM
You can always program this yourself. It's easy
"suppose you have work area for table
tables: knb1,
sbk1. "this one is used for select
"you fill it with some values
knb1-bukrs = '...'
knb1-akont = '...'
"now you want to check foreign key relationship, you can do it like
select single * from skb1
where bukrs = knb1-bukrs
and saknr = knb1-akont.
if sy-subrc = 0.
"here appropriate entry extits, so foreign key check is correct
else.
"here you know that such entry doesn't exist
endif.
So depending on result of select statement you can react accordingly. This simply validation can be programmed for any table and field you want.
Regards
Marcin
08-04-2009 7:24 PM
Of course,
but suppose I have to check all the integrity referential constraints among several tables, I have to do this every time. I hoped there was an automatic way in order to achieve the same result as you showed in the pseudo example.
Thanks a lot.
Bye,
Gabriele
08-04-2009 7:36 PM
Hi,
try this function modulke..
HELP_VALUES_GET_WITH_CHECKTAB...
Prabhudas
08-04-2009 7:44 PM
You can also create custom dynamic code for validation on different tables, i.e.
field-symbols <wa_table> type any.
data: tabname type string value 'KNB1'. "this table name can be parametrized so you can work on different tables
data: it_where_cond type table of string.
"this condition can be built dinamically
append 'bukrs = ''Some_value'' and' to it_where_cond.
append 'saknr = ''Some_value''.' to it_where_cond.
"now dynamic select statement
select * from (tabname)
into <wa>
where (it_where_cond).
This code can further be encasulated in custom FM so you would get generic foreign key check.
Regards
Marcin