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

Журнал приложений: простейший вызов



 
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
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Apr 12, 2008 12:55 pm    Post subject: Журнал приложений: простейший вызов Reply with quote

Code:
REPORT SBAL_DEMO_01  MESSAGE-ID BL.
***********************************************************************
***********************************************************************
*                   REPORT SBAL_DEMO_01
*
* This report shows a simple example how the application log function
* modules could be used.
* For this purpose this reports simulates the check of a flight
* (specified by carrier, connection ID and flight date).
* A log is created with BAL_LOG_CREATE.
* Messages are sent to this log using BAL_LOG_MSG_ADD
* (see form msg_add).
* Finally the log is displayed with BAL_DSP_LOG_DISPLAY.
* Nothing is saved on the database.
*
***********************************************************************
***********************************************************************


***********************************************************************
******************** SELECTION SCREEN *********************************
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-001.
PARAMETERS:
  P_CARRID TYPE BAL_CARRID DEFAULT 'SF',
  P_CONNID TYPE BAL_CONNID DEFAULT '0003',
  P_FLDATE TYPE BAL_FLDATE DEFAULT SY-DATUM.
SELECTION-SCREEN END OF BLOCK B01.


***********************************************************************
******************** CONSTANTS, TYPES, DATA ***************************
***********************************************************************
  SET EXTENDED CHECK OFF.
    INCLUDE SBAL_CONSTANTS.
  SET EXTENDED CHECK ON.
  DATA:
    G_S_LOG            TYPE BAL_S_LOG,
    G_VALUE            TYPE I,
    G_PASSENGER        TYPE BAL_CUSTMR,
    G_EVERYTHING_OK(1) TYPE C,
    G_DUMMY            TYPE C.                               "#EC NEEDED


***********************************************************************
************************ MAIN PROGRAM *********************************
***********************************************************************
END-OF-SELECTION.

***************************************************************
* create a log where all messages should be added to
***************************************************************
* define some header data of this log
  G_S_LOG-EXTNUMBER = 'Application Log Demo'.             "#EC NOTEXT
  G_S_LOG-ALUSER    = SY-UNAME.
  G_S_LOG-ALPROG    = SY-REPID.
* ... see structure BAL_S_LOG for further data ...
* ... which can be added to a log header       ...
* create a log
  CALL FUNCTION 'BAL_LOG_CREATE'
       EXPORTING
            I_S_LOG = G_S_LOG
       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.


***************************************************************
* do something to check if flight is allowed
***************************************************************
* ... result is negative:
* 305(BL): 'Flight allowance does not exist'
  MESSAGE E305 INTO G_DUMMY.
  PERFORM MSG_ADD USING PROBCLASS_VERY_HIGH.


***************************************************************
* do something to check if weight is OK
***************************************************************
* ... result is negative:
* 301(BL): 'Maximum weigth is exceeded'
  MESSAGE E301(BL) INTO G_DUMMY.
  PERFORM MSG_ADD USING PROBCLASS_VERY_HIGH.


***************************************************************
* do something to check if there are too many passengers
***************************************************************
* ... result is negative:
* 302(BL): 'Flight is overbooked'
  MESSAGE E302(BL) INTO G_DUMMY.
  PERFORM MSG_ADD USING PROBCLASS_HIGH.


***************************************************************
* do something to check if airplane is available
***************************************************************
* ... result is negative:
* 303(BL): 'Airplane &1 is not available'
  MESSAGE ID 'BL' TYPE 'E' NUMBER 303 WITH '747-400' INTO G_DUMMY.
  PERFORM MSG_ADD USING PROBCLASS_HIGH.


***************************************************************
* do something to check if the crew is OK
***************************************************************
* ... result is negative ....
* 308(BL): 'Stewardess &1 is ill and therefore not available'
  MESSAGE E308(BL) WITH 'JONES' INTO G_DUMMY.
  PERFORM MSG_ADD USING PROBCLASS_HIGH.


