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

Array Processing in ABAP

Former Member
0 Likes
8,010

Hi all,

I am a total newbie in ABAP.

I need to process an array in ABAP.

If it was in .NET C#, it will be like this:

String strArr = new String[5] { "A", "B", "C", "D", "E" };

int index = -1;

for (int i=0; i<strArr.length; i++)

{

if (myData.equals(strArr<i>))

{

index = i;

break;

}

}

Can someone please convert the above code into ABAP?

Urgent. Please help. <REMOVED BY MODERATOR>

THank you.

Edited by: Alvaro Tejada Galindo on Feb 22, 2008 5:37 PM

2 REPLIES 2
Read only

Former Member
0 Likes
3,108

Hi,

There is no concept of arrays in ABAP, we use internal tables to hold application data. U can use access internal tables with index.

Read table itab index l_index this is same as u do in case of arrrays a(l_index)

Instead use an Internal table to

populate the values and read them ..

say your Internal table has a field F1 ..


itab-f1 = 10.
append itab.
clear itab.

itab-f1 = 20.
append itab.
clear itab.

itab-f1 = 30.
append itab.
clear itab.

Now internal table has 3 values ...


use loop ... endloop to get the values ..

loop at itab.
write :/ itab-f1.
endloop.

Also you can do this way:

IT IS POSSIBLE TO DECLARE THE ONE -DIMENSIONAL ARRAY IN ABAP BY USING INTERNAL TABLES.

EX.)


DATA: BEGIN OF IT1 OCCURS 10,
VAR1 TYPE I,
END OF IT1.
IT1-VAR1 = 10.
APPEND IT1.
IT1-VAR1 = 20.
APPEND IT1.
IT1-VAR1 = 30.
APPEND IT1.
LOOP AT IT1.
WRITE:/ IT1-VAR1 COLOR 5.
END LOOP.

<REMOVED BY MODERATOR>

Cheers,

Chandra Sekhar.

Edited by: Alvaro Tejada Galindo on Feb 22, 2008 5:38 PM

Read only

0 Likes
3,108

the previous post is principally right, but uses a form of internal table (internal table with header line) that is depreciated. as a matter of fact it is even forbidden in an ABAP OO context.

This is the closest you can get to an array:


data: itab type standard table of i, "standard table of integer -> array of integer
        var type i. "variable of type integer

i = 1.
append i to itab.
i = 2.
append i to itab

Now you have the two values in your "array". you have to ways of accessing in a very perfomant way using field symbols.

a) directly by index


data: itab type standard table of i, "standard table of integer -> array of integer
        var type i. "variable of type integer
field-symbols:
        <fs> type i.

read table itab index 1 assigning <fs>.

b) looping at the whole table


data: itab type standard table of i, "standard table of integer -> array of integer
        var type i. "variable of type integer
field-symbols:
        <fs> type i.

loop at table itab assigning <fs>.
  "do something
endloop.