ABAP动态内表定义的实现

ZTEST_DYM_ITAB
*&---------------------------------------------------------------------*
*& Report  ZTEST_DYM_ITAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZTEST_DYM_ITAB.
*data: begin of it_per occurs 10,
*       BUKRS like glt0-bukrs,
*       RACCT like glt0-racct,
*       RTCUR like glt0-rtcur,
*       amount like glt0-tslvt,
*    end of it_per.
type-pools: slis.
*FIELD-SYMBOLS: <FS_DATA> type ref to DATA,
*              <FS_1> type any table,
*              <FS_2> type any,
*              <FS_3>.
*
* LS_FIELDCATALOG-FIELDNAME = 'BUKRS'.
* append LS_FIELDCATALOG to LT_FIELDCATALOG.
* LS_FIELDCATALOG-FIELDNAME = 'HKONT'.
* append LS_FIELDCATALOG to LT_FIELDCATALOG.
*
* loop at curr_tab.
*   LS_FIELDCATALOG-FIELDNAME = curr_tab-WAERS.
*   append LS_FIELDCATALOG to LT_FIELDCATALOG.
* endloop.
* assign LT_DATA to <FS_DATA>.
*
* call method cl_alv_table_create=>create_dynamic_table
*      exporting
*        it_fieldcatalog = LT_FIELDCATALOG
*      importing
*        ep_table = <FS_DATA>
*      exceptions
*        generate_subpool_dir_full = 1
*        others = 2.
*    assign <FS_DATA>->* to <FS_1>.
* create data NEW_LINE like line of <FS_1>.
* assign NEW_LINE->*  to <FS_2>.
******
*At this point i have <FS_1>,<FS_2> structure as ...
*BUKRS RACCT AM11 USD CAD INR JPY .......
******
*loop at it_per.
**
**here i want to assign it_per values to <FS_1>
**
*
*endloop.
data: it_fcat type slis_t_fieldcat_alv,
     is_fcat like line of it_fcat,
     it_sort type lvc_t_sort,
     is_sort like line of it_sort,
     wa_line   type slis_listheader,
     gs_layout   type lvc_s_layo,
     it_top_of_page  type slis_t_listheader.
*     event_receiver type ref to lcl_event_receiver.
data: it_fieldcat type lvc_t_fcat,
     is_fieldcat like line of it_fieldcat.
data: new_table type ref to data.
data: new_line  type ref to data.
data: new_line1  type ref to data.
data: ok_code like sy-ucomm,
     g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
     grid1  type ref to cl_gui_alv_grid,
     g_custom_container type ref to cl_gui_custom_container.
field-symbols: <l_table> type any table,    
              <l_line>  type any,     
              <l_line1>  type any table,    
              <l_field1> type any table,    
              <l_field> type any.     
is_fieldcat-fieldname = 'FIELD1'.
is_fieldcat-ref_field = 'MATNR'.
is_fieldcat-ref_table = 'MARA'.
append is_fieldcat to it_fieldcat.
is_fieldcat-fieldname = 'FIELD2'.
is_fieldcat-ref_field = 'SPRPS'.
is_fieldcat-ref_table = 'PA0001'.
append is_fieldcat to it_fieldcat.
is_fieldcat-fieldname = 'FIELD3'.
is_fieldcat-ref_field = 'BEGDA'.
is_fieldcat-ref_table = 'PA0002'.
append is_fieldcat to it_fieldcat.
is_fieldcat-fieldname = 'FIELD4'.
is_fieldcat-ref_field = 'NETPR'.
is_fieldcat-ref_table = 'EKPO'.
is_fieldcat-do_sum    = 'X'.
append is_fieldcat to it_fieldcat.
* Create a new Table      
call method cl_alv_table_create=>create_dynamic_table  
 exporting       
   it_fieldcatalog = it_fieldcat     
 importing       
   ep_table        = new_table.     
        
* Create a new Line with the same structure of the table.  
assign new_table->* to <l_table>.    
create data new_line like line of <l_table>.    
assign new_line->* to <l_line>.     
*create data new_line1 like  <l_table>.
*assign new_line1->* to <l_line1>.
*insert new_line1 into table <l_line1>.
do 5 times.
 assign component 'FIELD1' of structure <l_line> to <l_field>.
 <l_field> = '12345'.
 assign component 'FIELD2' of structure <l_line> to <l_field>.
 <l_field> = 'X'.
 assign component 'FIELD3' of structure <l_line> to <l_field>.
 <l_field> = '20030101'.
 assign component 'FIELD4' of structure <l_line> to <l_field>.
 <l_field> = '101'.
 insert <l_line> into table  <l_table>.
*insert new_line into table <l_line>.
Enddo.
data f1 like mara-matnr.
Write : ' Output the Dynamic Internal Table :' .
Uline.
   LOOP AT <l_table> ASSIGNING <l_line>.
      ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <l_line> TO <l_field>.
      f1 = <l_field>.
*      WRITE <l_field>.
       write f1.
      ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <l_line> TO <l_field>.
      WRITE <l_field>.
      ASSIGN COMPONENT 'FIELD3' OF STRUCTURE <l_line> TO <l_field>.
      WRITE <l_field>.
      ASSIGN COMPONENT 'FIELD4' OF STRUCTURE <l_line> TO <l_field>.
      WRITE <l_field>.
      uline.
   ENDLOOP.

转载于:https://www.cnblogs.com/afu7548/archive/2005/12/29/307607.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值