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: 

Customize a job log error in SM37???

Former Member
0 Kudos

Hi,

Is there a way to display specific custom info when a job has an error? The job log in SM37 is where I want it to display in.

For example, on a particular canceled job it displays an already custom message "check loads" message type "E".

Instead of this message, I need it to display a field in a table that it is running from. I know the name of the field, so when the job cancels, it would display the table field. Is there a way to code this to display this in the job log?

Also, I need the job to NOT cancel out after it encounters an error. I am assuming this is because of the type of message that is selected, namely "E". Which message type am I looking for?

THANKS

11 REPLIES 11

former_member200338
Active Contributor
0 Kudos

HI

Check transcation sm13 and sm21.

Regards,

Niyaz

Former Member
0 Kudos

But is running a job considered an update? Would you find this in SM13. I also noticed that SM21 deletes the old log files. I do not want this. I want to maintain a history.

Former Member
0 Kudos

Is the job for a custom program or standard SAP program?

0 Kudos

Do the jobs ZBW_CHECK_DTGT and ZBW_CHECK_DTGT_CMD sound familiar? If not, they are custom...

0 Kudos

Go to the step information and see if the program mentioned in there is a custom one or not. Job names are typically your choice (unless they are jobs created internally by a standard program).

If it is a custom program, all you have to do is change your message text where it is issued. Also change the E to a I so that the job is not cancelled. Just make sure that your program execution stops soon after the message since you are now changing the Error message (which stops any further execution of the program) to a Information message (which will continue to execute the program even after the message).

0 Kudos

Why would it matter if it was custom or not?

0 Kudos

It will tell if you have the control or not. If you are ready to modify standard code by getting the access key for a simple thing like having a message in the log, you can do it. Programatically there is no difference.

I hope that clarifies.

0 Kudos

This is the ending code that is in the program that I want to change:

select * from /BIC/PZINF_DTST appending corresponding fields of table
it_zinf_dtst where  /BIC/ZTZ_ZONE in s_tzone.

Read table it_zinf_dtst with key /BIC/ZRPT_STS = '102'
/BIC/ZRPT_CON = '99999'.
if sy-subrc = '0'.
  open dataset dsn for output in text mode encoding default.
  transfer flag_n to dsn.
  close dataset dsn.
  message 'check loads' type 'E'.
else.
  Read table it_zinf_dtst with key /BIC/ZRPT_STS = '101'
  /BIC/ZRPT_CON = '250'.
  if sy-subrc = '0'.
    open dataset dsn for output in text mode encoding default.
    transfer flag_n to dsn.
    close dataset dsn.
    message 'check loads' type 'E'.

  else.
    open dataset dsn for output in text mode encoding default.
    transfer flag_y to dsn.
    close dataset dsn.
  endif.
endif.
end-of-selection.

Ok. is it possible for me to input table field names in my "message"? I want it to display whatever is in the table field at the time of the error. Is this possible or does it only allow for a string variable in my message area in the job log?

0 Kudos

Hi.
Have you got the answer yet? Please give me the answer. I am also finding why a job is not be canceled when a message is type 'E'.

0 Kudos

Hi all.
I have found the answer. Must create new FM and bring message code into this FM with raising command.
And when you call this FM, add 'error_message' exception

https://answers.sap.com/questions/10720509/display-error-message-in-batch-job-log.htm

REPORT ztwh_test

DATA:
lv_number type tbtcjob-jobcount,
lv_name type tbtcjob-jobname,
lv_print_parameters type pri_params.

lv_name = 'ZMESSAGE'.

CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = lv_name
IMPORTING
jobcount = lv_number
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.

SUBMIT zmessage
TO SAP-SPOOL SPOOL PARAMETERS lv_print_parameters
WITHOUT SPOOL DYNPRO VIA JOB lv_name NUMBER lv_number AND RETURN.


IF sy-subrc EQ 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = lv_number
jobname = lv_name
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
OTHERS = 9.
ENDIF.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

REPORT zmessage.

START-OF-SELECTION.

CALL FUNCTION 'ZTWH_FMTEST'
EXCEPTIONS
error_message = 1.
IF sy-subrc <> 0.

ENDIF.

WRITE 'Test'.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FUNCTION ztwh_fmtest.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" EXCEPTIONS
*" RAISE_EXCEPTION
*"----------------------------------------------------------------------

MESSAGE e000 WITH 'An error occurred' RAISING raise_exception.

ENDFUNCTION.