‎2023 May 19 5:52 PM
I wrote up a program to perform mass updates on variants. I am using FM RS_VARIANT_CONTENTS to pass in report and variant from table VARID.
CALL FUNCTION 'RS_VARIANT_CONTENTS'
EXPORTING
report = gs_varid-report
variant = gs_varid-variant
move_or_write = 'M'
TABLES
valutab = gt_valtab
EXCEPTIONS
variant_non_existent = 1
variant_obsolete = 2
OTHERS = 3.
My main issue at the moment is that I am getting the below error when executing for all reports and variants in our DEV system. Did some debugging and found that one of (maybe many other programs) that passed through the FM is active but it contains a syntax-error: "Literals that take up more than one line are not permitted". I guess this trickles down into the RS_VARIANT_CONTENTS FM and I run into a hard stop and my program terminates.

Is there a way to catch this using TRY/CATCH or this is a non-catchable exception? Will I need to address the issue of the program being active with syntax issues to resolve it?
‎2023 May 20 8:35 PM
You could try to insure program is in a correct status before call of RS_VARIANT_CONTENTS FM
Some options
(If that's not enough try REPS_OBJECT_ACTIVATE Fm or READ FREPORT FOLLOWED by INSERT REPORT)
‎2023 May 21 6:56 AM
Put the relevant code into an RFC enabled function module and call it STARTING NEW TASK... When you get the error, the FM will fail with SYSTEM_FAILURE, which you can catch.
‎2023 May 21 1:04 PM
RS_VARIANT_CONTENTS_RFC can be used.
Note that if the calling program runs in dialog, there will be one popup each time a syntax error happens.
Another solution is to call RS_VARIANT_CONTENTS with parameter EXECUTE_DIRECT = 'X' and handling of special exception ERROR_MESSAGE (as jack.graus2 mentioned, although parameter EXECUTE_DIRECT = 'X' is missing).
‎2023 May 21 9:31 AM
Call the function module with EXCEPTION error_message. That will catch messages within the function module and return these as an exception.
CALL FUNCTION 'RS_VARIANT_CONTENTS'
EXPORTING
report = gs_varid-report
variant = gs_varid-variant
move_or_write = 'M'
TABLES
valutab = gt_valtab
EXCEPTIONS
variant_non_existent = 1
variant_obsolete = 2
error_message = 3
OTHERS = 4.
‎2023 May 21 1:01 PM
It doesn't work because the default parameter value EXECUTE_DIRECT = ' ', RS_VARIANT_CONTENTS leads to a SUBMIT rs_variant_values, whose program will send the abort message A093(DB) with 'Literals across more than one line are n' (or text depends on ABAP version), and MESSAGE cannot be caught by the error_message exception if they run in different internal sessions.
It will work if you call RS_VARIANT_CONTENTS with parameter EXECUTE_DIRECT = 'X', there's no SUBMIT.