Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Internal table with and with out work area.

Former Member
0 Kudos

Hi all,

in performance terms which one is better 1) internal table with header line or 2) itab w/o header line and explicit work area for that itab.

which one is better and how?

Thanks in advance.

SAI

1 ACCEPTED SOLUTION

former_member480923
Active Contributor
0 Kudos

Hi

the second option is better as it does not keep a fixed work area for all the tables, but would work better if Field symbols are used instead of WA.

Hope its helps

Anirban

7 REPLIES 7

former_member480923
Active Contributor
0 Kudos

Hi

the second option is better as it does not keep a fixed work area for all the tables, but would work better if Field symbols are used instead of WA.

Hope its helps

Anirban

Former Member
0 Kudos

Hai Sai Ram

Internal Table with header Line Improves the Performence

1)

TABLES CUSTOMERS.

  • Defining an internal table with header line

DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100

WITH HEADER LINE.

  • Reading all entries of the database table into the internal table

SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.

2)

Check the following code for the Difference

REPORT ZWRITEDOC LINE-SIZE 124 NO STANDARD PAGE HEADING.

TABLES: DD03L, "

DD04T, "R/3-DD: Textos de los elementos de datos

DD02T. "R/3-DD: Textos de tablas SAP

  • Tabla temporal con las lineas de cada tabla

DATA: BEGIN OF I_LINEAS OCCURS 100,

LINEA(80),

END OF I_LINEAS.

  • Tabla con las caracteristicas de la tabla

DATA: BEGIN OF I_TABLA OCCURS 100,

CAMPO(12),

TIPO(4),

LONG(5) TYPE I,

REF(20),

DESCR(40),

END OF I_TABLA.

DATA: D_NOMBRE(80),

D_DESCRIPCION(80).

DATA : BEGIN OF SOURCE OCCURS 1000,

LINE(72),

END OF SOURCE.

PARAMETERS: PROGRAM LIKE SY-REPID DEFAULT SY-REPID.

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'GRAB'.

PERFORM GRABAR.

ENDCASE.

START-OF-SELECTION.

SET PF-STATUS 'ZSTATUS1'.

READ REPORT PROGRAM INTO SOURCE.

DATA L_GRAB.

CLEAR L_GRAB.

LOOP AT SOURCE.

  • translate source to upper case.

IF L_GRAB IS INITIAL.

D_DESCRIPCION = I_LINEAS-LINEA.

ENDIF.

I_LINEAS = SOURCE.

SEARCH I_LINEAS-LINEA FOR 'BEGIN OF'.

IF SY-SUBRC = 0.

SEARCH I_LINEAS-LINEA FOR 'DATA'.

IF SY-SUBRC = 0.

L_GRAB = 'X'.

FREE I_LINEAS.

ENDIF.

ENDIF.

IF L_GRAB = 'X'.

I_LINEAS = SOURCE.

APPEND I_LINEAS.

SEARCH I_LINEAS-LINEA FOR 'END OF'.

IF SY-SUBRC = 0.

CLEAR L_GRAB.

PERFORM PROCESAR_FICHERO.

PERFORM IMPRIMIR.

FREE I_LINEAS.

CLEAR D_DESCRIPCION.

ENDIF.

ENDIF.

SEARCH I_LINEAS-LINEA FOR 'WITH HEADER LINE'.

IF SY-SUBRC = 0.

APPEND I_LINEAS.

PERFORM PROCESAR_FICHERO.

PERFORM IMPRIMIR.

ENDIF.

ENDLOOP.

&----


*& Form GRABAR

&----


  • Graba el fichero en c:\temp\p.rtf y lo abre con word.

----


FORM GRABAR.

CALL FUNCTION 'LIST_DOWNLOAD'

EXPORTING

  • LIST_INDEX = SLIST_INDEX_DEFAULT

METHOD = 'RTF'

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'EXECUTE_WINWORD'

EXPORTING

I_FILE = 'C:\TEMP\P.RTF'

EXCEPTIONS

OTHERS = 1.

ENDFORM. " GRABAR

&----


*& Form PROCESAR_FICHERO

&----


FORM PROCESAR_FICHERO.

DATA: L_AUX1(80),

L_AUX2(80).

FREE I_TABLA.

LOOP AT I_LINEAS.

CLEAR I_TABLA.

  • translate i_lineas-linea to upper case.

SEARCH I_LINEAS-LINEA FOR 'BEGIN OF'.

