ABAP101 Exercises - Beginner
ABAP101 Exercises - Beginner
Solution:
REPORT z_abap101_001.
Declare an integer.
Solution:
REPORT z_abap101_002.
DATA number_of_employees TYPE i.
Solution:
REPORT z_abap101_003.
TYPES number_of_unpaid_invoices TYPE n LENGTH 7.
Solution:
REPORT z_abap101_004.
TYPES creation_date TYPE d.
Solution:
REPORT z_abap101_005.
TYPES last_changed_at TYPE t.
Declare a structure type with 5 fields, each field with the same types from exercises 1 to 5.
Solution:
REPORT
z_abap101_006.
Notes:
: (semicolon) is recommend in this case
name - This is a char with length 10
n_employees - This component (called n_employees has the same type of the variable, but it is not
reusable)
Solution:
REPORT z_abap101_007.
TYPES same_type_of_sflight TYPE SFLIGHT.
Notes:
Double click on SFLIGHT
It's a global definition (it's inside the repository)
This is a TYPE, not a variable.
Declare a structure type with the following components of the global structure SFLIGHT:
CARRID, CONNID, FLDATE, PRICE, CURRENCY, PLANETYPE, SEATSMAX and
SEATSOCC.
Solution:
REPORT
z_abap101_008.
BEGIN OF some_components_sflight.
carrid
TYPE sflight-carrid.
connid
TYPE sflight-connid.
fldate
TYPE sflight-fldate.
price
TYPE sflight-price .
currency TYPE sflight-currency .
planetype TYPE sflight-planetype.
seatsmax TYPE sflight-seatsmax .
seatsoccupied TYPE sflight-seatsocc . " Different name for a component
END OF some_components_sflight.
Declare a structure type with the following components of the global structure SBOOK:
CARRID, CONNID, FLDATE, BOOKID, CUSTOMID.
Solution:
REPORT
z_abap101_009.
Declare a structure containing all the fields mentioned in exercises 8 and 9. Check it using
the ABAP Debugger.
Solution:
REPORT
z_abap101_010.
OF sflight_sbook.
some_components_sflight_2.
flight_booking AS book RENAMING WITH SUFFIX _book.
sflight_sbook.
Solution:
REPORT
z_abap101_011.
Declare a table type with all components of the global structure SFLIGHT.
Solution:
REPORT
Z_ABAP101_012.
Solution:
REPORT
Z_ABAP101_013.
Declare a table type with the following components of the table SBOOK: CARRID,
CONNID, FLDATE, BOOKID, CUSTOMID but using CUSTOMID as part of the table key.
Solution:
REPORT
Z_ABAP101_014.
Declare a variable of type character with 10 positions and give it Hello ABAP as an initial
value.
Solution:
REPORT
Z_ABAP101_015.
Declare a variable of numeric type with 4 positions and initial value 1234.
Solution:
REPORT
Z_ABAP101_016.
Solution:
REPORT
z_abap101_017.
Solution:
REPORT
z_abap101_018.
Solution:
REPORT
Z_ABAP101_019.
Solution:
REPORT
z_abap101_020.
Solution:
REPORT
Z_ABAP101_021.
Declare a variable of the same type of field carrid from table SPFLI.
Solution:
REPORT
Z_ABAP101_022.
Solution:
REPORT
z_abap101_023.
Solution:
REPORT
z_abap101_024.
Declare a structure with fields of the table SFLIGHT carrid, CONNID, FLDATE, PRICE,
CURRENCY, PLANETYPE, and SEATSMAX SEATSOCC.
Solution:
REPORT
z_abap101_025.
Declare a structure with all fields of the table SBOOK and the field TELEPHONE from
SCUSTOM table.
Solution:
REPORT
z_abap101_026.
Declare an internal table with fields of the table SBOOK CARRID, CONNID, FLDATE,
BOOKID, CUSTOMID.
Solution:
REPORT
z_abap101_027.
Declare an internal table with all table fields from table SCARR.
Solution:
REPORT
z_abap101_028.
Solution:
REPORT
z_abap101_029.
Declare an internal table with all table fields from SCARR and the field TELEPHONE
from table SCUSTOM.
Solution:
REPORT
z_abap101_030.
Solution:
REPORT
z_abap101_031.
Declare two constants which contain the values 'X' (true) and ' ' (false).
Note: This is a common practice as ABAP does not contain a boolean primitive type.
Solution:
REPORT
z_abap101_032.
Solution:
REPORT
z_abap101_033.
Solution:
REPORT
z_abap101_034.
Declare a work area of 5 constant components. All of them should have different primitive
types.
Solution:
REPORT
z_abap101_035.
Answer:
No. No initial value can be specified for internal tables and references
REPORT
z_abap101_036.
Declare all types and constants from type-pools ABAP and ICON.
Solution:
REPORT
z_abap101_037.
Solution:
REPORT
z_abap101_038.
Declare a type which is used in another type, variable, work area, internal table and
constant.
Solution:
REPORT
z_abap101_039.
Declare a variable which is used in another variable, type, work area, internal table and
constant.
Solution:
REPORT
z_abap101_040.
Solution:
REPORT
z_abap101_041.
START-OF-SELECTION.
DATA v_result TYPE i.
v_result = 2 + 3 * 5. " 25 or 17?
WRITE v_result.
Write an executable program that get two integers inside variables and perform the addition,
subtraction, multiplication, division and power between them.
Solution:
REPORT
z_abap101_042.
Write an executable program that get two integers inside parameters and perform the
addition, subtraction, multiplication, division and power between them.
Solution:
REPORT
z_abap101_043.
Write an executable program that concatenates two words and write the result.
Solution:
REPORT
z_abap101_044.
Write an executable program that concatenates two words and the current month, separating
each part by a "-" and write the result.
Solution:
REPORT
z_abap101_045.
Write an executable program that reads the current system date and write it in your language
in text format.
Ex: 20140727 should be written as July the Twenty-Seventh, 2014
Solution:
REPORT
z_abap101_046.
'January'.
'February'.
'March'.
'April'.
'May'.
'June'.
'July'.
'August'.
'September'.
'October'.
'November'.
'December'.
ENDCASE.
* Handle day
IF sy-datum+6(2) = '01'.
v_day = 'first'.
ELSEIF sy-datum+6(2) = '02'.
v_day = 'second'.
WHEN '23'.
v_day = 'twenty-third'.
WHEN '24'.
v_day = 'twenty-fourth'.
WHEN '25'.
v_day = 'twenty-fifth'.
WHEN '26'.
v_day = 'twenty-six'.
WHEN '27'.
v_day = 'twenty-seventh'.
WHEN '28'.
v_day = 'twenty-eighth'.
WHEN '29'.
v_day = 'twenty-first'.
WHEN '30'.
v_day = 'thirtieth'.
WHEN '31'.
v_day = 'thirty-first'.
ENDCASE.
ENDIF.
ENDIF.
* Handle Year
v_year = sy-datum(4).
* print result
WRITE: v_month, ' the ',
Write an executable program that reads the current system time and write the time in 6
different zones (3 of them should be compulsorily Greenwich, Delhi and Brasilia).
Solution:
REPORT
DATA
DATA
DATA
DATA
DATA
DATA
z_abap101_047.
v_timezone1
v_timezone2
v_timezone3
v_timezone4
v_timezone5
v_timezone6
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
tznzone
tznzone
tznzone
tznzone
tznzone
tznzone
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
v_timestamp
v_timestamp
v_timestamp
v_timestamp
v_timestamp
v_timestamp
TIME
TIME
TIME
TIME
TIME
TIME
ZONE
ZONE
ZONE
ZONE
ZONE
ZONE
v_timezone1.
v_timezone2.
v_timezone3.
v_timezone4.
v_timezone5.
v_timezone6.
NEW-LINE.
NEW-LINE.
NEW-LINE.
NEW-LINE.
NEW-LINE.
NEW-LINE.
Write an executable program that counts how many vowels are in the name of the user
running the program and print the result
Solution:
REPORT
z_abap101_048.
v_vowels_count.
v_vowels_count.
v_vowels_count.
v_vowels_count.
v_vowels_count.
* Another option
FIND ALL OCCURRENCES OF REGEX 'A|E|I|O|U' IN v_user MATCH COUNT
v_vowels_count.
WRITE v_vowels_total.
Write an executable program that counts a string length and if it's bigger than 2o characteres,
write 'Too big'. If not, write the string length.
Solution:
REPORT
z_abap101_049.
Write an executable program that counts from 1 to 100 and for each multiple of 8, write the
message: "The number [number] is a multiple of 8 ".
Solution:
REPORT
z_abap101_050.
Write an executable program that contains a routine which prints all usernames in the
system. (Check table USR04 and its content in transaction SE11, SE16 or SE16N).
Solution:
REPORT
z_abap101_051.
For this exercise, you should Read the help from command FORM completely. Then, write
an executable program that has a routine that receives four global variables and change their value.
Each variable will be received in a different way: 2 of them using the addition USING and the other
2 using the addition CHANGING from the FORM command. For each pair use and omit the adding
VALUE. Print the contents of all global variables before the routine is called, at the beginning of the
routine, at the end of the routine (after all values are changed) and after the PERFORM statement.
See how the contents of variables behave using the debugger.
Solution:
REPORT
DATA
DATA
DATA
DATA
z_abap101_052.
gv_a
gv_b
gv_c
gv_d
TYPE
TYPE
TYPE
TYPE
i
i
i
i
VALUE
VALUE
VALUE
VALUE
1.
2.
3.
4.
*&---------------------------------------------------------------------*
*&
Form form_parameters
*&---------------------------------------------------------------------*
* Get 4 parameters in different ways
*----------------------------------------------------------------------*
*
-->US_A
text
*
-->(USV_B)
text
*
-->CH_C
text
*
-->(CHV_D)
text
*----------------------------------------------------------------------*
FORM form_parameters
USING
us_a TYPE i
value(usv_b) TYPE i
CHANGING ch_c TYPE i
value(chv_d) TYPE i.
WRITE 'Inside FORM.'. NEW-LINE.
WRITE: 'us_a: ', us_a. NEW-LINE.
WRITE: 'usv_b: ', usv_b. NEW-LINE.
WRITE: 'ch_c: ', ch_c. NEW-LINE.
WRITE: 'chv_d: ', chv_d. NEW-LINE.
us_a = us_a +
usv_b = usv_b
ch_c = ch_c +
chv_d = chv_d
10.
+ 10.
10.
+ 10.
'gv_a:
'gv_b:
'gv_c:
'gv_d:
',
',
',
',
gv_a.
gv_b.
gv_c.
gv_d.
ENDFORM.
NEW-LINE.
NEW-LINE.
NEW-LINE.
NEW-LINE.
"form_parameters
START-OF-SELECTION.
WRITE 'Before FORM'. NEW-LINE.
WRITE: 'gv_a: ', gv_a. NEW-LINE.
WRITE: 'gv_b: ', gv_b. NEW-LINE.
WRITE: 'gv_c: ', gv_c. NEW-LINE.
WRITE: 'gv_d: ', gv_d. NEW-LINE.
PERFORM form_parameters
USING
gv_a
gv_b
CHANGING
gv_c
gv_d
.
WRITE 'After FORM'. NEW-LINE.
WRITE: 'gv_a: ', gv_a. NEW-LINE.
WRITE: 'gv_b: ', gv_b. NEW-LINE.
WRITE: 'gv_c: ', gv_c. NEW-LINE.
WRITE: 'gv_d: ', gv_d. NEW-LINE.
Write an executable program that has a routine that receives two numbers and returns the
largest of them, If the numbers are equal return the number itself.
Solution:
REPORT
z_abap101_053.
"get_larger
START-OF-SELECTION.
PERFORM get_larger USING 1 2 CHANGING gv_largest.
WRITE gv_largest EXPONENT 0. NEW-LINE.
PERFORM get_larger USING 4 3 CHANGING gv_largest.
WRITE gv_largest EXPONENT 0. NEW-LINE.
PERFORM get_larger USING 5 5 CHANGING gv_largest.
WRITE gv_largest EXPONENT 0. NEW-LINE.
PERFORM get_larger USING '6.2' '7.1' CHANGING gv_largest.
WRITE gv_largest EXPONENT 0. NEW-LINE.
Write an executable program that has a routine that receives two numbers and return a flag
(character with length 1). If the numbers are equal, set the flag with 'X. Otherwise set the flag to
space.
Solution:
REPORT
z_abap101_054.
"get_larger
START-OF-SELECTION.
PERFORM set_flag_if_equal USING 1 1 CHANGING gv_flag.
PERFORM set_flag_if_equal USING 4 3 CHANGING gv_flag.
PERFORM set_flag_if_equal USING 5 5 CHANGING gv_flag.
PERFORM set_flag_if_equal USING '6.2' '7.1' CHANGING gv_flag.
Write an executable program that has a routine that takes two numbers and writes the result
of the operation [higher_number / lower_number] if the numbers are different. If they are equal,
write the result of the operation [number ^ 2].
Solution:
REPORT
z_abap101_055.
"get_larger
*&---------------------------------------------------------------------*
*&
Form get_larger
*&---------------------------------------------------------------------*
* Compares 2 numbers and returns a flag (true) if they are equal
*----------------------------------------------------------------------*
*
-->NUMBER_A
Number A
*
-->NUMBER_B
Number B
*
-->FLAG
Equal numbers indicator
*----------------------------------------------------------------------*
FORM set_flag_if_equal
USING
number_a TYPE f
number_b TYPE f
CHANGING
flag TYPE c.
IF number_a = number_b.
flag = abap_true.
*
WRITE flag. NEW-LINE.
ELSE.
flag = abap_false.
ENDIF.
ENDFORM.
"get_larger
*&---------------------------------------------------------------------*
*&
Form division_or_power2
*&---------------------------------------------------------------------*
* takes two numbers and writes the result of the operation
* [higher_number / lower_number] if the numbers are different.
* If they are equal, write the result of the operation [number ^ 2].
*----------------------------------------------------------------------*
*
-->NUMBER_A
text
*
-->NUMBER_B
text
*
-->RESULT
text
*----------------------------------------------------------------------*
FORM division_or_power2
USING
number_a TYPE f
number_b TYPE f
CHANGING
result TYPE f.
DATA lv_number_equal TYPE c.
PERFORM set_flag_if_equal
USING
number_a
number_b
CHANGING
lv_number_equal.
IF lv_number_equal = abap_true.
result = number_a ** 2.
ELSE.
DATA lv_larger_number TYPE f.
PERFORM get_larger USING number_a number_b CHANGING lv_larger_number.
IF number_a = lv_larger_number.
result = number_a / number_b.
ELSE.
result = number_b / number_a.
ENDIF.
ENDIF.
WRITE result EXPONENT 0.
NEW-LINE.
ENDFORM.
START-OF-SELECTION.
"division_or_power2
PERFORM division_or_power2
USING 1 1
CHANGING gv_result.
PERFORM division_or_power2
USING 3 3
CHANGING gv_result.
PERFORM division_or_power2
USING 6 2
CHANGING gv_result.
PERFORM division_or_power2
USING 2 6
CHANGING gv_result.
PERFORM division_or_power2
USING 10 2
CHANGING gv_result.
PERFORM division_or_power2
USING 2 10
CHANGING gv_result.
Write an executable program that does NOT have a routine. The program should include a
work area with 5 fields of different types or more. Then, it must be populated and its fields should
be printed one per line, separated by one horizontal line. After testing your program, change the
output separating each field by two lines. During this process, refactor your code to include a
routine which handle the separation between each line.
Solution:
REPORT
z_abap101_056.
PERFORM separe_line.
*&---------------------------------------------------------------------*
*&
Form separe_line
*&---------------------------------------------------------------------*
* Separe each output line
*----------------------------------------------------------------------*
FORM separe_line.
DO 2 TIMES.
ULINE.
ENDDO.
ENDFORM.
"separe_line
Write an executable program with a routine that receives a work area containing five
different data types and count how many components are not filled. Finally, print result.
Solution:
REPORT
z_abap101_057.
"count_initial_components
START-OF-SELECTION.
PERFORM count_initial_components USING work_area.
work_area-str = 'This is a string'.
PERFORM count_initial_components USING work_area.
work_area-date = '20141225'. " Christmas
PERFORM count_initial_components USING work_area.
work_area-time = '134059'.
PERFORM count_initial_components USING work_area.
work_area-integer = 101.
PERFORM count_initial_components USING work_area.
work_area-hex = '0123456789ABCDEF'.
PERFORM count_initial_components USING work_area.
Write an executable program with a routine that receives a work area with at least 4
components. All components can only be declared using numeric and different primitive types. Your
routine should sum the values from all components and print the result.
Solution:
REPORT
z_abap101_058.
"sum_numeric_components
START-OF-SELECTION.
DATA work_area TYPE ty_work_area.
DATA work_area_doubled TYPE ty_work_area.
work_area-integer = 2.
work_area-float = '2.5'.
work_area-pack = '2.12345'.
work_area-decfloat34 = 1000000000000000000000000000000.
PERFORM sum_numeric_components USING work_area.
work_area_doubled-integer = work_area-integer * 2.
work_area_doubled-float = work_area-float * 2.
work_area_doubled-pack = work_area-pack * 2.
work_area_doubled-decfloat34 = work_area-decfloat34 * 2.
PERFORM sum_numeric_components USING work_area_doubled.
Write an executable program which has a routine that receives a work area with 3 char
components and 3 numeric components. The routine should clear some component values
according to the following rules:
1. Clear char components only if the sum of the numeric components is odd (ignoring possible
decimal places)
2. Clear numeric components only if the sum of vowels in the three char components is even
(ignoring lower/upper case)
Solution:
REPORT
z_abap101_059.
TYPES:
BEGIN OF ty_char_and_numeric,
char_comp1 TYPE string,
char_comp2 TYPE c LENGTH 3,
char_comp3 TYPE n LENGTH 10,
num_comp1 TYPE i,
num_comp2 TYPE f,
num_comp3 TYPE decfloat16,
END OF ty_char_and_numeric.
*&---------------------------------------------------------------------*
*&
Form clear_char_or_numeric
*&---------------------------------------------------------------------*
* This routine clears some component values according to the following rules:
* a. Clear char components only if the sum of the numeric components is odd
(ignoring possible decimal places)
* b. Clear numeric components only if the sum of vowels in the three char
components is even (ignoring lower/upper case)
*----------------------------------------------------------------------*
*
-->US_WA_CHAR_AND_NUMERIC text
*----------------------------------------------------------------------*
FORM clear_char_or_numeric USING us_wa_char_and_numeric TYPE
ty_char_and_numeric.
DATA lv_mod_result TYPE i.
DATA lv_sum_numeric TYPE i.
lv_sum_numeric =
us_wa_char_and_numeric-num_comp1 +
us_wa_char_and_numeric-num_comp2 +
us_wa_char_and_numeric-num_comp3.
lv_mod_result = lv_sum_numeric MOD 2.
IF lv_mod_result <> 0.
CLEAR:
us_wa_char_and_numeric-char_comp1,
us_wa_char_and_numeric-char_comp2,
us_wa_char_and_numeric-char_comp3.
RETURN.
ENDIF.
DATA lv_vowel_count TYPE i.
DATA lv_current_vowel_count TYPE i.
FIND ALL OCCURRENCES OF REGEX 'a|e|i|o|u|A|E|I|O|U' IN us_wa_char_and_numericchar_comp1 MATCH COUNT lv_current_vowel_count.
lv_vowel_count = lv_vowel_count + lv_current_vowel_count.
FIND ALL OCCURRENCES OF REGEX 'a|e|i|o|u|A|E|I|O|U' IN us_wa_char_and_numericchar_comp2 MATCH COUNT lv_current_vowel_count.
lv_vowel_count = lv_vowel_count + lv_current_vowel_count.
FIND ALL OCCURRENCES OF REGEX 'a|e|i|o|u|A|E|I|O|U' IN us_wa_char_and_numericchar_comp3 MATCH COUNT lv_current_vowel_count.
lv_vowel_count = lv_vowel_count + lv_current_vowel_count.
lv_mod_result = lv_vowel_count MOD 2.
IF lv_mod_result = 0.
CLEAR:
us_wa_char_and_numeric-num_comp1,
us_wa_char_and_numeric-num_comp2,
us_wa_char_and_numeric-num_comp3.
RETURN.
ENDIF.
ENDFORM.
"clear_char_or_numeric
START-OF-SELECTION.
DATA wa_char_cleared TYPE ty_char_and_numeric.
DATA wa_numeric_cleared TYPE ty_char_and_numeric.
wa_char_cleared-char_comp1 = 'This should be clea'.
wa_char_cleared-char_comp2 = 'red'.
wa_char_cleared-char_comp3 = '0123456789'.
wa_char_cleared-num_comp1 = 1.
wa_char_cleared-num_comp2 = 10.
wa_char_cleared-num_comp3 = 100.
WRITE:
wa_char_cleared-char_comp1,
wa_char_cleared-char_comp2,
wa_char_cleared-char_comp3,
wa_char_cleared-num_comp1,
wa_char_cleared-num_comp2,
wa_char_cleared-num_comp3.
NEW-LINE.
PERFORM clear_char_or_numeric USING wa_char_cleared.
WRITE:
wa_char_cleared-char_comp1,
wa_char_cleared-char_comp2,
wa_char_cleared-char_comp3,
wa_char_cleared-num_comp1,
wa_char_cleared-num_comp2,
wa_char_cleared-num_comp3.
NEW-LINE.
ULINE.
wa_numeric_cleared-char_comp1 = 'aeiouAEIOU'.
wa_numeric_cleared-char_comp2 = 'BCD'.
wa_numeric_cleared-char_comp3 = '0123456789'.
wa_numeric_cleared-num_comp1 = 2. " even
wa_numeric_cleared-num_comp2 = 10.
wa_numeric_cleared-num_comp3 = 100.
WRITE:
wa_numeric_cleared-char_comp1,
wa_numeric_cleared-char_comp2,
wa_numeric_cleared-char_comp3,
wa_numeric_cleared-num_comp1,
wa_numeric_cleared-num_comp2,
wa_numeric_cleared-num_comp3.
NEW-LINE.
PERFORM clear_char_or_numeric USING wa_numeric_cleared.
WRITE:
wa_numeric_cleared-char_comp1,
wa_numeric_cleared-char_comp2,
wa_numeric_cleared-char_comp3,
wa_numeric_cleared-num_comp1,
wa_numeric_cleared-num_comp2,
wa_numeric_cleared-num_comp3.
NEW-LINE.
Write an executable program which contains three internal tables (their type must contain at
least three components of different data types). Each table will have a different type (standard,
sorted and hashed). Add 3 identical values in each table and view the contents of each table in the
debugger.
Solution:
REPORT
z_abap101_060.
Write an executable program which has a routine that receives an internal table and print how many
fields are filled with their default value (the line type of the table must have at least 4 fields).
Hint: each primitive type has a default value. For example, 0 (zero) is the default value of integers
whereas space ( ' ' ) is the default value of characters.
Solution:
REPORT
z_abap101_061.
TYPES:
BEGIN OF ty_line,
id TYPE c LENGTH 10,
name TYPE string,
value TYPE i,
creation_date TYPE d,
END OF ty_line.
TYPES: ty_table TYPE STANDARD TABLE OF ty_line.
*&---------------------------------------------------------------------*
*&
Form count_initial_fields_of_table
*&---------------------------------------------------------------------*
* Counts how many fields are filled with their default value
*----------------------------------------------------------------------*
*
-->US_TABLE
internal table
*----------------------------------------------------------------------*
FORM count_initial_fields_of_table USING us_table TYPE ty_table.
DATA lwa_line TYPE ty_line.
DATA lv_initial_field_total TYPE i.
LOOP AT us_table INTO lwa_line.
IF lwa_line-id IS INITIAL.
lv_initial_field_total = lv_initial_field_total + 1.
ENDIF.
IF lwa_line-name IS INITIAL.
lv_initial_field_total = lv_initial_field_total + 1.
ENDIF.
IF lwa_line-value IS INITIAL.
lv_initial_field_total = lv_initial_field_total + 1.
ENDIF.
IF lwa_line-creation_date IS INITIAL.
lv_initial_field_total = lv_initial_field_total + 1.
ENDIF.
ENDLOOP.
WRITE: 'Number of initial values: ', lv_initial_field_total.
NEW-LINE.
ENDFORM.
"count_initial_fields_of_table
START-OF-SELECTION.
DATA itab TYPE ty_table.
DATA wa TYPE ty_line.
wa-id = '1'.
wa-name = 'John'.
wa-value = 50.
wa-creation_date = '20140727'.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_table USING itab.
wa-id = '2'.
wa-name = 'Mary'.
wa-value = 20.
* wa-creation_date = ?.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_table USING itab.
wa-id = '3'.
wa-name = 'Max'.
* wa-value = ?.
* wa-creation_date = ?.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_table USING itab.
wa-id = '4'.
* wa-name = ?.
* wa-value = ?.
* wa-creation_date = ?.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_table USING itab.
Write an executable program which has a routine that receives an internal table and prints
how many fields are blank by line (the type of table must have at least 4 fields). Output must be
generated as:
Line [line number] => [number of blank fields] + " blank fields"
Total: [total number of blank fields]
Solution:
REPORT
z_abap101_062.
TYPES:
BEGIN OF ty_line,
id TYPE c LENGTH 10,
name TYPE string,
value TYPE i,
creation_date TYPE d,
END OF ty_line.
TYPES: ty_table TYPE STANDARD TABLE OF ty_line.
*&---------------------------------------------------------------------*
*&
Form count_initial_fields_of_line
*&---------------------------------------------------------------------*
* Counts and prints how many fields are blank by line
*----------------------------------------------------------------------*
*
-->US_TABLE
internal table
*----------------------------------------------------------------------*
FORM count_initial_fields_of_line USING us_table TYPE ty_table.
DATA lwa_line TYPE ty_line.
DATA lv_initial_field_total TYPE i .
DATA lv_initial_field TYPE i.
LOOP AT us_table INTO lwa_line.
CLEAR lv_initial_field .
IF lwa_line-id IS INITIAL.
lv_initial_field = lv_initial_field + 1.
ENDIF.
IF lwa_line-name IS INITIAL.
lv_initial_field = lv_initial_field + 1.
ENDIF.
IF lwa_line-value IS INITIAL.
lv_initial_field = lv_initial_field + 1.
ENDIF.
IF lwa_line-creation_date IS INITIAL.
lv_initial_field = lv_initial_field + 1.
ENDIF.
WRITE: 'Line ', sy-tabix, ' => ', lv_initial_field, ' blank fields'.
NEW-LINE.
lv_initial_field_total = lv_initial_field_total + lv_initial_field.
ENDLOOP.
WRITE: 'Total: ', lv_initial_field_total.
WRITE: sy-uline.
ENDFORM.
"count_initial_fields_of_line
START-OF-SELECTION.
DATA itab TYPE ty_table.
DATA wa TYPE ty_line.
wa-id = '1'.
wa-name = 'John'.
wa-value = 50.
wa-creation_date = '20140727'.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_line USING itab.
wa-id = '2'.
wa-name = 'Mary'.
wa-value = 20.
* wa-creation_date = ?.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_line USING itab.
wa-id = '3'.
wa-name = 'Max'.
* wa-value = ?.
* wa-creation_date = ?.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_line USING itab.
*
*
wa-id = '4'.
wa-name = ?.
wa-value = ?.
wa-creation_date = ?.
APPEND wa TO itab.
CLEAR wa.
PERFORM count_initial_fields_of_line USING itab.
Write an executable program which has a routine that receives a standard internal table. The
line type used in the internal table declaration must contain at least three components any text type.
The routine should replace all occurrences of "space" by a "_" (underscore) using work areas (not
field symbols). Print the table contents before and after calling the routine. The internal table must
be populated with at least 10 records and contemplating some fields that have "space" in all field
values, other records containing spaces in just a few fields and other records without spaces at all.
Solution:
REPORT
z_abap101_063.
"replace_spaces
*&---------------------------------------------------------------------*
*&
Form print_itab
*&---------------------------------------------------------------------*
* Prints internal table contents
*----------------------------------------------------------------------*
*
-->US_ITAB
text
*----------------------------------------------------------------------*
FORM print_itab USING us_itab TYPE ty_tt_line.
DATA lwa TYPE ty_line.
LOOP AT us_itab INTO lwa.
WRITE: lwa-comp1 COLOR 1. NEW-LINE.
WRITE: lwa-comp2 COLOR 2. NEW-LINE.
WRITE: lwa-comp3 COLOR 3. NEW-LINE.
WRITE /.
ENDLOOP.
ENDFORM.
"print_itab
START-OF-SELECTION.
DATA itab TYPE ty_tt_line.
DATA wa TYPE ty_line.
wa-comp1 = 'ABAP 101'.
wa-comp2 = 'One Two Three Four Five Six Seven Eight Nine'.
wa-comp3 = '12345'.
APPEND wa TO itab.
CLEAR wa.
wa-comp1 = 'ABAP101'.
wa-comp2 = 'One/Two/Three/Four
wa-comp3 = '12 45'.
APPEND wa TO itab.
CLEAR wa.
Five/Six/Seven/Eight/Nine'.
Write an executable program which has a routine that receives a standard internal table. The
line type used in the internal table declaration must contain at least three components any text type.
The routine should replace all occurrences of "space" by a "_" (underscore) using field symbols
(and not work areas). Print the table contents before and after calling the routine. The internal table
must be populated with at least 10 records and contemplating some fields that have "space" in all
field values, other records containing spaces in just a few fields and other records without spaces at
all.
Solution:
REPORT
z_abap101_064.
ty_line.
<line>.
OF REGEX '\s' IN <line>-comp1 WITH '_' IN CHARACTER
ENDFORM.
"replace_spaces
*&---------------------------------------------------------------------*
*&
Form print_itab
*&---------------------------------------------------------------------*
* Prints internal table contents
*----------------------------------------------------------------------*
*
-->US_ITAB
text
*----------------------------------------------------------------------*
FORM print_itab USING us_itab TYPE ty_tt_line.
FIELD-SYMBOLS <line> TYPE ty_line.
LOOP AT us_itab ASSIGNING <line>.
WRITE: <line>-comp1 COLOR 1. NEW-LINE.
WRITE: <line>-comp2 COLOR 2. NEW-LINE.
WRITE: <line>-comp3 COLOR 3. NEW-LINE.
WRITE /.
ENDLOOP.
ENDFORM.
"print_itab
START-OF-SELECTION.
DATA itab TYPE ty_tt_line.
DATA wa TYPE ty_line.
wa-comp1 = 'ABAP 101'.
wa-comp2 = 'One Two Three Four Five Six Seven Eight Nine'.
wa-comp3 = '12345'.
APPEND wa TO itab.
CLEAR wa.
wa-comp1 = 'ABAP101'.
wa-comp2 = 'One/Two/Three/Four
wa-comp3 = '12 45'.
APPEND wa TO itab.
CLEAR wa.
Five/Six/Seven/Eight/Nine'.
Write an executable program which has a routine that receives an internal table of strings
and concatenates their values in four different ways:
1.
2.
3.
4.
Solution:
REPORT
z_abap101_065.
*&---------------------------------------------------------------------*
*&
Form concatenate_strings
*&---------------------------------------------------------------------*
* Concatenate strings from an internal table
*----------------------------------------------------------------------*
*
-->US_ITAB
Internal table of strings
*
-->CH_CONCATENATED_STRING Result
*----------------------------------------------------------------------*
FORM concatenate_strings
USING
us_t_strings TYPE table_of_strings
CHANGING
ch_concatenated_string TYPE string.
DATA t_copied_strings LIKE us_t_strings.
t_copied_strings = us_t_strings.
FIELD-SYMBOLS <string_line> TYPE string.
LOOP AT t_copied_strings ASSIGNING <string_line>.
CONCATENATE ch_concatenated_string <string_line> INTO
ch_concatenated_string.
ENDLOOP.
ENDFORM.
"concatenate_strings
*&---------------------------------------------------------------------*
*&
Form concatenate_strings_in_ways
*&---------------------------------------------------------------------*
* Receives an internal table of strings and concatenates
*
their values in four different ways:
* Way 1: concatenate internal table texts by the line order
* Way 2: concatenate internal table texts by the text ascending order
* Way 3: concatenate internal table texts by the text descending order
* Way 4: concatenate internal table texts by the line reverse order
*----------------------------------------------------------------------*
*
-->US_T_STRINGS
Table of strings
*
-->US_V_CONCAT_LOGIC
Concatenation way # (1-4)
*
-->CH_CONCATENATED_STRING Concatenated string
*----------------------------------------------------------------------*
FORM concatenate_strings_in_ways
USING
us_t_strings TYPE table_of_strings
us_v_concat_logic TYPE c
CHANGING ch_concatenated_string TYPE string.
DATA t_copied_strings LIKE us_t_strings.
t_copied_strings = us_t_strings.
CASE us_v_concat_logic.
WHEN '1'.
PERFORM concatenate_strings
USING
t_copied_strings
CHANGING
ch_concatenated_string
.
WHEN '2'.
SORT t_copied_strings.
PERFORM concatenate_strings
USING
t_copied_strings
CHANGING
ch_concatenated_string
.
WHEN '3'.
SORT t_copied_strings DESCENDING.
PERFORM concatenate_strings
USING
t_copied_strings
CHANGING
ch_concatenated_string
.
WHEN '4'.
* reverse loop
DATA vl_number_of_strings TYPE i.
FIELD-SYMBOLS <string_line> TYPE string.
DESCRIBE TABLE t_copied_strings LINES vl_number_of_strings.
WHILE vl_number_of_strings > 0.
"concatenate_strings_in_ways
START-OF-SELECTION.
DATA it_strings TYPE table_of_strings.
DATA gv_concatenated TYPE string.
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND
APPEND
'A'
'B'
'C'
'D'
'X'
'Y'
'Z'
'M'
'N'
'O'
TO
TO
TO
TO
TO
TO
TO
TO
TO
TO
it_strings.
it_strings.
it_strings.
it_strings.
it_strings.
it_strings.
it_strings.
it_strings.
it_strings.
it_strings.
PERFORM concatenate_strings_in_ways
USING
it_strings
'1'
CHANGING
gv_concatenated
.
WRITE: '1 - ', gv_concatenated, /.
CLEAR gv_concatenated.
PERFORM concatenate_strings_in_ways
USING
it_strings
'2'
CHANGING
gv_concatenated
.
WRITE: '2 - ', gv_concatenated, /.
CLEAR gv_concatenated.
PERFORM concatenate_strings_in_ways
USING
it_strings
'3'
CHANGING
gv_concatenated
.
WRITE: '3 - ', gv_concatenated, /.
CLEAR gv_concatenated.
PERFORM concatenate_strings_in_ways
USING
it_strings
'4'
CHANGING
gv_concatenated
.
WRITE: '4 - ', gv_concatenated, /.
CLEAR gv_concatenated.
Write an executable program with two parameters types as integers. The first represents a
number to be printed and the second represents the length of the number to be printed. Place zeros
to the left if necessary. Example:
Solution:
REPORT
z_abap101_066.
PARAMETERS:
p_number TYPE i,
p_length TYPE i.
START-OF-SELECTION.
DATA vl_number_string TYPE string.
DATA vl_number_length TYPE i.
DATA vl_number_with_left_zeros TYPE string.
vl_number_string = p_number.
CONDENSE vl_number_string NO-GAPS.
vl_number_length = strlen( vl_number_string ).
IF vl_number_length > p_length.
WRITE: vl_number_string(p_length).
ELSE.
DATA vl_zeros TYPE i.
DATA vl_left_zeros TYPE string.
vl_zeros = p_length - vl_number_length.
DO vl_zeros TIMES.
CONCATENATE vl_left_zeros '0' INTO vl_left_zeros.
ENDDO.
CONCATENATE vl_left_zeros vl_number_string INTO vl_number_with_left_zeros.
WRITE: vl_number_with_left_zeros.
ENDIF.
Write an executable program with two parameters which represents a base and exponent.
Print the result of exponentiation. As both parameters are required for the operation they should be
mandatory.
Solution:
REPORT
z_abap101_067.
Write an executable program with two parameters (a string and a number) The number
should be accepted only if it's less or equal to 25. The program should print the string as many times
as the value of the numeric parameter. The output should be as following
String = "ABAPers are not crazy people." Number = 21.
Line [1]: A
Line [2]: AB
Line [3]: ABA
Line [4]: ABAP
Line [5]: ABAPe
(...)
Line [21]: ABAPers are not crazy
Solution:
REPORT
z_abap101_068.
Write an executable program which has two internal tables, with a header line and the other
without. Add five records in each table. In the case of the one with header line, use it embed work
area. For the other one, use a work area declared explicitly. Print the contents of both internal tables.
Solution:
REPORT
z_abap101_069.
it_with_hat-id = 1.
it_with_hat-name = 'The One'.
it_with_hat-age = 10.
APPEND it_with_hat.
it_with_hat-id = 2.
it_with_hat-name = 'Bob'.
it_with_hat-age = 20.
APPEND it_with_hat.
it_with_hat-id = 3.
it_with_hat-name = 'Mary'.
it_with_hat-age = 30.
APPEND it_with_hat.
it_with_hat-id = 4.
it_with_hat-name = 'Chris'.
it_with_hat-age = 40.
APPEND it_with_hat.
it_with_hat-id = 5.
it_with_hat-name = 'Janet'.
it_with_hat-age = 50.
APPEND it_with_hat.
* Printing table WITHOUT header line
LOOP AT it_without_hat INTO wa_line.
WRITE: wa_line-id, wa_line-name, wa_line-age.
NEW-LINE.
ENDLOOP.
* Printing table WITH header line
LOOP AT it_with_hat.
WRITE: it_with_hat-id, it_with_hat-name, it_with_hat-age.
NEW-LINE.
ENDLOOP.
NEW-LINE.
*IF it_without_hat = it_with_hat. " Try to uncomment this IF
* WRITE 'Maybe the tables are not so equal because...'.
* NEW-LINE.
*ENDIF.
IF it_without_hat = it_with_hat[].
WRITE ' ... without using []s we are using the work area and not the internal
table'.
ENDIF.
Have a routine that receives an internal table (with at least three columns) and the sort it by
its first column.
Solution:
REPORT
z_abap101_070.
"sort_1st_column
START-OF-SELECTION.
* Populating the internal table WITHOUT HEADER LINE (hat)
DATA wa_person TYPE ty_person.
wa_person-id = 3.
wa_person-name = 'The One'.
wa_person-age = 30.
APPEND wa_person TO it_people.
wa_person-id = 2.
wa_person-name = 'Bob'.
wa_person-age = 20.
APPEND wa_person TO it_people.
wa_person-id = 1.
wa_person-name = 'Mary'.
wa_person-age = 10.
APPEND wa_person TO it_people.
wa_person-id = 5.
wa_person-name = 'Chris'.
wa_person-age = 50.
APPEND wa_person TO it_people.
wa_person-id = 4.
wa_person-name = 'Janet'.
wa_person-age = 40.
APPEND wa_person TO it_people.
WRITE 'Before SORT'. NEW-LINE.
LOOP AT it_people INTO wa_person.
WRITE: wa_person-id, wa_person-name, wa_person-age.
NEW-LINE.
ENDLOOP.
PERFORM sort_1st_column
CHANGING
it_people.
WRITE 'After SORT'. NEW-LINE.
LOOP AT it_people INTO wa_person.
WRITE: wa_person-id, wa_person-name, wa_person-age.
NEW-LINE.
ENDLOOP.
Have a routine that receives an internal table (with at least three columns) and a string with
the name of a column. Sort the table by the specified column accordingly.
Solution:
REPORT
z_abap101_071.
"sort_any_column
START-OF-SELECTION.
* Populating the internal table WITHOUT HEADER LINE (hat)
DATA wa_person TYPE ty_person.
wa_person-id = 3.
wa_person-name = 'The One'.
wa_person-age = 30.
APPEND wa_person TO it_people.
wa_person-id = 2.
wa_person-name = 'Bob'.
wa_person-age = 20.
APPEND wa_person TO it_people.
wa_person-id = 1.
wa_person-name = 'Mary'.
wa_person-age = 10.
APPEND wa_person TO it_people.
wa_person-id = 5.
wa_person-name = 'Chris'.
wa_person-age = 50.
APPEND wa_person TO it_people.
wa_person-id = 4.
wa_person-name = 'Janet'.
wa_person-age = 40.
APPEND wa_person TO it_people.
WRITE 'Before SORT by ID'. NEW-LINE.
LOOP AT it_people INTO wa_person.
WRITE: wa_person-id, wa_person-name, wa_person-age.
NEW-LINE.
ENDLOOP.
PERFORM sort_any_column
USING
'ID'
CHANGING
it_people.
WRITE 'After SORT ID'. NEW-LINE.
LOOP AT it_people INTO wa_person.
WRITE: wa_person-id, wa_person-name, wa_person-age.
NEW-LINE.
ENDLOOP.
PERFORM sort_any_column
USING
'NAME'
CHANGING
it_people.
WRITE 'After SORT NAME'. NEW-LINE.
LOOP AT it_people INTO wa_person.
WRITE: wa_person-id, wa_person-name, wa_person-age.
NEW-LINE.
ENDLOOP.
Have a routine that receives an internal table (with at least three fields) and another internal
table with the name of the columns to be ordered and order accordingly.
Solution:
REPORT
z_abap101_072.
(lv_first_column) ASCENDING
(lv_second_column) ASCENDING..
WHEN 3.
READ TABLE us_t_columns INDEX 1 INTO lv_first_column.
READ TABLE us_t_columns INDEX 2 INTO lv_second_column.
READ TABLE us_t_columns INDEX 3 INTO lv_third_column.
SORT ch_itab_people BY
(lv_first_column) ASCENDING
(lv_second_column) ASCENDING
(lv_third_column) ASCENDING.
ENDCASE.
ENDFORM.
"sort_any_columns
START-OF-SELECTION.
* Populating the internal table WITHOUT HEADER LINE (hat)
DATA wa_person TYPE ty_person.
wa_person-id = 3.
wa_person-name = 'The One'.
wa_person-age = 30.
APPEND wa_person TO it_people.
wa_person-id = 6.
wa_person-name = 'Peter'.
wa_person-age = 40.
APPEND wa_person TO it_people.
wa_person-id = 2.
wa_person-name = 'Bob'.
wa_person-age = 30.
APPEND wa_person TO it_people.
wa_person-id = 1.
wa_person-name = 'Mary'.
wa_person-age = 10.
APPEND wa_person TO it_people.
wa_person-id = 5.
wa_person-name = 'Chris'.
wa_person-age = 20.
APPEND wa_person TO it_people.
wa_person-id = 4.
wa_person-name = 'Bob'.
wa_person-age = 40.
APPEND wa_person TO it_people.
Contains a select-options for numeric values and print the result of multiplying each number
within the range of 3.
Solution:
REPORT
z_abap101_073.
Contains a select-options for numeric values and print all search criteria separated ",".
Solution:
REPORT
z_abap101_074.
Declare a select-options for numeric values without ranges. Then, validate if the number
zero is entered and if it is, show an error message.
Solution:
REPORT
z_abap101_075.
Declare a select-options for numeric values without multiple ranges. Then, validate if a
range bigger than 100 is entered and if it is, show an error message.
Solution:
REPORT
z_abap101_076.
Declare a parameter as a listbox containing all Airline codes com table SCARR.
Solution:
REPORT
z_abap101_077.
Declare three parameters as checkboxes. Each of them will represent a different flight class
(first, business and economy).
Solution:
REPORT
z_abap101_078.
Declare three parameters as radio buttons. Each of them will represent a different flight class
(first, business and economy).
Solution:
REPORT
z_abap101_079.
Declare three parameters as checkboxes. The first one should always be checked once the
program is started. Moreover, if the current day is between 1 and 10, the other two checkboxes
should be checked as well once the program is started.
Solution:
REPORT
z_abap101_080.
Declare three radio buttons and an input field. If any radio button is selected, the input field
should be cleared. Note: the field should be cleared as soon any radio buttons is selected and not
after the program is executed.
Solution:
REPORT
z_abap101_081.
PARAMETER
PARAMETER
PARAMETER
PARAMETER
p_first
p_busin
p_econo
p_input
AT SELECTION-SCREEN.
IF sy-ucomm = 'ACTION'.
CLEAR p_input.
ENDIF.
Declare three radio buttons and two input fields. If the first radio button is selected, both
input fields should be displayed and ready for input. If the second one is chosen, the first input field
should be mandatory and the second one should blocked for input. If the last radio button is chosen,
both input fields should not be displayed in the screen.
Solution:
REPORT
z_abap101_082.
PARAMETER
PARAMETER
PARAMETER
PARAMETER
PARAMETER
Declare four parameters. The first two should have a character type and the last two a
numeric type. Separate each pair in the selection screen using selection screen blocks. Both blocks
should contain a frame so it's possible to see the separation between them.
Solution:
REPORT
z_abap101_083.
Declare four parameters. The first two should have a character type and the last two a
numeric type. Separate each pair in the selection screen using selection screen blocks. Both blocks
should contain a frame so it's possible to see the separation between them. Each frame should have
a title. Also, define a text for each parameter label using text elements.
Solution:
REPORT
z_abap101_084.
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01. " Define in text
elements
PARAMETER p_text TYPE string. " Define in text elements
PARAMETER p_char TYPE c LENGTH 10. " Define in text elements
SELECTION-SCREEN END OF BLOCK b01.
SELECTION-SCREEN BEGIN OF BLOCK b02 WITH FRAME TITLE text-b02. " Define in text
elements
PARAMETER p_int TYPE i. " Define in text elements
PARAMETER p_p TYPE p LENGTH 10. " Define in text elements
SELECTION-SCREEN END OF BLOCK b02.
Declare a parameter with a text element and translate it to a different language. Then log
into your system using another language and check which text appears in your program.
Solution:
REPORT
z_abap101_085.
Solution:
REPORT
z_abap101_086.
Declare a button inside a selection screen and show an information message when it is
pressed.
Solution:
REPORT
z_abap101_087.
Create a tabbed block with 3 tabs. Each of them should have a different content.
Solution:
REPORT
z_abap101_088.
Declare three parameters. There should be a horizontal line separating the first two ones and
a blank line separating the last two.
Solution:
REPORT
z_abap101_089.
PARAMETERS p_1.
SELECTION-SCREEN ULINE.
PARAMETER p_2 TYPE i.
SELECTION-SCREEN SKIP 1.
PARAMETER p_3 TYPE d.
Declare a selection screen with 8 parameters and 3 select-options of your choice. Execute
your program and save a variant so you refer to your selection any time you want.
Solution:
REPORT
z_abap101_090.
Declare a selection screen with two date parameters. The first once should be typed with the
primitive type. The second, with type SYST-DATUM. Is there any different between them when
filling the selection screen? What about the documentation displayed when you hit F1 key?
Solution:
REPORT
z_abap101_091.
Declare a selection screen with two time parameters. The first once should be typed with the
primitive type. The second, with type SYST-UZEIT. Is there any different between them when
filling the selection screen? What about the documentation displayed when you hit F1 key?
Solution:
REPORT
z_abap101_092.
Declare a selection screen with a parameter representing a date. Then, save a variant so that
this field is filled with the last day of the previous month every time the variant is used.
Solution:
REPORT
z_abap101_093.
Declare a selection screen with a parameter representing a specific time. Then, save a
variant so that this field is filled with the current time minus 3 hours every time the variant is used.
Solution:
REPORT
z_abap101_094.
Declare a selection screen with a select-options representing a date range. Then, save a
variant so that it is filled with a range between the first day of the current month and the current date
every time the variant is used.
Solution:
REPORT z_abap101_095.
DATA v_date TYPE d.
SELECT-OPTIONS s_date FOR v_date.
Declare a selection screen with a select-options representing a time range. Then, save a
variant so that these fields are filled with the start of day until the current time every time the
variant is used.
Solution:
REPORT z_abap101_096.
DATA v_time TYPE t.
SELECT-OPTIONS s_time FOR v_time.
Declare a selection screen with one parameter and a select-options. Save a variant so that the
parameter is blocked for input and the select-options is hidden.
Solution:
REPORT z_abap101_097.
PARAMETERS p_total TYPE p LENGHT 5 DECIMALS 2.
SELECT-OPTIONS s_total FOR p_total.
Solution:
Open transaction SE93 and follow as below.
Click on create and fill the popup with the transaction name and description. It must be a report
transaction.
Create a transaction which points to a program and fills its selection screen automatically
using a predefined variant.
Solution:
Create a program with one parameter representing an executable program name (also known
as report). The program should execute the program entered in the parameter.
Solution:
REPORT Z_ABAP101_100.
PARAMETERS p_report TYPE char20 DEFAULT 'Z_ABAP101_'.
START-OF-SELECTION.
SUBMIT (p_report) VIA SELECTION-SCREEN AND RETURN.
Create a program with one select-options representing an executable program name (also
known as report). The program should execute all programs entered in the select-options one-byone. Keep in mind that after running a program, the execution should return back to the original
program.
Solution:
REPORT z_abap101_101.
DATA v_report TYPE char20.
SELECT-OPTIONS s_report FOR v_report NO INTERVALS.
START-OF-SELECTION.
LOOP AT s_report.
SUBMIT (s_report-low) VIA SELECTION-SCREEN AND RETURN.
ENDLOOP.