Skip to Content
1
Nov 17 at 09:55 AM

How to run a program in background

183 Views Last edit Nov 17 at 04:23 PM 5 rev

Hello Community,

I have an issue with a program that should be executed in the background if I press in the button bellow "1".

2111017-sap-enwi.png

The principle of the code is simple, if I click on the button, a job must be created, otherwise a simple execution.

2111019-sap-enwi-2.png

The problem here that after exectuing the program in the background, a message is displayed saying that the job is created.

2111020-sap-enwi-3.png

Unfortunately, in SM37 there is no job with such description when I try to check.

2111022-sap-enwi-4.png

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.

Attachments

sap-enwi.png (52.3 kB)
sap-enwi-2.png (4.8 kB)
sap-enwi-3.png (24.0 kB)
sap-enwi-4.png (42.6 kB)