webdynpro 上传text文件到table
1、节点创建,其中DATASOURCE存放uploadfile名称
2.layout布局
3、upload事件代码:
method ONACTIONUPLOAD . DATA: lo_Node type ref to If_Wd_Context_Node, lo_Elem type ref to If_Wd_Context_Element, lw_datasour type xstring, lw_string type string, lt_data type TABLE OF string, lt_field type TABLE OF string, lv_field TYPE string, ls_context type wd_this->Element_sflight, lt_context type wd_this->Elements_sflight . * get the datasource Xstring wd_context->get_attribute( EXPORTING name = ‘DATASOURCE‘ IMPORTING value = lw_datasour ). * convert the XString ==> string * CALL FUNCTION ‘ECATT_CONV_XSTRING_TO_STRING‘ * EXPORTING * IM_XSTRING = lw_datasour * IM_ENCODING = ‘UNICODE‘ * IMPORTING * EX_STRING = lw_string. DATA: conv TYPE REF TO CL_ABAP_CONV_IN_CE. CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE EXPORTING INPUT = lw_datasour ENCODING = ‘UTF-8‘ REPLACEMENT = ‘?‘ IGNORE_CERR = ABAP_TRUE RECEIVING CONV = conv. conv->READ( importing data = lw_string ). * get the data of file split lw_string at cl_abap_char_utilities=>newline into TABLE lt_data. * delete the header DELETE lt_data INDEX 1. * get all the field name LOOP AT lt_data into lw_string. SPLIT lw_string at cl_abap_char_utilities=>horizontal_tab into table lt_field. ***get all the 3 fields of one line READ TABLE lt_field INTO lv_field INDEX 1. ls_context-carrid = lv_field. READ TABLE lt_field INTO lv_field INDEX 2. ls_context-connid = lv_field. READ TABLE lt_field INTO lv_field INDEX 3. ls_context-text = lv_field. append ls_context to lt_context. ENDLOOP. * bind table lo_node = wd_context->get_child_node( ‘SFLIGHT‘ ). lo_node->bind_table( lt_context ). endmethod.
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。