Você está na página 1de 19

ABAP/4 Data Structures

Field string
ADDRESS NAME FIRST NAME CITY STREET

Internal tables
ADDRESS_LIST NAME FIRST NAME CITY STREET
Header line

Internal table

Declaring Field-strings

TABLES

TABNA.

DATA STRUC LIKE TABNA.


DATA : BEGIN OF STRUC, F1( 10 ) TYPE C, F2 LIKE TABNA - COUNTRY, . . . END OF STRUC.

DATA : BEGIN OF STRUC. INCLUDE STRUCTURE TABNA. DATA F1( 10 ) TYPE C. DATA END OF STRUC.

Assigning values to Field-Strings fields

MOVE ABC TO STRUC-F1. STRUC-F2 = XYZ . ADD 1 TO STRUC-F3.

Field to Field Transport


MOVE STRUC1 TO STRUC2. STRUC1
ID 000001 ID 000001 NAME1 JOHN NAME JOHN CITY MANILA CITY MANILA

STRUC2

MOVE-CORRESPONDING STRUC1 TO STRUC2.

STRUC1

ID

NAME1

CITY

000001
COUNTRY

JOHN
ID

MANILA
NAME CITY

STRUC2

000001

MANILA

Declaring Internal Tables

DATA : BEGIN OF IT_TAB OCCURS 10, F1 ( 10 ) TYPE C, F2 LIKE TABNA - COUNTRY, . . . END OF IT_TAB.

DATA : BEGIN OF IT_TABNA OCCURS 10, INCLUDE STRUCTURE TABNA. DATA : END OF IT_TABNA.

Filling Internal Tables (I)

APPEND <tab> APPEND <tab>

APPEND <tab> SORTED BY <field> Header line Header 400,000 line 1 400,000 2 1,000,000 1 500,000 3 2 7,800,000 4 3 50,000 5 4 6 140,000 5 7 6 8 7 9 8 10

COUNTRY COUNTRY
D D USA GB D GB A

SALES SALES

COUNTRY D D USA GB A GB

SALES 400,000 7,800,000 1,000,000 500,000 140,000 50,000 Header line 1 2 3 4 5

Filling Internal Tables (II)

SELECT * FROM TABNA. MOVE TABNA TO IT_TAB. APPEND IT_TAB. ENDSELECT.

SELECT * INTO IT_TAB FROM TABNA. APPEND IT_TAB. ENDSELECT.

SELECT * INTO TABLE IT_TAB FROM TABNA.

Compressing Internal Table Data

SELECT * FROM TABNA. MOVE-CORRESPONDING TABNA INTO IT_TAB. COLLECT IT_TAB. ENDSELECT

TABNA COUNTRY PH USA USA HK GB


HK

SALES

IT_TAB COUNTRY
COLLECT

SALES

600 100 300 400 200


50

PH USA HK GB

600 400 450 200

Processing an Internal Table

LOOP AT IT_TAB. (processing statements.) ENDLOOP.

SY-TABIX

Processing an Internal Table

AT FIRST - when processing first row AT LAST - when processing last row AT NEW f - when contents of field f changes AT END OF f - just before contents of field f changes

Reading a Single Table Entry

READ TABLE IT_TAB. READ TABLE IT_TAB WITH KEY . . . READ TABLE IT_TAB WITH KEY . . . BINARY SEARCH

READ TABLE IT_TAB INDEX idx . . .

Changing an Internal Table

DELETE

INSERT

MODIFY

Deleting an Internal Table

CLEAR <tab>.
Initialize the header line

REFRESH <tab>.
Delete all table lines Storage space is not released Paging is released

FREE <tab>.

Delete all table lines Storage space is released

Information About an Internal Table


DESCRIBE TABLE <tab>
REPORT B170D08F. TABLES: TABNA.

DATA:
. . .

BEGIN OF IT_TAB OCCURS 5, COUNTRY LIKE TABNA-COUNTY, ID LIKE TABNA-ID, NAME1 LIKE TABNA-NAME1, SALES LIKE TABNA-SALES, END OF TAB, LINE_COUNT TYPE I, OCCURS_COUNT TYPE I.

DESCRIBE TABLE IT_TAB LINES LINE_COUNT OCCURS OCCURS_COUNT. . . .

Event Commands (I)

INITIALIZATION AT SELECTION-SCREEN START-OF-SELECTION END-OF-SELECTION TOP-OF-PAGE END-OF-PAGE

Modularization

Internal Subroutine call

External Subroutine call

Function modules

Using Subroutines
REPORT B170D091. TABLES: . . . . DATA: ....
. . .

a1

a2

a3

a4

X
1

Y
1 2 2

PERFORM <name> USING <a1> <a2> <a3> <a4>.


. . .

X
f1

Y
f2

FORM <name> USING VALUE (<f1>) VALUE (<f2>) <f3> <f4>. <statements> ENDFORM.

1 Pass by value 2 Pass by reference

Processing Internal Tables


DATA : BEGIN OF IT - TAB OCCURS 10, COUNTRY LIKE TABNA-COUNTRY, NAME1 LIKE TABNA-NAME1. PERFORM SUB1 TABLES IT_TAB. PERFORM SUB2 TABLES IT_TAB. FORM SUB1 TABLES F_TAB1. LOOP AT F_TAB1. WRITE : / F_TAB1. ENDLOOP. ENDFORM. FORM SUB2 TABLES F_TAB2 STRUCTURE IT_TAB. LOOP AT F_TAB2. WRITE : / F_TAB2-COUNTRY F_TAB2-NAME1. ENDLOOP. ENDFORM.

Function Modules
Function Library
FM group: FIBU FM_01 ...
FM_02 ... Function module usage

Function module maintenance

FB_02 Interface Import Export Tables Exceptions Program Documentation Administration

FM group: XYZ FM_03 ...


FM_ 04 ...

PROGRAM . . . TABLES . . .

CALL FUNCTION FB_02 EXPORTING IMPORTING

Você também pode gostar