***************************************************************
* do something to check if the crew has enough time to sleep
***************************************************************
* ... result is negative:
* 309(BL): 'Relax phases for the crew are too short'
  MESSAGE E309(BL) INTO G_DUMMY.
  PERFORM MSG_ADD USING PROBCLASS_HIGH.


***************************************************************
* check passenger list
***************************************************************
  DO 60 TIMES.

*   derive passenger number
    WRITE SY-INDEX TO G_PASSENGER LEFT-JUSTIFIED.

*   assumption: everything is OK for this passenger
    G_EVERYTHING_OK = 'X'.


***************************************************************
*   non-smoker seat available ?
***************************************************************
*   ... for some passengers a non-smoker seat is not available:
    IF G_PASSENGER = 22 OR G_PASSENGER = 34 OR G_PASSENGER = 66.
*     310(BL): 'Passenger &1 can only be booked on smoker seat'
      MESSAGE E310(BL) WITH G_PASSENGER INTO G_DUMMY.
      PERFORM MSG_ADD USING PROBCLASS_MEDIUM.
      G_EVERYTHING_OK = ' '.
    ENDIF.


***************************************************************
*   is payment checked ?
***************************************************************
*   ... for some passengers payment is not yet checked:
    G_VALUE = SY-INDEX MOD 16.
    IF G_VALUE = 0.
*     304(BL): 'Payment for passenger &1 is not yet checked'
      MESSAGE W304(BL) WITH G_PASSENGER INTO G_DUMMY.
      PERFORM MSG_ADD USING PROBCLASS_MEDIUM.
      G_EVERYTHING_OK = ' '.
    ELSE.
*     306(BL): 'Payment for passenger &1 is done'
      MESSAGE S306(BL) WITH G_PASSENGER INTO G_DUMMY.
      PERFORM MSG_ADD USING PROBCLASS_MEDIUM.
    ENDIF.


***************************************************************
*   did passenger cancel his flight ?
***************************************************************
*   ... some passnegers have cancelled their flight:
    G_VALUE = SY-INDEX MOD 26.
    IF G_VALUE = 0.
*     307(BL): 'Flight for passenger &1 was cancelled'
      MESSAGE S307(BL) WITH G_PASSENGER INTO G_DUMMY.
      PERFORM MSG_ADD USING PROBCLASS_MEDIUM.
      G_EVERYTHING_OK = ' '.
    ENDIF.


***************************************************************
*   Everything is OK
***************************************************************
*   ... when no errors occured everything is OK for this passenger:
    IF G_EVERYTHING_OK = 'X'.
*     311(BL): 'Booked flight for passenger &1 is checked and OK'
      MESSAGE S311(BL) WITH G_PASSENGER INTO G_DUMMY.
      PERFORM MSG_ADD USING PROBCLASS_LOW.
    ENDIF.

  ENDDO.


***************************************************************
* display log file
***************************************************************
* - we do not specify a display profile I_S_DISPLAY_PROFILE
*   since we want to use the standard profile
* - we also do not specify any filter (I_S_LOG_FILTER, ...
*   I_T_MSG_HANDLE) since we want to display all messages available
  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
*      EXPORTING
*           I_S_LOG_FILTER         =
*           I_T_LOG_CONTEXT_FILTER =
*           I_S_MSG_FILTER         =
*           I_T_MSG_CONTEXT_FILTER =
*           I_T_LOG_HANDLE         =
*           I_T_MSG_HANDLE         =
*           I_S_DISPLAY_PROFILE    =
*           I_AMODAL               = ' '
       EXCEPTIONS
            OTHERS                 = 1.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


***********************************************************************
******************  FORMS *********************************************
***********************************************************************
*--------------------------------------------------------------------
* 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
* we do not specify I_LOG_HANDLE since we want to add this message
* 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_S_MSG       = L_S_MSG
*           I_LOG_HANDLE  =
       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.

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