Solved

Capture exception message but continue

  • 13 December 2023
  • 1 reply
  • 44 views

Userlevel 3
Badge +10

I have written a procedure to finish work orders, however if there is an error when calling the api to close I want it to log the problem but continue with the rest of orders.  How do I complete this in the code please ?

Sample code:

objversion_ varchar2(200);
  wo_objid_ varchar2(200);
  wo_objversion_ varchar2(200);
  null_ varchar2(32000) := NULL;
  error_message_ varchar2(2000);
  t_ date;

  CURSOR Cur Is
    Select wt.state, wt.objid, wt.objversion, wt.task_seq, wo.objid as wo_objid_, wo.objversion as wo_objversion_, wo.wo_no
    from ifsapp.ACTIVE_SEPARATE_UIV wo inner join ifsapp.JT_TASK_UIV wt On wo.wo_no = wt.wo_no
    where wo.mch_code='MATERIALS' and trunc(wo.reg_date) <= Trunc(sysdate)-30;
      
   BEGIN
   FOR cur_chief in cur loop

    If cur_chief.state In ('Released','New') Then
       Transaction_SYS.Log_Status_Info('Work Order: '||cur_chief.wo_no|| ' has been finished.' , 'INFO');
       IFSAPP.JT_TASK_API.START_WORK__( null_ , cur_chief.objid , cur_chief.objversion , null_ , 'DO' );
       Commit;
       IFSAPP.JT_TASK_API.END_WORK__( null_ , cur_chief.objid , cur_chief.objversion , null_ , 'DO' );
       Commit;
       objversion_ :=IFSAPP.JT_TASK_API.Get_Objversion(cur_chief.task_seq);
       IFSAPP.JT_TASK_API.FINISH__( null_ , IFSAPP.JT_TASK_API.Get_Objid(cur_chief.task_seq) , objversion_ , null_ , 'DO' );
       Commit;
     End if;

     If cur_chief.state = 'Work Started' Then
       Transaction_SYS.Log_Status_Info('Work Order: '||cur_chief.wo_no|| ' has been finished.' , 'INFO');
       IFSAPP.JT_TASK_API.END_WORK__( null_ , cur_chief.objid , cur_chief.objversion , null_ , 'DO' );
       Commit;
       objversion_ :=IFSAPP.JT_TASK_API.Get_Objversion(cur_chief.task_seq);
       IFSAPP.JT_TASK_API.FINISH__( null_ , IFSAPP.JT_TASK_API.Get_Objid(cur_chief.task_seq) , objversion_ , null_ , 'DO' );
       Commit;
     End if;

     If cur_chief.state = 'Work Done' Then
       Transaction_SYS.Log_Status_Info('Work Order: '||cur_chief.wo_no|| ' has been finished.'  , 'INFO');
       IFSAPP.JT_TASK_API.FINISH__( null_ ,  cur_chief.objid , cur_chief.objversion , null_ , 'DO' );
       Commit;
    --   IFSAPP.ACTIVE_SEPARATE_API.FINISH__( null_ ,  cur_chief.wo_objid_ ,  cur_chief.wo_objversion_ , null_ , 'DO' );
    --   Commit;
     End if;
     
      If cur_chief.state = 'Finished' Then
        Transaction_SYS.Log_Status_Info('Work Order: '||cur_chief.wo_no|| ' has been finished.' , 'INFO');
        IFSAPP.ACTIVE_SEPARATE_API.FINISH__( null_ ,  cur_chief.wo_objid_ ,  cur_chief.wo_objversion_ , null_ , 'DO' );
        Commit;
      End if;
      
       Begin
     Select sysdate into t_ from dual;
         exception when others then
         error_message_ := substr(SQLERRM, 1, 1990);
         Transaction_SYS.Log_Status_Info(error_message_ , 'INFO');
   End;
      
   END LOOP;

icon

Best answer by JannetteC 14 December 2023, 16:09

View original

1 reply

Userlevel 3
Badge +10

Hello all,

Silly mistake I have found the problem

Reply