IF SY-SUBRC = 0.

SPLIT I_LINEAS-LINEA AT 'BEGIN OF' INTO L_AUX1 D_NOMBRE.

SPLIT D_NOMBRE AT 'OCCURS' INTO D_NOMBRE L_AUX1.

ENDIF.

SEARCH I_LINEAS-LINEA FOR '('.

IF SY-SUBRC = 0.

SPLIT I_LINEAS-LINEA AT '(' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX1.

I_TABLA-CAMPO = L_AUX1.

SPLIT L_AUX2 AT ')' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX1.

IF L_AUX1 CO '0123456789 '.

I_TABLA-LONG = L_AUX1.

ENDIF.

I_TABLA-TIPO = 'CHAR'.

ENDIF.

SEARCH I_LINEAS-LINEA FOR 'LIKE'.

IF SY-SUBRC = 0.

SPLIT I_LINEAS-LINEA AT 'LIKE' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX1.

I_TABLA-CAMPO = L_AUX1.

SPLIT L_AUX2 AT ',' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX1.

I_TABLA-REF = L_AUX1.

ENDIF.

SEARCH I_LINEAS-LINEA FOR 'TYPE'.

IF SY-SUBRC = 0.

SPLIT I_LINEAS-LINEA AT 'TYPE' INTO L_AUX1 L_AUX2.

IF I_TABLA-CAMPO IS INITIAL.

CONDENSE L_AUX1.

I_TABLA-CAMPO = L_AUX1.

ENDIF.

SPLIT L_AUX2 AT ',' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX1.

CASE L_AUX1.

WHEN 'I'.

I_TABLA-TIPO = 'INT'.

I_TABLA-LONG = 4.

WHEN 'C'.

I_TABLA-TIPO = 'CHAR'.

WHEN 'N'.

I_TABLA-TIPO = 'NUMC'.

WHEN 'T'.

I_TABLA-TIPO = 'TIME'.

I_TABLA-LONG = 8.

WHEN OTHERS.

I_TABLA-TIPO = L_AUX1.

ENDCASE.

ENDIF.

SEARCH I_LINEAS-LINEA FOR '"'.

IF SY-SUBRC = 0.

SPLIT I_LINEAS-LINEA AT '"' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX2.

I_TABLA-DESCR = L_AUX2.

ENDIF.

SEARCH I_LINEAS-LINEA FOR 'INCLUDE STRUCTURE'.

IF SY-SUBRC = 0.

SPLIT I_LINEAS-LINEA AT 'INCLUDE STRUCTURE' INTO L_AUX1 L_AUX2.

SPLIT L_AUX2 AT '.' INTO L_AUX1 L_AUX2.

CONDENSE L_AUX1.

I_TABLA-CAMPO = 'INCLUDE STR'.

I_TABLA-REF = L_AUX1.

ENDIF.

SEARCH I_LINEAS-LINEA FOR 'WITH HEADER LINE'.

IF SY-SUBRC = 0.

IF NOT I_LINEAS-LINEA CA '"'.

SPLIT I_LINEAS-LINEA AT 'OCCURS' INTO L_AUX1 L_AUX2.

IF SY-SUBRC = 0.

SPLIT L_AUX1 AT 'LIKE' INTO L_AUX1 L_AUX2.

IF SY-SUBRC = 0.

CONDENSE L_AUX2.

IF NOT L_AUX2 IS INITIAL.

I_TABLA-CAMPO = '...'.

I_TABLA-TIPO = 'TABI'.

I_TABLA-REF = L_AUX2.

SELECT SINGLE * FROM DD02T

WHERE TABNAME = L_AUX2

AND DDLANGUAGE = SY-LANGU.

IF SY-SUBRC = 0.

I_TABLA-TIPO = 'TABE'.

I_TABLA-DESCR = DD02T-DDTEXT.

ENDIF.

IF L_AUX1 CA ':'.

SPLIT L_AUX1 AT 'DATA:' INTO L_AUX1 L_AUX2.

ELSE.

SPLIT L_AUX1 AT 'DATA' INTO L_AUX1 L_AUX2.

ENDIF.

D_NOMBRE = L_AUX2.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

IF NOT I_TABLA-CAMPO IS INITIAL.

APPEND I_TABLA.

ENDIF.

ENDLOOP.

LOOP AT I_TABLA WHERE NOT REF IS INITIAL.

SPLIT I_TABLA-REF AT '-' INTO L_AUX1 L_AUX2.

