Batch program status.

Question: Good day,

I am trying to determine the status of a program within a job. I can determine whether the job that contains the program is running, but can anybody assist me in determining which actual program within the job is running?

Thanks in advance.

Answer:
You should be able to use SM66 Global Work Process Overview to check which program a job is running. You can also use it to debug the program.

Answer:
What I'm trying to do is write a FM that checks whether either a job or program is running and return a flag. I'm using tables TBTCO & TBTCP to check this. The only problem is that the status on TBTCO will always be 'R'unning when any of the programs in the job are running. I need to find a way to determine which specific step is running.

Thanks.

Answer:
Sorry, misunderstood you. I haven't actually tried using this but SM66 uses a function called DB_WP_CURRENT_SQL to bring back details for a work process from a system table. You'd need to send it the work process number though. Might help you.

Answer:
Thanks for the help, I'll give it a shot.

cbr.

Answer:
I guess it's my fault that I forgot to mention I am working on 4.6C. Can't find this FM. Not too worry, I'll keep searching.

Cheers,
cbr.

Answer:
Yes, release 6.20 and above only. Aren't we lucky. You must have an equivalent. Try running ST05 performance trace against SM66 and look for a select from v$session (if you're on Oracle) or anything that looks as if it might be a system table (if you're using another database).

Answer:
There's a status on TBTCP too, did you try checking it?
_________________
Close, but no sig.

Answer:
Yep, it's a 'P' (scheduled). There is no status to indicate whether it's running on this file so I resorted to checking at the job level. I'm not sure whether this will suffice for the customer, but now I'm dead keen to find a solution.

Answer:
Strange that they put it there but it doesn't do anything. You could try reading the log messages, there's usually one that marks the start of each step.

If you're trying to stop a program running twice in parallel, there are other ways of doing it.
_________________
Close, but no sig.

Answer:
Hi Sark,

Very strange indeed. I'm currently looking into reading the job log. The client wants a function that they can pass either a job or program to and the function must return whether the job/program is running. It's simply that batch program A needs to check whether batch program B is running and if it is, do not start. I obviously can't use scheduler functionality with dependencies in this case, thus looking for an alternate way. I'm pretty sure that the client will be satisfied with checking the status of the job that the program is a step within, but there must be some way to do this. I looked through a lot of posts yesterday and it seems I'm not the only one trying to solve this!

Thanks for the assistance, if I solve this I will most definitely post the solution.
_________________
Regards,

cbr.

Answer:
Lock objects are the generally accepted way to do this, please see older discussions for pros and cons.
_________________
Kind Regards

Rosie Brent

Please remember to search the forum and check the FAQ before posting questions, thank you.

Tuly Idiot most of the time, part-time Guru

Answer:
Sark: BP_JOBLOG_READ is the function module to call and that is easy enough to do, although I've encountered another problem here. Sometimes (depending on the job) the log is updated when the step starts running, and sometimes it only updates when the job finishes.



RosieBrent: I'll pursue your suggestion.

Thanks to all.
_________________
Regards,

cbr.

Answer:
For reading batch job logs, have a look at topic 0018 in the Abappers Knowledge corner.

This might help with the job status:

*
*          Batch statuses
*
           c_batch_new          like apql-status  value ' ',
           c_batch_processed    like c_batch_new  value 'F',
           c_batch_batch        like c_batch_new  value 'R',
           c_batch_incorrect    like c_batch_new  value 'E',
           c_batch_in_error     like c_batch_new  value 'E',
           c_batch_created      like c_batch_new  value 'C',
           c_batch_background   like c_batch_new  value 'S',
           c_batch_closed       like c_batch_new  value '*',

And


Form Process_Batch tables t_results
                   using pu_groupid like apqi-groupid.
*
*
     Data: t_list type standard table of abaplist
                  initial size 0
                  with header line,
*
           t_asci type standard table of Ascii_List
                  Initial size 0
                  with header line,
*
           t_apql  type standard table of apql         " TemSe info
                   Initial size 0
                   With header line,
*
         w_lines       type i,                         " # Batch jobs
         w_jobname     like tbtcjob-jobname,           " Selected job
         w_qid         like apql-qid,                  " Que ID
         w_released    like btch0000-char1,
         w_text        like t100-text,
         w_overtime    type boolean,                   " Time limit
                                                       " exceeded
         w_status      like apql-status.               " Batch status.
*
*    If there is more than one session,  then select the last one
*
     Move pu_groupid to w_jobname.
     Zap g_results-list.
     Concatenate Text-068 w_jobname
            into w_text
       separated by ' '.
     Call Function 'SAPGUI_PROGRESS_INDICATOR'
       Exporting
         Percentage       = 0
         Text             = w_text.
     Clear g_results. Move True to g_results-result.
*
*    Decide on the program to use.
*
     If pu_groupid+0(4) = c_interface_id.
        Move c_zpgxn015 to g_results-progm.
     Else.
        Move c_zcoin006 to g_results-progm.
     EndIf.
     Move pu_groupid to g_results-batch.
     Append g_results to t_results.
*
*    Wait for the batch to be activated.  This is dependant on
*    timing and this program can be run before the batch has been
*    entered in the queue....
*
*    Clear the list from the previous run....
*
     Export ' ' To Memory ID '%_LIST'.
     Move False to w_overtime.
*
*    Wait for the batch to appear in APQI.
*
     Do.
        Select single qstate
          into w_status
          from apqi
         where mandant = sy-mandt and
               groupid = pu_groupid.
        If sy-subrc = 0.
           Exit.
        Else.
           If sy-index > c_batch_wait_time.
              Move True to w_overtime.
              Exit.
           Else.
              Wait up to 1 seconds.
           EndIf.
        EndIf.
     EndDo.
*
*    Run out of time ????
*
     If w_overtime = False.
        Do.
           Submit RSBDCsub
                  Exporting List To Memory
                  with mappe    = pu_groupid
                  with Von      = sy-datum
                  with Bis      = sy-datum
                  with z_verarb = True
                  with fehler   = false
                  with logall   = true
              and return.
           Commit Work.
*
*          If the report ran,  this does not neccessarily
*          mean the batch did.  Get the report back and look
*          for the job number.
*
           If sy-subrc = 0.
              Call Function 'LIST_FROM_MEMORY'
                Tables
                   Listobject       = t_list
                Exceptions
                   Not_Found        = 0
                   Others           = 0.
              Call Function 'LIST_TO_ASCI'
                Tables
                   Listasci                 = t_asci
                   Listobject               = t_list
                Exceptions
                   Empty_List               = 0
                   List_Index_Invalid       = 0
                   Others                   = 0.
*
*             Get the Queue ID
*
              Read Table t_asci index 4.
              Search t_asci-line for 'Queue ID'.
              Read Table t_asci index 6.
              Move t_asci-line+sy-fdpos(20) to w_qid.
              Condense w_qid.
              If w_qid co c_numbers.
                 Exit.
              Else.
*
*                Break out of here after 5 minutes if there is
*                no activity
*
                 If sy-index > c_batch_wait_time.
                    Move True to w_overtime.
                    Exit.
                 Else.
                    Wait up to 1 seconds.
                 EndIf.
              EndIf.
           EndIf.
        EndDo.
     EndIf.
*
*    Did the submit work ?
*
     If w_overtime = False.
*
*       Get the job log.  Wait for it to appear
*
        Do.
           Call Function 'BDC_PROTOCOL_SELECT'
              Exporting
                  Name               = pu_groupid
                  Session_User       = sy-uname
                Tables
                  Apqltab            = t_apql
                Exceptions
                  Invalid_Data       = 0
                  Others             = 0.
*
*          Get the relevant job record back.
*
           Read Table t_apql with key qid = w_qid.
           If sy-subrc = 0.
              Exit.
           Else.
              If sy-index > c_batch_wait_time.
                 Move True to w_overtime.
                 Exit.
              Else.
                 Wait up to 1 seconds.
              EndIf.
           EndIf.
        EndDo.
*
        If w_overtime = False.
*
*          Batch is now running.....
*
           Concatenate pu_groupid Text-094
                  into w_text separated by ' '.
           Call Function 'SAPGUI_PROGRESS_INDICATOR'
             Exporting
               Percentage       = 0
               Text             = w_text.

           Move pu_groupid     to g_results-jobname.
           Move t_apql-TemSeId to g_results-TemSeId.
*
*          Wait for the batch to complete.
*
           Do.
              Move '*' to w_status.
              Select single qstate
                into w_status
                from apqi
               where mandant = sy-mandt and
                     qid     = w_qid.
*
*             Whats the batch up to ?
*
              Case w_status.
                   When c_batch_processed. Exit.
                   When c_batch_in_error.
                        Move False    to g_results-result.
                        Move text-070 to g_results-msg.
                        Exit.
                   When c_batch_incorrect.
                        Move False    to g_results-result.
                        Move text-070 to g_results-msg.
                        Exit.
              EndCase.
              Wait up to 1 seconds.
           EndDo.
*
*          Get the batch logs,
*
           Perform Get_log tables g_results-joblog
                            using g_results-TemSeId.
*
*          Find any 'E' or 'A' class messages.
*
           Loop at g_results-joblog into g_joblog.
                If g_joblog-Mart = c_error
                   or g_joblog-Mart = c_abort.
                      If g_results-msg <> ''.
                         Append g_results to t_results.
                      EndIf.
                      Move g_joblog-text to g_results-msg.
                      Move false to g_results-result.
                EndIf.
           EndLoop.
*
*          If there are no failure messages then hunt for a success
*          message.
*
           If g_results-result = True.
              Loop at g_results-joblog into g_joblog.
                   Case pu_groupid.
                        When c_interface_id.
                             If g_joblog-mid = 'F5'
                                and g_joblog-mnr = 312.
                                    If g_results-msg <> ''.
                                       Append g_results to t_results.
                                       Move g_joblog-text
                                         to g_results-msg.
                                    EndIf.
                             EndIf.
                   EndCase.
              EndLoop.
           EndIf.
        Else.
           Move text-069 to g_results-msg.
           Move False to g_results-result.
        EndIf.
     Else.
        Move text-090 to g_results-msg.
        Move False to g_results-result.
     EndIf.
     Append g_results to t_results.
EndForm.

_________________
Regards

R


Abap KC
SFMDR
Copyright ?2007 - 2008 www.jt77.com