Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to find out the primary key column of a database table?

Hi

Given the following scenario :

Given an inputfield, the user can enter a table name. The code behind will base on the table name given and extract out the fieldname of the primary key and concatenate the two field to become a unique string.

Eg. Order ID and Product ID make out a primary key.

How do i achieve that? Any code sample?

Regards,

Rayden

Tags:
Former Member
Former Member replied

Check the below code :

REPORT zTest no standard page heading.

data : i_DD03P like DD03P occurs 0 with header line.

data v_table like DCOBJDEF-NAME.

parameters : p_table like dd02l-tabname.

start-of-selection.

v_table = p_table.

CALL FUNCTION 'BDL_DDIF_TABL_GET'

EXPORTING

NAME = v_table

STATE = 'A'

LANGU = 'E'

  • IMPORTING

  • GOTSTATE =

  • DD02V_WA =

  • DD09L_WA =

TABLES

DD03P_TAB = i_DD03P

  • DD05M_TAB =

  • DD08V_TAB =

  • DD12V_TAB =

  • DD17V_TAB =

EXCEPTIONS

ILLEGAL_INPUT = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at i_DD03P.

if i_dd03p-KEYFLAG = 'X'.

write:/ 'Key fields', i_dd03p-FIELDNAME.

endif.

endloop.

Thanks

Seshu

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question