abap complete internal tables

Internal tables

 

When you are using ABAP/4, you will mainly work with tables. Tables are the most important data structures in the R/3 system. Data with a long life are stored in relational databases.

Apart from database tables, you can create internal tables that exist only at runtime of the program. ABAP/4 offers several operations for working with internal tables. You can, for example, search for lines or append, insert, or delete lines.

The number of lines of an internal table is not fixed. If required, the system expands internal tables at runtime. That means, if you want to read a database table into an internal table, you must not know the size of the database table in advance. This makes internal tables easy to use.

You can use internal tables for table calculations on subsets of database tables. You can, for example, read a certain part of one or more database tables into an internal table. You can use internal tables for calculating totals or for creating ranked lists.

 

And you can use internal tables to reorganize table contents or database tables according to the needs of the program. To create a list, you can read certain data from one or more large customer tables into an internal table. At runtime of your program, you can then access this data directly, without having to start the time-consuming database scan for each program call.

After working through the exercises below, you are able to

 

· declare an internal table

· fill an internal table

· change, output, and delete individual elements

· sort tables by any fields

· understand and use control levels.

 

 

Declaring a structure

 

Before you can use structures and internal tables in your program, you must declare them.

 

Example

 

Declare a structure that contains one column for the departure city (CITYFROM), one for the arrival city (CITYTO), one for the airline (CARRID), and one for the flight connection (CONNID). Use parts of the structure of database table SPFLI.

 

1. Create a new program. When maintaining the attributes, make sure to use the logical database F1S for data retrieval.

2. Declare the structure using the statement pattern. Position the cursor in the declaration section of your program and choose Pattern.

3. On the dialog box, mark the radio button Internal table.

 

Note

 

There is no extra pattern for structures. Since it takes only two modifications to change the declaration of an internal table into the declaration of a structure, we, nevertheless, use the statement pattern for internal tables here.

 

4. Mark with LIKE fields fr. and enter the name of the database table into the adjacent input field.

 

The item with LIKE fields fr. allows you to select parts of the structure of a database table. If you mark with LIKE for struct. of instead, you copy the entire structure of the database table.

 

5. Choose Continue.

6. Mark the fields which you need in the internal table.

7. Choose Copy.

8. Specify the name <structure> of the structure to be defined and choose Continue.

9. Replace the keyword DATA, used for the declaration of an internal table, by the keyword TYPES, used for structures, and delete the option OCCURS 0 from the pattern. The declaration then looks like this:

 

TYPES: BEGIN OF structure,

CARRID LIKE SPFLI-CARRID,

CONNID LIKE SPFLI-CONNID,

CITYFROM LIKE SPFLI-CITYFROM,

CITYTO LIKE SPFLI-CITYTO,

END OF structure.

 

The statement block starts with the keyword TYPES. The beginning of the declaration of structure <structure> is marked by the statement BEGIN OF <structure>. Then, the individual fields of the structure are declared. The declaration ends with the line END OF <structure>. To declare additional fields for the structure, include the field declarations between BEGIN OF <structure> and END OF <structure>.

 

 

Declaring an internal table

 

In the last exercise, you declared a structure. Now, declare an internal table, based on this structure.

 

Example

 

Declare an internal table, based on the structure <structure> you declared in the last exercise.

 

1. Fetch the program created for the last exercise into the editor.

2. Declare the internal table in the declaration section of your program below the declaration of the structure. The statement you need is:

 

DATA itab TYPE structure OCCURS 0.

 

The statement starts with the keyword DATA, followed by the name of the internal table.

The keyword TYPE refers to the previously declared structure <structure>.

The keyword OCCURS defines the structure as internal table. The number behind OCCURS determines the number of lines the table has after initialization. As mentioned in Internal tables, the size of an internal table is variable, that is, the system can expand the number of lines beyond the predefined size, if required.

 

Note

 

If you forget to include the keyword OCCURS into the declaration, the result is a field string instead of an internal table. However, you use such a field string as work area for an internal table.

 

 

Defining the work area

 

