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
Further I’ll be Declaring Few Methods
Implementation of these Methods
Selection Screen Elements
Initialization of the Class by creating the Object as per the Requirement, then Creating the Log and Displaying.
The Result Output Will Be Displayed as Below
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( ).
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 Further I’ll be Declaring Few MethodsImplementation of these Methods Selection Screen Elements Initialization of the Class by creating the Object as per the Requirement, then Creating the Log and Displaying. The Result Output Will Be Displayed as Below 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( ). Read More Application Development Blog Posts articles
#SAP