Monitoring the SCC4 transaction
Hi,
I found it interesting to share this code because it serves to monitor the SCC4 , it is a transaction that opens the SAP environment to change … where they can be made without request.
This can cause several problems with audit inconsistency environments … We will have a table that stores user data and email that will receive the notification.
After a job is triggered to run Z program at this point if the environment is open, it will trigger an email displaying the environment and principal for people registered in the table.
Steps:
1 – Create Table
Table: ZBASIS_DEST_MAIL
MAND | MANDT | CLNT | 3 | 0 | Client |
USUARIO | XUBNAME | CHAR | 12 | 0 | User Name in User Master Record |
AD_SMTPADR | CHAR | 241 | 0 | E-Mail Address |
2 – Create program
ABAP:
*&---------------------------------------------------------------------*
*& Report ZJOB_STATUS_SCC4
*&
*&---------------------------------------------------------------------*
*& mail: tobias@tolfo.com.br
*&phone: +55 5599510981
*&---------------------------------------------------------------------*
REPORT ZJOB_STATUS_SCC4.
TABLES: T000.
TYPES: BEGIN OF ty_tbtco,
jobname TYPE tbtco-jobname,
sdlstrtdt TYPE tbtco-sdlstrtdt,
sdlstrttm TYPE tbtco-sdlstrttm,
END OF ty_tbtco.
TYPES: BEGIN OF ty_tbtcom,
sdlstrtdt TYPE tbtco-sdlstrtdt,
sdlstrttm TYPE tbtco-sdlstrttm,
END OF ty_tbtcom.
DATA: it_t000 TYPE TABLE OF t000,
gt_tbtco TYPE TABLE OF ty_tbtco,
gt_dest_mail TYPE TABLE OF zbasis_dest_mail.
DATA: wa_dest_mail TYPE zbasis_dest_mail,
wa_t000 TYPE t000,
wa_tbtco TYPE ty_tbtco.
*validacao dos parametros
PERFORM parameters_t000.
*&---------------------------------------------------------------------*
*& Form parameters
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM parameters_t000 .
* Ini.1- Seleciona os mandantes que estao abertos
SELECT *
FROM t000
INTO TABLE it_t000
WHERE CCCORACTIV <> '2' OR CCNOCLIIND <> '3'.
* End.1
* Ini.2 - Verifica se existe algum ambiente aberto, se verdadeiro ele vai selecionar
* os emails que devem receber a notificacao, caso contrario nao executa o programa.
IF it_t000 IS NOT INITIAL.
PERFORM select_mail.
ELSE.
EXIT.
ENDIF.
* End.2
ENDFORM. " parameters_t000
*&---------------------------------------------------------------------*
*& Form SELECIONA_EMAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM select_mail .
* Ini. 3 - Seleciona os emails
SELECT *
FROM ZBASIS_DEST_MAIL
INTO TABLE gt_dest_mail.
* End. 3
* Ini 4. Verifica se existe algum email cadastrado para enviar a notificacao.
* e realiza a chamada.
IF gt_dest_mail[] IS INITIAL.
MESSAGE text-003 TYPE 'S'.
STOP.
ENDIF.
PERFORM send_mail.
ENDFORM. " select_mail
*&---------------------------------------------------------------------*
*& Form send_mail
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM send_mail .
DATA: lt_receivers TYPE TABLE OF somlreci1,
lt_txt TYPE TABLE OF solisti1.
DATA: wa_doc_data TYPE sodocchgi1,
wa_receivers TYPE somlreci1,
wa_txt TYPE solisti1.
REFRESH: lt_receivers, lt_txt.
CLEAR: wa_receivers, wa_txt, wa_doc_data.
LOOP AT gt_dest_mail INTO wa_dest_mail.
wa_receivers-receiver = wa_dest_mail-email.
wa_receivers-rec_type = 'U'.
APPEND wa_receivers TO lt_receivers.
CLEAR wa_receivers.
ENDLOOP.
* Ini.5 - Montanto as mensagens
wa_doc_data-obj_descr = 'Status do Ambientes atraves da SCC4 - ' && sy-host && sy-mandt.
wa_txt-line = 'Ambientes Alterados: ' .
APPEND wa_txt TO lt_txt.
LOOP AT it_t000 INTO wa_t000.
wa_txt-line(32) = wa_t000-mtext.
WRITE wa_t000-mandt TO wa_txt-line+35(12).
WRITE wa_t000-changeuser TO wa_txt-line+50(11).
WRITE wa_t000-changedate TO wa_txt-line+70(13).
APPEND wa_txt TO lt_txt.
* End.5
ENDLOOP.
* Chama funcao para o envio do email
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_data = wa_doc_data
document_type = 'RAW'
put_in_outbox = 'X'
commit_work = 'X'
TABLES
object_content = lt_txt
receivers = lt_receivers
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.
ENDFORM. " send_mail
2 – Create JOB
The job time is the User discretion, in my case I use 1 minute.
3 – Email layout received
Any doubts I am available,
Tobias Tolfo
Hi Tobias
Thanks for sharing an info about SCC4 alert notification. Can we have the ABAP program that includes more details about what's the changes was done along with system time
Thanks & Regards
Pawan K Mishra
Hi Tobias, thank you for sharing.
I have a question, I see you are calling a function SO_NEW_DOCUMENT_SEND_API1, is that function already in SAP ? or if it is not, is that something you can share too ?
Thanks !
Thank you Tobias. This code will work quite well for us as we have a new team of Basis folks.
Kind regards, Teren