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

do...varying... with variable starting point 'from'

Former Member
0 Likes
3,023

Hi together,

I want to use 'do...varying...' in order to add special columns (e.g. hsl03 to hsl10 of tabel faglfext).

The problem is that the starting point ( hsl03) is set variably:

DO x TIMES VARYING i_sum FROM faglflext-hslxx NEXT 'faglflext-hslxx + 1'

Thanks for any help

Hi together,

I want to use 'do...varying...' in order to add special columns (e.g. hsl03 to hsl10 of tabel faglfext).

The problem is that the starting point ( hsl03) is set variably:

DO x TIMES VARYING i_sum FROM faglflext-hslxx NEXT 'faglflext-hslxx + 1'

Thanks for any help

3 REPLIES 3
Read only

Former Member
0 Likes
2,433

The 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.

*Code to demonstrate VARYING command

  • The varying comand works on the position within the row, therfore

  • each field must be the same number of fields apart.

DATA: ld_p0121 type p0121-rfp01,

ld_numcont type i.

DO 21 TIMES VARYING ld_p0121 FROM p0121-RFP01 NEXT p0121-RFP02.

IF not ld_p0121 IS INITIAL.

ld_numcont = ld_numcont + 1.

ENDIF.

ENDDO.

*Code to demonstrate multiple field VARYING command

DATA: ld_kst0x LIKE p0027-kst02,

ld_auf0x LIKE p0027-auf02,

ld_psp0x LIKE p0027-psp02.

DO 25 TIMES VARYING ld_kst0x FROM p0027-kst02 NEXT p0027-kst03

VARYING ld_auf0x FROM p0027-auf02 NEXT p0027-auf03

VARYING ld_psp0x FROM p0027-psp02 NEXT p0027-psp03.

PERFORM get_cost_center_and_text USING ld_kst0x

ld_auf0x

ld_psp0x.

APPEND output_tab.

ENDDO.

Read only

0 Likes
2,433

Hi,

I know, how it works in general.

If you look at your exaple:

DO 21 TIMES VARYING ld_p0121 FROM p0121-RFP01 NEXT p0121-RFP02.

My problem is that position/fieldname p0121-RFP01 is 'unknown' because it is set dynamically by entering the

starting period on the selection dynpro of the report.

e.g. you want to calculate the sum of faglflext-hsl02 to faglflext-hsl06.

Therefore you put period 2 ...to 6 into the according parameter fields.

In this case the coding would be like:

do 5 times varying i_sum from faglflext-hsl02 next faglflext-hsl03.

i_total = i_total + i_sum.

...

Read only

0 Likes
2,433

Hi,

Thanks for your help.

Gues I´ve resolved the puzzle.