打開SAP 客戶端工具 ABAP 中 創建包(SE80) 創建函數組 展開ABAP 工作台,雙擊ABAP Dictionary 字典: 選擇第三個data type,輸入數據結構名稱ZSQL_CLAUSE_ELEMENTS,點擊創建: 選中Structure結構,點擊確定: 輸入簡稱,增加一個數據元 ...
打開SAP 客戶端工具
ABAP 中 創建包(SE80)
創建函數組
展開ABAP 工作台,雙擊ABAP Dictionary 字典:
選擇第三個data type,輸入數據結構名稱ZSQL_CLAUSE_ELEMENTS,點擊創建:
選中Structure結構,點擊確定:
輸入簡稱,增加一個數據元素TEXT,類型為SO_TEXT
同樣的方法,我們創建Structure結構ZTABLEROWS,增加一條數據元素,名字任意如ZTABLEROWS,數據元素 CHAR2000
保存這兩個structure,然後點擊上方的結構樹按鈕,打開Structure所在包目錄
展開Structure目錄,就可以看到我們定義的那兩個結構了,分別右擊>Activate激活
FUNCTION HHDI_EXTRACT_TABLE_DATA.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" FIELDS STRUCTURE ZSQL_CLAUSE_ELEMENTS
*" FROMCLAUSE STRUCTURE ZSQL_CLAUSE_ELEMENTS
*" WHERECLAUSE STRUCTURE ZSQL_CLAUSE_ELEMENTS
*" DATA STRUCTURE ZTABLEROWS
*"----------------------------------------------------------------------
*"----------------------------------------------------------------------
*" Copy selected fields from QUERY_TABLE to DATA_STRUCTURE
*"----------------------------------------------------------------------
TYPE-POOLS: abap.
DATA:
columnName TYPE SO_TEXT,
fieldDataDescrRef TYPE REF TO abap_componentdescr,
numberFields TYPE i,
fieldDescr TYPE abap_componentdescr,
fieldname TYPE string,
fieldDescrTab TYPE abap_component_tab,
rowStructDescr TYPE REF TO cl_abap_structdescr,
rowReference TYPE REF TO data,
returnRowString TYPE string,
dataFieldString TYPE string,
dataline LIKE data,
fromClauseRow TYPE ZSQL_CLAUSE_ELEMENTS,
fromClauseString TYPE string,
whereClauseRow TYPE ZSQL_CLAUSE_ELEMENTS,
whereClauseString TYPE string,
fieldsRow TYPE ZSQL_CLAUSE_ELEMENTS.
FIELD-SYMBOLS:
<datarow> TYPE ANY,
<datafield> TYPE ANY.
* CREATE DataStructure with field names
* Datatypes are read from fieldnames of FIELDS input table
DESCRIBE TABLE FIELDS LINES numberFields.
LOOP AT FIELDS INTO fieldsRow.
fieldname = SY-TABIX.
* names need to be unique and must start with a char
CONCATENATE 'string' fieldname INTO fieldname.
CONDENSE fieldname.
fieldDescr-name = fieldname.
* for dictionary lookup we need to change columnnames from Open SQL
* to dictionary notation
columnName = fieldsRow-TEXT.
REPLACE FIRST OCCURRENCE OF SUBSTRING '~' IN columnName WITH '-' RESPECTING CASE.
fieldDescr-type ?= cl_abap_typedescr=>describe_by_name( columnName ).
APPEND fieldDescr TO fieldDescrTab.
ENDLOOP.
rowStructDescr = cl_abap_structdescr=>create( fieldDescrTab ).
* now we create the actual data structure in memory
create data rowReference type HANDLE rowStructDescr.
* finally we assign it to the Field-symbol used by the select statement
ASSIGN rowReference->* TO <datarow>.
* End Create DataStructure
* to simplify calls we concatenate from and whereclause into strings
* this way caller doesn't need to check word wrappings
fromClauseString = ''.
LOOP AT FROMCLAUSE INTO fromClauseRow.
CONCATENATE fromClauseString fromClauseRow-TEXT INTO fromClauseString.
ENDLOOP.
whereClauseString = ''.
LOOP AT WHERECLAUSE INTO whereClauseRow.
CONCATENATE whereClauseString whereClauseRow-TEXT INTO whereClauseString.
ENDLOOP.
* Now start actual select operation
SELECT (FIELDS) FROM (fromClauseString) INTO <datarow> WHERE (whereClauseString).
* we read all fields of the current row, cast it to string and
* concatenate it into a dataline with division chars.
CLEAR: returnRowString.
DO numberFields TIMES.
ASSIGN component sy-index of structure <datarow> to <datafield>.
dataFieldString = <datafield>.
CONCATENATE returnRowString '|' datafieldstring INTO returnRowString.
ENDDO.
dataline = returnRowString.
* finally dataline is added to the return table.
INSERT dataline INTO TABLE data.
ENDSELECT.
ENDFUNCTION.
函數
l 新建abap function
註意函數的名稱一定為:HHDI_EXTRACT_TABLE_DATA
先把HHDI_EXTRACT_TABLE_DATA的源碼貼進去
點擊左邊的table表格tab,新增4個表,FIELDS /FROMCLAUSE /WHERECLAUSE /DATA,類型都為LIKE,後面的結構類型按照文檔源碼,前三個輸入ZSQL_CLAUSE_ELEMENTS,最後一個輸入ZTABLEROW
like報參數過時的錯誤,回車再回車即可。
再次check
沒有錯誤則表示function 可以了,註意還需要設置函數可以遠程訪問
最後再激活一下。
在HHDI中SAP數據連接配置:
數據抽取任務的配置:
SELECT語句參考:
select KNA1~NAME2,KNVV~KUNNR,KNA1~LAND1 from KNA1 INNER JOIN KNVV ON KNA1~KUNNR = KNVV~KUNNR where KNA1~NAME2 <>'' AND KNA1~LAND1 = 'US'
註意OPENSQL不支持SELECT *
簇表數據量太大會導致SAP報緩存溢出的錯誤,可用WHERE語句控制其數據範圍,數據量過大時,可以再HHDI的作業流程中採用迴圈方式取數。