2014 Oct 02 5:09 PM
Hello guys, i started learning ABAP for a few weeks and i come across internal tables. I searched the forums and learned a few things so i wrote these 2 reports. Both accomplish the same task, but i like the second one ( REPORT TABLE 2 ) because i wrote less code but i know there must be some more differences between them. In the first report i am declaring a line type called "str",after i declare a table type based on line type called " itab02_typ", followed by a table called "itab02" based on the table type.
Maybe is there a preformance difference between these 2 reports? Thank you very much.
REPORT ZTABLE1.
types: BEGIN OF str,
carrid TYPE spfli-carrid,
connid type spfli-connid,
cityfrom type spfli-cityfrom.
types end of str.
*Declare the 'Table Type' based on the 'Line Type'
TYPES itab02_typ TYPE STANDARD TABLE OF str.
*Declare the table based on the 'Table Type'
DATA itab02 TYPE itab02_typ.
*Declare the Work Area to use with Internal Table
DATA wa_itab02 TYPE str.
SELECT CARRID CONNID CITYFROM INTO CORRESPONDING FIELDS OF TABLE ITAB02 FROM SPFLI.
LOOP AT ITAB02 INTO wa_itab02.
new-line.
WRITE:
wa_itab02-carrid,
wa_itab02-connid,
wa_itab02-cityfrom.
ENDLOOP.
REPORT ZTABLE2.
types: BEGIN OF str,
carrid type spfli-carrid,
connid type spfli-connid,
cityfrom type spfli-cityfrom.
types end of str.
"Declaring an internal table and a work area.
data: itab type table of str,
wa_itab type str.
select carrid connid cityfrom INTO CORRESPONDING FIELDS OF TABLE ITAB FROM SPFLI.
LOOP AT ITAB INTO WA_ITAB.
NEW-LINE.
WRITE: WA_ITAB-CARRID,
WA_ITAB-CONNID,
WA_ITAB-CITYFROM.
ENDLOOP.
2014 Oct 02 5:18 PM
Hi Andrei,
There is no real difference between the two programs. I would normally only do a type declaration for the table type (your itab02_typ in 2nd example) in a larger program where we might want to define methods or subroutines where the table is passed from/to as a parameter; then it's best to have a declared type. But in a case like this one, the extra type definition doesn't buy you anything. In the end, both versions create the same type of internal table and will have identical results and performance. For a difference in performance based on internal table processing you would have to have a real difference in the table type: using a SORTED or HASHED table instead of a STANDARD table (which both of your versions result in).
Jim
2014 Oct 02 5:18 PM
Hi Andrei,
There is no real difference between the two programs. I would normally only do a type declaration for the table type (your itab02_typ in 2nd example) in a larger program where we might want to define methods or subroutines where the table is passed from/to as a parameter; then it's best to have a declared type. But in a case like this one, the extra type definition doesn't buy you anything. In the end, both versions create the same type of internal table and will have identical results and performance. For a difference in performance based on internal table processing you would have to have a real difference in the table type: using a SORTED or HASHED table instead of a STANDARD table (which both of your versions result in).
Jim