ABAP 7.4 new Feature (iv): Inner table access expression

Source: Internet
Author: User

Now the new syntax supports itab[] This array-like form, but note that if the inner table does not contain a deep struct, itab[1 [2] is not allowed, which is one of the differences between the two-dimensional array.
Can only be used in the form of itab[1]-colname, that is, using itab[] generally to return a row of data, if you want to access a row of a column, add-and column name.
Use the main index to access the inner table wa = itab[idx].
Equivalent to READ TABLE itab INDEX idx into WA.
use secondary/Level two index to access inner table WA = itab[key key index IDX].
Equivalent to READ TABLE itab index idx USING key key into WA. Note Here Itab must specify secondary index, KEY is secondary index name is not an inner table field. Example:

Types:begin of Ty,
  a type I,
  b type I,
  C type I,
  END of Ty.
DATA it2 TYPE TABLE of Ty with KEY a.
DATA wa like line of  it.
The DATA AA TYPE SORTED TABLE of Ty with the UNIQUE key A with
                                Non-unique SORTED key Second_key The components
                                b C.

AA = VALUE # (a = one
              b = c = +) (A = b = all
              c = +)
              (A = + b = c = +)).
*wa = it2[1].
WA = aa[KEY second_key INDEX 1].
Cl_demo_output=>display (WA).
Here AA defines the primary index key A, and also defines a level two index Second_key, which consists of field B C. WA = aa[KEY second_key INDEX 1]. This specifies a second_key with a level two index.

Way to access the inner table AA, then the default is in ascending order, so index 1 is actually the second row of AA (b=22 minimum). Results:



If you change the first line of B to 22 then WA is the first line, should be the smallest of B first and second row, then compare level two so the C field, see which is the smallest. Use the Inner table key to access the inner table

Like above

WA = itab[key key col1 = ... col2 = ...].

WA = itab[Key key Components col1 = ... col2 = ...].

Equivalent to read table with Table key key compnents col1 =. col2 = .... Into WA.

Note that this method must be specified so that the field that forms the key is completed.

link/Deep structure access

• itab[...] -comp
• ... struct-comp[...] ...
• itab[...] [ ... ] ...

For example, on the code and the result graph:

Types:begin of STRUC1, col1 Type I, col2 type I, END of STRUC1, ITAB1 type TABLE of STRUC1 with EMPTY KEY, ITAB2 type TABLE of ITAB1 with EMPTY KEY, BEGIN of STRUC2, col1 Type I, col2 type itab2, END of

STRUC2, Itab3 TYPE TABLE of STRUC2 with EMPTY KEY. DATA (ITAB) = value itab3 (<span style= "White-space:pre" > </span> (col1 = 1 col2 = value ITAB2 (<span style= "White-space:pre" > </span> VALUE itab1 (<span style= "White-space:pre" > </span> col 1 = 2 col2 = 3) <span style= "White-space:pre" > </span> (col1 = 4 col2 = 5)) <span style= "White  -space:pre "> </span> (VALUE itab1 (<span style=" White-space:pre "> </span> (col1 = 6 col2 = 7) <span style= "White-space:pre" > </span> (col1 = 8 col2 = 9)))) <span style= "White-space :p Re "> </span> (col1 = col2 = VALUE itab2 (<span style=" White-space:p Re "> </span> (VALUE itab1 (<span style=" White-space:pre "> </span> (col1 = one col2 = 12 ) <span style= "White-space:pre" > </span> (col1 = col2 =))) <span style= "White-space:pre" &					Gt </span> (VALUE itab1 (<span style= "White-space:pre" > </span> (col1 = col2 = +) <
Span style= "White-space:pre" > </span> (col1 = col2 = 18)))).
* Reading the column with value, with a read table statements read table Itab into DATA (WA1) INDEX 2.
READ TABLE wa1-col2 into DATA (WA2) INDEX 1.
READ TABLE wa2 into DATA (WA3) INDEX 2.
DATA (NUM1) = Wa3-col1.
Cl_demo_output=>write (NUM1).
* Reading the column with value chained table Expressions DATA (num2) = itab[2]-col2[1 [2]-col1.
Cl_demo_output=>write (num2). Cl_demo_output=>display ().


Note here that ITAB1 to 3 are types.  The point is data (num2) = itab[2]-col2[1 [2]-col1. Itab[2] is to take itab3 second line,

Then itab[2]-col2[1 [2] is to take the second row of the column col2, because the column col2 is also an inner table containing ITAB1, so col2[1 [2] is the first

The second row of the table in the ITAB1, and 13 14 that line.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.