4

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.
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
rodders
  • 229
  • 1
  • 6
  • 9

2 Answers2

6

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_GETinstead 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.

rplantiko
  • 2,698
  • 1
  • 22
  • 21
  • That answer can't be more precise. – Nelson Miranda Jul 21 '15 at 23:16
  • Thanks for the tips, all this ABAP malarkey is new to me. Re. the use of the function, although my code is just retrieving BSAK's metadata this is only for debugging convenience, in reality there are some 6k tables I need the metadata for. Am I right in assuming querying the tables directly would be more convenient in that case? – rodders Jul 22 '15 at 08:19
  • I just tested it. On my system, calling `DDIF_FIELDINFO_GET` for 39512 database tables needed a total time of 878 seconds. For a one-time action (migration of the DDIC), this would be an acceptable performance in my eyes. If you still insist on your own `SELECT` statement, check the logic that is implemented in that function module (and be grateful that SAP is open-source :-) ). There is another table `DDFTX` involved which assists the text determination. – rplantiko Jul 22 '15 at 10:22
  • Lovely, thank you sir! Customer wants faster so will have to go the select route. – rodders Jul 22 '15 at 14:20
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.

vwegert
  • 18,371
  • 3
  • 37
  • 55