反饋已提交
網絡繁忙
通用查詢比 簡單通用查詢取數 增加了表間聯動的能力,且支援多表查詢。但操作起來會複雜一些,完全透過 open SQL 語句實現。
需要在 ECC6 以上的版本,並在 SAP 系統中新增一個帆軟提供的 ABAP Function。
我方的 ABAP Function 的名稱為「EXTRACT_TABLE_DATA」,不可改變,將其新增到 SAP 系統中,函式內容如下:
FUNCTION 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 ZALBUS_STRUCT_WHERECLAUSE, fromClauseString TYPE string, whereClauseRow TYPE ZALBUS_STRUCT_WHERECLAUSE, whereClauseString TYPE string, fieldsRow TYPE ZALBUS_STRUCT_WHERECLAUSE. 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.
注1:若出現多個欄位到一欄的情況,需要將程式碼中的一行:CONCATENATE returnRowString '^' datafieldstring INTO returnRowString. 更換成 CONCATENATE returnRowString '|' datafieldstring INTO returnRowString.
注2:sap 資料集支援結構型參數。
1)新增 SAP 資料集,如下圖所示:
2)選擇資料連結,並將 Function 改為「通用查詢取數(適用於ECC6以上版本) 」,如下圖所示:
Select:放的是要查的表以及欄位,格式是:表~欄位名(如果同一個表中多個欄位,則用多個表~欄位名形式寫,逗號隔開)
From:放的是表名以及表與表之間的聯動關係;
Where:放篩選條件;
按照上面的格式做一個簡單範例,資料集配置如下圖所示:
簡單範例中的查詢語句如下:
點選「預覽」按鈕,可查看上面語句執行的結果,如下圖所示:
預覽沒問題後,點選「確定」,就可以將資料集新增到 FineReport 中,如下圖所示:
FineReport 提供了 EXTRACT_TABLE_DATA 的原始碼及後續的資料集使用程式。
EXTRACT_TABLE_DATA 的建立程式及出現的問題解決請參見:通用查询取数中的函数
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉
反馈已提交
网络繁忙