‎2011 Sep 09 5:40 AM
Hi Experts,
I have written a program prog1. In prog1 I am submitting prog2 as a background Job using Job_open , Job_close FM.The requirement is I have to read the spool number generated by prog2.Prog1 will start the job and read the spool number and do some processing on the data.So I have used start immediate to start the prog2.But prog1 completes before prog2. So it is not able to read the spool number of prog2.Is there any way to keep the program prog1 in waiting state until the Spool generates?
Please reply with any fruitful solution.Here the piece of code I have written in my program prog1.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
JOBCOUNT = g_jobcount
JOBNAME = g_jobname "prog2
STRTIMMED = c_selected
EXCEPTIONS
CANT_START_IMMEDIATE = 1
INVALID_STARTDATE = 2
JOBNAME_MISSING = 3
JOB_CLOSE_FAILED = 4
JOB_NOSTEPS = 5
JOB_NOTEX = 6
LOCK_FAILED = 7
INVALID_TARGET = 8
OTHERS = 9
.
IF SY-SUBRC <> 0.
MESSAGE text-096 TYPE 'I'.
ENDIF.
* Get Spool Number
PERFORM f10000_get_spool_no ON COMMIT.
COMMIT WORK AND WAIT.
<Added code tags>
Thanks in advance.
Edited by: Suhas Saha on Sep 9, 2011 11:12 AM
‎2011 Sep 09 7:07 AM
Hello,
You can call the FM 'BP_JOB_READ' to get the spool details for the particular job.
But prog1 completes before prog2. So it is not able to read the spool number of prog2.Is there any way to keep the program prog1 in waiting state until the Spool generates?
The idea is to put the above FM call in a recursion viz., WHILE...ENDWHILE or DO...ENDDO. The Exit criteria should be based on JOB_READ_JOBHEAD-STATUS = 'F'(finished) or 'A'(aborted).
Hope this is clear.
BR,
Suhas
‎2011 Sep 09 7:17 AM
Hi Suhas,
Thanks for the reply.Can you tell me performance wise which is better while or Do?
Regards,
Soma
‎2011 Sep 09 7:34 AM
Can you tell me performance wise which is better while or Do?
Hello Soma,
WHILE v/s DO - Afaik there are no performance implications to consider. Maybe the "performance" gurus might offer some light!
I generally prefer WHILE over DO because in the former you don't need to maintain any EXIT criteria, so he chances of an infinite loop is less
@Ravi: If we use a WHILE iteration to check the job status WAIT is not required.
BR,
Suhas
‎2011 Sep 09 7:57 AM
Hi Suhas,
.. Yes. no need for WAIT inside WHILE and ENDWHILE. I just thought , the program will countineously try to read and check status of job untill it is finished or terminated. So i thought , instead of checking status contineously , we could give some rest to the system like 30 seconds.. or..
Its just my thougth. Please correct me if im wrong.
Regards,
Ravi.
‎2011 Sep 09 9:17 AM
I generally prefer WHILE over DO because in the former you don't need to maintain any EXIT criteria, so he chances of an infinite loop is less
There is an exit criteria for While, the logical expression immediately after WHILE constitutes the exit criteria.
WHILE LOG_EXP
ENDWHILE.
Where as in case of DO ENDDO, you would write it down with may be an IF Statement and EXIT command.
Afaik, there are no performance issues in either case, it is about usability. In case of a DO ENDO, there is atleast one iteration, where as in case of While Endwhile, it depends on the Logical expression.
So depending on the need you could choose either of them.
Yes. no need for WAIT inside WHILE and ENDWHILE. I just thought , the program will countineously try to read and check status of job untill it is finished or terminated. So i thought , instead of checking status contineously , we could give some rest to the system like 30 seconds.. or..
You don't need WAIT in either case DO or WHILE.
There are certain implications involved when you use WAIT, like an implicit Database commit that it invokes etc...so be real careful when using them in order to not compromise the transaction data.
Regards,
Chen
‎2011 Sep 09 9:41 AM
Hi Experts,
@Suhas and @Chen thanks to lights on WAIT statement..
Regards,
Ravi.
‎2011 Sep 09 9:42 AM
Hello Chen,
You didn't get my point
Where as in case of DO ENDDO, you would write it down with may be an IF Statement and EXIT command.
Now that's exactly what i meant by EXIT criteria!! (See the EXIT in CAPS)
BR,
Suhas
PS: I'm sorry if my reply caused confusion!
‎2011 Sep 09 7:25 AM
Hi,
As said, you can use the FM inside WHILE...ENDWHILE.. with an WAIT UPTO 30 SECONDS statemnet..
hence FM willl check status of JOB for every 30 seconds or ( approximate time needed for execution of report)
Regards,
Ravi.