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..range.. error with dynamic variables

Former Member
0 Likes
696

Hi Baper's,

I'm experiencing a 'DO_WHILE_VARY_NOT_IN_RANGE'

runtime error whilst attempting a do...varying statement. The problem is that the fields that vary are all dymnically determined at runtime and assigned to field symbols. (see code snippet below).


   Data: l_percnt(2) type n.
   assign: hsl03 to <fs_loop_fld1>.
               hsl04 to <fs_loop_fld2>
  
   do l_percnt times varying l_amt from <fs_loop_fld1>
                                                 next <fs_loop_fld2>. 
 

The syntax check states that a range is required, but when I enter either

range glpct

or

 assign glpct to <fs_work_area>.... range <fs_work_area> 

. The runtime error dump is the same.

Any thoughts on how to get this to work would be greatly appeciated.

Cheers,

Stephen

2 REPLIES 2
Read only

Former Member
0 Likes
481

Hi,

U can use DO Varying in the case where u have fields in atable like belwo.

See this code

DATA: BEGIN OF WORD, 
        ONE   VALUE 'E', 
        TWO   VALUE 'x', 
        THREE VALUE 'a', 
        FOUR  VALUE 'm', 
        FIVE  VALUE 'p', 
        SIX   VALUE 'l', 
        SEVEN VALUE 'e', 
        EIGHT VALUE '!', 
      END   OF WORD, 
      LETTER1, LETTER2. 
DO VARYING LETTER1 FROM WORD-ONE NEXT WORD-THREE 
   VARYING LETTER2 FROM WORD-TWO NEXT WORD-FOUR. 
  WRITE: LETTER1, LETTER2. 
  IF LETTER2 = '!'. 
    EXIT. 
  ENDIF. 
ENDDO.

DATA: i_knc1    TYPE STANDARD TABLE OF knc1,
         w_knc1        TYPE knc1,
        lv_debit  LIKE knc1-um01s,
        lv_credit LIKE knc1-um01h.
 
 
*Calculate AR Balance for each of the customer
  CLEAR lv_ar_bal.
 
  LOOP AT i_knc1 INTO w_knc1.
    lv_ar_bal  = w_knc1-umsav.
 
    DO 15 TIMES
     VARYING lv_debit  FROM w_knc1-um01s NEXT w_knc1-um02s
     VARYING lv_credit FROM w_knc1-um01h NEXT w_knc1-um02h.
      lv_ar_bal = lv_ar_bal + lv_debit - lv_credit.
    ENDDO.
 
    IF lv_ar_bal <= 0.
      DELETE i_knc1 WHERE kunnr = w_knc1-kunnr.
    ENDIF.
    CLEAR w_knc1.
  ENDLOOP.

Check this table KNC1 and compare the same with ur table.

Hope this clears you.

Read only

0 Likes
481

Hi Judith,

Sorry for the delay in responding. Thanks for the information, but I knew that about 'do x times...', my issue was that I couldn't get it to work when using dynamic variables for the from...next...and range variables (i.e. ...from <field-symbol1> next <field-symbol2> range....).

As it was, I worked it out, I was assigning the field name to the field symbol, not the field value ( I was coding 'move w_knc1-um01s to <field-symbol1>' rather than 'move (w_knc1-um01s) to <field-symbol1>'). Once I sorted that out, it worked a peach.

Cheers,

Stephen