This is not very common, but in some cases table structures can hold a repetition of values in a single row. Thus a record from the transparent table holds columns with similar information. An example would be from HR: table PA0008
also known as Infotype 8. This table has fields called LGA01, LGA02, LGA03 ... LGA40
The VARYING
option on the DO .. ENDDO
statement can be a great help here.
This is how it works: a DO .. ENDDO
loop is defined based on the information of the (record)structure of data, in this example PA0008
. To do this, the following bits of information need to be supplied to the statement:
- The number of repetitions (in the exampe: 40)
- The starting point of the repetition (in the example:
FROM lw_pa0008-lga01
) - The distance between the first field and it's follower (in the example:
NEXT lw_pa0008-lga02
) - The variable to store the result in (in the example:
VARYING lw_wages-lgart
) - And this whole setup can be repeated for other fields - if needed (in the example:
VARYING lw_wages-betrg ...
)
So a working example:
TYPES: BEGIN OF ty_wages, lgart TYPE pa0008-lga01, betrg TYPE pa0008-bet01, END OF ty_wages. DATA: lw_wages TYPE ty_wages, lw_pa0008 TYPE pa0008. SELECT * FROM pa0008 INTO lw_pa0008 UP TO 312 ROWS. "<= fill in a random number to get test data ENDSELECT. write: / lw_pa0008-pernr. DO 40 TIMES VARYING lw_wages-lgart FROM lw_pa0008-lga01 NEXT lw_pa0008-lga02 VARYING lw_wages-betrg FROM lw_pa0008-bet01 NEXT lw_pa0008-bet02. write: / lw_wages-lgart, lw_wages-betrg. ENDDO.