Application Development and Automation 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: 
Read only

checking foreign key relation while updating table though program

uttam_kumar4
Explorer
0 Likes
1,239

Hi Experts,

I have a table A in which a field z_field  is having Entry/Check on table B. So if I update table A in SM30 I can see that it is checking table B for field Z_field so if I enter anything that is not available in B it would throw error.

How can we achieve the same when we are uploading data through a program using modify statement.

thanks

Rahul.

5 REPLIES 5
Read only

Former Member
0 Likes
879

Select by fkey in B table and if not exist, adapt your code.

Hope it helps.

Read only

0 Likes
879

I wanted it without code.. with code of course I can do that.

Thanks & regards,

Rahul

Read only

0 Likes
879

If you want stuff without code, then why post in ?

Thomas

Read only

0 Likes
879

No way as far as I know.

If you insert value by value then in screen fields, google check table and value table.

From Abap, unlike for instance MS Sql there is no auto check when inserting. Thats what frustrated me for a while, but Sap wanted to work on most Databases so here You go.

You can manipulate DB directly, constraint, but I would not do that for such trivial thing...or ever.

2 lines of code, 1 select and IF

I recommend get data in Alv, test mode, flag wrong inserts etc.

Without code, use Winshuttle.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
879

You could use a generic check tool which was developed in HR : method CHECK_STRUCTURE of class CL_HRBAS_FOREIGN_KEY_CHECK.


ls_structure-mtart = '????'. " wrong value
CREATE OBJECT: lr_key_check, lr_message_handler.
TRY.
     lr_key_check->check_structure(
       EXPORTING
         structure             = ls_structure
         excluded_fields       = lt_excluded_fields
         ignore_initial_fields = lv_ignore_initial_fields
         message_handler       = lr_message_handler
       IMPORTING
         is_ok                 = is_ok ).
   CATCH cx_hrbas_violated_assertion.
ENDTRY.

Regards,

Raymond