ABAP-基于MEMORY动态传参
Posted ricoo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP-基于MEMORY动态传参相关的知识,希望对你有一定的参考价值。
EXPORT ... TO MEMORY ID ...
IMPORT ... TO MEMORY ID ...
如何传递动态内表数据:
1.发送方根据动态内表记录重新生成新的内表结构体,并将动态数据转换到新的内表,传值两个记录表:结构体,数据记录。
2.接收方根据结构体重新生成新的内表,根据新生成内表接收数据。
1.发送方
function zfgtr_17_bill_detail. *"---------------------------------------------------------------------- *"*"本地接口: *" TABLES *" ET_RETURN STRUCTURE BAPIRET2 OPTIONAL *" IT_ANY_TAB OPTIONAL *" IT_ANY_TAB_01 OPTIONAL *"---------------------------------------------------------------------- data: lr_any_t type ref to data, lr_any_s type ref to data. data: lr_dref type ref to data, lr_stru type ref to cl_abap_structdescr, lr_table type ref to cl_abap_tabledescr, lr_elem type ref to cl_abap_elemdescr, lt_para type cl_abap_structdescr=>component_table, lt_comp type cl_abap_structdescr=>component_table. field-symbols: <fs_tab> type any, <ft_tab> type standard table. try.
lr_stru ?= cl_abap_tabledescr=>describe_by_data( it_any_tab_01 ). loop at lr_stru->components[] into data(ls_comps). if ls_comps-type_kind = ‘P‘ or ls_comps-type_kind = ‘X‘. else. ls_comps-length = ls_comps-length / 2. endif. append initial line to lt_comp assigning field-symbol(<fs_comp>). <fs_comp>-name = ls_comps-name. <fs_comp>-type ?= cl_abap_elemdescr=>get_by_kind( p_type_kind = ls_comps-type_kind p_length = ls_comps-length p_decimals = ls_comps-decimals ). unassign <fs_comp>. endloop. if lt_comp[] is not initial. clear:lr_stru,lr_table. lr_stru = cl_abap_structdescr=>create( lt_comp ). lr_table = cl_abap_tabledescr=>create( lr_stru ). create data lr_any_s type handle lr_stru. assign lr_any_s->* to <fs_tab>. create data lr_any_t type handle lr_table. assign lr_any_t->* to <ft_tab>. endif. move-corresponding it_any_tab_01[] to <ft_tab>[]. free memory id ‘ZDTR0780_V1‘. free memory id ‘ZDTR0780_V2‘. export tab = lr_stru->components to memory id ‘ZDTR0780_V1‘. export tab = <ft_tab>[] to memory id ‘ZDTR0780_V2‘. submit zdtr0780 and return.
catch cx_root into data(lr_root). data(lv_msg) = lr_root->get_text( ). perform frm_public_message_get tables et_return using ‘ZMCTR0040‘ ‘000‘ ‘E‘ lv_msg space space space. endtry. endfunction.
2.接收方
form frm_get_data . data: lr_any_t type ref to data, lr_any_s type ref to data. data: lr_dref type ref to data, lr_stru type ref to cl_abap_structdescr, lr_table type ref to cl_abap_tabledescr, lr_elem type ref to cl_abap_elemdescr, lt_para type cl_abap_structdescr=>component_table, lt_comp type cl_abap_structdescr=>component_table. data: lt_comps type table of abap_compdescr. field-symbols: <fs_tab> type any, <ft_tab> type standard table. import tab = lt_comps from memory id ‘ZDTR0780_V1‘. loop at lt_comps into data(ls_comps). if ls_comps-type_kind = ‘P‘ or ls_comps-type_kind = ‘X‘. else. ls_comps-length = ls_comps-length / 2. endif. append initial line to lt_comp assigning field-symbol(<fs_comp>). <fs_comp>-name = ls_comps-name. <fs_comp>-type ?= cl_abap_elemdescr=>get_by_kind( p_type_kind = ls_comps-type_kind p_length = ls_comps-length p_decimals = ls_comps-decimals ). unassign <fs_comp>. endloop. if lt_comp[] is not initial. clear:lr_stru,lr_table. lr_stru = cl_abap_structdescr=>create( lt_comp ). lr_table = cl_abap_tabledescr=>create( lr_stru ). create data lr_any_s type handle lr_stru. assign lr_any_s->* to <fs_tab>. create data lr_any_t type handle lr_table. assign lr_any_t->* to <ft_tab>. endif. import tab = <ft_tab>[] from memory id ‘ZDTR0780_V2‘. free memory id ‘ZDTR0780_V1‘. free memory id ‘ZDTR0780_V2‘.
move-corresponding <ft_tab>[] to gt_alv[].
endform.
以上是关于ABAP-基于MEMORY动态传参的主要内容,如果未能解决你的问题,请参考以下文章