根據欄位名等查詢SAP的表或結構(程式程式碼)
在SAP中找表對初學者來說是很復雜的事情,所以為自己寫了一個找表的程式,程式碼如下:
*&---------------------------------------------------------------------*
*& Report Z_FIND_TABLE
*&---------------------------------------------------------------------*
*&查詢表或結構
*&
*&---------------------------------------------------------------------*
REPORT Z_FIND_TABLE.
TABLES: TADIR,TRDIRT,TSTC,DD03L,DD02L,DD04L,DD02T,DD03T,DD04T.
TYPE-POOLS: SLIS.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF FIELDCAT,
EVENT_EXIT TYPE SLIS_T_EVENT_EXIT,
EVENT_EXIT_LN LIKE LINE OF EVENT_EXIT,
SORTCAT TYPE SLIS_T_SORTINFO_ALV,
SORTCAT_LN LIKE LINE OF SORTCAT,
EVENTCAT TYPE SLIS_T_EVENT,
EVENTCAT_LN LIKE LINE OF EVENTCAT.
DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: GC_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'ALV_TOP_OF_PAGE'.
DATA : PS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: BEGIN OF WA_ITAB,
TABNAME LIKE DD02L-TABNAME,
TABTEXT LIKE DD02T-DDTEXT,
TABCLASS LIKE DD02L-TABCLASS,
FIELDNAME LIKE DD03L-FIELDNAME,
FIELDTEXT LIKE DD03T-DDTEXT,
END OF WA_ITAB.
DATA: ITAB LIKE WA_ITAB OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: V_TNAME FOR DD02L-TABNAME, "表名
V_TABCLS FOR DD02L-TABCLASS DEFAULT 'TRANSP', "表型別
V_FNAME FOR DD03L-FIELDNAME. "欄位名
PARAMETERS: P_TTEXT LIKE DD02T-DDTEXT. "本
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS: P_TAB AS CHECKBOX. "只查詢表記錄
SELECTION-SCREEN END OF BLOCK B2.
START-OF-SELECTION.
PERFORM GET_DATA.
REFRESH GT_LIST_TOP_OF_PAGE[].
PERFORM E04_COMMENT_BUILD .
CLEAR FIELDCAT.
REFRESH FIELDCAT.
PERFORM BUILD_FIELDCAT.
PERFORM BUILD_EVENTCAT.
PERFORM ALV_DISPLAY.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM GET_DATA .
CLEAR: ITAB[], ITAB.
CONCATENATE '%' P_TTEXT '%' INTO P_TTEXT.
IF P_TAB = 'X'.
SELECT A~TABNAME C~DDTEXT AS TABTEXT A~TABCLASS INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM DD02L AS A
INNER JOIN DD03L AS B ON A~TABNAME = B~TABNAME
INNER JOIN DD02T AS C ON A~TABNAME = C~TABNAME AND C~DDLANGUAGE = SY-LANGU
LEFT JOIN DD03T AS D ON B~FIELDNAME = D~FIELDNAME AND D~DDLANGUAGE = SY-LANGU
WHERE A~TABNAME IN V_TNAME
AND A~TABCLASS IN V_TABCLS
AND B~FIELDNAME IN V_FNAME
AND C~DDTEXT LIKE P_TTEXT.
SORT ITAB BY TABNAME.
DELETE ADJACENT DUPLICATES FROM ITAB.
ELSE.
SELECT A~TABNAME C~DDTEXT AS TABTEXT A~TABCLASS B~FIELDNAME D~DDTEXT AS FIELDTEXT INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM DD02L AS A
INNER JOIN DD03L AS B ON A~TABNAME = B~TABNAME
INNER JOIN DD02T AS C ON A~TABNAME = C~TABNAME AND C~DDLANGUAGE = SY-LANGU
LEFT JOIN DD03T AS D ON B~FIELDNAME = D~FIELDNAME AND D~DDLANGUAGE = SY-LANGU
WHERE A~TABNAME IN V_TNAME
AND A~TABCLASS IN V_TABCLS
AND B~FIELDNAME IN V_FNAME
AND C~DDTEXT LIKE P_TTEXT.
SORT ITAB BY TABNAME FIELDNAME.
DELETE ADJACENT DUPLICATES FROM ITAB.
ENDIF.
ENDFORM. " GET_DATA
*&--------------------------------------------------------------------*
*& FORM BUILD_EVENTCAT
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
FORM BUILD_EVENTCAT.
DATA : LS_EVENT TYPE SLIS_ALV_EVENT.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = EVENTCAT.
READ TABLE EVENTCAT
WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
INTO LS_EVENT.
IF SY-SUBRC = 0.
MOVE GC_FORMNAME_TOP_OF_PAGE TO LS_EVENT-FORM.
APPEND LS_EVENT TO EVENTCAT.
ENDIF.
ENDFORM. " BUILD_EVENTCAT
*&----------------------------------------------------
*& FORM ALV_DISPLAY
* TEXT
*-----------------------------------------------------
* --> P1 TEXT
* < -- P2 TEXT
*-----------------------------------------------------
FORM ALV_DISPLAY.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'ZTEST_JIM_002'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = PS_LAYOUT
IT_FIELDCAT = FIELDCAT
I_SAVE = 'A'
IT_EVENTS = EVENTCAT
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " ALV_DISPLAY
*&--------------------------------------------------------------------*
*& FORM ALV_TOP_OF_PAGE
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
FORM ALV_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
* I_LOGO = 'SAPLOGO' .
* I_END_OF_LIST_GRID = 'X'.
ENDFORM. "ALV_TOP_OF_PAGE
*-----------------------------------------------------
* FORM BUILD_FIELDCAT
*-----------------------------------------------------
* ........
*-----------------------------------------------------
FORM BUILD_FIELDCAT.
DATA : COL_POS TYPE I VALUE 0.
PS_LAYOUT-GET_SELINFOS = 'X'.
PS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
PS_LAYOUT-DETAIL_POPUP = 'X'.
PS_LAYOUT-NO_KEYFIX = ''.
PS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
ADD 1 TO COL_POS.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-REF_FIELDNAME = 'TABNAME'.
FIELDCAT_LN-FIELDNAME = 'TABNAME '.
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '表格名'.
FIELDCAT_LN-COL_POS = COL_POS.
APPEND FIELDCAT_LN TO FIELDCAT.
ADD 1 TO COL_POS.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-REF_FIELDNAME = 'TABTEXT'.
FIELDCAT_LN-FIELDNAME = 'TABTEXT '.
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '表格說明'.
FIELDCAT_LN-COL_POS = COL_POS.
APPEND FIELDCAT_LN TO FIELDCAT.
ADD 1 TO COL_POS.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-REF_FIELDNAME = 'TABCLASS'.
FIELDCAT_LN-FIELDNAME = 'TABCLASS '.
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '表格類別'.
FIELDCAT_LN-COL_POS = COL_POS.
APPEND FIELDCAT_LN TO FIELDCAT.
IF P_TAB <> 'X'.
ADD 1 TO COL_POS.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-REF_FIELDNAME = 'FIELDNAME'.
FIELDCAT_LN-FIELDNAME = 'FIELDNAME'.
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '欄位名'.
FIELDCAT_LN-COL_POS = COL_POS.
APPEND FIELDCAT_LN TO FIELDCAT.
ADD 1 TO COL_POS.
CLEAR FIELDCAT_LN.
FIELDCAT_LN-TABNAME = 'ITAB'.
FIELDCAT_LN-REF_FIELDNAME = 'FIELDTEXT'.
FIELDCAT_LN-FIELDNAME = 'FIELDTEXT'.
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '欄位說明'.
FIELDCAT_LN-COL_POS = COL_POS.
APPEND FIELDCAT_LN TO FIELDCAT.
ENDIF.
ENDFORM. "BUILD_FIELDCAT
*&--------------------------------------------------------------------*
*& FORM USER_COMMAND
*&--------------------------------------------------------------------*
* TEXT
*---------------------------------------------------------------------*
* -->UCOMM TEXT
* -->SELFIELD TEXT
*---------------------------------------------------------------------*
FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
READ TABLE ITAB INDEX SELFIELD-TABINDEX.
CHECK SY-SUBRC = 0.
CASE UCOMM.
WHEN '&IC1'.
CASE SELFIELD-SEL_TAB_FIELD.
WHEN 'ITAB-TABNAME'.
SET PARAMETER ID 'DTB' FIELD ITAB-TABNAME.
CALL TRANSACTION 'SE11' AND SKIP FIRST SCREEN.
ENDCASE.
WHEN 'PRI' .
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form E04_COMMENT_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*
*----------------------------------------------------------------------*
FORM E04_COMMENT_BUILD .
DATA : LIST_LINE LIKE LINE OF GT_LIST_TOP_OF_PAGE.
DATA: I_COUNT TYPE I, C_COUNT(5) TYPE C.
LIST_LINE-TYP = 'H'.
LIST_LINE-KEY = ''.
DESCRIBE TABLE ITAB LINES I_COUNT.
C_COUNT = I_COUNT.
CONCATENATE '符合條件的記錄數:' C_COUNT INTO LIST_LINE-INFO.
APPEND LIST_LINE TO GT_LIST_TOP_OF_PAGE.
ENDFORM. " E04_COMMENT_BUILD
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-908162/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Java根據前端返回的欄位名進行查詢資料Java前端
- 根據欄位查表名
- Java根據前端返回的欄位名進行查詢資料的方法Java前端
- SQL server根據表名查詢表主鍵SQLServer
- Laravel ORM 中,根據關聯查詢的欄位值,對主查詢排名LaravelORM
- sql根據多個欄位查詢重複記錄SQL
- 揭秘PostgreSQL:如何查詢表欄位名稱SQL
- 「SAP技術」SAP WM 如何根據TR號碼查詢TO號碼?
- 根據使用者名稱和密碼查詢使用者密碼
- mysql根據查詢結果批量更新多條資料(插入或更新)MySql
- jackson根據屬性名動態序列化物件欄位物件
- SAP定價的合計欄位的程式碼照抄
- 查詢資料庫表及表欄位資料庫
- 根據查詢條件批量修改表資料
- mybatis根據表逆向自動化生成程式碼MyBatis
- MySQL Connector/Python 查詢如何返回欄位名MySqlPython
- SAP RETAIL 根據Merchandise Category Hierarchy Level查詢物料清單AIGo
- 自己封裝的公共獲取資料的方法(支援按欄位名查詢,時間查詢,分頁,關聯查詢),只需一行程式碼封裝行程
- list集合根據某欄位分組
- mybatis入門程式:mybatis根據使用者名稱稱模糊查詢使用者資訊MyBatis
- pid,sid相互查詢,根據PID查詢sqlSQL
- mysql基礎 依據一個欄位查詢另外一個欄位存在不同的值MySql
- golang將切片或陣列根據某個欄位進行分組Golang陣列
- SQL Server 查詢表註釋和欄位SQLServer
- SAP WM初階根據Group Number來查詢與之有關的TO單
- [程式碼結構設計]根據不同條件使用不同實現類的業務程式碼設計
- MySQL8 根據某屬性查詢欄位排名由自定義變數到rank()的變動MySql變數
- linux根據字尾查詢文字Linux
- 根據api檔案生成程式碼API
- 如何自行查詢出 SAP ABAP 標準的 OData 服務返回資料的後臺資料庫表和表欄位名稱資料庫
- 根據emp,dept,salgrade表進行的sql查詢語句(1)SQL
- SAP RETAIL 如何根據分配表查到根據它建立的採購訂單?AI
- sql小筆記(增刪改查——新增列、修改表名、列的欄位型別等)SQL筆記型別
- 根據json內容更新表的一行,欄位數量不固定,但名稱需要一致JSON
- [js] 根據元素ID遍歷樹形結構,查詢到所有父元素IDJS
- mysql like查詢 - 根據多個條件的模糊匹配查詢MySql
- SAP MM 事務程式碼RWBE查詢庫存
- 同一張表的兩個欄位比較查詢
- 如何查詢SAP Fiori UI上某個欄位對應的底層資料庫表UI資料庫