To change or output the contents of an internal table, you need a work area. When processing an internal table, the system always fills the work area with the contents of the current table line. You can then process the work area.

How to define a work area:

 

1. If you use an internal table with header line, the system automatically creates a work area (the header line) with the same name as the internal table.

2. If you use an internal table without header line, define a field string of the same structure and use it as work area for the internal table.

 

In the exercises below, you will work with internal tables without header lines. Therefore, you need a work area.

 

Example

 

Define a work area for the internal table without header line created in the last exercise.

 

1. Fetch the program you created in the last exercise into the editor.

2. Incluse this line to declare a work area <wa> for the internal table <itab>:

 

DATA: wa TYPE structure.

 

3. Check the syntax and save your program.

 

You defined a work area <wa> with the same structure <structure>as the internal table <itab>. You can use this work area in the exercises below to display or change the contents of the internal table. You can access the fields of the work area as you would access fields in the work area of database tables. First, specify the name of the work area <wa>, then a hyphen, and finally the field name:

WA-CONNID is the field CONNID of work area WA.

 FOR RELATED POSTS U CAN ALSO BROWSE

http://www.abapprogramming.blogspot.com

 

 

 

 

About these ads

18 Responses to abap complete internal tables

  1. sami says:

    Effective tutorial. but I did not get what ’0′ does in ‘OCCURS 0′. Does it mean that the internal table itab has zero line at the start?

    Thanks

  2. Rais Ahmad says:

    we can specify occurs 0. If you do this, the system allocates 8KB pages of memory at a time. However, there are no advantages to using occurs 0 other than the fact it is only a little easier to code occurs 0 than it is to estimate the size of the
    internal table.

  3. debt program says:

    You also have a chance to improve your credit score.
    One obtains a loan, even with poor credit record. Banks and other financing institutions are rising to
    offer a help with debt at some point in a person’s life they come to a conclusion that they are becoming more trustworthy. You will have a chance of borrowing best help with debt, by contrast, lenders aren’t on the hook if used-car values plummet.

  4. Hello there! Very valuable hint on this post! It is the little tweaks which result in the largest change.
    Appreciate it!

  5. I’ve been surfing online more than 4 hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the net will be much more useful than ever before.

  6. Do keep your computer save by following these tips.
    Software wise, it would be a good idea to clean up
    your computer registry using a registry cleaner. If
    you are searching for a qualified technician to check and spot your and to solve them immediately then you should take a look at Connect Global.

  7. Ahaa, its good discussion regarding this
    piece of writing here at this web site, I have read all that, so
    now me also commenting at this place.

  8. Hey there very nice blog! Wonderful. Amazing . I will bookmark your blog
    and also use the rss feeds also. Regards!

  9. Hello there, You have done an excellent job. I’ll certainly digg it and personally suggest to my friends. I am confident they will be benefited from this web site.

  10. I am really enjoying the theme/design of your weblog.
    Do you ever run into any browser compatibility issues?

    A few of my blog readers have complained about my website not
    operating correctly in Explorer but looks great in Opera.
    Do you have any suggestions to help fix this issue?

  11. Hi there, yes this post is actually nice and I have learned lot of things
    from it regarding blogging. thanks.

  12. I think all your tips are wonderful! Break up and also list it down.
    It always seems better and more readable if you write
    your points like that. Thanks a lot for the tips! Thanks a lot!

  13. Generally I do not read article on blogs, however I would like to say that this write-up
    very compelled me to try and do so! Your writing taste has been amazed me.
    Thank you, very great article.

  14. Thanks , I have recently been searching for info about this topic for a while and
    yours is the greatest I’ve found out so far.
    But, what about the bottom line? Are you positive about the source?

  15. Hello my family member! I want to say that this post is awesome, nice written and include almost all significant infos.

    I would like to peer more posts like this .

  16. What’s up to every , because I am truly eager of reading this blog’s post to be updated on a regular basis.
    It carries nice information.

  17. Sweet blog! Ifound it while browsing on Yahoo News.
    Do you have any tips on howw tto get listed in Yahoo
    News? I’ve been trying for a while but I never seem to get there!
    Many thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: