问题
I'm trying to query SAP's data dictionary through ERPConnect's ABAP API. The code below retrieves the table names and various field properties fine but fails to show the field description. Anyone knows why?
Thanks
REPORT ZSELECTCOMMAND.
TABLES: DD02L,
DD03L,
DD02T, DD04T.
DATA: BEGIN OF tb_meta,
tabname TYPE DD02L-tabname,
fieldname TYPE DD03L-fieldname,
datatype TYPE DD03L-datatype,
leng TYPE DD03L-leng,
decimals TYPE DD03L-decimals,
position TYPE DD03L-position,
desc TYPE DD04T-ddtext,
END OF tb_meta.
DATA utb_meta LIKE STANDARD TABLE OF tb_meta.
DATA: ln_meta LIKE LINE OF utb_meta, m1 TYPE i, m2 TYPE i.
SELECT
tb~tabname
fld~fieldname
fld~datatype fld~leng
fld~decimals fld~position
x~ddtext
INTO CORRESPONDING FIELDS OF TABLE utb_meta
FROM
dd02L AS tb
INNER JOIN dd03L AS fld
ON tb~tabname = fld~tabname
INNER JOIN DD04T AS x
ON fld~ROLLNAME = x~ROLLNAME
AND x~DDLANGUAGE = 'EN'
WHERE
CONTFLAG IN ('A', 'C', 'S')
AND
APPLCLASS <> ''
AND
tb~TABNAME NOT LIKE '/%'
AND
tb~TABNAME NOT LIKE '%_BAK'
AND
tb~TABNAME = 'BSAK'.
*GET RUN TIME FIELD m1.
loop at utb_meta into ln_meta.
write:/
ln_meta-tabname
&& '>>' && ln_meta-fieldname
&& '>>' && ln_meta-datatype
&& '>>' && ln_meta-leng
&& '>>' && ln_meta-decimals
&& '>>' && ln_meta-position
&& '>>' && ln_meta-desc.
endloop.
回答1:
There are different places where text information of a table field or structure field can be stored. The data element texts that you are selecting from DD04T
are only one place for those texts. You can define table components with built-in data types instead of dictionary data types, then the texts will be stored in DD03T
(for example)
For these reasons (technical details of the DD*
tables), I would strongly recommend you to use the function module DDIF_FIELDINFO_GET
instead of rolling your own DD*
select. Just pass the parameters TABNAME
and LANGU
, and the resulting internal table DFIES_TAB
will contain all the information you need, including texts.
回答2:
In addition to @rplantiko's suggestions, I'd suggest to use the RPY_*
function modules that are already RFC-enabled and might be easier to access out of the box.
来源:https://stackoverflow.com/questions/31547643/get-table-field-description-programmatically