Chinaunix首页 | 论坛 | 博客
  • 博客访问: 285149
  • 博文数量: 62
  • 博客积分: 2966
  • 博客等级: 少校
  • 技术积分: 615
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-07 23:16
个人简介

Be a simple man

文章分类

全部博文(62)

文章存档

2012年(6)

2011年(15)

2010年(6)

2009年(3)

2008年(5)

2007年(27)

我的朋友

分类:

2007-08-09 18:07:59

REPORT z_jason_test_addfield .

DATA: BEGIN OF itab OCCURS 0,
      f1 TYPE i,
      f2 TYPE i,
      f3 TYPE i,
      f4 TYPE i,
      END OF itab.
DATA: total TYPE i.
PERFORM writeitab.
PERFORM addfield TABLES itab
                 CHANGING total.
WRITE:/ total.
*---------------------------------------------------------------------*
*       FORM writeitab                                                *
*---------------------------------------------------------------------*
FORM writeitab.
  itab-f1 = 1.
  itab-f2 = 2.
  itab-f3 = 3.
  itab-f4 = 4.
  APPEND itab.
  itab-f1 = 2.
  itab-f2 = 3.
  itab-f3 = 4.
  itab-f4 = 5.
  APPEND itab.
  itab-f1 = 2.
  itab-f2 = 3.
  itab-f3 = 4.
  itab-f4 = 5.
  APPEND itab.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  addfield
*&---------------------------------------------------------------------*
FORM addfield TABLES itab
              CHANGING tmp TYPE i.
  DATA: BEGIN OF headtab OCCURS 0 ,
          length    TYPE i ,
          decimals  TYPE i,
          type_kind TYPE c,
          name(30)  TYPE c,
        END OF headtab.
  DATA: sum TYPE i,
        n TYPE i,
        count TYPE i ,
        count2 LIKE count,
        descr_ref TYPE REF TO cl_abap_structdescr.
  FIELD-SYMBOLS: TYPE abap_compdescr .
  FIELD-SYMBOLS TYPE ANY.
  descr_ref ?= cl_abap_typedescr=>describe_by_data( itab ).
  LOOP AT descr_ref->components ASSIGNING .
    MOVE-CORRESPONDING TO headtab.
    APPEND headtab.
  ENDLOOP.
  DESCRIBE TABLE headtab LINES n.
  LOOP AT itab.
    count = n.
    DO count TIMES.
      ASSIGN COMPONENT count OF STRUCTURE itab TO .
      sum = sum + .
      count = count - 1.
    ENDDO.
    total = total + sum.
    CLEAR sum.
  ENDLOOP.
ENDFORM.                    " addfield
阅读(1494) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~