很多时候我们需要在一个循环或者批量处理很多名称类似的变量,且这些变量名是可序的,即存在数字规律的,比如WORD01,WORD02等等。那么一个很好用的语法可以实现:VARYING 可以使用DO-VARING

DO 39 TIMES VARYING l_value FROM t_list_history_03-zhr_col01 NEXT t_list_history_03-zhr_col02.
      PERFORM sub_set_cell_value USING application l_row l_col l_value.
      l_row = l_row + 1.
    ENDDO.

以下是SAP帮助文档

DO - varying

Syntax

DO ... VARYING dobj FROM dobj1 NEXT dobj2 [RANGE range].
  [statement_block]
ENDDO.

Effect

: The addition VARYING assigns a new value to a variable dobj for each run of a DO loop. It can be used more than once in a DO statement.

dobj1 and dobj2 are the first two data objects in a sequence of data objects that are the same distance apart in the memory. The data types of the data objects dobj, dobj1, and dobj2 must be flat.

In Unicode programs, dobj, dobj1, and dobj2 must be compatible. Also in Unicode programs, dobj1 and dobj2 must either be structure components that belong to the same structure, or subareas of the same data object specified by offset/length specifications.

In the first completion of the loop, the content of the data object dobj1 is assigned to dobj, and in the second loop, the content of the data object dobj2 is assigned. In the subsequent loops, dobj is assigned the content of the data object that is the same distance in the memory from the previously assigned data object, as dobj2 is from dobj1. There is no type conversion.

If the processing block is not exited within the loop, the content of the variable dobj at the end of the loop run is assigned to the previously assigned data object dobj1 or dobj2 without conversion.

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

Note

: Instead of the addition VARYING, the statement ASSIGN should be used in the loop with the addition INCREMENT.

Example

: In the first DO loop, subareas of the data object text are edited using offset/length access. In Unicode programs, the addition RANGE must be specified here. In the second DO loop, the program accesses the components of the data object text. In this case, it is not necessary to specify RANGE. The third DO loop shows how the functions of the second loop can be programmed using the statement ASSIGN INCREMENT.

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.

Exceptions

Non-Catchable Exceptions

  • Cause: Impermissible access to tables, strings, field or object references within the range specified by the RANGE addition.
    Runtime Error: DO_WHILE_VARY_ILLEGAL_ACCESS
  • Cause: Access to data outside the range specified by the RANGE addition.
    Runtime Error: DO_WHILE_VARY_NOT_IN_RANGE

DO - varying相关推荐

  1. GLSL三种修饰符区别与用途(uniform,attribute和varying)

    2019独角兽企业重金招聘Python工程师标准>>> 1.uniform变量 uniform变量是application传递给shader的变量,在application外部赋值, ...

  2. Space Time Varying Color Palette

    PDF Space Time Varying Color Palettes from Bo Zhou 转载于:https://www.cnblogs.com/Jedimaster/p/4941857. ...

  3. Postgresql的character varying = bytea问题

    Java开发Postgresql 数据库兼容应用的问题,与Oracle有一些不同: Java类型映射数据库类型的不同,Oracle jdbc驱动程序处理Java String类型可正常映射到数据库的N ...

  4. 关于字段超长导致的插入错误的提示信息(value too long for type character varying)

    关于字段超长导致的插入错误的提示信息 背景 你们肯定遇到过这样的错误,跑的程序需要插入或更新一张表,值的长度超过字段最大限制而报错.要如何定位是哪个字段长度过小导致的? 方法 1.先要获取错误信息 最 ...

  5. JPA ERROR: value too long for type character varying(100)

    生产上出现问题,一个功能导入Excel,本来代码中写的是两万条记录,但是现实是只能导入20条记录.然后查看日志发现报错. ERROR: value too long for type characte ...

  6. 使用string_to_array时,报错operator does not exist: character varying = text[]

    我: 在pgsql中使用 a.type in ( string_to_array( (select cii.type from cinfo cii where cii.cidx = a.cidx), ...

  7. Cg学习记录003 之Varying参数

    其实在Cg中是没有varying这种类型限制符的. 如何让程序不仅仅输出一个单一的颜色,而是可以随顶点改变的颜色或纹理坐标集呢? Cg教程中给出如下范例: // This is C3E2v_varyi ...

  8. 【我的OpenGL学习进阶之旅】解决着色器语法错误:The shader uses varying u_Color, but previous shader does not write to it

    一.错误描述 在加载完顶点着色器和片段着色器,然后link生成program的时候,出现了错误,如下所示: 2021-12-31 09:34:01.072 15937-16006/com.oyp.op ...

  9. SpringBoot:ERROR: column “***“ is of type numeric but expression is of type character varying

    问题 SpringBoot:在postgresql数据库提交数据时,出现ERROR: column "***" is of type numeric but expression ...

最新文章

  1. asp.net动态换肤
  2. C#——扩展.NET Framework基本类型的功能DEMO
  3. scrapy框架之递归解析和post请求
  4. python装饰器的顺序_python中多个装饰器的执行顺序详解
  5. java学习(30):巩固练习
  6. Java开发者必须掌握的20个Spring常用注解
  7. Hbase+Phoenix+Mybatis+Springboot整合查询数据
  8. Redhat AS4上中文乱码问题解决方案
  9. Linux如何确认连接域名,linux 查看服务器域名
  10. PS换证件照底色,完美扣除头发丝并调整优化边缘
  11. excel 如何批量删除必表中的空白行
  12. 操作系统 - startx/xinit
  13. python做excel数据条件_懂点EXCEL就行!教你利用Python做数据筛选(上)
  14. 美国公布全球“野鸡大学”名单
  15. 谷粒商城高级篇(36)——商品上架之上传数据到Elasticsearch
  16. 工程硕士计算机专业开题报告,计算机技术工程硕士论文
  17. RPM打包之spec示例
  18. 圣诞树太俗气,圣诞牛才够创意----阿里巴巴B2B高上大玩法的启示
  19. Seafile开源文件同步和分享SAAS云盘
  20. 【备考之路】(一)软考【系统集成项目管理工程师】备考经验

热门文章

  1. IPad Pro 2018 Unity 屏幕适配 解决无法全屏问题
  2. Xshell密钥认证
  3. 如何看待996的工作模式
  4. 分享一份软件测试项目(Python项目)
  5. electron 主进程和渲染进程的通信
  6. 三维向量求夹角(0-360)
  7. C++ MFC打开图片并进行简单算法处理
  8. CSDN博客插入图片
  9. 用png格式图片和非png格式图片做水印图片
  10. 一步一步构建手机WebApp开发——环境搭建