- •Introduction to the abap Workbench
- •15 Introduction to the abap Workbench
- •49 Exercise 3: Creating Transactions
- •Case pa_op.
- •When ’/’.
- •In debugging mode.
- •127 Exercise 7: Working with Internal Tables
- •Loop at it_spfli into wa_spfli.
- •Into (field_1, ... , field_n)
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •Insert wa_flight into table it_flight.
- •Wa_flight-percentage, ’%’.
- •Id ’actvt’ field ’02’.
- •Id ’actvt’ field actvt_display.
- •Into corresponding fields of wa_flight
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •195 Exercise 11: Subroutines
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •Clear wa_flight. At line-selection.
- •Wa_flight-fldate.
- •Wa_sbook-cancelled.
- •Wa_sbook-loccurkey.
- •Id ’actvt’ field actvt_display. If sy-subrc ne 0.
- •Into corresponding fields of wa_flight
- •100 * Wa_flight-seatsocc / wa_flight-seatsmax.
- •At line-selection. Call screen 100.
- •Wa_sbook-bookid.
- •Id ’carrid’ field wa_sbook-carrid
- •Id ’actvt’ field actvt_change.
- •When ’back’.
- •303 Exercise 17: Creating an Interface
- •When ’rw’.
- •Importing
- •If container_r is initial.
127 Exercise 7: Working with Internal Tables
Exercise Duration: 30 Minutes
Exercise Objectives
After completing this exercise, you will be able to:
• Search for suitable table types in the ABAP Dictionary
• Define internal tables based on a global table type
• Fill internal tables using array fetch
• Process the content of internal tables using a loop
Business Example
You are to output flight dates stored in database table SPFLI in a list by using an internal table (as temporary storage).
System Data
System: Will be assigned Client: Will be assigned User ID: Will be assigned Password: Will be assigned
Set up instructions: No special instructions when using a standard training
system
Task 1:
Define internal table
1. Create the executable program ZBC400_##_ITAB_LOOP without a “TOP
include”.
2. Buffer the data from the database table SPFLI in an internal table. You should define an internal table with a line type that is compatible with the line structure of SPFLI.
In the ABAP Dictionary, search for all table types that match this condition.
Hint: Have the transparent table SPFLI displayed in the ABAP Dictionary. There, use the appropriate pushbutton to list the where-used list of SPFLI. (Pay attention to the correct selection when triggering the where-used list)
3. Define an internal table (name suggestion: it_spfli) based on one of the found global table types.
Continued on next page
4. Define a suitable work area for the internal table (name suggestion:
wa_spfli).
Task 2:
Fill and output the internal table
1. Program an array fetch access to all data records in the database table SPFLI
as follows:
SELECT * FROM spfli INTO TABLE it_spfli.
2. Use the LOOP statement to output the buffered data in the internal table in a list.
Solution 7: Working with Internal Tables
Task 1:
Define internal table
1. Create the executable program ZBC400_##_ITAB_LOOP without a “TOP
include”.
a) Carry out this step as usual.
2. Buffer the data from the database table SPFLI in an internal table. You should define an internal table with a line type that is compatible with the line structure of SPFLI.
In the ABAP Dictionary, search for all table types that match this condition.
Hint: Have the transparent table SPFLI displayed in the ABAP Dictionary. There, use the appropriate pushbutton to list the where-used list of SPFLI. (Pay attention to the correct selection when triggering the where-used list)
a) Carry out this step as described.
3. Define an internal table (name suggestion: it_spfli) based on one of the found global table types.
a) See source code excerpt in the model solution.
4. Define a suitable work area for the internal table (name suggestion:
wa_spfli).
a) See source code excerpt in the model solution.
Task 2:
Fill and output the internal table
1. Program an array fetch access to all data records in the database table SPFLI
as follows:
SELECT * FROM spfli INTO TABLE it_spfli.
a) See source code excerpt in the model solution.
Continued on next page
2. Use the LOOP statement to output the buffered data in the internal table in a list.
a) See source code excerpt in the model solution.
Result
Source code excerpt: SAPBC400TSS_ITAB_LOOP
REPORT sapbc400tss_itab_loop.
DATA it_spfli TYPE sbc400_t_spfli. DATA wa_spfli LIKE LINE OF it_spfli.
SELECT * FROM spfli INTO TABLE it_spfli.
* at least one dataset selected
IF sy-subrc = 0.
