Intro to ABAP - Chapter 07_V1.ppt
Transcript of Intro to ABAP - Chapter 07_V1.ppt
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
1/34
IBM Global Services
© Copyright IBM Corporation 2003
Address List
StructureStructure
Data Structures
Address List
InternalInternal
TableTable
LNLN FNFN CityCity ST.ST. LNLN FNFN CityCity ST.ST.
LNLN FNFN CityCity ST.ST.
LNLN FNFN CityCity ST.ST.
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
2/34
IBM Global Services
© Copyright IBM Corporation 2003
Declaring a Structure - Method #1
1 REPORT YN1C0008.
2
3 TABLES: TABNA.
4 DATA: BEGIN OF ADDRESS,
5 FLAG TYPE C,
6 ID LIKE TABNA-ID,
7 NAE1 LIKE TABNA-NAE1, 8 CITY LIKE TABNA-CITY,
! END OF ADDRESS.
10 O"E #$% TO ADDRESS-FLAG.
11 O"E #0001% TO ADDRESS-ID.
12 O"E #S&'()% TO ADDRESS-NAE1.
13 O"E #P)'*+*)'+% TO ADDRESS-CITY.
14
15 /RITE ADDRESS.16
17
18
1!
20
21
22
23
Basic Syntax:
DATA: BEGIN OF
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
3/34
IBM Global Services
© Copyright IBM Corporation 2003
REPORT Yxxxxxxx.
TYPES: BE!" O $DDR%
&$%
!D &!'E EMP&OYEE-!D%
"$ME1 &!'E EMP&OYEE-"$ME1%
(!TY &!'E EMP&OYEE-(!TY%
E"D O $DDR.
D$T$: $DDRESS TYPE $DDR.
MO)E: *+, TO $DDRESS-&$%
*1, TO $DDRESS-!D%
*Sith, TO $DDRESS-"$ME1%
*Philadel/hia, TO $DDRESS-(!TY.
0R!TE $DDRESS.
Declaring a Structure - Method #
Basic Syntax:
T*+ES: BEGIN OF
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
4/34
IBM Global Services
© Copyright IBM Corporation 2003
Po/ulating a Structure 3ith
ield-42-ield Trans/ort
REPORT Y15DM65.
T$B&ES: EMP&OYEE.
D$T$: BE!" O $DDRESS%
&$%
!D &!'E EMP&OYEE-!D%
"$ME &!'E EMP&OYEE-"$ME1%
(!TY &!'E EMP&OYEE-(!TY%
E"D O $DDRESS.
SE&E(T 7 ROM EMP&OYEE.
MO)E-(ORRESPO"D!" EMP&OYEE TO
$DDRESS.
0R!TE: 8 $DDRESS-&$% $DDRESS-!D%
$DDRESS-"$ME% $DDRESS-(!TY.
(&E$R $DDRESS.
E"DSE&E(T.
E-+LO*EE
Address
ID Nae# City
# Electr(nics Inc. /ald(r'
-O0E1CO22ES+ONDING E-+LO*EETO ADD2ESS.
Fla% ID Nae City# /ald(r'
Clear
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
5/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le T2/es
Standard
Sorted
Hashed
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
6/34
IBM Global Services
© Copyright IBM Corporation 2003
REPORT Y15DM69.
T$B&ES: EMP&OYEE.
TYPES: BE!" O EMP%
!D &!'E EMP&OYEE-!D%
"$ME1 &!'E EMP&OYEE-"$ME1%
(O"TRY &!'E EMP&OYEE-(O"TRY%
E"D O EMP.
D$T$: EMPT$B TYPE ST$"D$RD T$B&E
O EMP !"!T!$& S!;E 1 0!T<
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
7/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 'e2s
Implicit Key
- ll character !ields
"#plicit Key
-
$ser%de!ined e&g& ' (I)H * $+I,$"-+.+%$+I,$" / K" 1I"4 1I"2 &&&
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
8/34
IBM Global Services
© Copyright IBM Corporation 2003
Si=e o> an !nternal Ta4le
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
9/34
IBM Global Services
© Copyright IBM Corporation 2003
A++END
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
10/34
IBM Global Services
© Copyright IBM Corporation 2003
REPORT Y15DM?.
T$B&ES: EMP&OYEE.
TYPES: BE!" O EMP%
(O"TRY &!'E EMP&OYEE-(O"TRY%
!D &!'E EMP&OYEE-!D%
S$&$RY &!'E EMP&OYEE-S$&$RY%
E"D O EMP.
D$T$: EMPT$B TYPE ST$"D$RD T$B&E
O EMP !"!T!$& S!;E 1 0!T<
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
11/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ith
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
12/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ith
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
13/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ith
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
14/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ith
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
15/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ith
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
16/34
IBM Global Services
© Copyright IBM Corporation 2003
(reating an !nternal Ta4le 3ithout a
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
17/34
IBM Global Services
© Copyright IBM Corporation 2003
Se3arate Internal Table /(rArea
+er'(rance Issues
Nested Internal Tables
!nternal Ta4le 3ithout a
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
18/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ithout a
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
19/34
IBM Global Services
© Copyright IBM Corporation 2003
!nternal Ta4le 3ithout a
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
20/34
IBM Global Services
© Copyright IBM Corporation 2003
Trans>erring $B$P Dictionar2 Ta4le Structures
2E+O2T *#=D-9#.
TABLES: E-+LO*EE.
DATA: E-+TAB LI?E STANDA2D TABLE OFE-+LO*EE INITIAL SI5E # /IT6 6EADE2
LINE.
SELECT F2O- E-+LO*EE.
-O0E E-+LO*EE TO E-+TAB.
A++END E-+TAB.
ENDSELECT.
T&e internal tableE-+TAB 4ill &a@e t&e
exact sae structure ast&e dicti(nary table
E-+LO*EE.
N(tice t&e -O0Estateent instead (' a
-O0E1CO22ES+ONDING.
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
21/34
IBM Global Services
© Copyright IBM Corporation 2003
$utoatic ield (onersion
M.5"%C.66"S7.+I+G or M.5" !ield to !ield
- Individ8al !ield type conversion
M.5"
-
Str8ct8re to str8ct8re- 1ield to str8ct8re
- Str8ct8re to !ield
Intermediate C type
1ollo9ed by adoption o! ne9 types
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
22/34
IBM Global Services
© Copyright IBM Corporation 2003
Mass Reading >ro Data4ase Ta4les into !nternal Ta4les
2E+O2T *#=D-;.
TABLES: E-+LO*EE.
DATA: E-+TAB LI?E STANDA2D TABLEE-+LO*EE INITIAL SI5E # /IT6 6EADE2LINE.
SELECT F2O- E-+LO*EE INTO TABLEE-+TAB
/6E2E CO7NT2* 7SA.
SELECT F2O-
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
23/34
IBM Global Services
© Copyright IBM Corporation 2003
Processing an !nternal Ta4le
2E+O2T *#=D-9.
TABLES: E-+LO*EE.
T*+ES: BEGIN OF E-+,
CO7NT2* LI?E E-+LO*EE1CO7NT2*,
NA-E# LI?E E-+LO*EE1NA-E#,
SALES LI?E E-+LO*EE1SALES, END OF E-+.
DATA: E-+TAB T*+E STANDA2D TABLE OF E-+ INITIALSI5E # /IT6 6EADE2 LINE.
SELECT F2O- E-+LO*EE.
-O0E1CO22ES+ONDING E-+LO*EE TO E-+TAB.
A++END E-+TAB.
ENDSELECT.
LOO+ AT E-+TAB /6E2E CO7NT2* BET/EEN A ANDD.
/2ITE: E-+TAB1CO7NT2*, E-+TAB1NA-E#,E-+TAB1SALES.
ENDLOO+.
IF S*1S7B2C NE . /2ITE: NO ENT2IES. ENDIF.
T&is LOO+ AT
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
24/34
IBM Global Services
© Copyright IBM Corporation 2003
S2ste ield SY-T$B!+
2E+O2T *#=D-9;.
TABLES: E-+LO*EE.
T*+ES: BEGIN OF E-+,
CO7NT2* LI?E E-+LO*EE1CO7NT2*,
NA-E# LI?E E-+LO*EE1NA-E#, END OF E-+.
DATA: E-+TAB T*+E STANDA2D TABLE OF E-+
INITIAL SI5E # /IT6 6EADE2 LINE.
+A2A-ETE2S: STA2T LI?E S*1TABI DEFA7LT #,
END LI?E S*1TABI DEFA7LT $.
SELECT F2O- E-+LO*EE. -O0E1CO22ES+ONDING E-+LO*EE TO E-+TAB.
A++END E-+TAB.
ENDSELECT.
LOO+ AT E-+TAB F2O- STA2T TO END.
/2ITE: S*1TABI, E-+TAB1CO7NT2*, E-+TAB1NA-E#.
ENDLOO+.
screen(ut3ut
S*1TABI
IBM Gl b l S i
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
25/34
IBM Global Services
© Copyright IBM Corporation 2003
$ccuulating Data 3ithin an
!nternal Ta4le
2E+O2T *#=D-98.
TABLES: E-+LO*EE.
T*+ES: BEGIN OF E-+,
CO7NT2* LI?E E-+LO*EE1CO7NT2*,
SALES LI?E E-+LO*EE1SALES,
END OF E-+.
DATA: E-+TAB T*+E STANDA2D TABLE OFE-+ INITIAL SI5E # /IT6 6EADE2 LINE.
SELECT F2O- E-+LO*EE.
-O0E1CO22ES+ONDING E-+LO*EE TOE-+TAB.
COLLECT E-+TAB.
ENDSELECT.
LOO+ AT E-+TAB.
/2ITE: E-+TAB1CO7NT2*, E-+TAB1SALES.
ENDLOO+.
COLLECT ,
6eaderLine
A 371,065.00
CH 45,305.00
D 8,200,000.00F 0.00
GB 500,000.00
NL 577,000.00
NO 234.00
USA 1,000,000.00
HK 0.00
screen(ut3ut
IBM Gl b l S i
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
26/34
IBM Global Services
© Copyright IBM Corporation 2003
Sorting an !nternal Ta4le
2E+O2T *#=D-99.
TABLES: E-+LO*EE.
T*+ES: BEGIN OF E-+,
CO7NT2* LI?E E-+LO*EE1CO7NT2*,
NA-E# LI?E E-+LO*EE1NA-E#,
SALES LI?E E-+LO*EE1SALES,
END OF E-+.
DATA: E-+TAB T*+E STANDA2D TABLE OF E-+INITIAL SI5E # /IT6 6EADE2 LINE.
SELECT F2O- E-+LO*EE.
-O0E1CO22ES+ONDING E-+LO*EE TOE-+TAB.
A++END E-+TAB.
ENDSELECT.
SO2T E-+TAB B* SALES DESCENDING.
LOO+ AT E-+TAB.
/2ITE: ITAB1CO7NT2*, ITAB1NA-E#, ITAB1SALES.
S(rtin% (3ti(ns:
#J SO2T
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
27/34
IBM Global Services
© Copyright IBM Corporation 2003
(ontrol &eel Processing
) 1I6S)
) +"( : !ield ;
) "+ : !ield ;
) S)
IBM Global Services
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
28/34
IBM Global Services
© Copyright IBM Corporation 2003
2E+O2T *#=D-9=.
TABLES: E-+LO*EE.
T*+ES: BEGIN OF E-+,
CO7NT2* LI?E E-+LO*EE1CO7NT2*,
NA-E# LI?E E-+LO*EE1NA-E#,
END OF E-+TAB.
DATA: E-+TAB T*+E STANDA2D TABLE OFE-+ INITIAL SI5E # /IT6 6EADE2 LINE.
SELECT F2O- E-+LO*EE.
-O0E1CO22ES+ONDING E-+LO*EE TOE-+TAB.
A++END E-+TAB.
ENDSELECT.
2EAD TABLE ….
Reading a Single Ta4le Entr2
IBM Global Services
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
29/34
IBM Global Services
© Copyright IBM Corporation 2003
Reading a Single Ta4le Entr2 -
O/tions
2EAD TABLE
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
30/34
IBM Global Services
© Copyright IBM Corporation 2003
Maintaining !nternal Ta4les
SELECT F2O- E-+LO*EE.
-O0E1CO22ES+ONDING E-+LO*EE TOE-+TAB.
A++END E-+TAB.
ENDSELECT.
2EAD TABLE E-+TAB INDE #.
-O0E ABC TO E-+TAB1NA-E#.
-ODIF* E-+TAB INDE S*1TABI.
IF S*1S7B2C NE .
/2ITE Atte3t t( (di'y 'ailed..
ELSE.
/2ITE: E-+TAB1CO7NT2*, E-+TAB1NA-E#.
ENDIF.
INSE2T E-+TAB INDE #.
DELETE E-+TAB INDE S*1TABI.
INSE2T
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
31/34
IBM Global Services
© Copyright IBM Corporation 2003
0orCing 3ith an !nternal Ta4le
3ithout a
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
32/34
IBM Global Services
© Copyright IBM Corporation 2003
Deleting an !nternal Ta4le
LEA2
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
33/34
IBM Global Services
© Copyright IBM Corporation 2003
!n>oration a4out an !nternal Ta4le
REPORT Y15DM?.
T$B&ES: EMP&OYEE.
TYPES: BE!" O EMP%
(O"TRY &!'E EMP&OYEE-(O"TRY%
"$ME1 &!'E EMP&OYEE-"$ME1%
E"D O EMP%
D$T$: EMPT$B TYPE ST$"D$RD T$B&E O EMP!"!T!$& S!;E 1 0!T<
-
8/17/2019 Intro to ABAP - Chapter 07_V1.ppt
34/34
IBM Global Services
REPORT Y15DM.
T$B&ES: EMP&OYEE.
TYPES: BE!" O EMP%
(O"TRY &!'E EMP&OYEE-(O"TRY%
"$ME1 &!'E EMP&OYEE-"$ME1%
E"D O EMP%
D$T$: EMPT$B TYPE ST$"D$RD T$B&E O EMP
!"!T!$& S!;E 1 0!T<