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 catch error or exception for FM JOB_OPEN in code

Former Member
0 Kudos

Hi,

i am calling the FM 'JOB_OPEN' in my code to catch the error message when sy-subrc ne 0 but it is giving dump as there is nothing coming in sy-msgid, sy-msgtype. but when i just run this FM in SE37 then I am able to get the error for example when I pass blank for jobname then error comes is 'job missing' which is fine.

But this error I am not able to display from ABAP code which is as :

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = g_jobname

IMPORTING

jobcount = g_jobcount

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Please suggest how to correct it ???

Thanks,

Mohan

5 REPLIES 5

Former Member
0 Kudos

Hello,

Try in the following way.

data:g_jobname type TBTCJOB-JOBNAME,g_jobcount type TBTCJOB-JOBCOUNT.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = g_jobname

IMPORTING

jobcount = g_jobcount

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3.

IF sy-subrc = 3.

MESSAGE 'Job missing' type 'E'.

ENDIF.

Thanks.

Ramya.

Former Member
0 Kudos

try this way


 CALL FUNCTION 'JOB_OPEN'
           EXPORTING
             jobname          = g_jobname
           IMPORTING
             jobcount         = g_jobcount
           EXCEPTIONS
             cant_create_job  = 1
             invalid_job_data = 2
             jobname_missing  = 3.
         IF sy-subrc NE 0.  
            if sy-subrc = 1.
              message 'cant_create_job  '   type 'E'.   "Exxception 1
            elseif sy-subrc = 2.
              message 'invalid_job_data  '   type 'E'.   "Exxception 2
            else.
              message ' jobname_missing '   type 'E'.   "Exxception 3
            endif.
       ENDIF.

Regards,

Prabhudas

Former Member
0 Kudos

try this way


 CALL FUNCTION 'JOB_OPEN'
           EXPORTING
             jobname          = g_jobname
           IMPORTING
             jobcount         = g_jobcount
           EXCEPTIONS
             cant_create_job  = 1
             invalid_job_data = 2
             jobname_missing  = 3.
         IF sy-subrc NE 0.  
            if sy-subrc = 1.
              message 'cant_create_job  '   type 'E'.   "Exxception 1
            elseif sy-subrc = 2.
              message 'invalid_job_data  '   type 'E'.   "Exxception 2
            else.
              message ' jobname_missing '   type 'E'.   "Exxception 3
            endif.
       ENDIF.

Regards,

Prabhudas

Former Member
0 Kudos

This I checked..n its fine ..but my question is after the sy-subrc is ne 0 then why the msgid is coming as blank...from the code..though it is fine when it is run from SE37..is some issue with JOB_OPEN itself ?

Former Member
0 Kudos

giving the text for different sy-subrc check and displaying those text