某种业务场景下,将一个工作区的多个字段整理到一个内表中

 1 DATA:num TYPE i.
 2 CONSTANTS: times TYPE i VALUE 29.
 3 DATA: BEGIN OF ih_lgty,
 4   lgty TYPE lgtyp,
 5 END OF ih_lgty,
 6 it_lgty LIKE TABLE OF ih_lgty.
 7 FIELD-SYMBOLS: <lgty> TYPE any,
 8                <t334t> LIKE t334t.
 9 
10 DATA:lh_t334t LIKE t334t,
11      lt_t334t LIKE TABLE OF t334t.
12 
13 SELECT SINGLE
14   *
15   INTO  lh_t334t
16   FROM t334t
17   WHERE lgnum = 'NJ1'
18   AND kzear = 'A'
19   AND lgtkz = 'BC1'.
20 ***  将一个工作区的数据整理到一个内表中
21 ASSIGN lh_t334t TO <t334t>.
22 DO times TIMES.
23   num = 10 + sy-index.
24   UNASSIGN <lgty>.
25   ASSIGN  COMPONENT num OF  STRUCTURE  <t334t> TO  <lgty>.
26   ih_lgty-lgty =  <lgty>.
27   APPEND ih_lgty TO it_lgty.
28 ENDDO.
29 DELETE it_lgty WHERE lgty IS INITIAL.
30 ***
31 SORT it_lgty.
32 DELETE ADJACENT DUPLICATES FROM it_lgty COMPARING ALL FIELDS.
33 num = lines( it_lgty ).
34 WRITE:num.

工作区中的数据:

整理后,内表中的数据:

posted @ 2014-08-18 09:26  小鱼儿游  阅读(355)  评论(0编辑  收藏  举报