Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Query DD03L using an ABAP program

sas70
Explorer
0 Kudos
806

Hello Professionals

I am trying to leverage the code posted in this place (below) to output the technical fieldnames and related attributes from some SAP tables like T000, T001...

However, while the code's syntax is correct, I get no output. I am coming from a web development background and ABAP is new to me 🙂

Thanks

*&---------------------------------------------------------------------*
*& Report ZMY_ALV_10
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZMY_ALV_10.

FIELD-SYMBOLS:
<fieldname> TYPE ANY, "Name of field
<line> TYPE ANY, "Line structure for table
<fieldvalue> TYPE ANY. "Value of field

DATA: l_shorttext LIKE dd03m-ddtext.

DATA: wa_dd03l LIKE dd03l.
DATA WA_PA1_DELTA.


SELECT * FROM dd03l INTO wa_dd03l

WHERE tabname = 'ZHR_INTER_PA1_DL'.
* Assign name of field
ASSIGN COMPONENT 2 OF STRUCTURE wa_dd03l TO <fieldname>.

* Assign structure for internal table
ASSIGN wa_pa1_delta TO <line>.

* Assign field value from structure
ASSIGN COMPONENT <fieldname> OF STRUCTURE <line> TO <fieldvalue>.

* Find DD text for field
SELECT SINGLE ddtext
FROM dd03m
INTO l_shorttext
WHERE tabname = 'ZHR_INTER_PA1_DL' AND
fieldname = <fieldname> AND
ddlanguage = 'EN'.


WRITE: / <fieldname>, l_shorttext, ' : ', <fieldvalue>.

ENDSELECT.

Source : https://www.henrikfrank.dk/abaptips/abapindex.htm?page=abap%20language%2Fdynamic%20programming%2Fdyn...

7 REPLIES 7

adityaIngale
Active Participant
0 Kudos
659

What is your requirement? Can you explain in details?

sas70
Explorer
0 Kudos
659

Aditya,

Thank you for the followup. Basically I am collecting configuration and master data tables within specific clients and trying to download their structure to Excel as well access these tables programmatically to perform some summing and grouping by specific fields to summarise transactions by targeted field names such as Material type, document type, or even by any structural elements such as storage location, sales office…to collect some KPIs somewhat mimic the behaviour of ST13 (Table analysis).

Many thanks

Omar

abityildiz
Active Participant
0 Kudos
659

Hello,

Can you try this code:

FIELD-SYMBOLS:
<fieldname> TYPE ANY, "Name of field
<line> TYPE ANY, "Line structure for table
<fieldvalue> TYPE ANY. "Value of field

DATA: l_shorttext LIKE dd03m-ddtext.

DATA: wa_dd03l LIKE dd03l.



SELECT * FROM dd03l INTO wa_dd03l

WHERE tabname = 'ZHR_INTER_PA1_DL'.
* Assign name of field
ASSIGN COMPONENT 2 OF STRUCTURE wa_dd03l TO <fieldname>.

* Assign structure for internal table
ASSIGN wa_dd03l TO <line>.

* Assign field value from structure
ASSIGN COMPONENT 2 OF STRUCTURE <line> TO <fieldvalue>.

* Find DD text for field
SELECT SINGLE ddtext
FROM dd03m
INTO l_shorttext
WHERE tabname = 'ZHR_INTER_PA1_DL' AND
fieldname = <fieldname> AND
ddlanguage = 'EN'.


WRITE: / <fieldname>, l_shorttext, ' : ', <fieldvalue>.

ENDSELECT.

0 Kudos
659

Hello Abit

Thank you for your followup.

While your code's syntax is correct, I get no output on my end.

Best reagrds

Omar

touzik_itc
Active Participant
0 Kudos
659

To read and display table content of an arbitrary table:

PARAMETERS tabname TYPE tabname.

DATA dataref TYPE REF TO data.
CREATE DATA dataref TYPE TABLE OF (tabname).

FIELD-SYMBOLS <lt_data> TYPE ANY TABLE.
ASSIGN dataref->* TO <lt_data>.

SELECT * FROM (tabname) INTO TABLE @<lt_data>.
cl_demo_output=>display( <lt_data> ).

To read and display table structure:

DATA lt_comp TYPE TABLE OF dd03p.
CALL FUNCTION 'DD_TABL_GET'
EXPORTING
tabl_name = tabname
withtext = abap_true
langu = 'E'
TABLES
dd03p_tab_a = lt_comp
EXCEPTIONS
OTHERS = 1.

DATA lt_desc TYPE TABLE OF string.
lt_desc = VALUE #( FOR <wa> IN lt_comp ( |Name { <wa>-fieldname }, data type { <wa>-rollname }, description { <wa>-ddtext }| ) ).
cl_demo_output=>display( lt_desc ).

0 Kudos
659

Hello Andrei

Thank you for the follow-up.

The first piece of code does not work for me as I am running Pack 7 so my editor does not recognize the inline declarations made in your code.

For the second piece, I get an error message that field <tabname> is unknown.

Best reagrds

Omar

0 Kudos
659

Hello Omar,

what kind of error do you get in the first part? All variables and field symbols are declared explicitly here. In the second part there is no field symbol <tabname>. The variable tabname is decalared in the first part with a PARAMETERS statement.