Topic: 求助一个初级问题

ERP俱乐部

第 1 页 总共 1 页 [共有 4 条记录]


Posted by james23 on 2009-01-01 08:10 上午
各位大侠,小弟初学,问个白痴问题。。。
REPORT  Z123.
data:  begin of line,
         name(10) type c,
         address(10) type c,
         no type i,
       end of line,
       itab type standard table of line.

START-OF-SELECTION.
   DO 20 TIMES.
     line-name = 'james'.
     line-address = 'home'.
     line-no = sy-index.
     APPEND line TO itab.
   ENDDO.
   LOOP AT itab INTO line.
     WRITE: / line-name, line-address, line-no.
   ENDLOOP.
   CLEAR itab.
APPEND line TO itab行报错,说是    A line of "ITAB" and "LINE" are not mutually convertible. In a Unicode program "ITAB" must have the same structure layout as "LINE" independent of the length of a . Unicode character. Unicode character.
是在说结构体line和内表itab的行结构不匹配吧,可问题内表itab就是根据line创建的阿,怎么回事,那位大哥指教一下。      
       
      


Posted by im0o海星 on 2009-01-02 10:13 上午
itab type standard table of line.

here, 'type' change 'like' .

the 'line' is the dictionary's structor.

Posted by james23 on 2009-01-04 09:39 下午
真的OK了,太感谢了,可我还是不太明白,麻烦您用汉语解释一下,line如果是数据字典里的结构,那它就是全局变量了,可我在程序里也定义line了,那局部变量不是应该覆盖同名的全局变量吗,为什么系统会把line识别为数据字典里的line?

Posted by cleanpig on 2009-01-08 10:35 上午
假如你在数据字典dictionary 中定义了一个名为line 的结构,这个line只能是一个类型,而并非变量,它不占内存的。

在你这个程序中, 由于你用的是data关键字,你所定义的line 是一个structe 的变量,而并非局部类型。

当你建立内表变量 itab的时候,使用的关键字是TYPE, 也就是说该内表要参照一个类型line。 然而你在程序中没有定义相应的类

型line( 你所定义的line 是一个变量),所以系统会去参照数据字典dictionary中是否存在一个名为line的全局 structure类型。

但如果你使用like 关键字, 也就是说,你希望参照一个变量的结构去建立内表, 而程序中的line是一个结构体变量,故程序可以通过。

这样讲 你能明白了嘛?