Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to run a program in background

former_member834551
Discoverer

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.

1 ACCEPTED SOLUTION

ThorstenHoefer
Active Contributor
10 REPLIES 10

BaerbelWinkler
Active Contributor

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!

ThorstenHoefer
Active Contributor

0 Kudos

Hi Thorsten,

M Hamdi is asking for a program, not a Function Module.

Thanks.

Patrice

0 Kudos

Hi,

why can't you call the program in the function modul to start it asynchron?

0 Kudos

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

FredericGirod
Active Contributor
    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' ...

Sandra_Rossi
Active Contributor
0 Kudos

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.

kaus19d
Active Contributor
0 Kudos

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

former_member834551
Discoverer

Thank you for the notes, I have edited my question.

Patrice
Participant

Hi M Hamdi,

Here are common reasons for not finding jobs in SM37:

  • A filter is set for the user. To remove the filter, display any job in SM37, then go in menu Edit (Traiter), Delete filter (Supprimer filtres).
  • The job status is Scheduled but the "Sched." ("Planif.") checkbox is not checked by default.
  • Slight difference in the job name. Try using some wildcard characters (*).
  • The job was run with a different user. Use of a batch user is common, so entering * in the User name field (Nom d'utilisateur) sometimes help.
  • The job is triggered after an event. If it is the case and none is specified it won't be found. Specify the event or just enter * to include all jobs that are run after an event.
  • The date/time selection is not valid. Make sure it includes the desired times.

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