cancel
Showing results for 
Search instead for 
Did you mean: 

Questions for "Do.. varying statement".

Former Member
0 Kudos

Hi all.

I have a problem.

I want upgrade system from SAP R/3 Enterprise to EHP4 FOR SAP ERP 6.0 / NW7.01.

I have a work area with some field


Data: begin of work_area,
   LA01 type c value "01",
   LB01 type c value "02",
   LA02 type c value "11",
   LB02 type c value "12",
   LA03 type c value "21",
   LB03 type c value "22",
end of work_area.

data:begin of work_area2,
   LA01 like work_area-LA01,
   LB01 like work_area-LB01,
end of work_area2.

** In old system**
Do 2 times.
   varying work_area2 from work_area-la01 next work_area-la02.
Enddo.

***In new system***
Do 2 times.
   varying work_area2-la01 from work_area-la01 next work_area-la02.
   varying work_area2-lb01 from work_area-lb01 next work_area-lb02.
Enddo.

I don't want use many varying statement in new system.

Can you help me some solutions?

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

SharathSYM
Contributor
0 Kudos

Loops with the VARY or VARYING can cause problems in Unicode, because, on the one hand, you cannot be sure that you are accessing memory contents with the correct type and, on the other hand, memory could be inadvertently overwritten.


DO ... VARYING f FROM f1 NEXT f2.

WHILE ... VARY f FROM f1 NEXT f2.

With these statements, the fields f, f1 and f2 must be type-compatible with one another.

To avoid overwriting memory contents, a RANGE for valid accesses is implicitly or explicitly implemented for these statements.

Error: Could not specify the access range automatically. This means that you need a RANGE addition.

Solution:

If the RANGE f3 addition is specified, a syntax or runtime error is triggered, should f1 or f2 not be included in f3. For f3, only structures and elementary fields of the types C, N, or X are permitted.

If the RANGE addition is not specified, it is implicitly defined with FROM f1 NEXT f2 as follows:

u2022 If the syntax check recognizes that both f1 and f2 are components of the same structure, the valid RANGE area is defined from the smallest structure containing f1 and f2.

u2022 There is a syntax error if the syntax check recognizes that f1 and f2 are not part of the same structure.

u2022 A valid range must be defined explicitly using RANGE if the syntax check does no recognize that f1 and f2are not together.

If a deep structure is defined as a RANGE addition, the system checks for every loop pass that there are no field references, object references, tables, or strings within the accessed range.

Example:


DO 10 TIMES VARYING B FROM A+9(1) NEXT A+8(1). "In 4.6 version.

Will be replaced with


DO 10 TIMES VARYING B FROM A+9(1) NEXT A+8(1) RANGE A+0(1).

For more details goto Link:

http://wiki.sdn.sap.com/wiki/display/SI/UCCHECK%28UnicodeComplaince%29-CommonErrorsand+Solutions

Former Member
0 Kudos

Thanks for help.

But if some field in work_area type P. Can't use offset for varying statement.

Anybody help me?

SharathSYM
Contributor
0 Kudos

I had given the example just for understanding.

You can try using any fields for ... VARYING f FROM f1 NEXT f2

just be sure that the fields f1 and f2 should be type-compatible and convertible to f.

Just for reference an Example:-


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.

The resulting output is the character string

"E x a m p l e !".

Former Member
0 Kudos

I understand but i have example for you.


DATA: BEGIN OF WORK_AREA,
   LA01(2) TYPE C VALUE '01',
   LB01(2) TYPE P VALUE 02,
   LA02(2) TYPE C VALUE '11',
   LB02(2) TYPE P VALUE 12,
   LA03(2) TYPE C VALUE '21',
   LB03(2) TYPE P VALUE 22,
   LA04(2) TYPE C VALUE '31',
   LB04(2) TYPE P VALUE 32,
   LA05(2) TYPE C VALUE '41',
   LB05(2) TYPE P VALUE 42,
END OF WORK_AREA.

DATA:BEGIN OF WORK_AREA4,
   LA01 LIKE WORK_AREA-LA01,
   LB01 LIKE WORK_AREA-LB01,
END OF WORK_AREA4.

I want copy data from work_area-la01 next work_area-la02 into work_area4. How can i use varying statement?

Thanks

Edited by: hieudv91 on Feb 9, 2012 10:52 AM