FIELD SYMBOLS 動態內錶

2021-10-07 04:15:08 字數 3792 閱讀 9719

動態內錶構建步驟

(1)獲得主資料:獲取將要展示的資料

(2)構建fieldcat :根據選擇螢幕來動態的構建fieldcat

(3)根據fieldcat構建動態內錶:根據已經構建好的fieldcat來構建內表字段,                cl_alv_table_create=>create_dynamic_table

(4)將主資料新增到動態內錶 :將獲取到的主資料新增到對應字段

form buils_dytable .

perform get_data . "獲得主資料

perform build_fieldcat . "構建動態fieldcat

perform build_dynamic_table."構建動態內錶

perform add_data. "向動態內錶新增資料

endform.

資料定義

tables ztest_table.

data gt_main type table of ztest_table.

data gs_main type ztest_table.

data gt_fieldcat type lvc_t_fcat. "fieldcat

data gs_fieldcat type lvc_s_fcat. "fieldcat 工作區

data **_fieldcat type c length 20 .

data **_month type c length 20 .

field-symbols: type standard table , " 動態內錶

type any , " 工作區

type any . "動態內表字段

data **_pos type i .

define __buildfieldcat. "巨集 構建fieldcat

clear gs_fieldcat .

**_pos = **_pos + 1.

gs_fieldcat-fieldname = &1.

gs_fieldcat-scrtext_l = &2.

gs_fieldcat-outputlen = 20.

gs_fieldcat-currency = &3 .

end-of-definition.

parameters p_year type ztest_table-zyear .

select-options s_name for gs_main-company.

select-options s_mathon for gs_main-zmonth.

獲得主資料

form get_data .

select *

from ztest_table

into corresponding fields of table gt_main

where zyear eq p_year

and company in s_name

and zmonth in s_mathon .

endform.

構建fieldcat

form build_fieldcat .

data lv_index type n length 2 .

__buildfieldcat 'zyear' '年份' '' .

__buildfieldcat 'company' '公司' '' .

do 12 times.

lv_index = sy-index .

if lv_index in s_mathon. "根據選擇螢幕動態構建月份

concatenate 'month_' lv_index into **_fieldcat .

concatenate lv_index '月' into **_month .

__buildfieldcat **_fieldcat **_month 'wears' .

endif.

enddo.

__buildfieldcat 'wears' '金額單位' '' .

endform.

構建動態內錶

form build_dynamic_table .

data lt_dytable type ref to data.

data ls_dytable type ref to data.

call method cl_alv_table_create=>create_dynamic_table

exporting

* i_style_table =

it_fieldcatalog = gt_fieldcat

* i_length_in_byte =

importing

ep_table = lt_dytable

* e_style_fname =

exceptions

generate_subpool_dir_full = 1

others = 2.

if sy-subrc <> 0.

* implement suitable error handling here

endif.

assign lt_dytable->* to .

create data ls_dytable like line of .

assign ls_dytable->* to .

endform.

將主資料和動態內錶相關聯

form add_data .

data ls_main type ztest_table. "避免at事件中字元欄位變*

sort gt_main by zyear company.

loop at gt_main into ls_main .

move-corresponding ls_main to gs_main .

at new company .

clear .

assign component 'company' of structure to .

if sy-subrc eq 0.

= gs_main-company .

endif.

assign component 'zyear' of structure to .

if sy-subrc eq 0.

= gs_main-zyear .

endif.

assign component 'wears' of structure to .

if sy-subrc eq 0.

= gs_main-wears .

endif.

endat.

concatenate 'month_' gs_main-zmonth into **_fieldcat.

assign component **_fieldcat of structure to .

if sy-subrc eq 0.

= gs_main-incom .

endif.

at end of company .

endat .

endloop.

endform.

動態 指標field symbols初探

data begin ofstruc,comp1 type c length 1 value 1 comp2 type c length 20 value 22222 co type string value bruce king endof struc,comp value type c leng...

資料引用與field symbols

type ref to 以下簡稱 trt 和 field symbol 以下簡稱 fs 在 abap 中都有著類似指標的作用 下面結合對比和例項來介紹下兩者的用法和區別之處。先預定義型別ty ym,內錶it ym,工作區wa ym,變數v ym char20 以供後面使用 type ref to 和...

ABAP動態內錶

定義的動態內錶,對應內錶一行的工作區 field symbols type standard table type any.form create dynamic table data lt fcat type slis t fieldcat alv,ls fcat like line of lt ...