2022 Nov 17 9:55 AM
Hello Community,
I have an issue with a program that should be executed in the background if I press in the button bellow "1".
The principle of the code is simple, if I click on the button, a job must be created, otherwise a simple execution.
The problem here that after exectuing the program in the background, a message is displayed saying that the job is created.
Unfortunately, in SM37 there is no job with such description when I try to check.
Here is the Code for the background execution :
FORM f_treatment_batch .
DATA: lv_jobname TYPE tbtcjob-jobname VALUE 'ANNULATION_MES',
lv_jobnbre TYPE tbtcjob-jobcount,
lv_id TYPE indx-srtfd.
CONCATENATE lv_jobname sy-datum INTO lv_jobname SEPARATED BY '_'.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_jobname
IMPORTING
jobcount = lv_jobnbre
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
lv_id = 'ANNUL_MES' && lv_jobnbre.
EXPORT gt_mes_immo TO DATABASE indx(zz) ID lv_id.
SUBMIT zfi_annulation_mes_batch VIA JOB lv_jobname
NUMBER lv_jobnbre
WITH p_jobnbr EQ lv_jobnbre
WITH p_datc EQ p_datc
WITH p_dever EQ p_dever
WITH p_stock EQ p_stock
WITH p_devst EQ p_devst
WITH p_mes EQ p_mes
* WITH gt_mes_immo EQ gt_mes_immo
USER sy-uname
TO SAP-SPOOL
WITHOUT SPOOL DYNPRO
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_jobnbre
jobname = lv_jobname
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
invalid_target = 8
invalid_time_zone = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
MESSAGE s398(00) WITH 'Job' lv_jobname lv_jobnbre 'lancé'.
LEAVE TO CURRENT TRANSACTION.
ENDIF.
ENDFORM.
THANK YOU FOR YOU HELP.
2022 Nov 17 1:08 PM
Hi,
you can call a function in background by "starting new task"
2022 Nov 17 10:53 AM
mohamed.hamdi
Hi Mohamed,
your question will be easier to read if you embed images via the 3rd icon from the right in the editor menu and use the last icon "CODE" to add your ABAP-code. You should be able to edit your question accordingly.
Hope this helps!
2022 Nov 17 1:08 PM
Hi,
you can call a function in background by "starting new task"
2022 Nov 18 4:03 PM
Hi Thorsten,
M Hamdi is asking for a program, not a Function Module.
Thanks.
Patrice
2022 Nov 19 6:15 PM
Hi,
why can't you call the program in the function modul to start it asynchron?
2022 Nov 24 9:01 PM
Hi Thorsten,
He could, but it is not what he is asking and I fail to see what would be gained from doing that. The SUBMIT command works and the job is created. He is just asking why he can't see his job in SM37. And the answer is probably that he didn't write the correct program name in the selection screen (ZFI_ANNULATION_MES instead of ZFI_ANNULATION_MES_BATCH).
Patrice
2022 Nov 17 2:10 PM
CALL FUNCTION 'JOB_OPEN' ...
SUBMIT z_my_program
VIA JOB lv_nom_job
NUMBER lv_numero_job
WITH p_toto = iv_toto
AND RETURN.
CALL FUNCTION 'JOB_CLOSE' ...
2022 Nov 17 2:49 PM
I confirm that it will be much easier for us to read your question with the images embedded, instead of attaching the screenshots as hyperlinks.
It's also faster for you to take a screenshot and directly paste it in the text using Ctrl+V.
2022 Nov 17 2:54 PM
Hi mohamed.hamdi,
A good alternative would be to save as Variant & then ask your Basis resource to trigger a Job via SM36. Other options
Thanks,
Kaushik
2022 Nov 17 4:25 PM
2022 Nov 18 4:03 PM
Hi M Hamdi,
Here are common reasons for not finding jobs in SM37:
In this particular case you didn't write the correct program name in the selection screen of SM37 (ZFI_ANNULATION_MES instead of ZFI_ANNULATION_MES_BATCH). That's probably the only problem.
I hope this helps.
Thanks.
Patrice