how to fill errors in background job Text per item in a Custom API as scheduled database task
Hi guys,
I have created a custom api which calculates and updates some planning data for inventory parts.
How can I show the parts and error message in the background job Text area (DEFERRED_JOB_STATUS) ?
What is the EXCEPTION handling that I need to use?
Thank you for your feedback!
Regards Martina
Page 1 / 1
Hi Alhagmo,
You can try Transaction_Sys.Log_Error__ method. If you know which exception it would throw you can catch it, else just try to wrap this with a normal Exception block. Product-related code doesn’t throw a certain exception type it's usually throwing an exception by Error_Sys.Record_General.
Hi infaz,
thank you for your hint. I have used 2 functions from this Package:
My pleasure, I hope you want to stop and not commit any inventory part planning data if an error occurred, else you should try something like an Oracle Savepoint and commit whatever went ok.
Hi @ALHAGMO,
I have done a few changes to your code. Could you try the below?
BEGIN info_ := '';
FOR rec_ IN get_part_no LOOP DECLARE BEGIN --(+) START SAVEPOINT before_change_; --(+) FINISH
The column TRANSACTION_SYS_STATUS_TAB.TEXT is limited to 2000 characters, but sometimes you might want to write a longer status text in multiple pieces, like for a really big attr_ string.
You might not also know whether your code is being run as a background job, interactively in SQL*Plus or PL/SQL Developer for debugging, or inside of the IFS Enterprise Explorer application.
I wrote my own general-purpose trace function to handle all these use cases. When it breaks apart a long status, it attempts to wrap by word.
position_of_next_lf_ := DBMS_LOB.INSTR(text_buffer_, CHR(10), 1); IF remaining_length_ < max_length_ AND position_of_next_lf_ = 0 THEN next_text_ := NULL; ELSE IF position_of_next_lf_ > 0 AND position_of_next_lf_ < max_length_ THEN piece_length_ := position_of_next_lf_ - 1; position_of_next_start_ := position_of_next_lf_ + 1; next_text_ := SUBSTR(text_buffer_, position_of_next_start_); text_buffer_ := SUBSTR(text_buffer_, 1, piece_length_); ELSE piece_length_ := max_length_; position_of_next_start_ := max_length_ + 1; next_text_ := SUBSTR(text_buffer_, position_of_next_start_); text_buffer_ := SUBSTR(text_buffer_, 1, piece_length_); -- attempt to word wrap by searching for a space from the end SELECT REVERSE(DBMS_LOB.SUBSTR(text_buffer_, max_length_, 1)) INTO reversed_buffer_ FROM DUAL; first_space_in_rev_buffer_ := INSTR(reversed_buffer_, ' '); IF first_space_in_rev_buffer_ BETWEEN 2 AND 20 THEN text_buffer_ := text_buffer_ || next_text_; piece_length_ := max_length_ - first_space_in_rev_buffer_; position_of_next_start_ := piece_length_ + 2; next_text_ := SUBSTR(text_buffer_, position_of_next_start_); text_buffer_ := SUBSTR(text_buffer_, 1, piece_length_); END IF; END IF; END IF;
IF transaction_sys.is_session_deferred THEN IF status_type_ IN ('INFO', 'WARNING') THEN transaction_sys.log_status_info( info_ => text_buffer_, status_type_ => status_type_); ELSIF status_type_ = 'PROGRESS' THEN transaction_sys.set_progress_info(text_buffer_); ELSE transaction_sys.log_status_info( info_ => text_buffer_, status_type_ => 'INFO'); END IF; ELSIF USER = 'IFSSYS' THEN trace_sys.put_line(text_ => text_buffer_); ELSE sid_ := SYS_CONTEXT('USERENV', 'SID'); SELECT program INTO program_ FROM v$session WHERE sid = sid_; IF UPPER(program_) LIKE 'SQLPLUS%' OR UPPER(program_) LIKE 'PLSQLDEV%' THEN dbms_output.put_line(text_buffer_); END IF; END IF;
EXIT WHEN next_text_ IS NULL; timestamp_ := timestamp_ + INTERVAL '0.000000001' SECOND; prefix_ := TO_CHAR(timestamp_, 'YYYY-MM-DD HH24:MI:SS.FF') || ':'; text_buffer_ := prefix_ || next_text_; END LOOP; END trace__;
The column TRANSACTION_SYS_STATUS_TAB.TEXT is limited to 2000 characters, but sometimes you might want to write longer status texts, like for a really big attr_ string.
You might want to output trace information in your code without knowing in advance whether you're executing the code inside SQL*Plus or PL/SQL Developer for debugging, inside IFS Enterprise Explorer, or inside a background job.
I wrote a general-purpose trace function to accomplish these tasks. It attempts to word-wrap a long status line.
position_of_next_lf_ := DBMS_LOB.INSTR(text_buffer_, CHR(10), 1); IF remaining_length_ < max_length_ AND position_of_next_lf_ = 0 THEN next_text_ := NULL; ELSE IF position_of_next_lf_ > 0 AND position_of_next_lf_ < max_length_ THEN piece_length_ := position_of_next_lf_ - 1; position_of_next_start_ := position_of_next_lf_ + 1; next_text_ := SUBSTR(text_buffer_, position_of_next_start_); text_buffer_ := SUBSTR(text_buffer_, 1, piece_length_); ELSE piece_length_ := max_length_; position_of_next_start_ := max_length_ + 1; next_text_ := SUBSTR(text_buffer_, position_of_next_start_); text_buffer_ := SUBSTR(text_buffer_, 1, piece_length_); -- attempt to word wrap by searching for a space from the end SELECT REVERSE(DBMS_LOB.SUBSTR(text_buffer_, max_length_, 1)) INTO reversed_buffer_ FROM DUAL; first_space_in_rev_buffer_ := INSTR(reversed_buffer_, ' '); IF first_space_in_rev_buffer_ BETWEEN 2 AND 20 THEN text_buffer_ := text_buffer_ || next_text_; piece_length_ := max_length_ - first_space_in_rev_buffer_; position_of_next_start_ := piece_length_ + 2; next_text_ := SUBSTR(text_buffer_, position_of_next_start_); text_buffer_ := SUBSTR(text_buffer_, 1, piece_length_); END IF; END IF; END IF;
IF transaction_sys.is_session_deferred THEN IF status_type_ IN ('INFO', 'WARNING') THEN transaction_sys.log_status_info( info_ => text_buffer_, status_type_ => status_type_); ELSIF status_type_ = 'PROGRESS' THEN transaction_sys.set_progress_info(text_buffer_); ELSE transaction_sys.log_status_info( info_ => text_buffer_, status_type_ => 'INFO'); END IF; ELSIF USER = 'IFSSYS' THEN trace_sys.put_line(text_ => text_buffer_); ELSE sid_ := SYS_CONTEXT('USERENV', 'SID'); SELECT program INTO program_ FROM v$session WHERE sid = sid_; IF UPPER(program_) LIKE 'SQLPLUS%' OR UPPER(program_) LIKE 'PLSQLDEV%' THEN dbms_output.put_line(text_buffer_); END IF; END IF;
EXIT WHEN next_text_ IS NULL; timestamp_ := timestamp_ + INTERVAL '0.000000001' SECOND; prefix_ := TO_CHAR(timestamp_, 'YYYY-MM-DD HH24:MI:SS.FF') || ':'; text_buffer_ := prefix_ || next_text_; END LOOP; END trace__;