Joined: 21 Nov 2008 Posts: 25 Location: СПб - Валлдорф
Posted: Fri Feb 06, 2009 11:45 am Post subject: Распараллеливание записи в AppLOG через RFC
Распараллеливание записи в Application LOG через RFC.
модули /DT0/WRITE_APPL_LOG_QRFC и /DT0/WRITE_APPL_LOG должны быть помечены возможностью RFC вызова.
Code:
* Haupt Programm um ru Eintragen APPL Log
************************************************************************
function /dt0/add_appl_log.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(IV_LOG_HANDLE) TYPE BALLOGHNDL
*" VALUE(IS_MSG) TYPE BAL_S_MSG
*" VALUE(IS_LOG) TYPE BAL_S_LOG
*" EXPORTING
*" VALUE(EV_LOG_HANDLE) TYPE BALLOGHNDL
*"----------------------------------------------------------------------
* Beim Aufruf ohne Appl Log Handle wird per aRFC (wegen commit)
* die Meldung angelegt und auf das ermittelte Handle gewartet.
* Beim Aufruf mit Appl Log Handle wird per qRFC (wegen commit und
* Serialisierung) die Meldung angelegt und es muß nicht gewartet werden.
data:
lv_zaehler type i,
lv_fehler type sy-subrc,
lv_pid type wpinfo-wp_pid,
lv_task(8),
lv_zh(2).
call function 'TH_GET_OWN_WP_NO'
importing
wp_pid = lv_pid.
lv_task = lv_pid.
lv_zaehler = 1.
lv_fehler = 1.
if iv_log_handle is initial.
* Es ex. noch kein Handle => Eigenen Prozeß aRFC starten und warten auf Handle
gv_appl_log_process_running = 'X'.
while lv_fehler <> 0.
call function '/DT0/WRITE_APPL_LOG'
starting new task lv_task
performing appl_log_end on end of task
exporting
iv_log_handle = iv_log_handle
is_msg = is_msg
is_log = is_log
exceptions
communication_failure = 1
system_failure = 2
resource_failure = 3
others = 4.
lv_fehler = sy-subrc.
if lv_fehler <> 0.
wait up to 1 seconds.
* Falls PID < 8 Zeichen => zähler dazu - kann ruhig größer 8 zeichen sein
lv_zh = lv_zaehler.
concatenate
lv_pid
lv_zh
into
lv_task.
condense lv_task no-gaps.
endif.
add 1 to lv_zaehler.
if lv_zaehler = 20.
clear gv_appl_log_process_running.
exit.
endif.
endwhile.
* Warten bis Appl Log geschrieben
lv_zaehler = 1.
while gv_appl_log_process_running = 'X'.
wait until gv_appl_log_process_running = space up to 1 seconds.
add 1 to lv_zaehler.
if lv_zaehler = 4000.
exit.
endif.
endwhile.
else.
* Handle ex. schon => qRFC starten
while lv_fehler <> 0.
call function '/DT0/WRITE_APPL_LOG_QRFC'
starting new task lv_task
exporting
iv_log_handle = iv_log_handle
is_msg = is_msg
is_log = is_log
exceptions
communication_failure = 1
system_failure = 2
resource_failure = 3
others = 4.
lv_fehler = sy-subrc.
if lv_fehler <> 0.
wait up to 1 seconds.
* Falls PID < 8 Zeichen => zähler dazu - kann ruhig größer 8 zeichen sein
lv_zh = lv_zaehler.
concatenate
lv_pid
lv_zh
into
lv_task.
condense lv_task no-gaps.
endif.
add 1 to lv_zaehler.
if lv_zaehler = 20.
exit.
endif.
endwhile.
gv_log_handle = iv_log_handle.
endif.
ev_log_handle = gv_log_handle.
endfunction.
*&---------------------------------------------------------------------*
*& Form APPL_LOG_END
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form appl_log_end using taskname.
if lv_log_exists is initial.
* ApplLog Handle anlegen
call function 'BAL_LOG_CREATE'
exporting
i_s_log = is_log
importing
e_log_handle = lv_log_handle
exceptions
log_header_inconsistent = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
exit.
endif.
endif.
* Message hinzufügen
call function 'BAL_LOG_MSG_ADD'
exporting
i_log_handle = lv_log_handle
i_s_msg = is_msg
* IMPORTING
* E_S_MSG_HANDLE =
* E_MSG_WAS_LOGGED =
* E_MSG_WAS_DISPLAYED =
exceptions
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
others = 4.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
exit.
endif.
ev_log_handle = lv_log_handle.
refresh: lt_log_handle.
append lv_log_handle to lt_log_handle.
* Message speichern
call function 'BAL_DB_SAVE'
exporting
* I_CLIENT = SY-MANDT
* I_IN_UPDATE_TASK = ' '
i_save_all = 'X'
i_t_log_handle = lt_log_handle
* IMPORTING
* E_NEW_LOGNUMBERS =
exceptions
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
others = 4.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
exit.
endif.
* ApplLog Memory freigeben
call function 'BAL_LOG_REFRESH'
exporting
i_log_handle = lv_log_handle
exceptions
log_not_found = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
commit work.
endfunction.
* Aufrufen FM WRITE_APPL_LOG mit RFC
* RFC fähiger Baustein
************************************************************************
function /dt0/write_appl_log_qrfc .
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(IV_LOG_HANDLE) TYPE BALLOGHNDL
*" VALUE(IS_MSG) TYPE BAL_S_MSG
*" VALUE(IS_LOG) TYPE BAL_S_LOG
*"----------------------------------------------------------------------
data:
lv_queue_name type trfcqnam.
gv_log_handle = iv_log_handle.
concatenate
'AL'
gv_log_handle
into
lv_queue_name.
call function 'TRFC_SET_QIN_PROPERTIES'
exporting
* QOUT_NAME = ' '
qin_name = lv_queue_name
* QIN_COUNT =
* CALL_EVENT = ' '
* NO_EXECUTE = ' '
exceptions
invalid_queue_name = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
call function '/DT0/WRITE_APPL_LOG'
in background task
exporting
iv_log_handle = iv_log_handle
is_msg = is_msg
is_log = is_log.
commit work.
endfunction.
*&---------------------------------------------------------------------*
*& Report /DT0/ADD_APPL_LOG_DEMO
*& Demo report to use RFC AppLOG
*&---------------------------------------------------------------------*
*& ACHTUNG: im SMQR queue AL* muss registrieren werden.
*& die Ergenisse seht im SLG1 transaction
*&---------------------------------------------------------------------*
report /dt0/add_appl_log_demo.
include:
sbal_constants. "constants for application log
data:
lv_s_log type bal_s_log,
lv_s_msg type bal_s_msg,
lv_log_handle type balloghndl,
lv_dummy(2) type c,
ls_context type bal_s_cont,
ls_parm type bal_s_parm,
lt_param type bal_t_par,
ls_param type bal_s_par.
* in first call of fm /DT0/ADD_APPL_LOG the HANDLE (lv_log_handle) is empty
* first call create the queue and write HEADER (lv_s_log) and first MESSAGE (lv_s_msg)
* Define header of the log record.
* the important thing is choose the OBJECT.
* Objects are maintained in tx SLG0. Select proper one or create new one
lv_s_log-extnumber = 'Application Log Demo'. "#EC NOTEXT
lv_s_log-aluser = sy-uname.
lv_s_log-alprog = sy-repid.
lv_s_log-object = 'BCT1'.
lv_s_log-extnumber = 'ANY'.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.