标签:
"COPY别人的
TYPE-POOLS:ADBC. DATA LV_SQL TYPE STRING. DATA LV_FROM TYPE STRING. DATA LV_WHERE TYPE STRING. DATA LV_WHERE2 TYPE STRING. DATA LV_WHERE3 TYPE STRING. DATA : V_ROWS TYPE I. DATA : LT_META TYPE ADBC_RS_METADATA_DESCR_TAB, LT_COLUMN TYPE ADBC_COLUMN_TAB, LS_META LIKE LINE OF LT_META, LS_COLUMN LIKE LINE OF LT_COLUMN. *Define variables for the connection DATA: LR_DBCONN TYPE REF TO CL_SQL_CONNECTION, LV_CON TYPE DBCON_NAME VALUE ‘HDB‘, LR_SQL_ENV TYPE REF TO CL_SQL_STATEMENT, LR_SQL_RESULT TYPE REF TO CL_SQL_RESULT_SET, LR_SQL_EXC TYPE REF TO CX_SQL_EXCEPTION, "#EC NEEDED LR_PAR_EXC TYPE REF TO CX_PARAMETER_INVALID, "#EC NEEDED DREF TYPE REF TO DATA, TAB_REF TYPE REF TO DATA, GT_COMPONENTS TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE, GS_COMPONENTS LIKE LINE OF GT_COMPONENTS. FIELD-SYMBOLS : <TABLE> TYPE ANY TABLE, <STR> TYPE ANY. *Get connection LR_DBCONN = CL_SQL_CONNECTION=>GET_CONNECTION( CON_NAME = LV_CON ). CREATE OBJECT LR_SQL_ENV EXPORTING CON_REF = LR_DBCONN. LV_SQL = ‘SELECT * FROM ZLYTEST01‘. LR_SQL_RESULT = LR_SQL_ENV->EXECUTE_QUERY( LV_SQL ). LT_META = LR_SQL_RESULT->GET_METADATA( ). LOOP AT LT_META INTO LS_META. LS_COLUMN = LS_META-COLUMN_NAME. APPEND LS_COLUMN TO LT_COLUMN. GS_COMPONENTS-NAME = LS_META-COLUMN_NAME. GS_COMPONENTS-TYPE ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( P_DATA = LS_META-DATA_TYPE ). APPEND GS_COMPONENTS TO GT_COMPONENTS. ENDLOOP. DATA LR_TABLEDESCR TYPE REF TO CL_ABAP_TABLEDESCR. LR_TABLEDESCR = CL_ABAP_TABLEDESCR=>CREATE( P_LINE_TYPE = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = GT_COMPONENTS ) ). CREATE DATA TAB_REF TYPE HANDLE LR_TABLEDESCR. * get REFERENCE OF LT_DATA INTO tab_ref. LR_SQL_RESULT->SET_PARAM_TABLE( EXPORTING ITAB_REF = TAB_REF " Reference to Output Variable CORRESPONDING_FIELDS = LT_COLUMN ). **Execute the query LR_SQL_RESULT->NEXT_PACKAGE( ). V_ROWS = LR_SQL_RESULT->NEXT( ). ASSIGN TAB_REF->* TO <TABLE>.
标签:
原文地址:http://www.cnblogs.com/sapSB/p/5765605.html