Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active October 28, 2022 13:47
Show Gist options
  • Save stevewithington/a527e4257635b0159a21fbb7f050cbf4 to your computer and use it in GitHub Desktop.
Save stevewithington/a527e4257635b0159a21fbb7f050cbf4 to your computer and use it in GitHub Desktop.
SAP: Query recordset of SAP tables, columns/fields, and their descriptions
USE {YOUR-SAP-DBNAME-GOES-HERE};
GO
SELECT
D3L.POSITION AS SOURCE_COLUMN_POSITION
, D2L.TABNAME AS SOURCE_TABLE_NAME
, D2T.DDTEXT AS SOURCE_TABLE_DESC
, D3L.FIELDNAME AS SOURCE_COLUMN_NAME
, D4T.DDTEXT AS SOURCE_COLUMN_DESC
, D4T.REPTEXT AS SOURCE_COLUMN_HEADER
, D4T.SCRTEXT_S AS SOURCE_COLUMN_LABEL_SHORT
, D4T.SCRTEXT_M AS SOURCE_COLUMN_LABEL_MEDIUM
, D4T.SCRTEXT_L AS SOURCE_COLUMN_LABEL_LONG
FROM {YOUR-SCHEMA}.DD02L D2L /* SAP Tables */
INNER JOIN erp.DD03L D3L ON D3L.TABNAME = D2L.TABNAME /* Table Fields */
AND D2L.AS4LOCAL = D3L.AS4LOCAL /* Activation status */
INNER JOIN erp.DD02T D2T ON D2L.TABNAME = D2T.TABNAME /* SAP DD: SAP Table Texts */
INNER JOIN erp.DD04T D4T ON D4T.ROLLNAME = D3L.ROLLNAME /* R/3 DD: Data Element Texts */
WHERE 1=1
--AND D2L.TABNAME = '{SOME-TABLE-NAME, e.g., LFA1}' /* To filter for specific table */
AND D2L.AS4LOCAL = 'A' /* Activated Tables Only */
AND D2L.TABCLASS IN ('TRANSP','POOL','CLUSTER') /* Ignoring: INITTAB (Structure), VIEW, and APPEND tables */
AND D3L.PRECFIELD = ' ' /* Ignore .INCLUDE fields */
AND D4T.DDLANGUAGE = 'E' /* English Only */
AND D2T.DDLANGUAGE = 'E' /* English Only */
ORDER BY D2T.TABNAME ASC, D3L.POSITION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment