Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anoop_L
Explorer
0 Likes
1,093

Hello Community, I would like to exhibit a scenario to Create and Display Application Log using Object Oriented Approach with use of Function Modules in Report Program. 

For this scenario the report stimulates to check the availability of Flight Specified by Carrier and Connection ID using Function Modules - 

BAL_LOG_CREATE,

BAL_LOG_MSG_ ADD and

BAL_DSP_LOG_DISPLAY. 

Firstly, In Class Definition I’ve Created the Selection Screen Elements Carrier (Carrid) Connection ID (Connid) and Flight Date (Fldate) which would be constants under Public Section 

 

Anoop_L_0-1736245775583.png

Further I’ll be Declaring Few Methods

Anoop_L_1-1736245802780.png

Implementation of these Methods 

 

Anoop_L_3-1736245908994.png

Anoop_L_4-1736245908995.png 

Anoop_L_5-1736245908995.png

Anoop_L_6-1736245908996.png

Anoop_L_9-1736245908998.png

Anoop_L_10-1736245908998.png

Anoop_L_11-1736245952807.png

Anoop_L_12-1736245952810.png

Anoop_L_13-1736245952812.png

Selection Screen Elements 

Anoop_L_14-1736245952814.png

Initialization of the Class by creating the Object as per the Requirement, then Creating the Log and Displaying. 

Anoop_L_15-1736245952815.png

Anoop_L_16-1736245952816.png

The Result Output Will Be Displayed as Below 

Anoop_L_17-1736245952817.png

I've Posted the Code Below.

INCLUDE SBAL_CONSTANTS.

***********************************************************************
************************* CLASS DEFINITIONS ***************************
***********************************************************************

CLASS lcl_application_log DEFINITION.
  PUBLIC SECTION.
    CONSTANTS:
      c_default_carrid TYPE bal_carrid VALUE 'SF',
      c_default_connid TYPE bal_connid VALUE '0003',
      c_default_fldate TYPE bal_fldate VALUE '        '.

    TYPES:
      BEGIN OF ty_passenger,
        number TYPE bal_custmr,
        everything_ok TYPE c LENGTH 1,
      END OF ty_passenger.

    DATA:
      g_s_log       TYPE bal_s_log,
      g_message       TYPE c,
      g_passenger   TYPE ty_passenger.

    METHODS:
      constructor,
      create_log,
      check_flight_allowance,
      check_weight,
      check_passenger_capacity,
      check_airplane_availability,
      check_crew_availability,
      check_crew_sleep_time,
      process_passengers,
      add_message IMPORTING i_probclass TYPE bal_s_msg-probclass,
      display_logs.

  PRIVATE SECTION.
    DATA:
      lt_passengers TYPE TABLE OF ty_passenger.
ENDCLASS.

CLASS lcl_application_log IMPLEMENTATION.

  METHOD constructor.
    " Initialize class attributes if needed
    CLEAR g_s_log.
    CLEAR g_passenger.
  ENDMETHOD.

  METHOD create_log.
    " Set log header data and create a log
    g_s_log-extnumber = 'Application Log Demo'.
    g_s_log-aluser    = sy-uname.
    g_s_log-alprog    = sy-repid.

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

  METHOD check_flight_allowance.
    MESSAGE e305(bl) INTO g_message.
    add_message( i_probclass = probclass_very_high ).
  ENDMETHOD.

  METHOD check_weight.
    MESSAGE e301(bl) INTO g_message.
    add_message( i_probclass = probclass_very_high ).
  ENDMETHOD.

  METHOD check_passenger_capacity.
    MESSAGE e302(bl) INTO g_message.
    add_message( i_probclass = probclass_high ).
  ENDMETHOD.

  METHOD check_airplane_availability.
    MESSAGE ID 'BL' TYPE 'E' NUMBER 303 WITH '747-400' INTO g_message.
    add_message( i_probclass = probclass_high ).
  ENDMETHOD.

  METHOD check_crew_availability.
    MESSAGE e308(bl) WITH 'ANOOP' INTO g_message.
    add_message( i_probclass = probclass_high ).
  ENDMETHOD.

  METHOD check_crew_sleep_time.
    MESSAGE e309(bl) INTO g_message.
    add_message( i_probclass = probclass_high ).
  ENDMETHOD.

  METHOD process_passengers.
    DO 60 TIMES.
      " Assign passenger number
      WRITE sy-index TO g_passenger-number LEFT-JUSTIFIED.
      g_passenger-everything_ok = 'X'.

      " Check non-smoker seat availability
      IF g_passenger-number = 22 OR g_passenger-number = 34 OR g_passenger-number = 66.
        MESSAGE e310(bl) WITH g_passenger-number INTO g_message.
        add_message( i_probclass = probclass_medium ).
        g_passenger-everything_ok = ' '.
      ENDIF.

      " Check payment status
      IF sy-index MOD 16 = 0.
        MESSAGE w304(bl) WITH g_passenger-number INTO g_message.
        add_message( i_probclass = probclass_medium ).
        g_passenger-everything_ok = ' '.
      ELSE.
        MESSAGE s306(bl) WITH g_passenger-number INTO g_message.
        add_message( i_probclass = probclass_medium ).
      ENDIF.

      " Check flight cancellations
      IF sy-index MOD 26 = 0.
        MESSAGE s307(bl) WITH g_passenger-number INTO g_message.
        add_message( i_probclass = probclass_medium ).
        g_passenger-everything_ok = ' '.
      ENDIF.

      " Everything OK for the passenger
      IF g_passenger-everything_ok = 'X'.
        MESSAGE s311(bl) WITH g_passenger-number INTO g_message.
        add_message( i_probclass = probclass_low ).
      ENDIF.
    ENDDO.
  ENDMETHOD.

  METHOD add_message.
    DATA: l_s_msg TYPE bal_s_msg.

    " Define message for the 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.

    CALL FUNCTION 'BAL_LOG_MSG_ADD'
      EXPORTING
        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.
  ENDMETHOD.

  METHOD display_logs.
    " Display the log file
    CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
      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.
  ENDMETHOD.

ENDCLASS.

***********************************************************************
************************* SELECTION SCREEN ****************************
***********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-001.
PARAMETERS:
  p_carrid TYPE bal_carrid DEFAULT lcl_application_log=>c_default_carrid,
  p_connid TYPE bal_connid DEFAULT lcl_application_log=>c_default_connid,
  p_fldate TYPE bal_fldate DEFAULT lcl_application_log=>c_default_fldate.
SELECTION-SCREEN END OF BLOCK b01.

***********************************************************************
************************* MAIN PROGRAM ********************************
***********************************************************************

START-OF-SELECTION.
  DATA(lo_app_log) = NEW lcl_application_log( ).

  " Create a log
  lo_app_log->create_log( ).

  " Perform various checks
  lo_app_log->check_flight_allowance( ).
  lo_app_log->check_weight( ).
  lo_app_log->check_passenger_capacity( ).
  lo_app_log->check_airplane_availability( ).
  lo_app_log->check_crew_availability( ).
  lo_app_log->check_crew_sleep_time( ).

  " Process all passengers
  lo_app_log->process_passengers( ).

  " Display the logs
  lo_app_log->display_logs( ).

 

2 Comments