Topic 06 - Exercise - HungN6
Topic 06 - Exercise - HungN6
Step 3 : Check the source code and make sure you follow below Coding covnentio
Bước 3: Kiểm tra code xem có giống convention bên dưới chưa, nếu chưa thì sửa lại
Exercise 2: Recursion
1. Research what Recursion is in programming
https://afteracademy.com/blog/what-is-recursion-in-programming
*** For vietnamese material please check Google
2. Use Recursion to solve Fibonacci problem in Topic 2, instead of using LOOP
3. Recursion can make your program run forever. Please check careful that you can exit the Recu
4. Trường hợp vướn phải vòng lặp vô hạn hoặc xử lý không thể kết thúc, sử dụng tcode SM50 để tắt cưỡ
Print the contents of all global variables before the routine is called, at the beginning of the routine, at the
Write an executable program that contains 2 routines that prints all usernames in the system. (Check tab
1. First Routine: Get data from USR04
2. Second Routine: Print all the data
below Coding covnention
l that you can exit the Recursion. And DEBUG in your first run
ử dụng tcode SM50 để tắt cưỡng bức (End Process) hoặc thông báo Senior trong nhóm
eginning of the routine, at the end of the routine (after all values are changed) and after the PERFORM statement.
mes in the system. (Check table USR04 and its content in transaction SE11, SE16 or SE16N).
FORM statement.
System : S4J
Exercise 1:
Target Table: SPFLI Flight schedule
SLFIGHT Flight Information
T005T Country Name
SCARR Airline
Selection Screen:
Report Output:
*** You can check the Technical design for program outline
*&---------------------------------------------------------------------*
*& DATA DECLARATION
*&---------------------------------------------------------------------*
5. Create a sorted table from Table Name SCARR to store Airliner Name
*&---------------------------------------------------------------------*
*& SELECTION SCREEN
*&---------------------------------------------------------------------*
*** Check Exercise sheet
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
4.1. At new block of FLDATE, CARRID, CONNID, COUNTRYFR, CITYFROM, COUNTRYTO, CITYTO
Read Sorted Table of TY_COUNTRY into a work area (Work Area: Country From)
using table key LAND1 = COUNTRYFR of current looping record
Read Sorted Table of TY_COUNTRY into a work area (Work Area: Country To)
using table key LAND1 = COUNTRYTO of current looping record
Selection screen
Report output
INCLUDE yHUNGN6_D06_incl_definations
Form get_data_flight
Form output_report
Form main_program
Selection screen
Output report
**Include
INCLUDE yHUNGN6_D06_incl_definations.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b-01 WITH FRAME TITLE TEXT-t01.
SELECT-OPTIONS fldate FOR gs_report-fldate.
SELECT-OPTIONS carrid FOR gs_report-carrid.
SELECT-OPTIONS connid FOR gs_report-connid.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS countfr FOR gs_report-countryfr.
SELECT-OPTIONS cityfrom FOR gs_report-cityfrom.
SELECT-OPTIONS countto FOR gs_report-countryto.
SELECT-OPTIONS cityto FOR gs_report-cityto.
SELECTION-SCREEN END OF BLOCK b-01.
*Main Processing
PERFORM main_program.
*&---------------------------------------------------------------------*
*& Form get_data_flight
*&---------------------------------------------------------------------*
*& Select data from SFLIGHT inner join SPFLI
*&---------------------------------------------------------------------*
*& --> c_t_s_REPORT
*&---------------------------------------------------------------------*
FORM get_data_flight USING c_ts_report TYPE ty_t_report.
SELECT
spfli~countryfr,
spfli~cityfrom,
spfli~countryto,
spfli~cityto,
sflight~fldate,
spfli~carrid,
spfli~connid,
spfli~deptime,
spfli~arrtime,
spfli~period,
sflight~seatsmax,
sflight~seatsmax_b,
sflight~seatsmax_f,
sflight~seatsocc,
sflight~seatsocc_b,
sflight~seatsocc_f
FROM sflight INNER JOIN spfli
** Join Condition
ON sflight~carrid = spfli~carrid
AND sflight~connid = spfli~connid
**Query Condition
WHERE sflight~fldate IN @fldate
AND spfli~carrid IN @carrid
AND spfli~connid IN @connid
AND spfli~countryfr IN @countfr
AND spfli~cityfrom IN @cityfrom
AND spfli~countryto IN @countto
AND spfli~cityto IN @cityto
**Order By
ORDER BY spfli~cityfrom,
spfli~cityto,
sflight~fldate,
spfli~deptime,
spfli~arrtime
ENDFORM.
*&---------------------------------------------------------------------*
*& Form get_data_country
*&---------------------------------------------------------------------*
*& Select data from Country Text Table T005T
*&---------------------------------------------------------------------*
*& <-- C_TS_COUNTRY
*&---------------------------------------------------------------------*
FORM get_data_country CHANGING c_ts_country TYPE ty_t_country.
SELECT land1, " Country code
landx " Country Name
FROM t005t
WHERE spras = @sy-langu
INTO TABLE @c_ts_country.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form get_airline_name
*&---------------------------------------------------------------------*
*& Select data from Airline Table SCARR
*&---------------------------------------------------------------------*
*& <-- C_TS_AIRLINE
*&---------------------------------------------------------------------*
FORM get_airline_name CHANGING c_ts_airline TYPE ty_t_airline.
SELECT * FROM scarr
INTO TABLE @c_ts_airline.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form output_report
*&---------------------------------------------------------------------*
*& Loop at internal table of TY_REPORT to output report
*&---------------------------------------------------------------------*
*& --> U_T_REPORT
*& --> U_T_COUNTRY
*& --> U_T_SCARR
*&---------------------------------------------------------------------*
FORM output_report USING u_t_flisch TYPE ty_t_report
u_t_country TYPE ty_t_country
u_t_scarr TYPE ty_t_airline.
LOOP AT u_t_flisch ASSIGNING FIELD-SYMBOL(<lfs_flisch>).
DATA: ls_countryfr TYPE ty_country.
DATA: ls_countryto TYPE ty_country.
AT NEW cityto.
ULINE.
WRITE:/(20) 'Country from:',(20) ls_countryfr-landx,(20) '-Country to:',(2
/(20) 'City From:',(20) <lfs_flisch>-cityfrom,(20) '-City To:',(20) <lfs_f
ULINE.
ENDAT.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form main_program
*&---------------------------------------------------------------------*
*& Main Program
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM main_program .
**Declare a sorted table from Table Name SCARR to store Airliner Name
DATA: lt_s_scarr TYPE ty_t_airline.
**Select data from SFLIGHT inner join SPFLI
PERFORM get_data_flight USING lt_report.
ENDFORM.
Exercise 2
*&---------------------------------------------------------------------*
*& Report YHUNGN6_D02_EX02
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yhungn6_d06_ex02.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
**Parameter for number of Iterations, accept integer number
*Parameters for number of Iterations
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE TEXT-t01.
PARAMETERS: p_number TYPE i OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.
START-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form fibonanci_calculation
*&---------------------------------------------------------------------*
*& Fibonanci Main Calculation Logic
*&---------------------------------------------------------------------*
*& --> LD_NUMBER
*& --> LD_RESULT
*&---------------------------------------------------------------------*
FORM fibonanci_calculation CHANGING p_number
p_ld_number1
p_ld_number2
p_ld_number3
p_ld_iteration TYPE i.
IF p_number > 0.
WRITE: / p_ld_iteration && |. | && p_ld_number1.
p_ld_number3 = p_ld_number1 + p_ld_number2.
p_ld_number1 = p_ld_number2.
P_ld_number2 = p_ld_number3.
p_number -= 1.
p_ld_iteration += 1.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form main_fibo
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_NUMBER
*&---------------------------------------------------------------------*
FORM main_fibo USING p_numbers TYPE i.
ld_number1 = 0.
ld_number2 = 1.
ENDFORM.
Exercise 3
*&---------------------------------------------------------------------*
*& Report YHUNGN6_D06_EX03
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yhungn6_d06_ex03.
*Declare 4 Datas and Insert Value
DATA: gd_num1 TYPE i VALUE 1,
gd_num2 TYPE i VALUE 2,
gd_num3 TYPE i VALUE 3,
gd_num4 TYPE i VALUE 4.
*Caling SubRoutine with 2 Value for Using and 2 Value for Changing
PERFORM modify_values USING gd_num1
gd_num2
CHANGING gd_num3
gd_num4.
*&---------------------------------------------------------------------*
*& Form modify_values
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GV_NUM1
*& --> GV_NUM2
*& <-- GV_NUM3
*& <-- GV_NUM4
*&---------------------------------------------------------------------*
FORM modify_values USING VALUE(p_gd_num1)
VALUE(p_gd_num2) "If omit Value, change the Value inside Form still affect
TYPE i
CHANGING p_gd_num3
p_gd_num4
TYPE i.
WRITE: / 'At the end of the routine (after all values are changed):'.
WRITE: / 'Number 1 Using = ' && | | && p_gd_num1,
/ 'Number 2 Using = ' && | | && p_gd_num2,
/ 'Number 3 Changing = ' && | | && p_gd_num3,
/ 'Number 4 changing = ' && | | && p_gd_num4.
ENDFORM.
Exercise 4
*&---------------------------------------------------------------------*
*& Report YHUNGN6_D06_EX04
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT yhungn6_d06_ex04.
***Include
INCLUDE yhungn6_incl_definations.
*Main Processing
PERFORM main_program.
*&---------------------------------------------------------------------*
*& Form main_program
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM main_program .
DATA: lt_username TYPE ty_t_username.
---------------------*
---------------------*
---------------------*
---------------------*
TLE TEXT-t01.
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
y_t_country.
---------------------*
---------------------*
---------------------*
---------------------*
y_t_airline.
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
er number
LE TEXT-t01.
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
---------------------*
_username.
---------------------*
---------------------*
---------------------*
---------------------*
_username.
username>).