Sie sind auf Seite 1von 4

BC400 Lesson: Working with InternaI TabIes

Exercise 7: Working with InternaI TabIes


Exercise Objectives
AIter completing this exercise, you will be able to:
Search Ior suitable table types in the $%$3 'LFWLRQDU\
DeIine internal tables based on a global table type
Fill internal tables using array Ietch
Process the content oI internal tables using a loop
Business ExampIe
You are to output Ilight dates stored in database table SPFLI in a list by using an
internal table (as temporary storage).
Task 1:
DeIine internal table
1. Create the executable program ZBC400_##_ITAB_LOOP without a 'TOP
include.
2. BuIIer the data Irom the database table SPFLI in an internal table. You
should deIine an internal table with a line type that is compatible with the
line structure oI SPFLI.
In the $%$3 'LFWLRQDU\, search Ior all table types that match this condition.
Hint: Have the transparent table SPFLI displayed in the $%$3
'LFWLRQDU\. There, use the appropriate pushbutton to list the
ZKHUHXVHG OLVW oI SPFLI. (Pay attention to the correct selection
when triggering the where-used list)
3. DeIine an internal table (name suggestion: it_spfli) based on one oI the
Iound global table types.
4. DeIine a suitable work area Ior the internal table (name suggestion:
wa_spfli).
Task 2:
Fill and output the internal table
1. Program an array Ietch access to all data records in the database table SPFLI
as Iollows:
SELECT * FROM spfli INTO TABLE it_spfli.
&RQWLQXHG RQ QH[W SDJH
2006/Q2 2006 SAP AG. All rights reserved. 135




Unit 4: Basic ABAP Language EIements BC400
2. Use the LOOP statement to output the buIIered data in the internal table
in a list.
136 2006 SAP AG. All rights reserved. 2006/Q2




BC400 Lesson: Working with InternaI TabIes
SoIution 7: Working with InternaI TabIes
Task 1:
DeIine internal table
1. Create the executable program ZBC400_##_ITAB_LOOP without a 'TOP
include.
a) Carry out this step as usual.
2. BuIIer the data Irom the database table SPFLI in an internal table. You
should deIine an internal table with a line type that is compatible with the
line structure oI SPFLI.
In the $%$3 'LFWLRQDU\, search Ior all table types that match this condition.
Hint: Have the transparent table SPFLI displayed in the $%$3
'LFWLRQDU\. There, use the appropriate pushbutton to list the
ZKHUHXVHG OLVW oI SPFLI. (Pay attention to the correct selection
when triggering the where-used list)
a) Carry out this step as described.
3. DeIine an internal table (name suggestion: it_spfli) based on one oI the
Iound global table types.
a) See the source code excerpt Irom the model solution.
4. DeIine a suitable work area Ior the internal table (name suggestion:
wa_spfli).
a) See the source code excerpt Irom the model solution.
Task 2:
Fill and output the internal table
1. Program an array Ietch access to all data records in the database table SPFLI
as Iollows:
SELECT * FROM spfli INTO TABLE it_spfli.
a) See the source code excerpt Irom the model solution.
&RQWLQXHG RQ QH[W SDJH
2006/Q2 2006 SAP AG. All rights reserved. 137




Unit 4: Basic ABAP Language EIements BC400
2. Use the LOOP statement to output the buIIered data in the internal table
in a list.
a) See source code excerpt in the model solution.
ResuIt
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.
LOOP AT it_spfli INTO wa_spfli.
WRITE: / wa_spfli-carrid,
wa_spfli-connid,
wa_spfli-cityfrom,
wa_spfli-cityto,
wa_spfli-deptime,
wa_spfli-arrtime.
ENDLOOP.
ELSE.
WRITE 'No data found !'.
ENDIF.
138 2006 SAP AG. All rights reserved. 2006/Q2

Das könnte Ihnen auch gefallen