‎2012 Jan 05 7:03 PM
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
‎2012 Jan 06 12:54 PM
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
‎2012 Jan 05 7:14 PM
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
‎2012 Jan 05 7:17 PM
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.
‎2012 Jan 05 7:28 PM
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.
‎2012 Jan 05 7:17 PM
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.
‎2012 Jan 05 9:03 PM
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
‎2012 Jan 05 9:53 PM
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
‎2012 Jan 05 10:02 PM
@Grzegorz Glowacki
did you read the requirement? the discussion is about the uncaught exceptions. can you catch them with
EXCEPTIONS
ERROR_MESSAGE = 1.
‎2012 Jan 05 10:18 PM
‎2012 Jan 05 10:37 PM
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.
‎2012 Jan 05 10:42 PM
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
‎2012 Jan 05 10:48 PM
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.
‎2012 Jan 06 10:41 AM
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
‎2012 Jan 06 12:54 PM
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
‎2012 Jan 06 2:08 PM
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?
‎2012 Jan 06 2:13 PM
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
‎2012 Jan 06 4:14 PM
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.
‎2012 Jan 06 4:17 PM
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
‎2012 Jan 06 3:33 PM
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.