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 loop

Former Member
0 Likes
1,724

Hi Experts,

I have a code in ECC version like this:

DO 6 TIMES

VARYING W_COUNT FROM <FS1> NEXT <FS2>

VARYING W_AMOUNT FROM <FS3> NEXT <FS4>.

FROM <FS3> NEXT <FS4>.

W_DISCPERCENT = W_AMOUNT / W_SUM_REC_AMT * 100.

WRITE AT W_COLPOS(5) W_COUNT .

WRITE (12)W_AMOUNT DECIMALS 0

CURRENCY W_WAERS. "GAP03/4.

WRITE (7) W_DISCPERCENT .

W_COLPOS = W_COLPOS + 27.

ENDDO.

So when i exicute my pgm it is giving error like:

Could not specify access range automatically.This means the u need a Range addition

How to do this?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
883

Hi,

You need to add the range addition also.

The addition RANGE determines the memory area that can be processed using the addition VARYING. After RANGE, an elementary data object range of type c, n, or x, or a structure can be specified. The memory area of range must include the ranges of dobj1 and dobj2. In deep structures, the deep components are exceptions to the permitted area. The DO loop must be ended before non-permitted memory areas are accessed, that is, areas outside of range or their deep components. Otherwise this may lead to an untreatable exception.

If RANGE is not explicitly specified, the permitted memory area is determined as follows:

In non-Unicode programs and before release 6.10, the permitted memory area of dobj1 extends to the limit of the current data area of the ABAP program. If the RANGE addition is not specified, there is a danger of unintentionally overwriting the memory.

In Unicode programs, , <b>RANGE can only be omitted if it can be statically determined that dobj1 and dobj2 are components of the same structure. The permitted memory area is then determined from the smallest substructure that contains dobj1 and dobj2.</b>

Regards,

Richa

7 REPLIES 7
Read only

former_member186741
Active Contributor
0 Likes
883

The Range option specifies the limits of the assignment. In the following example the 'range' option was used to ensure that the field-symbol <source_figure> was always within the limts of structure variable T_KNC1. It is used as protection to ensure the program does not accidentally overwrite some storage that it should not.

CONCATENATE l_month_slot_name l_month_slot

INTO l_month_slot_name.

ASSIGN (l_month_slot_name) TO <month_total>.

ASSIGN (l_total_name) TO <source_figure>.

DO l_period_ct TIMES.

MOVE <source_figure> TO <month_total>.

ADD <source_figure> TO w_total-new_umsa1.

ASSIGN <source_figure> INCREMENT 1 TO <source_figure>

RANGE t_knc1.

ASSIGN <month_total> INCREMENT 1 TO <month_total>

RANGE w_total.

ENDDO.

In your example it would be similar:

DO 6 TIMES

VARYING W_COUNT FROM <FS1> NEXT <FS2> <b>range your_structure</b>

VARYING W_AMOUNT FROM <FS3> NEXT <FS4>.

FROM <FS3> NEXT <FS4> <b>range your_structure</b>.

W_DISCPERCENT = W_AMOUNT / W_SUM_REC_AMT * 100.

WRITE AT W_COLPOS(5) W_COUNT .

WRITE (12)W_AMOUNT DECIMALS 0

CURRENCY W_WAERS. "GAP03/4.

WRITE (7) W_DISCPERCENT .

W_COLPOS = W_COLPOS + 27.

ENDDO.

Read only

Former Member
0 Likes
884

Hi,

You need to add the range addition also.

The addition RANGE determines the memory area that can be processed using the addition VARYING. After RANGE, an elementary data object range of type c, n, or x, or a structure can be specified. The memory area of range must include the ranges of dobj1 and dobj2. In deep structures, the deep components are exceptions to the permitted area. The DO loop must be ended before non-permitted memory areas are accessed, that is, areas outside of range or their deep components. Otherwise this may lead to an untreatable exception.

If RANGE is not explicitly specified, the permitted memory area is determined as follows:

In non-Unicode programs and before release 6.10, the permitted memory area of dobj1 extends to the limit of the current data area of the ABAP program. If the RANGE addition is not specified, there is a danger of unintentionally overwriting the memory.

In Unicode programs, , <b>RANGE can only be omitted if it can be statically determined that dobj1 and dobj2 are components of the same structure. The permitted memory area is then determined from the smallest substructure that contains dobj1 and dobj2.</b>

Regards,

Richa

Read only

0 Likes
883

Hi Thanks,

So in the above code where exactly i have to add RANGE?

Regards

Read only

0 Likes
883

Ravi,

I have already shown you where to put the range, the only thing you have to determine is what to put as the value where I have put 'your_structure'. If you can't figure it out show all your code and someone will be able to help you:

DO 6 TIMES

VARYING W_COUNT FROM <FS1> NEXT <FS2><b> range your_structure</b>

VARYING W_AMOUNT FROM <FS3> NEXT <FS4>.

FROM <FS3> NEXT <FS4> <b>range your_structure</b>.

W_DISCPERCENT = W_AMOUNT / W_SUM_REC_AMT * 100.

WRITE AT W_COLPOS(5) W_COUNT .

WRITE (12)W_AMOUNT DECIMALS 0

CURRENCY W_WAERS. "GAP03/4.

WRITE (7) W_DISCPERCENT .

W_COLPOS = W_COLPOS + 27.

ENDDO.

Read only

0 Likes
883

HI Thanks,

But here i have 2 structures:

like

VARYING W_COUNT FROM <FS1> NEXT <FS2>

VARYING W_AMOUNT FROM <FS3> NEXT <FS4>.

So which structure i have to give here?

is like this?

VARYING W_COUNT FROM <FS1> NEXT <FS2> RANGE <FS1>

VARYING W_AMOUNT FROM <FS3> NEXT <FS4>.

Read only

0 Likes
883

show us the code just before this where <FS1>,<FS2> etc are initially given values. Maybe the names are constructed in a variable and then assigned to start with?

Read only

Former Member
0 Likes
883

see the sample code for Using the Varing it was working .....

DATA: BEGIN OF text, 
        word1 TYPE c LENGTH 4 VALUE 'AAAA', 
        word2 TYPE c LENGTH 4 VALUE 'BBBB', 
        word3 TYPE c LENGTH 4 VALUE 'CCCC', 
        word4 TYPE c LENGTH 4 VALUE 'DDDD', 
      END OF text. 

DATA: word  TYPE c LENGTH 4, 
      char1 TYPE c LENGTH 1, 
      char2 TYPE c LENGTH 1, 
      leng TYPE i. 

FIELD-SYMBOLS <word> LIKE text-word1. 
DATA inc TYPE i. 

DESCRIBE FIELD text LENGTH leng IN CHARACTER MODE. 
leng = leng / 2. 

DO leng TIMES VARYING char1 FROM text(1) 
                            NEXT text+2(1) RANGE text 
              VARYING char2 FROM text+1(1) 
                            NEXT text+3(1) RANGE text. 
  WRITE: char1, char2. 
  char1 = 'x'. 
  char2 = 'y'. 
ENDDO. 

DO 4 TIMES VARYING word FROM text-word1 NEXT text-word2. 
  WRITE / word. 
ENDDO. 

DO. 
  inc = sy-index  - 1. 
  ASSIGN text-word1 INCREMENT inc TO <word> RANGE text. 
  IF sy-subrc = 0. 
    WRITE / <word>. 
  ELSE. 
    EXIT. 
  ENDIF. 
ENDDO.

Girish