Posted: Sat Apr 12, 2008 12:58 pm Post subject: Журнал приложений: поиск/счит. данных в опер. памяти
Code:
REPORT sbal_demo_03 MESSAGE-ID bl.
***********************************************************************
***********************************************************************
* REPORT SBAL_DEMO_03
*
* This report demonstrates how data of logs and messages can be read
* from the application log.
* For this purpose this report creates several logs using
* BAL_LOG_CREATE and adds messages to it using BAL_LOG_MSG_ADD.
*
* After this all created log handles for flight calculation
* are read with BAL_GLB_SEARCH_LOG.
* For one of these logs the header data are read with BAL_LOG_HDR_READ.
*
* Using BAL_GLB_SEARCH_MSG this report then searches for all messages
* which belong to calculation logs and have an error with problem
* class 'very high'. If something is found, one of these messages
* is read with BAL_LOG_MSG_READ.
*
* Now the user recieves a popup containing log header data
* (in this case the name of this transaction) and message data
* (in this case the message text of this prio-very-high error).
* When the user chooses 'Display Log' the log ist displayed,
* otherwise this transaction ends.
*
***********************************************************************
***********************************************************************
***********************************************************************
******************** SELECTION SCREEN *********************************
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE text-001.
PARAMETERS:
p_carrid TYPE bal_carrid DEFAULT 'SF',
p_fldate TYPE bal_fldate DEFAULT sy-datum.
SELECTION-SCREEN END OF BLOCK B01.
***********************************************************************
******************** GLOBAL DATA **************************************
***********************************************************************
SET EXTENDED CHECK OFF.
INCLUDE sbal_constants.
SET EXTENDED CHECK ON.
CONSTANTS:
const_calculation_object TYPE bal_s_log-object VALUE 'BCT1'.
DATA:
g_retcode TYPE i,
g_text1(70) TYPE c,
g_text2(70) TYPE c,
g_text3(70) TYPE c,
g_r_object TYPE bal_s_obj,
g_s_log_filter TYPE bal_s_lfil,
g_t_log_handle TYPE bal_t_logh,
g_log_handle TYPE balloghndl,
g_s_log TYPE bal_s_log,
g_txt_altcode(70) TYPE c,
g_r_msgty TYPE bal_s_msty,
g_r_probclass TYPE bal_s_prcl,
g_s_msg_filter TYPE bal_s_mfil,
g_t_msg_handle TYPE bal_t_msgh,
g_msg_handle TYPE balmsghndl,
g_answer(1) TYPE c,
g_s_fcat TYPE bal_s_fcat,
g_s_display_profile TYPE bal_s_prof,
g_date_string(30) TYPE c.
***********************************************************************
******************** MAIN PROGRAM *************************************
***********************************************************************
END-OF-SELECTION.
******************************************************************
* calculate flights
******************************************************************
PERFORM flights_calculate CHANGING g_retcode.
* only continue when something went wrong
CHECK g_retcode NE 0.
******************************************************************
* find out all calculation logs which have been created
******************************************************************
g_r_object-sign = 'I'.
g_r_object-option = 'EQ'.
g_r_object-low = const_calculation_object.
APPEND g_r_object TO g_s_log_filter-object.
CALL FUNCTION 'BAL_GLB_SEARCH_LOG'
EXPORTING
i_s_log_filter = g_s_log_filter
IMPORTING
e_t_log_handle = g_t_log_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
******************************************************************
* read Name and Text for Transaction
******************************************************************
READ TABLE g_t_log_handle INTO g_log_handle INDEX 1.
CALL FUNCTION 'BAL_LOG_HDR_READ'
EXPORTING
i_log_handle = g_log_handle
IMPORTING
e_s_log = g_s_log
e_txt_altcode = g_txt_altcode
EXCEPTIONS
OTHERS = 0.
* create text for first line in popup
CONCATENATE 'Transaktion:'(tra) g_txt_altcode
'Durchgefќhrt von:'(usr) g_s_log-aluser
INTO g_text1 SEPARATED BY space.
g_text2 = 'Ergebnis:'(res).
******************************************************************
* find out all errors with problem class 'very high'
******************************************************************
g_r_msgty-sign = 'I'.
g_r_msgty-option = 'EQ'.
g_r_msgty-low = 'E'.
APPEND g_r_msgty TO g_s_msg_filter-msgty.
g_r_probclass-sign = 'I'.
g_r_probclass-option = 'EQ'.
g_r_probclass-low = probclass_very_high.
APPEND g_r_probclass TO g_s_msg_filter-probclass.
CALL FUNCTION 'BAL_GLB_SEARCH_MSG'
EXPORTING
i_s_log_filter = g_s_log_filter
i_s_msg_filter = g_s_msg_filter
IMPORTING
e_t_msg_handle = g_t_msg_handle
EXCEPTIONS
OTHERS = 1.
******************************************************************
* read text for this message
******************************************************************
IF sy-subrc = 0.
READ TABLE g_t_msg_handle INTO g_msg_handle INDEX 1.
CALL FUNCTION 'BAL_LOG_MSG_READ'
EXPORTING
i_s_msg_handle = g_msg_handle
IMPORTING
e_txt_msg = g_text3
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
g_text1 = 'Siehe Protokoll'(see).
* text-com = 'Please analyse log files'.
ENDIF.
ENDIF.
******************************************************************
* issue popup to select messages to inform user
******************************************************************
CALL FUNCTION 'POPUP_TO_DECIDE'
EXPORTING
textline1 = g_text1
textline2 = g_text2
textline3 = g_text3
text_option1 = 'Protokoll anzeigen'(log)
text_option2 = 'Transaktion beenden'(end)
titel = space
cancel_display = ' '
IMPORTING
answer = g_answer.
******************************************************************
* show logs if specified
******************************************************************
IF g_answer = '1'.
CONCATENATE 'Abrechnung Fluggesellschaft'(car) p_carrid
INTO g_s_display_profile-title
SEPARATED BY space.
WRITE p_fldate TO g_date_string.
CONCATENATE 'Datum'(dat) g_date_string
INTO g_s_display_profile-root_text
SEPARATED BY space.
g_s_fcat-ref_table = 'BAL_S_SHOW'.
g_s_fcat-ref_field = 'EXTNUMBER'.
g_s_fcat-outputlen = 30.
APPEND g_s_fcat TO g_s_display_profile-lev1_fcat.
g_s_fcat-ref_table = 'BAL_S_SHOW'.
g_s_fcat-ref_field = 'T_MSG'.
g_s_fcat-outputlen = 60.
APPEND g_s_fcat TO g_s_display_profile-mess_fcat.
g_s_display_profile-show_all = 'X'.
g_s_display_profile-disvariant-report = sy-repid.
* when you use also other ALV lists in your report,
* please specify a handle to distinguish between the display
* variants of these different lists, e.g:
g_s_display_profile-disvariant-handle = 'LOG'.
* we now display our logs:
* - since there might also be logs from other applications in the
* memory (perhaps created by some other function modules)
* we specify explicitly which logs should be displayed
* by G_T_LOG_HANDLE.
* - we also want to use our own display profile G_S_DISPLAY_PROFILE
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_t_log_handle = g_t_log_handle
i_s_display_profile = g_s_display_profile
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
***********************************************************************
*************************** FORMS *************************************
***********************************************************************
*-----------------------------------------------------------------
* FORM flights_calculate
*-----------------------------------------------------------------
FORM flights_calculate
CHANGING
c_retcode TYPE i.
DATA:
l_connid TYPE bal_s_ex01-connid,
l_connid_txt(40) TYPE c,
l_passenger TYPE bal_s_ex01-id,
l_s_log TYPE bal_s_log,
l_s_msg_defaults TYPE bal_s_mdef,
l_dummy(1) TYPE c. "#EC NEEDED
* carry out calculation for all flights done by P_CARRID on P_FLDATE
DO 3 TIMES.
* derive connection ID
l_connid = sy-index.
CASE l_connid.
WHEN '001'. l_connid_txt = 'Hamburg - New York'(c01).
WHEN '002'. l_connid_txt = 'Hamburg - Toronto'(c02).
WHEN '003'. l_connid_txt = 'Hamburg - Madrid'(c03).
ENDCASE.
* open log file for one flight
l_s_log-object = const_calculation_object.
l_s_log-extnumber = l_connid_txt.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = l_s_msg_defaults-log_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* put all following messages into this log
CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET'
EXPORTING
i_s_msg_defaults = l_s_msg_defaults
EXCEPTIONS
OTHERS = 0.
* no carry out calculation for this log
IF l_connid = 2.
* there is one flight which was cancelled
MESSAGE w319 INTO l_dummy.
* 319(BL): 'Flight was cancelled'.
PERFORM msg_add USING probclass_high.
c_retcode = 1.
ELSE.
* carry out claculation for all passengers
DO 60 TIMES.
* derive number of passenger ID
l_passenger = sy-index.
* for some passengers calculation is not possible
IF ( l_connid = '003' ) AND
( l_passenger = '021' OR l_passenger = '045' ).
MESSAGE e318 WITH l_passenger INTO l_dummy.
* 318(BL): 'passengers did not confirm flight'
PERFORM msg_add USING probclass_very_high.
c_retcode = 1.
ELSE.
MESSAGE s317 WITH l_passenger INTO l_dummy.
* 317(BL): 'Calculation successfully done'.
PERFORM msg_add USING probclass_medium.
ENDIF.
ENDDO.
ENDIF.
ENDDO.
ENDFORM.
*--------------------------------------------------------------------
* FORM MSG_ADD
*--------------------------------------------------------------------
FORM msg_add USING value(i_probclass) TYPE bal_s_msg-probclass.
DATA:
l_s_msg TYPE bal_s_msg.
* define data of message for Application Log
l_s_msg-msgty = sy-msgty.
l_s_msg-msgid = sy-msgid.
l_s_msg-msgno = sy-msgno.
l_s_msg-msgv1 = sy-msgv1.
l_s_msg-msgv2 = sy-msgv2.
l_s_msg-msgv3 = sy-msgv3.
l_s_msg-msgv4 = sy-msgv4.
l_s_msg-probclass = i_probclass.
* ... see structure BAL_S_LOG or report SBAL_DEMO_02 for ...
* ... further data which can be added to a message ...
* add this message to log file
* (I_LOG_HANDLE is not specified, we want to add to the default log.
* If it does not exist we do not care =>EXCEPTIONS log_not_found = 0)
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
* I_LOG_HANDLE =
i_s_msg = l_s_msg
EXCEPTIONS
log_not_found = 0
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
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.