VARYING command is a function of the DO loop which allows you to move horizontaly along a table row without actually having to specify each individual field name. i.e. if the table row had the fields: Field1 Field2 Field3 Field4 etc you would be able to loop around each field using only one DO..VARYING command.
For sample, we want to read field LGA01 – LGA40 and BET01 – BET40 from P0008 infotype, and get their value according your condition.
DO 40 TIMES VARYING lv_lga FROM p0008-lga01 NEXT p0008-lga02
VARYING lv_betrg FROM p0008-bet01 NEXT p0008-bet02.
IF lv_lga IN lr_lgart.
IF lv_betrg NE 0.
lv_z = lv_betrg.