========================================================================================
dataset和internal table 的最大区别在于前者允许每一行记录的结构不同,后者的结构固定。本文主要介绍如何使用dataset存取数据。
首先要定义dataset摘录行的数据类型,它是通过field-groups声明的,field-groups和field-symbols有相似之处,但决不一样。
field-goups存放的是多个变量地址值合并的结果,而field symbols存放的是一个变量的地址。当然二者都是通过指针的方式存取数据,前者可以理解成一个由指针变量作为组件的结构。
声明完以后,通过insert variables into field-group将变量指定给相应的field-group.这相当于field-symbol的assign功能。
然后,给变量赋值
之后extract field-group,这个动作就把对应变量组的值对应的加到dataset中去了。相当于internal table 的append动作。
最后取数:
通过 loop. ... ... endloop. 当中可能用到at关键字。
===========================================================================================
以下是本人设计的一个应用实例:
field-groups : header , person_sex, person_info.data: name type c length 10,
sex type c,
country type c length 10,
p_id type n length 10.
insert: name sex into header,
country p_id into person_info.
name = 'Zhangsan'.
sex = 'M'.
extract person_sex.
country = 'China'.
p_id = '43143215'.
extract person_info.
country = 'UK'.
p_id = '65453542'.
extract person_info.
country = 'USA'.
p_id = '12334254'.
extract person_info.
name = 'Lisi'.
sex = 'M'.
extract person_sex.
country = 'China'.
p_id = '9996234'.
extract person_info.
country = 'UK'.
p_id = '7435423'.
extract person_info.
country = 'USA'.
p_id = '45326534'.
extract person_info.
name = 'Wangwu'.
sex = 'M'.
extract person_sex.
country = 'China'.
p_id = '0002365'.
extract person_info.
country = 'UK'.
p_id = '8566211'.
extract person_info.
country = 'USA'.
p_id = '8965897'.
extract person_info.
LOOP .
at first.
write:/ 'Personel information:'.
endat.
at person_sex.
uline.
write:/ name, sex.
endat.
at person_info.
write:/ name, sex, country, p_id.
endat.
at last.
uline.
write:/ 'The end of list.'.
endat.
ENDLOOP.