2014 Jan 25 6:56 PM
Hi ,
As part of mail automation i am selecting status of the process chains from RSPCPROCESSLOG table.In the select am putting a condition to ignore active,planned,finished status jobs,which of course left is failed ones.I am able to do that.But now the problem is if am doing a repeat for process chain which in turn will create a new entry as active in the table.But unfortunately failed entry will exist in the table,which in turn is creating a wrong mail alert.h
We can see status of the process chain as 'A' as well as 'X'.i want to ignore those conditions where chain with failed and active status is there.
2014 Jan 26 6:59 AM
Hi,
You have to select the all entries based on the process chain and condition should be ( WHERE STATE in ( 'A' , 'X' ).
so your internal table should contains the entries of A and X as well.
Read table internal table with key STATE = 'A'.
if sy- subrc = 0.
delete the entry
endif.
2014 Jan 26 6:59 AM
Hi,
You have to select the all entries based on the process chain and condition should be ( WHERE STATE in ( 'A' , 'X' ).
so your internal table should contains the entries of A and X as well.
Read table internal table with key STATE = 'A'.
if sy- subrc = 0.
delete the entry
endif.
2014 Jan 26 8:46 AM
Hi Kiran,
Thanks for the reply.
Attaching my piece of code
start-of-selection.
wait until gs_job-actual_state <> 'G'.
ls_date = sy-datum.
ls_date = ls_date - 1.
select LOG_ID
TYPE
EVENT_START
JOB_COUNT
BATCHDATE
BATCHTIME
VARIANTE
INSTANCE
STATE
ACTUAL_STATE
STARTTIMESTAMP
ENDTIMESTAMP
from RSPCPROCESSLOG
into table gt_job
where state not in ('F','G','A','P',' ')
and batchdate between ls_date and sy-datum.
check sy-subrc = 0.
READ TABLE gt_job INTO gs_job WITH KEY state = 'A'.
if sy-subrc = 0.
DELETE gt_job.
endif.
IF GT_JOB[] IS NOT INITIAL.
select CHAIN_ID
LOG_ID
DATUM
ZEIT
MANUAL_ABORT
from RSPCLOGCHAIN
into table gt_jobname
for all entries in gt_job
where log_id = gt_job-log_id.
ENDIF.
But the problem is still i can see my internal table with 'X' in it which is throwing automatic mail.
Table entry
Now the active jobs are in finished state.problem is log_id is same for all subsequent chains and i don't know how to remove thta entry from internal table as we know after doing repeat it might have completed.
Any suggestions on this.
Regards,
Kannan
2014 Jan 26 10:08 AM
chekck the sample code below.
select LOG_ID
TYPE
EVENT_START
JOB_COUNT
BATCHDATE
BATCHTIME
VARIANTE
INSTANCE
STATE
ACTUAL_STATE
STARTTIMESTAMP
ENDTIMESTAMP
from RSPCPROCESSLOG
into table gt_job
where state not in ('F','G','A','P',' ')
and batchdate between ls_date and sy-datum.
check sy-subrc = 0.
* again you need to check any of the process chain is having A and X
LOOP AT gt_job INTO WA_JOB.
CLEAR: WA_JOB.
SELECT SINGLE LOG_ID FROM RSPCPROCESSLOG
INTO L_LOGID WHERE LOG_ID = WA_JOB-LOG_ID AND
TYPE = WA_JOBTYPE AND
JOB_COUNT = WA_JOB-JOB_COUNT
STATE = 'A'.
IF SY-SUBRC NE 0.
CONTINUE.
ELSE.
* AVOID THE RECORDS WHICH ARE HAVING THE X AND A
DELETE GT_JOB FROM WA_JOB.
ENDIF.
CLEAR: WA_JOB.
ENDLOOP.
2014 Jan 26 11:51 AM
Hi Kiran,
Thanks for your suggestions.
lets put it this way.
i have 2 queries
1.
Here lineitem marked in red got failed in system(status X) but did a repeat and it again failed.table level it created two entries as follows.
As per my select it is picking this two line items and marking it as the second chain failure.I want only one mail alert for this.
2.
The line item marked in yellow,
As per the modification done in the code as follows
The table level entry
Have one entry as X and other one after doing repeat it completed successfully and became F.
Since we are using a select single based on the looping of same GT_job table it is having only the entry in "X" state, select query keeps failing and chain is populated into mail trigger.
Hope it clarifies further regarding my requirement to you.
Regards,
Kannan
2014 Jan 26 1:48 PM
Hi Nair,
Just understand the query!
First time if you read the select you are only selecting the failed entries! so there is no chance to get the entries in gt_job with status 'A'.
select LOG_ID
TYPE
EVENT_START
JOB_COUNT
BATCHDATE
BATCHTIME
VARIANTE
INSTANCE
STATE
ACTUAL_STATE
STARTTIMESTAMP
ENDTIMESTAMP
from RSPCPROCESSLOG
into table gt_job
where state not in ('F','G','A','P',' ')
and batchdate between ls_date and sy-datum.
* do you want to delete the duplicates by comparing the fields from gt_job! do let me know how you want to delete the duplicates.
*I understand that as per the below screen shot you don't want process the highlighted entry again! because the process id is failed first and when it re process success again. in this situation you can't notify the mail!
so to avoid this entry from the gt_job I suggested the loop as below.
Need to check the entry again, check the where condition as per your screen shot! I don't know the field names.
* in this gt_job you have the all failed entries
LOOP AT gt_job INTO WA_JOB.
CLEAR: WA_JOB.
* now you are checking any of the failed entry is re process and success- check the tables with the active state entries
* check the correct where condtions again!
SELECT SINGLE LOG_ID FROM RSPCPROCESSLOG
INTO L_LOGID
WHERE LOG_ID = WA_JOB-LOG_ID AND
TYPE = WA_JOBTYPE AND
JOB_COUNT = WA_JOB-JOB_COUNT
STATE = 'A'.
IF SY-SUBRC NE 0. " it means no entry find withe active
CONTINUE.
ELSE.
* if record found with active remove from the gt_job
DELETE GT_JOB FROM WA_JOB.
ENDIF.
CLEAR: WA_JOB.
2014 Jan 26 2:25 PM
Hi Kiran,
Am new to Abap.Thanks for helping me understand better.
Your understanding regarding mail alert is correct.
As per my first select gt_job will have all failed entries regardless of whether during the second run it was successful or not.here we are looping the gt_job into a work area.and further...
SELECT SINGLE LOG_ID FROM RSPCPROCESSLOG
INTO L_LOGID
WHERE LOG_ID = WA_JOB-LOG_ID AND
TYPE = WA_JOBTYPE AND
JOB_COUNT = WA_JOB-JOB_COUNT
STATE = 'A'.
you are trying to pass the entry and using it as key trying to delete.I got your point.
But in my case mentioned select is failing (sy-subrc -4) and is continue to fetch the next record.I checked in the table level as am able to see one with "X" state and other with "F" (finished)state..
attaching my code
TYPES:BEGIN OF TY_JOB,
LOG_ID type RSPC_LOGID,
TYPE type RSPC_TYPE,
EVENT_START type BTCEVENTID,
JOB_COUNT type BTCJOBCNT,
BATCHDATE type BTCRELDT,
BATCHTIME type BTCRELTM,
VARIANTE type RSPC_VARIANT,
INSTANCE type RSPC_INSTANCE,
STATE type RSPC_STATE,
ACTUAL_STATE type RSPC_STATE,
STARTTIMESTAMP type RSTIMESTMPL,
ENDTIMESTAMP type RSTIMESTMPL,
end of ty_job,
BEGIN OF TY_JOBNAME,
CHAIN_ID TYPE RSPC_CHAIN,
LOG_ID TYPE RSPC_LOGID,
DATUM TYPE SYDATUM,
ZEIT TYPE SYUZEIT,
MANUAL_ABORT TYPE RSPC_MANUAL_ABORT,
END OF TY_JOBNAME.
data: gt_job type table of ty_job,
gt_jobb type table of ty_job,
gt_jobname type table of ty_jobname,
gs_job type ty_job,
gs_jobname type ty_jobname,
gs_maildata type SODOCCHGI1,
mailtxt type table of SOLISTI1 with header line,
mailrec type table of SOMLRECI1 with header line,
OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE,
OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
ls_log_id type RSPC_LOGID,
ls_date type sydatum,
ls_time type sy-uzeit,
ls_params like pri_params,
ls_jobcount like tbtcjob-jobcount,
ls_jobname like tbtcjob-jobname,
gt_JOB_LOG type TABLE OF RSPC_S_MSG,
gs_job_log type rspc_s_msg,
TAB_LINES LIKE SY-TABIX.
* DATA L_NUM(3).
*constants: cv_1 value 'G',
* cv_2 value 'A',
* cv_3 value 'F',
* cv_4 value 'P'.
start-of-selection.
wait until gs_job-actual_state <> 'G'.
ls_date = sy-datum.
ls_date = ls_date - 1.
select LOG_ID
TYPE
EVENT_START
JOB_COUNT
BATCHDATE
BATCHTIME
VARIANTE
INSTANCE
STATE
ACTUAL_STATE
STARTTIMESTAMP
ENDTIMESTAMP
from RSPCPROCESSLOG
into table gt_job
where state not in ('F','G','A','P',' ')
and batchdate between ls_date and sy-datum.
check sy-subrc = 0.
*READ TABLE gt_job INTO gs_job WITH KEY state = 'F'.
*if sy-subrc = 0.
* DELETE gt_job.
* endif.
loop at gt_job into gs_job.
SELECT SINGLE log_id
from RSPCPROCESSLOG
into ls_log_id
WHERE log_id = gs_job-log_id
AND type = gs_job-type
and job_count = gs_job-job_count
and state in ('A','F','G').
if sy-subrc ne 0.
CONTINUE.
else.
DELETE gt_job from gs_job.
endif.
CLEAR gs_job.
ENDLOOP.
IF GT_JOB[] IS NOT INITIAL.
select CHAIN_ID
LOG_ID
DATUM
ZEIT
MANUAL_ABORT
from RSPCLOGCHAIN
into table gt_jobname
for all entries in gt_job
where log_id = gt_job-log_id.
ENDIF.
loop at gt_jobname into gs_jobname.
mailtxt-line = gs_jobname-chain_id.
append mailtxt.
endloop.
loop at gt_job_log into gs_job_log.
if gs_job_log-msgv4 = text-004.
CONCATENATE gs_job_log-msgv1
gs_job_log-msgv2
gs_job_log-msgv4 into mailtxt SEPARATED BY space.
append mailtxt.
endif.
ENDLOOP.
clear: gs_maildata,mailrec,mailtxt.
gs_maildata-obj_name = text-002.
gs_maildata-obj_descr = text-001.
gs_maildata-obj_langu = sy-langu.
mailrec-receiver = 'ZAPO_JOBS'.
mailrec-rec_type = 'C'.
append mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = gs_maildata
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
OBJECT_HEADER = mailtxt
OBJECT_CONTENT = mailtxt
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = mailrec
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
I dont want to send mail when
1.Process chain failed first time on rerun it got success.
2.Process chain failed first on rerun need to send mail,but dont want 2 entries saying same chain is failed.
Suggestions are welcome.
Regards
Kannan
2014 Jan 26 3:51 PM
Hi Nair,
I think the code is ok! just modified as per the second situation!
TYPES:BEGIN OF TY_JOB,
LOG_ID type RSPC_LOGID,
TYPE type RSPC_TYPE,
EVENT_START type BTCEVENTID,
JOB_COUNT type BTCJOBCNT,
BATCHDATE type BTCRELDT,
BATCHTIME type BTCRELTM,
VARIANTE type RSPC_VARIANT,
INSTANCE type RSPC_INSTANCE,
STATE type RSPC_STATE,
ACTUAL_STATE type RSPC_STATE,
STARTTIMESTAMP type RSTIMESTMPL,
ENDTIMESTAMP type RSTIMESTMPL,
end of ty_job,
BEGIN OF TY_JOBNAME,
CHAIN_ID TYPE RSPC_CHAIN,
LOG_ID TYPE RSPC_LOGID,
DATUM TYPE SYDATUM,
ZEIT TYPE SYUZEIT,
MANUAL_ABORT TYPE RSPC_MANUAL_ABORT,
END OF TY_JOBNAME.
data: gt_job type table of ty_job,
gt_jobb type table of ty_job,
gt_jobname type table of ty_jobname,
gs_job type ty_job,
gs_jobname type ty_jobname,
gs_maildata type SODOCCHGI1,
mailtxt type table of SOLISTI1 with header line,
mailrec type table of SOMLRECI1 with header line,
OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE,
OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
ls_log_id type RSPC_LOGID,
ls_date type sydatum,
ls_time type sy-uzeit,
ls_params like pri_params,
ls_jobcount like tbtcjob-jobcount,
ls_jobname like tbtcjob-jobname,
gt_JOB_LOG type TABLE OF RSPC_S_MSG,
gs_job_log type rspc_s_msg,
TAB_LINES LIKE SY-TABIX.
* DATA L_NUM(3).
*constants: cv_1 value 'G',
* cv_2 value 'A',
* cv_3 value 'F',
* cv_4 value 'P'.
start-of-selection.
wait until gs_job-actual_state <> 'G'.
ls_date = sy-datum.
ls_date = ls_date - 1.
select LOG_ID
TYPE
EVENT_START
JOB_COUNT
BATCHDATE
BATCHTIME
VARIANTE
INSTANCE
STATE
ACTUAL_STATE
STARTTIMESTAMP
ENDTIMESTAMP
from RSPCPROCESSLOG
into table gt_job
where state not in ('F','G','A','P',' ')
and batchdate between ls_date and sy-datum.
check sy-subrc = 0.
loop at gt_job into gs_job.
SELECT SINGLE log_id
from RSPCPROCESSLOG
into ls_log_id
WHERE log_id = gs_job-log_id
AND type = gs_job-type
and job_count = gs_job-job_count
and state in ('A','F','G').
if sy-subrc ne 0.
CONTINUE.
else.
DELETE gt_job from gs_job.
endif.
CLEAR gs_job.
ENDLOOP.
* if two entries are exists - need to send one mail only
DELETE ADJACENT DUPLICATES from gt_job comparing type job_count.....
IF GT_JOB[] IS NOT INITIAL.
select CHAIN_ID
LOG_ID
DATUM
ZEIT
MANUAL_ABORT
from RSPCLOGCHAIN
into table gt_jobname
for all entries in gt_job
where log_id = gt_job-log_id.
ENDIF.
loop at gt_jobname into gs_jobname.
mailtxt-line = gs_jobname-chain_id.
append mailtxt.
endloop.
loop at gt_job_log into gs_job_log.
if gs_job_log-msgv4 = text-004.
CONCATENATE gs_job_log-msgv1
gs_job_log-msgv2
gs_job_log-msgv4 into mailtxt SEPARATED BY space.
append mailtxt.
endif.
ENDLOOP.
clear: gs_maildata,mailrec,mailtxt.
gs_maildata-obj_name = text-002.
gs_maildata-obj_descr = text-001.
gs_maildata-obj_langu = sy-langu.
mailrec-receiver = 'ZAPO_JOBS'.
mailrec-rec_type = 'C'.
append mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = gs_maildata
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
OBJECT_HEADER = mailtxt
OBJECT_CONTENT = mailtxt
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = mailrec
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
2014 Jan 27 6:05 PM
Hi Kiran,
Thanks for the helping hand..maximum rewards for you..
Completed my mail automation with kiind of modification attaching my code...
*&---------------------------------------------------------------------*
*& Report ZPROCESS_AUTO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZPROCESS_AUTO.
TYPES:BEGIN OF TY_JOB,
LOG_ID type RSPC_LOGID,
TYPE type RSPC_TYPE,
EVENT_START type BTCEVENTID,
JOB_COUNT type BTCJOBCNT,
BATCHDATE type BTCRELDT,
BATCHTIME type BTCRELTM,
VARIANTE type RSPC_VARIANT,
INSTANCE type RSPC_INSTANCE,
STATE type RSPC_STATE,
ACTUAL_STATE type RSPC_STATE,
STARTTIMESTAMP type RSTIMESTMPL,
ENDTIMESTAMP type RSTIMESTMPL,
end of ty_job,
BEGIN OF TY_JOBNAME,
CHAIN_ID TYPE RSPC_CHAIN,
LOG_ID TYPE RSPC_LOGID,
DATUM TYPE SYDATUM,
ZEIT TYPE SYUZEIT,
MANUAL_ABORT TYPE RSPC_MANUAL_ABORT,
END OF TY_JOBNAME.
data: gt_job type table of ty_job,
gt_jobb type table of ty_job,
gt_jobname type table of ty_jobname,
gs_job type ty_job,
gs_jobname type ty_jobname,
gs_maildata type SODOCCHGI1,
mailtxt type table of SOLISTI1 with header line,
mailrec type table of SOMLRECI1 with header line,
OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE,
OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE,
ls_log_id type RSPC_LOGID,
ls_date type sydatum,
ls_time type sy-uzeit,
ls_params like pri_params,
ls_jobcount like tbtcjob-jobcount,
ls_jobname like tbtcjob-jobname,
gt_JOB_LOG type TABLE OF RSPC_S_MSG,
gs_job_log type rspc_s_msg,
TAB_LINES LIKE SY-TABIX.
* DATA L_NUM(3).
*constants: cv_1 value 'G',
* cv_2 value 'A',
* cv_3 value 'F',
* cv_4 value 'P'.
start-of-selection.
wait until gs_job-actual_state <> 'G'.
ls_date = sy-datum.
ls_date = ls_date - 1.
select LOG_ID
TYPE
EVENT_START
JOB_COUNT
BATCHDATE
BATCHTIME
VARIANTE
INSTANCE
STATE
ACTUAL_STATE
STARTTIMESTAMP
ENDTIMESTAMP
from RSPCPROCESSLOG
into table gt_job
where state not in ('F','G','A','P')
and batchdate between ls_date and sy-datum.
check sy-subrc = 0.
sort gt_job by log_id type variante state.
Delete ADJACENT DUPLICATES FROM gt_job COMPARING log_id type variante state.
loop at gt_job into gs_job.
SELECT SINGLE log_id
from RSPCPROCESSLOG
into ls_log_id
WHERE log_id = gs_job-log_id
AND type = gs_job-type
and variante = gs_job-variante
and state not in ('X','').
if sy-subrc ne 0.
CONTINUE.
else.
DELETE gt_job INDEX sy-tabix.
endif.
CLEAR gs_job.
ENDLOOP.
if GT_JOB[] IS NOT INITIAL.
select CHAIN_ID
LOG_ID
DATUM
ZEIT
MANUAL_ABORT
from RSPCLOGCHAIN
into table gt_jobname
for all entries in gt_job
where log_id = gt_job-log_id.
endif.
CHECK gt_jobname is NOT INITIAL.
loop at gt_jobname into gs_jobname.
mailtxt-line = gs_jobname-chain_id.
append mailtxt.
CALL FUNCTION 'RSPC_API_CHAIN_GET_LOG'
EXPORTING
I_CHAIN = gs_jobname-chain_id
I_LOGID = gs_jobname-log_id
* I_DONT_POLL = 'X'
TABLES
E_T_LOG = gt_job_log[]
.
ENDLOOP.
*check gt_jobname is NOT INITIAL.
* loop at gt_jobname into gs_jobname.
* mailtxt-line = gs_jobname-chain_id.
* append mailtxt.
* endloop.
sort gt_job_log by msgty msgv1 msgv2 msgv4.
Delete adjacent DUPLICATES FROM gt_job_log COMPARING msgty msgv1 msgv2 msgv4.
loop at gt_job_log into gs_job_log.
if gs_job_log-msgv4 = text-004.
CONCATENATE gs_job_log-msgv1
gs_job_log-msgv2
gs_job_log-msgv4 into mailtxt SEPARATED BY space.
append mailtxt.
endif.
ENDLOOP.
clear: gs_maildata,mailrec,mailtxt.
gs_maildata-obj_name = text-002.
gs_maildata-obj_descr = text-001.
gs_maildata-obj_langu = sy-langu.
mailrec-receiver = 'ZAPO_JOBS'.
mailrec-rec_type = 'C'.
append mailrec.
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = gs_maildata
DOCUMENT_TYPE = 'RAW'
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
* IMPORTING
* SENT_TO_ALL =
* NEW_OBJECT_ID =
TABLES
OBJECT_HEADER = mailtxt
OBJECT_CONTENT = mailtxt
* CONTENTS_HEX =
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = mailrec
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.