SELECT SINGLE * FROM DD03L

WHERE TABNAME = L_AUX1

AND FIELDNAME = L_AUX2.

IF SY-SUBRC = 0.

I_TABLA-TIPO = DD03L-DATATYPE.

I_TABLA-LONG = DD03L-INTLEN.

IF I_TABLA-DESCR IS INITIAL.

SELECT SINGLE * FROM DD04T

WHERE ROLLNAME = DD03L-ROLLNAME

AND DDLANGUAGE = SY-LANGU.

IF SY-SUBRC = 0.

I_TABLA-DESCR = DD04T-DDTEXT.

ENDIF.

ENDIF.

MODIFY I_TABLA.

ENDIF.

ENDLOOP.

ENDFORM. " PROCESAR_FICHERO

&----


*& Form IMPRIMIR

&----


FORM IMPRIMIR.

DATA L_AUX(80).

FORMAT COLOR COL_NORMAL INTENSIFIED ON.

ULINE AT 1(80).

WRITE: / SY-VLINE,

(76) D_NOMBRE CENTERED,

SY-VLINE.

SPLIT D_DESCRIPCION AT '*' INTO L_AUX D_DESCRIPCION.

WRITE: / SY-VLINE,

(76) D_DESCRIPCION CENTERED,

SY-VLINE.

NEW-LINE.

ULINE AT 1(80).

DETAIL.

FORMAT COLOR OFF.

WRITE: /

SY-VLINE,

(10) 'CAMPO',

SY-VLINE,

(4) 'TIPO',

SY-VLINE,

(4) 'LONG',

SY-VLINE,

(16) 'REFERENCIA',

SY-VLINE,

(30) 'DESCRIPCION',

SY-VLINE.

NEW-LINE.

ULINE AT 1(80).

DETAIL.

LOOP AT I_TABLA.

WRITE: /

SY-VLINE,

(10) I_TABLA-CAMPO,

SY-VLINE,

I_TABLA-TIPO,

SY-VLINE,

(4) I_TABLA-LONG,

SY-VLINE,

(16) I_TABLA-REF,

SY-VLINE,

(30) I_TABLA-DESCR,

SY-VLINE.

ENDLOOP.

NEW-LINE.

ULINE AT 1(80).

SKIP 2.

ENDFORM. " IMPRIMIR

Thanks & regards

Sreeni

nishanthbhandar
Contributor
0 Kudos

Option 2 is better in terms of performance.In case of option 1 memory is allocated to the table header line even though it might not get used in the program.But in case of explicit header line you would be making use of the workarea only when required.

<i>reward helpful answers</i>

Cheers

Nishanth

Former Member
0 Kudos

HI

GOOD

INTERNAL TABLE WITH HEADER LINE->

http://sap.mis.cmich.edu/sap-abap/abap04/sld012.htm

Internal Tables With Header Line

You access internal tables record by record. You must use a work area as an interface for transferring data to and from the table.

When you read data from an internal table, the contents of a specified table record or line overwrites the contents of the work area. Then, you can reference the contents of the work area in your program. When you write data to an internal table, you must first enter the data in the work area from with the system can transfer the data to the internal table.

INTERNAL TABLE WITHOUT HEADER LINE=>

http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb36a1358411d1829f0000e829fbfe/content.htm

THANKS

MRUTYUN

former_member186741
Active Contributor
0 Kudos

tables without header lines occupy less space. Header line or work area use within a loop is identical in terms of performance.

Looping through a table assigning a field-symbol instead of using a header line (or a work area) is more efficient as it doesn't physically transfer the data to the eader line or work area, instead the field symbol is used as a cursor. But this option can be used even for tables with header lines. But this performance benefit will only be apparent if you have massive tables.

former_member188685
Active Contributor
0 Kudos

Hi Sai ram,

Option two is Better, here when you want to use explicit work area you will allocate memory for it or else you will leave, But in case of header line the memory will allocated when it is declared.

Regards

vijay

former_member404244
Active Contributor
0 Kudos

Hi,

Option two is Better, always using without header line,becoz

if u use with haeder line it allocates memory...

when ever declaring internal tables try to declare with types(structure),for example..

types : begin of ty_tab,

matnr type matnr,

end of ty_tab.

data : it_tab type standard table of ty_tab,

wa_tab type ty_tab.

The above type declaration is better.Also try to use fieldsymbols which increase the perforamnce

Pls reward points if u find useful.

Regards,

Nagaraj