ABAP Programming Tips Tricks
ABAP Programming Tips Tricks
NO YES
&olumn Update
-%DATE S!L"G$T SET SEATSOCC = SEATSOCC - 1.
+rray Insert
Page 1 4/8/2009
S!0!&T
SELECT !ROM S&OO' "NTO S&OO'_#A -% TO 10 RO#S. SELECT S"NGLE A"R%!ROM A"R%TO "NTO )A%18 A%9* !ROM S%!L" #$ERE CARR"D = S&OO'_#A-CARR"D AND CONN"D = S&OO'_#A-CONN"D. SELECT S"NGLE NAME "NTO NAME1 !ROM SA"R%ORT
Ravi K
Page 2
4/8/2009
Ravi K
Page 3
4/8/2009
Ravi K
Page 4
4/8/2009
9ottom up strategy
Entr:es:?0)BCter t+DEe*810):nner t+DEes* L:ne ;:<t=: ?00 )BCter*8 . ):nner* DO ?0 T"MES. CLEAR #A. DO 10 T"MES. A%%END N TO #A-"NTTA&. ADD 1 TO N. ENDDO. A%%END #A TO "TA&. ENDDO. 'illing an internal table with the bottom up strategy, you have to pay move costs several times depending on the depth of the data structure. The contents of nested inner tables are moved to every super ordinate level of the data structure.
Ravi K
Page 5
4/8/2009
Internal tables can be compared in logical expressions 1ust li"e other data ob1ects. Two internal tables are e$ual if they have the same number of lines and each pair of corresponding lines is e$ual. If an internal table itab has a header line, the table itself is accessed by itabFG.
Ravi K
Page 6
4/8/2009
Ravi K
Page 7
4/8/2009
Untyped parameters
%ER!ORM -%1 -S"NG 10 M1-D"M"D M1-KAE$L M1"SOCODE M1-ANDEC M1-%R"MAR/. !ORM -%1 -S"NG RE%EAT D"M"D KAE$L "SOCODE ANDEC %R"MAR/ . "<ent:G+E sBCrGe GB<e EeJt +n< r:g=t: DO RE%EAT T"MES. T001_#A-D"M"D = D"M"D. T001_#A-KAE$L = KAE$L. T001_#A-"SOCODE = "SOCODE. T001_#A-ANDEC = ANDEC. T001_#A-%R"MAR/ = %R"MAR/. ENDDO. END!ORM. If you specify the type for formal parameters in your source code, the +9+.=J compiler can optimi-e your code more thoroughly. In addition, the ris" of using the wrong se$uence of parameters in a .erform statement is much less.
Typed parameters
%ER!ORM -%9 -S"NG 10 M1-D"M"D M1-KAE$L M1"SOCODE M1-ANDEC M1-%R"MAR/. !ORM -%9 -S"NG RE%EAT T/%E " D"M"D L"'E T001-D"M"D KAE$L L"'E T001-KAE$L "SOCODE L"'E T001-"SOCODE ANDEC L"'E T001-ANDEC %R"MAR/ L"'E T001-%R"MAR/ . "<ent:G+E sBCrGe GB<e EeJt +n< r:g=t: DO RE%EAT T"MES. T001_#A-D"M"D = D"M"D. T001_#A-KAE$L = KAE$L. T001_#A-"SOCODE = "SOCODE. T001_#A-ANDEC = ANDEC. T001_#A-%R"MAR/ = %R"MAR/. ENDDO. END!ORM.
If
DATA C T/%E C. "! C = 'A'. #R"TE '1'. ELSE"! C = '&'. #R"TE '9'. ELSE"! C = 'C'. #R"TE '7'. ELSE"! C = 'D'. #R"TE '.'. ELSE"! C = 'E'. #R"TE '?'. ELSE"! C = '!'. #R"TE '1'. ELSE"! C = 'G'. #R"TE 'L'. ELSE"! C = '$'. #R"TE 'M'. END"!. &+S! statements are clearer and a little faster than I' constructions.
&ase
DATA C T/%E C. CASE C. #$EN 'A'. #R"TE '1'. #$EN '&'. #R"TE '9'. #$EN 'C'. #R"TE '7'. #$EN 'D'. #R"TE '.'. #$EN 'E'. #R"TE '?'. #$EN '!'. #R"TE '1'. #$EN 'G'. #R"TE 'L'. #$EN '$'. #R"TE 'M'. ENDCASE.
I' i ; c.
DATA C)M* T/%E C. "! 197.?1LM = C. END"!. &omparing & with & its faster as comparing & with a great number
I' c ; c.
DATA C)M* T/%E C. "! '197.?1LM' = C. END"!. &omparing & with & its faster as comparing & with a great number
4o
DATA C T/%E C. DATA " T/%E ". " = 0. DO. "! C NE S%ACE. EX"T. END"!. ADD 1 TO ". "! " GT 10. C = 'X'. END"!. ENDDO.
#hile
DATA C T/%E C. DATA " T/%E ". " = 0. #$"LE C = S%ACE. ADD 1 TO ". "! " GT 10. C = 'X'. END"!. END#$"LE.
Ravi K
Page 8
4/8/2009
&ase
)" = ? :n t=:s test* CASE ". #$EN 1. %ER!ORM #$EN 9. %ER!ORM #$EN 7. %ER!ORM #$EN .. %ER!ORM #$EN ?. %ER!ORM #$EN 1. %ER!ORM #$EN L. %ER!ORM #$EN M. %ER!ORM ENDCASE. %21. %29. %27. %2.. %2?. %21. %2L. %2M.
.erform i 2f ...
)" = ? :n t=:s test* %ER!ORM " O! %21 %29 %27 %2. %2? %21 %2L %2M.
+ very fast way to call a certain routine using a given index is the .erform i 2f ... statement.
FIELD CONVERSION
Type .
DATA % T/%E % 2AL-E 1. READ TA&LE TA& "NTO TA&_#A "NDEX %. Use fields of type I for typical integral variables li"e indices.
Type I
DATA " T/%E " 2AL-E 1. READ TA&LE TA& "NTO TA&_#A "NDEX ".
Type &
MO2E S%ACE TO S/-S-&RC. CASE S/-S-&RC. #$EN '1'. #$EN '9'. #$EN '7'. #$EN '.'. ENDCASE. Use numeric literals or named constants with a number type instead of character strings if you are dealing with type I or integral type . fields.
Type I
S/-S-&RC = 0. CASE S/-S-&RC. #$EN 1. #$EN 9. #$EN 7. #$EN .. ENDCASE.
Type %
DATA: N1)1?* T/%E N 2AL-E '197.?1LM00197.?'8 N9)1?* T/%E N 2AL-E '?.79100ML1?.791'8 N7)1?* T/%E N. N7 = N1 N N9. Use number types for arithmetic. Use type % fields only for pure digit strings that are not intended for calculations, e.g., telephone numbers or parts of a date or time field.
Type .
DATA: %1 T/%E % 2AL-E '197.?1LM00197.?'8 %9 T/%E % 2AL-E '?.79100ML1?.791'8 %7 T/%E %. %7 = %1 N %9.
Several Types
DATA: !1 T/%E " 2AL-E 98 !9 T/%E % DEC"MALS 9 2AL-E '7.1.'8 !7 T/%E !. !7 = !1 !9.
Ravi K
Page 9
4/8/2009
Ravi K
Page 10
4/8/2009