Application Development and Automation 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: 
Read only

internal tables

Former Member
0 Likes
1,025

Hello to all ,

Please tell me which is the best practice to define a internal table .

Bye ..

11 REPLIES 11
Read only

Former Member
0 Likes
994

hi,

the best way to declare is to define types and then declare the internal table of that type.

regards,

madhumitha.

Read only

0 Likes
994

Hi,

this is way which i follow...

TYPES : BEGIN OF ts_dd04l,

rollname TYPE dd04l-rollname,

shlpname TYPE dd04l-shlpname,

END OF ts_dd04l,

tt_dd04l TYPE STANDARD TABLE OF ts_dd04l.

DATA: wa_dd04l TYPE ts_dd04l, "wa

it_dd04l TYPE tt_dd04l. "table

Read only

Former Member
0 Likes
994

Hi Anubhav,

A good practise is (like already mentioned) create the type declaration for the table, then create the table as a standard table with the type defined above.

Also DO NOT create the table with a header line, since all OO objects dont support internal tables with header lines. Hence create a work area awith the same types structure.

Hope it helps.

Rgds,

Aditya

Read only

Former Member
0 Likes
994

Hi,

Check this example..It is better to create internal table without header line.

Example

-


TYPES: BEGIN OF TYPE_MAT_DETAIL,

MATNR TYPE MATNR,

WERKS TYPE WERKS_D,

VKORG TYPE VKORG,

END OF TYPE_MAT_DETAIL.

DATA: T_MAT_DETAIL TYPE STANDARD TABLE OF TYPE_MAT_DETAIL.

DATA: WA_MAT_DETAIL TYPE TYPE_MAT_DETAIL.

LOOP AT T_MAT_DETAIL INTO WA_MAT_DETAIL.

WRITE: / WA_MAT_DETAIL-MATNR.

ENDLOOP.

Thanks,

Naren

Read only

Former Member
0 Likes
994

Example:


TYPES: BEGIN OF ty_mara,
             matnr LIKE mara-matnr,
             matkl LIKE mara-matkl,
             END OF ty_mara.

DATA: i_mara TYPE STANDARD TABLE of ty_mara,
          wa_mara TYPE ty_mara.

So after selecting data to i_mara.

While u loop aor read always do as

LOOP AT i_mara INTO wa_mara.
.............
MODIFY i_mara from wa_mara.
clear wa_mara.
ENDLOOP.

If u appen tehn 
APPEND wa_mara TO i_mara.

READ i_mara INTO wa_mara WITH KEY .....

Hope this helps.

Read only

Former Member
0 Likes
994

Hi,

This is the best way i think.

TYPES : BEGIN OF ts_dd04l,

rollname TYPE dd04l-rollname,

shlpname TYPE dd04l-shlpname,

END OF ts_dd04l,

tt_dd04l TYPE STANDARD TABLE OF ts_dd04l.

DATA: wa_dd04l TYPE ts_dd04l, "work area

it_dd04l TYPE tt_dd04l.

Read only

Former Member
0 Likes
994

hi Anubhav,

As long as u don't specify occurs n it's a good practice but it's always advantageous using a header line . Also for best Practices u can follow this in SE38 transaction environment->examples->performance Examples.

pl. Provide points if found helpful

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
994

Hi,

If you want the all the fields in a table or structure,

data itab type standard table of table_name.

If you want only few fields from several structures,

types : begin of ty,

f1 type d1-f1,

f2 type d2-f2,

end of ty.

data itab type standard table of ty.

Read only

Former Member
0 Likes
994

Hi,

Data : begin of itab occurs 0.

(req fields),

end of itab.

Thiis will be a internal table with a work area...

but when u yse TYPES to declre a table.. please follow this..

*TYPES : BEGIN OF tp_test,

  • vbeln LIKE vbak-vbeln,

  • auart LIKE vbak-auart,

  • END OF tp_test.

*

*DATA : wa_test TYPE tp_test. " work area of type tp_test

*

*DATA : t_test TYPE tp_test OCCURS 0.. " internal table without a header line

*

*DATA : tt_test TYPE STANDARD TABLE OF tp_test. " internal table without a header line

*

*DATA : ttt_test TYPE STANDARD TABLE OF tp_test WITH HEADER LINE. " internal table with header line

Hope this helps..

Award if useful..

Rajiv

Read only

0 Likes
994

as per my coding standards

TYPES:BEGIN OF ty_ekes,
         ebeln TYPE ebeln,    "Purchasing Document Number
         ebelp TYPE ebelp,    "Item Number of Purchasing Document
         etens TYPE etens,    "Sequential Number of Vendor Confirmation
         ebtyp TYPE ebtyp,    "Confirmation category
         vbeln TYPE vbeln_vl, "Delivery
         vbelp TYPE posnr_vl, "Delivery item
         eindt TYPE bbein,    "Delivery date of vendor confirmation
        END OF ty_ekes,
        ty_ekes_t     TYPE STANDARD TABLE OF ty_ekes.

 DATA: it_ekes   TYPE ty_ekes_t,  Internal table
           wa_ekes TYPE  ty_ekes.    work area.

Read only

Former Member
0 Likes
994

Hello Anubhav,

DATA: lwa_t001 type t001,

gt_t001 like standard table of lwa_t001.

This is one of the good practice.

And dont ever declare an internal table with header line. It will have lot of performance issues.

Regs,

Venkat Ramanan N