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

Capturing a system error from a FM

Former Member
0 Likes
6,781

I'm adding/deleting/updating records in KNMT via the RV_CUSTOMER_MATERIAL_UPDATE function module. I'm trying to find a way to catch the errors from this function module. For example, if I try to insert a material that already exists, I get a "System error during INSERT (table KNMT subrc 4)" error and it stops the program. What I want to do is collect that error, write a message to the screen, and go on to the next record to insert/delete/update/etc. There are no exceptions to the FM so I'm not sure how i'm supposed to do it. I've tried a TRY/CATCH with a cx_root. I've also tried using the FMs MESSAGES_INITIALIZE and MESSAGES_GIVE but I can get them to work. Can anyone point me in the right direction?

Thanks,

CD

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
4,269

HI,

Its a Update function module and please do not use it inside your custom program. Its a matter of data integrity. Please go for BDC if there is no function modules available.

Kesav

18 REPLIES 18
Read only

Former Member
0 Likes
4,269

Hi Curit,

If the exception handling techniques are not working i would suggest to apply a bandage before insert/modify entries in

KNMT using F.M RV_CUSTOMER_MATERIAL_UPDATE .

You can check if the entry already exist in database and skip that record store it in message internal table and process next record.

This way we can avoid dumps.

Thanks

Bhanu

Read only

0 Likes
4,269

I can do that for now, but I would like to be able to catch them in case there are errors I'm not aware of and such. Thank you for your suggestion.

Read only

0 Likes
4,269

Curtis,

you can use cx_sy_open_sql_db to catch sqlerrors

loop at it into wa.
  TRY.
    call FM with the inserts and all... 
    CATCH cx_sy_open_sql_db INTO lf_err.
      lf_message= lf_err->get_text( ).
  ENDTRY.
endloop.

Read only

Former Member
0 Likes
4,269

why dont you validate before the FM call, validate what ever errors you are expecting. prepare a error table.. pass only the validated entries to the FM.

at the end display the success records and the error records.

Read only

Former Member
0 Likes
4,269

Well, the FM is not documented and not released, so it would be better to find a standard way to do this.

Failing that, you can do a where used list of the FM and try to figure out what SAP does before and after calling it.

Rob

Read only

Former Member
4,269

Hi,

There is an easy way to achieve what you need. Use the following syntax:


CALL FUNCTION 'RV_CUSTOMER_MATERIAL_UPDATE'
  TABLES 
    ...
  EXCEPTIONS
    ERROR_MESSAGE = 1. "or any other valid sy-subrc value

It might look unbelievable, but I've tried it (on other FM) and it really works. You can use any number you want as the sy-subrc value for the ERROR_MESSAGE exception and of course handle the exception afterwards, based on the sy-subrc value.

Hope this helps,

Grzegorz

Read only

0 Likes
4,269

@Grzegorz Glowacki

did you read the requirement? the discussion is about the uncaught exceptions. can you catch them with

EXCEPTIONS
    ERROR_MESSAGE = 1.

Read only

0 Likes
4,269

@Soumyaprakash Mishra - did you try it??

Rob

Read only

0 Likes
4,269

i dint even read the FM, i am just trying to give a generic view here. as i think OP would have faced some particular problem where he cannot capture what happened though exception in FM.

Read only

0 Likes
4,269

You don't have to read the FM. Grzegorz Glowacki was giving a general solution to any FM with this problem. Try creating a FM with one line

message e000 with '123'.

Then call it as suggested.

Rob

Read only

0 Likes
4,269

try creating a FM(there are FMs like this) without a error message. then?

try creating a FM with the error message but not with a raising statement. then?

so i know Glowacki might be trying to give the solution for this FM. but could you validate me on the points which i am referring to here.

p.s: @ROb:: its worth discussing on threads where you are in. definitely forced us to the edge to learn. thanks really.

Read only

Former Member
0 Likes
4,269

Hi,

Let me give you some more details then, if further questions arised. I offerd an almost-ready-to-use code for the FM mentioned in the initial question. But the addition of

EXCEPTIONS
    ERROR_MESSAGE = 1.

works for every function module you could use. In my case the FM PRELIMINARY_POSTING_FB01 that I was calling from my custom code, used to raise a message type 'E' in some cases. But I did not want that message to interrupt the execution of my code. Instead of that, I caught the error and handled it myself. And ERROR_MESSAGE = 1 got the job done. So I think you should give it a try

Hope this helps,

Grzegorz

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
4,270

HI,

Its a Update function module and please do not use it inside your custom program. Its a matter of data integrity. Please go for BDC if there is no function modules available.

Kesav

Read only

0 Likes
4,269

The ERROR_MESSAGE = 1 thing works, but I can't tell what the error is. I tried combining that with the MESSAGE_GIVE but no dice. I will use this for now and just display an generic error message on the screen. I'll still try to look for a way to capture the error though.

@Keshav

I've only dealt with BDC once, and it wasn't a nice experience. I don't remember the scope of the project, but I remember that I would have unexpected pop-ups/screens sometimes, so the BDC would not work right sometimes. Does the FM I'm trying to use not have the data integrity checks in them? Or is BDC just a best practice?

Read only

0 Likes
4,269

BDC is a standard way of doing this. The FM you are trying to use is not. SAP performs all its validations before calling this fm (without the ERROR_MESSAGE = 1 workaround).

It may be more work using batch input, but you are assured that the results will be correct.

Have you looked for BAPIs?

Rob

Read only

0 Likes
4,269

I will go ahead and do this via BDC if that's the case. I haven't looked for BAPIs, but if BDC is the recommended way to do it, then I'll do it that way.

@Gzreg

The error was in the SY variables. I totally forgot about them. Thanks.

@All

Thanks so much for your help all.

Read only

0 Likes
4,269

BDC is not the recommended way; it's a recommended way. If you can find a BAPI, that will eliminate your problems with batch input.

Rob

Read only

Former Member
0 Likes
4,269

Have you checked the sy-msgid, sy-msgno, sy-msgty and similar fields for error details? As far as I remember, you should find it there.