Posted: Sat Apr 12, 2008 1:01 pm Post subject: Журнал приложений: сохранение и загрузка журналов
Code:
REPORT sbal_demo_04 MESSAGE-ID bl.
***********************************************************************
***********************************************************************
* REPORT SBAL_DEMO_05
*
* This report demonstrates the database related features of the
* application log. This report calcuates invoices for
* all flights which took place on a certain date.
* The user can choose between three different options:
*
* 1. carry out calculation run in simulation mode (nothing is saved)
* - invoices are calculated but not yet saved
* they have temporal document numbers
* many errors and messages are created containing these numbers
* - logs are displayed. All messages contain these numbers
* 2. carry out this calculation run in real mode (logs are saved)
* - invoices are calculated but not yet saved
* they have temporal document numbers
* many errors and messages are created containing these numbers
* - database numbers for all these invoices are derived
* and replaced in theses documents
* - all messages containing these numbers are changed
* (BAL_DB_SAVE_PREPARE)
* - logs are saved on DB (BAL_DB_SAVE)
* - logs are displayed. All messages contain the final
* document numbers
*
* 3. show logs for all calculation runs which have been created
* so far (for all flights on the date specified):
* - BAL_DB_SEARCH Searches for logs on the database
* - BAL_DB_LOAD Loads these logs from the database
*
***********************************************************************
***********************************************************************
***********************************************************************
******************** SELECTION SCREEN *********************************
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE text-001.
PARAMETERS:
p_fldate TYPE bal_fldate DEFAULT sy-datum.
SELECTION-SCREEN END OF BLOCK B01.
SELECTION-SCREEN BEGIN OF BLOCK B02 WITH FRAME TITLE text-002.
PARAMETERS:
p_simu RADIOBUTTON GROUP sel DEFAULT 'X',
p_real RADIOBUTTON GROUP sel,
p_logs RADIOBUTTON GROUP sel.
SELECTION-SCREEN END OF BLOCK B02.
***********************************************************************
******************** CONSTANTS, TYPES, DATA ***************************
***********************************************************************
* all logs are saved with this application object:
CONSTANTS:
const_object_flight_invoice TYPE bal_s_log-object VALUE 'BCT1'.
* an invoice for a flight (in principle)
TYPES:
BEGIN OF s_invoice,
number TYPE bal_s_ex03-invoice,
data TYPE c,
error TYPE c,
END OF s_invoice,
t_invoice TYPE s_invoice OCCURS 0.
* global data
DATA:
g_t_invoice TYPE t_invoice,
g_temporal_invoice_number(4) TYPE n,
g_final_invoice_number(10) TYPE n VALUE '1060077890',
g_t_replace_message TYPE bal_t_rplv,
g_t_replace_context TYPE bal_t_rplc,
g_extnum TYPE bal_s_log-extnumber,
g_r_object TYPE bal_s_obj,
g_r_extnumber TYPE bal_s_extn,
g_s_log_filter TYPE bal_s_lfil,
g_t_log_header TYPE balhdr_t.
***********************************************************************
******************** MAIN PROGRAM *************************************
***********************************************************************
END-OF-SELECTION.
*****************************************************************
* create external number which is used to select logs later on
*****************************************************************
* in this case a calculation run is characterized by the date
* for which it is carried out
g_extnum = p_fldate.
*****************************************************************
* carry out invoice calculation in simulation mode
*****************************************************************
IF NOT p_simu IS INITIAL.
* calculate flights
PERFORM calculate_flights
USING
p_fldate
g_extnum
CHANGING
g_t_invoice.
* display log files which have been created
PERFORM display_logs USING 'X'.
ENDIF.
*****************************************************************
* carry out invoice calculation in real mode
*****************************************************************
IF NOT p_real IS INITIAL.
* calculate flights
PERFORM calculate_flights
USING
p_fldate
g_extnum
CHANGING
g_t_invoice.
* derive new numbers for all created invoices
PERFORM invoice_save_prepare
CHANGING
g_t_invoice
g_t_replace_message
g_t_replace_context.
* replace numbers in logs
CALL FUNCTION 'BAL_DB_SAVE_PREPARE'
EXPORTING
i_replace_in_all_logs = 'X'
i_t_replace_message_variables = g_t_replace_message
i_t_replace_context_fields = g_t_replace_context
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.
* save logs
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_save_all = 'X'
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.
* display log files which have been created
PERFORM display_logs USING 'X'.
ENDIF.
*****************************************************************
* show logs of previous invoice calculations
*****************************************************************
IF NOT p_logs IS INITIAL.
* create a filter with all relevant criteria:
g_r_object-sign = 'I'.
g_r_object-option = 'EQ'.
g_r_object-low = const_object_flight_invoice.
APPEND g_r_object TO g_s_log_filter-object.
g_r_extnumber-sign = 'I'.
g_r_extnumber-option = 'EQ'.
g_r_extnumber-low = p_fldate.
APPEND g_r_extnumber TO g_s_log_filter-extnumber.
* search on DB for these logs
CALL FUNCTION 'BAL_DB_SEARCH'
EXPORTING
i_s_log_filter = g_s_log_filter
IMPORTING
e_t_log_header = g_t_log_header
EXCEPTIONS
OTHERS = 0.
* load logs from DB
CALL FUNCTION 'BAL_DB_LOAD'
EXPORTING
i_t_log_header = g_t_log_header
EXCEPTIONS
OTHERS = 0.
* display logs
PERFORM display_logs USING ' '.
ENDIF.
***********************************************************************
******************** FORMS ********************************************
***********************************************************************
*--------------------------------------------------------------------
* FORM display_logs
*--------------------------------------------------------------------
FORM display_logs USING value(i_show_all) TYPE c.
DATA:
l_s_display_profile TYPE bal_s_prof,
l_s_fcat TYPE bal_s_fcat.
* create a display profile
WRITE p_fldate TO l_s_display_profile-root_text.
CONCATENATE 'Abrechnungslфufe fќr alle Flќge vom'(003)
l_s_display_profile-root_text
INTO l_s_display_profile-root_text
SEPARATED BY space.
l_s_display_profile-head_size = 57.
l_s_display_profile-show_all = i_show_all.
IF i_show_all = 'X'.
l_s_display_profile-exp_level = 1.
ENDIF.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_SHOW'.
l_s_fcat-ref_field = 'ALDATE'.
l_s_fcat-cltxt_add = 'X'.
l_s_fcat-coltext = 'Durchgefќhrt am'(004).
APPEND l_s_fcat TO l_s_display_profile-lev1_fcat.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_SHOW'.
l_s_fcat-ref_field = 'ALTIME'.
APPEND l_s_fcat TO l_s_display_profile-lev1_fcat.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_EX03'.
l_s_fcat-ref_field = 'CARRID'.
l_s_fcat-cltxt_add = 'X'.
APPEND l_s_fcat TO l_s_display_profile-lev2_fcat.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_EX03'.
l_s_fcat-ref_field = 'CONNID'.
l_s_fcat-cltxt_add = 'X'.
APPEND l_s_fcat TO l_s_display_profile-lev3_fcat.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_EX03'.
l_s_fcat-ref_field = 'INVOICE'.
l_s_fcat-cltxt_add = 'X'.
APPEND l_s_fcat TO l_s_display_profile-lev4_fcat.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_EX03'.
l_s_fcat-ref_field = 'INVOICE'.
APPEND l_s_fcat TO l_s_display_profile-mess_fcat.
CLEAR l_s_fcat.
l_s_fcat-ref_table = 'BAL_S_SHOW'.
l_s_fcat-ref_field = 'T_MSG'.
l_s_fcat-outputlen = 70.
APPEND l_s_fcat TO l_s_display_profile-mess_fcat.
l_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:
l_s_display_profile-disvariant-handle = 'LOG'.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = l_s_display_profile
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.
*--------------------------------------------------------------------
* FORM invoice_save_prepare
*--------------------------------------------------------------------
FORM invoice_save_prepare
CHANGING
c_t_invoice TYPE t_invoice
c_t_replace_message TYPE bal_t_rplv
c_t_replace_context TYPE bal_t_rplc.
DATA:
l_s_replace_message TYPE bal_s_rplv,
l_s_replace_context TYPE bal_s_rplc.
FIELD-SYMBOLS:
<l_s_invoice> TYPE s_invoice.
* derive final number for invoices
ADD 1 TO g_final_invoice_number.
* put result into invoice
<l_s_invoice>-number = g_final_invoice_number.
* record new invoice number
l_s_replace_context-new_value = <l_s_invoice>-number.
APPEND l_s_replace_context TO c_t_replace_context.
l_s_replace_message-new_value = <l_s_invoice>-number.
APPEND l_s_replace_message TO c_t_replace_message.
ENDLOOP.
ENDFORM.
*--------------------------------------------------------------------
* FORM calculate_flights
*--------------------------------------------------------------------
FORM calculate_flights
USING
value(i_fldate) TYPE bal_s_ex03-fldate
value(i_extnum) TYPE c
CHANGING
c_t_invoice TYPE t_invoice.
DATA:
l_carrid TYPE bal_s_ex03-carrid,
l_connid TYPE bal_s_ex03-connid.
* carry out invoice calculation for all airlines (in this case 4)
DO 4 TIMES.
CASE sy-index.
WHEN 1. l_carrid = 'SF'.
WHEN 2. l_carrid = 'AB'.
WHEN 3. l_carrid = 'XY'.
WHEN 4. l_carrid = 'AP'.
ENDCASE.
* for each airline calculate invoices for all connections
DO 3 TIMES.
l_connid = sy-index.
PERFORM calculate_flight
USING
l_carrid
l_connid
i_fldate
i_extnum
CHANGING
c_t_invoice.
ENDDO.
ENDDO.
ENDFORM.
*--------------------------------------------------------------------
* FORM calculate_flight
*--------------------------------------------------------------------
FORM calculate_flight
USING
value(i_carrid) TYPE bal_s_ex03-carrid
value(i_connid) TYPE bal_s_ex03-connid
value(i_fldate) TYPE bal_s_ex03-fldate
value(i_extnum) TYPE c
CHANGING
c_t_invoice TYPE t_invoice.
DATA:
l_log_handle TYPE balloghndl,
l_s_log TYPE bal_s_log,
l_s_invoice TYPE s_invoice,
l_create_new_invoice TYPE i,
l_passenger_id TYPE bal_s_ex03-id,
l_s_mdef TYPE bal_s_mdef,
l_s_context TYPE bal_s_ex03,
l_dummy TYPE c. "#EC NEEDED
********************************************************************
* create log file
********************************************************************
l_s_log-object = const_object_flight_invoice.
l_s_log-extnumber = i_extnum.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = l_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.
********************************************************************
* for all passengers create invoices
********************************************************************
l_create_new_invoice = 0.
DO 40 TIMES.
* derive passenger id
l_passenger_id = sy-index.
********************************************************************
* when a new invoice is to be created derive a new number
********************************************************************
IF l_create_new_invoice = 0.
ADD 1 TO g_temporal_invoice_number.
CONCATENATE '$' g_temporal_invoice_number INTO l_s_invoice-number.
ENDIF.
********************************************************************
* set defaults for all following messages
********************************************************************
l_s_mdef-log_handle = l_log_handle.
l_s_context-carrid = i_carrid.
l_s_context-connid = i_connid.
l_s_context-fldate = i_fldate.
l_s_context-invoice = l_s_invoice-number.
l_s_mdef-context-tabname = 'BAL_S_EX03'.
l_s_mdef-context-value = l_s_context.
CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET'
EXPORTING
i_s_msg_defaults = l_s_mdef
EXCEPTIONS
OTHERS = 0.
********************************************************************
* add data for this passenger to this invoice
********************************************************************
* ....
********************************************************************
* some activities for this invoice might fail and cause errors:
********************************************************************
IF i_carrid = 'AB' AND i_connid = 2 AND l_passenger_id = 15.
* 318(BL): 'Calculation impossible. Passenger &1 did not confirm'
MESSAGE w318 WITH l_passenger_id INTO l_dummy.
PERFORM msg_add.
l_s_invoice-error = 'X'.
ELSEIF i_carrid = 'XY' AND i_connid = 3 AND l_passenger_id = 22.
* 321(BL): 'Address data for passenger &1 in invoice &2 incomplete'
MESSAGE e321 WITH l_passenger_id l_s_invoice-number INTO l_dummy.
PERFORM msg_add.
l_s_invoice-error = 'X'.
ELSEIF i_carrid = 'SF' AND i_connid = 1 AND l_passenger_id = 10.
* 323(BL): 'New pricing: Special prices in document &1 invalid'
MESSAGE w323 WITH l_s_invoice-number INTO l_dummy.
PERFORM msg_add.
l_s_invoice-error = 'X'.
ELSEIF i_carrid = 'SF' AND i_connid = 2 AND l_passenger_id = 5.
* 322(BL): 'Invoice &1 is not complete'
MESSAGE e322 WITH l_s_invoice-number INTO l_dummy.
PERFORM msg_add.
l_s_invoice-error = 'X'.
ENDIF.
********************************************************************
* is a new invoice to be created ?
********************************************************************
l_create_new_invoice = l_passenger_id MOD 9.
IF l_create_new_invoice = 0.
PERFORM invoice_add USING l_s_invoice CHANGING c_t_invoice.
CLEAR l_s_invoice.
ENDIF.
ENDDO.
IF NOT l_s_invoice IS INITIAL.
PERFORM invoice_add USING l_s_invoice CHANGING c_t_invoice.
CLEAR l_s_invoice.
ENDIF.
ENDFORM.
*--------------------------------------------------------------------
* FORM MSG_ADD
*--------------------------------------------------------------------
FORM invoice_add
USING
i_s_invoice TYPE s_invoice
CHANGING
c_t_invoice TYPE t_invoice.
DATA:
l_dummy TYPE c. "#EC NEEDED
* put the invoice to table of invoices
APPEND i_s_invoice TO c_t_invoice.
IF i_s_invoice-error IS INITIAL.
* 324(BL): 'Invoice &1 was successfully created'
MESSAGE s324(bl) WITH i_s_invoice-number INTO l_dummy.
PERFORM msg_add.
ENDIF.
ENDFORM.
*--------------------------------------------------------------------
* FORM MSG_ADD
*--------------------------------------------------------------------
FORM msg_add.
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.
* ... 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.