SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Распараллеливание записи в AppLOG через RFC



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Arch & Logs
View previous topic :: View next topic  
Author Message
menx
Участник
Участник



Joined: 21 Nov 2008
Posts: 25
Location: СПб - Валлдорф

PostPosted: Fri Feb 06, 2009 11:45 am    Post subject: Распараллеливание записи в AppLOG через RFC Reply with quote

Распараллеливание записи в 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.

  receive results from function '/DT0/WRITE_APPL_LOG'
           importing
                ev_log_handle = gv_log_handle
           exceptions
                communication_failure = 1
                system_failure        = 2
                resource_failure      = 3
                others                = 4.

  gv_appl_log_process_running = space.

endform.                    " APPL_LOG_END



* Eintragen APPL Log
* RFC fähiger Baustein
************************************************************************
  function /dt0/write_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
*"----------------------------------------------------------------------
  data:
    lv_log_exists,
    lv_log_handle type balloghndl,
    lt_log_handle type bal_t_logh.

  lv_log_handle = iv_log_handle.

  clear: lv_log_exists, ev_log_handle.

  if not iv_log_handle is initial.
*   Versuchen ApplLog Handle zu laden
    refresh: lt_log_handle.
    append lv_log_handle to lt_log_handle.
    call function 'BAL_DB_LOAD'
      exporting
*       I_T_LOG_HEADER                      =
        i_t_log_handle                      = lt_log_handle
*       I_T_LOGNUMBER                       =
*       I_CLIENT                            = SY-MANDT
*       I_DO_NOT_LOAD_MESSAGES              = ' '
*       I_EXCEPTION_IF_ALREADY_LOADED       =
      importing
        e_t_log_handle                      = lt_log_handle
*       E_T_MSG_HANDLE                      =
      exceptions
        no_logs_specified                   = 1
        log_not_found                       = 2
        log_already_loaded                  = 3
        others                              = 4.
    if sy-subrc = 0.
      lv_log_exists = 'X'.
    endif.
  endif.

  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'.

* Define messages
lv_s_msg-msgty     = 'I'.
lv_s_msg-msgid     = 'SABAPDOCU'.
lv_s_msg-msgno     = '045'.
lv_s_msg-msgv1     = 'Parameter1'.
lv_s_msg-msgv2     = 'Parameter2'.
lv_s_msg-msgv3     = 'Parameter3'.
lv_s_msg-msgv4     = 'Parameter4'.
lv_s_msg-probclass = probclass_high.

ls_param-parname = 'USERNAME'.
ls_param-parvalue = 'Rogi'.
append ls_param to lt_param.
ls_parm-t_par = lt_param.

ls_parm-altext = 'ZBALTEST'.
lv_s_msg-params = ls_parm.

data: ls_my_context   type brf_ptest_str.
ls_my_context-client = '333'.
ls_my_context-value = 'Nasenbaer'.
lv_s_msg-context-tabname = 'BRF_PTEST_STR'.
lv_s_msg-context-value   = ls_my_context.


call function '/DT0/ADD_APPL_LOG'
  exporting
    iv_log_handle = lv_log_handle
    is_msg        = lv_s_msg
    is_log        = lv_s_log
  importing
    ev_log_handle = lv_log_handle.


* after the first call new HANDLE of queue is created
* define and add new message for header
do 5 times.

  lv_s_msg-msgty     = 'I'.
  lv_s_msg-msgid     = 'SABAPDOCU'.
  lv_s_msg-msgno     = '001'.
  lv_dummy           = sy-index.
  concatenate
    'TEST MESSAGE'
    lv_dummy
  into lv_s_msg-msgv1.
  lv_s_msg-probclass = probclass_medium.

  call function '/DT0/ADD_APPL_LOG'
    exporting
      iv_log_handle = lv_log_handle
      is_msg        = lv_s_msg
      is_log        = lv_s_log
    importing
      ev_log_handle = lv_log_handle.

  lv_s_msg-msgno     = '005'.
enddo.

commit work.

* to search result use tx SLG1
call transaction 'SLG1'.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Arch & Logs All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.