‎2005 Nov 25 12:26 PM
Hai..Can anyone check the below program and correct it.
I am unable to see the output in SP01 (SPOOL REQUEST)
MY PROGRAM:-
REPORT zh_test4.
TABLES : mara, TBTCO.
DATA : BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
END OF itab.
****background data declarations
data : job_name like TBTCO-JOBNAME.
data : job_num like TBTCO-JOBCOUNT,
rep like sy-repid.
***selection screen
PARAMETERS : p_matnr LIKE mara-matnr default '1500-610'.
SELECT matnr FROM mara INTO TABLE itab WHERE matnr EQ p_matnr.
job_name = 'HARI'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
DELANFREP = ' '
JOBGROUP = ' '
jobname = job_name
SDLSTRTDT = NO_DATE
SDLSTRTTM = NO_TIME
IMPORTING
jobcount = job_num
EXCEPTIONS
CANT_CREATE_JOB = 1
INVALID_JOB_DATA = 2
JOBNAME_MISSING = 3
OTHERS = 4
.
IF sy-subrc <> 0.
write 😕 ' Job opening problem'.
else.
write 😕 'Job succesfully opened', sy-subrc.
ENDIF.
MOVE SY-UNAME TO TBTCO-AUTHCKNAM.
rep = sy-repid.
job_name = 'HARI'.
CALL FUNCTION 'JOB_SUBMIT'
EXPORTING
ARCPARAMS =
authcknam = SY-UNAME
jobcount = job_num
jobname = job_name
LANGUAGE = SY-LANGU
PRIPARAMS = ' '
REPORT = 'ZH_TEST4'
VARIANT = 'VAR'
IMPORTING
STEP_NUMBER =
EXCEPTIONS
BAD_PRIPARAMS = 1
BAD_XPGFLAGS = 2
INVALID_JOBDATA = 3
JOBNAME_MISSING = 4
JOB_NOTEX = 5
JOB_SUBMIT_FAILED = 6
LOCK_FAILED = 7
PROGRAM_MISSING = 8
PROG_ABAP_AND_EXTPG_SET = 9
OTHERS = 10
.
IF sy-subrc <> 0.
WRITE 😕 'JOB SUBMIT PROBLEM',
job_name,
job_num,
rep,
sy-subrc.
else.
write 😕 'Job succesfully submitted in background', sy-subrc.
ENDIF.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = job_num
jobname = job_name
LASTSTRTDT = NO_DATE
LASTSTRTTM = NO_TIME
PRDDAYS = 0
PRDHOURS = 0
PRDMINS = 0
PRDMONTHS = 0
PRDWEEKS = 0
PREDJOB_CHECKSTAT = ' '
PRED_JOBCOUNT = ' '
PRED_JOBNAME = ' '
SDLSTRTDT = datum
SDLSTRTTM = uzeit
STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYS
STRTIMMED = 'X'
TARGETSYSTEM = ' '
START_ON_WORKDAY_NOT_BEFORE = SY-DATUM
START_ON_WORKDAY_NR = 0
WORKDAY_COUNT_DIRECTION = 0
RECIPIENT_OBJ =
TARGETSERVER = ' '
DONT_RELEASE = ' '
TARGETGROUP = ' '
IMPORTING
JOB_WAS_RELEASED = 'X'.
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.
write 😕 'Unable to close the Job', rep, sy-subrc.
else.
write 😕 'Succesfully closed the job', sy-subrc.
ENDIF.
‎2005 Nov 25 12:44 PM
Hari,
Check whether u have authorization to create a Background Job ????
Thanks
Kam
‎2005 Nov 25 12:45 PM
Hi It is working perfectly ok for me.
please check it.
check the config properties.
regards
vijay
‎2005 Nov 25 1:46 PM
It is working for me too..
but i am unable to see the output in SP01.
Can anyone tell me
where to use JOB_OPEN,JOB_SUBMIT and JOB_CLOSE in events(like start-of-selection, end-of-selection).
‎2005 Nov 25 2:07 PM
JOB_OPEN is used to create a background job. This we can use when we need to execute programs in background using a job. For eg
submit report ztest via job NOBNAME number JOBCOUNT(populated from above fm).
Then the open job is closed by JOB_CLOSE function module.
Hope this will give some idea.
‎2005 Nov 25 12:52 PM
Hello,
you're trying to submit the same report (zh_test4) without any variant in background. I think, you should see messages in syslog like 'Error planning job...'.
you're lucky, that this results in error, otherwise you'ld have an endless job-loop.
Regards wolfgang
‎2005 Nov 25 1:16 PM
Hai..
even if i running with my variant ..it is showing that the job is finished in SM37.
bUT I AM UNABLE TO SEE THE OUTPUT IN SP01.
Please tell me wher I done wrong.
your help is apreciated.
‎2005 Nov 25 3:45 PM
How is your job ever going to "Job Finished" status if you are submitting the same program that you are in again and again? It will never reach the JOB_CLOSE part of it. Hre is how your flow is:
Select data.
Job open.
submit this report via job.-->control goes back to the begining of the program because you are executing it again in this job.
.....
job close.<--- it will never reach this.Are you just testing out how this can be done? This doesn't look like a real production program. What you need to do here is to check if the program is run in the background or not. If so, then don't do the JOB related calls again. Something like this.
start-of-selection.
if sy-batch = 'X'.
*-- program running in background, then just select the
data and write the output
else.
*-- program is run online, create the job and submit the
report
endif.
Let me know if you need an example.
Regards,
Srinivas
‎2005 Nov 25 3:49 PM
Here is an example, slightly different from your version.
REPORT ztest.
PARAMETERS: p_vbeln LIKE vbak-vbeln,
p_bkrun NO-DISPLAY.
DATA: ls_vbak LIKE vbak.
DATA: v_answer,
v_jobcount LIKE tbtcjob-jobcount.
IF p_bkrun IS INITIAL.
*-- not background processing
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
textline1 = 'This may time out.'
textline2 = 'Do you want to run in background?'
titel = 'Warning!!!'
cancel_display = space
IMPORTING
answer = v_answer.
IF v_answer = 'J'.
*-- run in the background
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = 'ZTEST'
IMPORTING
jobcount = v_jobcount
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
*-- submit the program in the background
SUBMIT ztest
WITH p_bkrun = 'X'
WITH p_vbeln = p_vbeln
USER sy-uname
VIA JOB 'ZTEST' NUMBER v_jobcount AND RETURN.
*-- close the job
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = v_jobcount
jobname = 'ZTEST'
strtimmed = 'X'
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'W' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
EXIT.
ELSE.
CLEAR v_answer.
ENDIF.
ENDIF.
CHECK v_answer IS INITIAL.
SELECT SINGLE * FROM vbak
INTO ls_vbak
WHERE vbeln = p_vbeln.
IF sy-subrc <> 0.
WRITE:/ 'Invalid Order Id.'.
ENDIF.
*-----------------
END-OF-SELECTION.
*-----------------
CHECK v_answer IS INITIAL.
IF p_bkrun IS INITIAL.
WRITE:/ 'Here is the result running the program in foreground.'.
ELSE.
WRITE:/ 'Here is the result running the program in background.'.
ENDIF.
WRITE:/ ls_vbak-vbeln,
ls_vbak-vkorg.