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: 

Use of foreign key check in ABAP reports

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

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

6 REPLIES 6

MarcinPciak
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

Hi,

try this function modulke..

HELP_VALUES_GET_WITH_CHECKTAB...

Prabhudas

0 Kudos

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