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: 

creating DDIC structures during runtime

Former Member
0 Kudos

Hi,

does someone know how to create a structure in the data dictionary dynamically - f.e. with a FB?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi jim,

You can do it using the function module

'RPY_TABLE_INSERT'. After creating the table or

structure you can as well activate it alos.

This is the sample code for that.

REPORT YTABCREATE .

  • DOMINE DATA STRUCTURES.

DATA : DOMA_NAME LIKE RPY_DOMA-DOMANAME,

DOMA_INF LIKE RPY_DOMA ,

TRANSPORT_NUMBER LIKE RGLIF-TRKORR,

DEVELOPMENT_CLASS LIKE RGLIF-DEVCLASS VALUE '$TMP'.

DATA : BEGIN OF DOMA_VALUES OCCURS 0.

INCLUDE STRUCTURE RPY_DVAL.

DATA : END OF DOMA_VALUES.

  • DATAELEMENT DATA STRUCTURES.

DATA : DATAELEMENT_NAME LIKE RPY_DTEL-DTELNAME,

DTEL_INF LIKE RPY_DTEL .

  • TABLE DATA STRUCTURES.

DATA : TABLE_NAME LIKE RPY_TABL-TABLNAME,

TABL_INF LIKE RPY_TABL,

TABL_TECHNICS LIKE RPY_TBTECH,

TABL_TECHNICS1 LIKE DD09V.

DATA : BEGIN OF TABL_FIELDS OCCURS 0.

INCLUDE STRUCTURE RPY_FIEL_U.

DATA : END OF TABL_FIELDS.

DATA : BEGIN OF TABL_FIELDS1 OCCURS 0.

INCLUDE STRUCTURE RPY_FIEL.

DATA : END OF TABL_FIELDS1.

DATA : BEGIN OF I_DATA OCCURS 0,

DATA LIKE RPY_DTEL-DTELNAME,

DOM LIKE RPY_DTEL-DOMANAME,

DDTXT LIKE RPY_DTEL-DDTEXT,

HEAD LIKE RPY_DTEL-HEADTEXT,

SHORT LIKE RPY_DTEL-SCRTEXT_S,

MID LIKE RPY_DTEL-SCRTEXT_M,

LONG LIKE RPY_DTEL-SCRTEXT_L,

END OF I_DATA.

DATA : BEGIN OF IT_TABM OCCURS 0,

TABNAME LIKE RPY_TABL-TABLNAME,

FIELDNAME LIKE RPY_FIEL_U-FIELDNAME,

DTELNAME LIKE RPY_FIEL_U-DTELNAME,

DTXT LIKE RPY_DTEL-DDTEXT,

KEYFLAG LIKE RPY_FIEL_U-KEYFLAG,

NOTNULL LIKE RPY_FIEL_U-NOTNULL,

END OF IT_TABM.

DATA : BEGIN OF IT_TABC OCCURS 0,

TABNAME LIKE RPY_TABL-TABLNAME,

TABNAME1 LIKE RPY_TABL-TABLNAME,

END OF IT_TABC.

DEVELOPMENT_CLASS = 'YHPA0'.

TRANSPORT_NUMBER = 'HT6K901262'.

**********************************************************************

    • TABLE CREATION

**********************************************************************

******Here you can pass the values depending on ur req.

TABL_INF-TABLNAME = TABNAME1.

TABL_INF-LANGUAGE = SY-LANGU.

TABL_INF-TABLCLASS = TABCLASS.

TABL_INF-SQLTAB = SQLTAB.

TABL_INF-BUFFERED = BUFFERED.

TABL_INF-SHORTTEXT = DDTEXT.

TABL_INF-ACTTYPE = AUTHCLASS.

TABL_INF-INCLEXIST = LANGDEP.

TABL_INF-MASTERLANG = MASTERLANG.

TABL_INF-MAINTFLAG = MAINFLAG.

TABL_INF-DELIVERYCL = CONTFLAG.

TABL_INF-MOD_USER = Sy-uname.

TABL_INF-MOD_DATE = SY-DATUM.

TABL_INF-MOD_TIME = SY-UZEIT.

TABL_TECHNICS-TABLNAME = TABNAME1.

TABL_TECHNICS-LANGUAGE = SY-LANGU.

TABL_TECHNICS-TABLCAT = TABKAT.

TABL_TECHNICS-TABLCLASS = TABART.

TABL_TECHNICS-BUFFERING = PUFFERUNG.

TABL_TECHNICS-KEYFIELDNO = SCHFELDANZ.

TABL_TECHNICS-LOGGING = PROTOKOLL.

TABL_TECHNICS-STORETYPE = SPEICHPUFF.

TABL_TECHNICS-MODUSER = 'RAVIP'.

TABL_TECHNICS-MODDATE = SY-DATUM.

TABL_TECHNICS-MODTIME = SY-UZEIT.

TABL_TECHNICS-TRANSPFLAG = TRANSPFLAG.

TABL_TECHNICS-TRANSLATE = UEBERSETZ.

******Here you pass all the fields

TABL_FIELDS1-TABLNAME = TABNAME1.

TABL_FIELDS1-FIELDNAME = FIELDNAME.

TABL_FIELDS1-CHECKTABLE = CHECKTABLE.

TABL_FIELDS1-KEYFLAG = KEYFLAG.

TABL_FIELDS1-POSITION = POSITION.

TABL_FIELDS1-REFTABLE = REFTABLE.

TABL_FIELDS1-REFFIELD = REFFIELD.

TABL_FIELDS1-INCLNAME = PRECFIELD.

TABL_FIELDS1-NOTNULL = NOTNULL.

TABL_FIELDS1-DTELNAME = DTELNAME.

APPEND : TABL_FIELDS1.

CLEAR : TABL_FIELDS1.

CALL FUNCTION 'RPY_TABLE_INSERT'

EXPORTING

LANGUAGE = SY-LANGU

TABLE_NAME = TABLE_NAME

  • WITH_DOCU = ' '

  • DOCUTYPE = 'T'

TRANSPORT_NUMBER = TRANSPORT_NUMBER

DEVELOPMENT_CLASS = DEVELOPMENT_CLASS

TABL_INF = TABL_INF

TABL_TECHNICS = TABL_TECHNICS

TABLES

TABL_FIELDS = TABL_FIELDS[]

  • DOCU_TABLE_USER =

  • DOCU_TABLE_TECH =

EXCEPTIONS

CANCELLED = 1

ALREADY_EXIST = 2

PERMISSION_ERROR = 3

NAME_NOT_ALLOWED = 4

NAME_CONFLICT = 5

DB_ACCESS_ERROR = 6

OTHERS = 7

.

IF SY-SUBRC <> 0.

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

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

ELSE.

CLEAR TABL_TECHNICS1.

MOVE-CORRESPONDING TABL_TECHNICS TO TABL_TECHNICS1.

CALL FUNCTION 'DD_TABT_PUT'

EXPORTING

DD09L_WA = TABL_TECHNICS1

  • PRID = 0

  • PUT_STATE = 'N'

TABL_NAME = TABLE_NAME

  • EXCEPTIONS

  • ILLEGAL_VALUE = 1

  • OBJECT_INCONSISTENT = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ELSE.

CALL FUNCTION 'DD_TABL_ACTIVATE'

EXPORTING

TABNAME = TABLE_NAME

  • AUTH_CHK = 'X'

  • PRID = 0

  • IMPORTING

  • RESULT =

EXCEPTIONS

ACT_REFUSED = 1

ACT_FAILURE = 2

ACT_UNLOCK_FAILURE = 3

ILLEGAL_VALUE = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDIF.

Hope this will help you.

Thanks & Regards,

Siri.

Message was edited by: Srilatha T

13 REPLIES 13

RichHeilman
Developer Advocate
Developer Advocate

I think that it is possible, but why do you want to create it in the dictionary?

Regards,

Rich Heilman

Former Member
0 Kudos

LOL

Thanks for ure reply Rich. I am just smiling because, in a similar thread u asked the threat creator the same question.

ok-just imagine i need it that way (persistant). somekind of moving datastructures between systems. so, if u know how it works to create it dynamical just let me know.

Im checking some FBs right now like:

BM_STRUCTURE_CREATE and

RPY_TABLE_INSERT

but iam not sure that they will do what i want them for...

0 Kudos

Ok, so to clarify, you want to create a structure(data element) like you do in SE11 programmically, right? Will you be deleting it when you are done as well?

Regards,

Rich Heilman

Former Member
0 Kudos

no, it needs to exist further after finishing the prog. Therefore the DDIC entry.

0 Kudos

Check out the function modules in the function group SDIF.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi jim,

You can do it using the function module

'RPY_TABLE_INSERT'. After creating the table or

structure you can as well activate it alos.

This is the sample code for that.

REPORT YTABCREATE .

  • DOMINE DATA STRUCTURES.

DATA : DOMA_NAME LIKE RPY_DOMA-DOMANAME,

DOMA_INF LIKE RPY_DOMA ,

TRANSPORT_NUMBER LIKE RGLIF-TRKORR,

DEVELOPMENT_CLASS LIKE RGLIF-DEVCLASS VALUE '$TMP'.

DATA : BEGIN OF DOMA_VALUES OCCURS 0.

INCLUDE STRUCTURE RPY_DVAL.

DATA : END OF DOMA_VALUES.

  • DATAELEMENT DATA STRUCTURES.

DATA : DATAELEMENT_NAME LIKE RPY_DTEL-DTELNAME,

DTEL_INF LIKE RPY_DTEL .

  • TABLE DATA STRUCTURES.

DATA : TABLE_NAME LIKE RPY_TABL-TABLNAME,

TABL_INF LIKE RPY_TABL,

TABL_TECHNICS LIKE RPY_TBTECH,

TABL_TECHNICS1 LIKE DD09V.

DATA : BEGIN OF TABL_FIELDS OCCURS 0.

INCLUDE STRUCTURE RPY_FIEL_U.

DATA : END OF TABL_FIELDS.

DATA : BEGIN OF TABL_FIELDS1 OCCURS 0.

INCLUDE STRUCTURE RPY_FIEL.

DATA : END OF TABL_FIELDS1.

DATA : BEGIN OF I_DATA OCCURS 0,

DATA LIKE RPY_DTEL-DTELNAME,

DOM LIKE RPY_DTEL-DOMANAME,

DDTXT LIKE RPY_DTEL-DDTEXT,

HEAD LIKE RPY_DTEL-HEADTEXT,

SHORT LIKE RPY_DTEL-SCRTEXT_S,

MID LIKE RPY_DTEL-SCRTEXT_M,

LONG LIKE RPY_DTEL-SCRTEXT_L,

END OF I_DATA.

DATA : BEGIN OF IT_TABM OCCURS 0,

TABNAME LIKE RPY_TABL-TABLNAME,

FIELDNAME LIKE RPY_FIEL_U-FIELDNAME,

DTELNAME LIKE RPY_FIEL_U-DTELNAME,

DTXT LIKE RPY_DTEL-DDTEXT,

KEYFLAG LIKE RPY_FIEL_U-KEYFLAG,

NOTNULL LIKE RPY_FIEL_U-NOTNULL,

END OF IT_TABM.

DATA : BEGIN OF IT_TABC OCCURS 0,

TABNAME LIKE RPY_TABL-TABLNAME,

TABNAME1 LIKE RPY_TABL-TABLNAME,

END OF IT_TABC.

DEVELOPMENT_CLASS = 'YHPA0'.

TRANSPORT_NUMBER = 'HT6K901262'.

**********************************************************************

    • TABLE CREATION

**********************************************************************

******Here you can pass the values depending on ur req.

TABL_INF-TABLNAME = TABNAME1.

TABL_INF-LANGUAGE = SY-LANGU.

TABL_INF-TABLCLASS = TABCLASS.

TABL_INF-SQLTAB = SQLTAB.

TABL_INF-BUFFERED = BUFFERED.

TABL_INF-SHORTTEXT = DDTEXT.

TABL_INF-ACTTYPE = AUTHCLASS.

TABL_INF-INCLEXIST = LANGDEP.

TABL_INF-MASTERLANG = MASTERLANG.

TABL_INF-MAINTFLAG = MAINFLAG.

TABL_INF-DELIVERYCL = CONTFLAG.

TABL_INF-MOD_USER = Sy-uname.

TABL_INF-MOD_DATE = SY-DATUM.

TABL_INF-MOD_TIME = SY-UZEIT.

TABL_TECHNICS-TABLNAME = TABNAME1.

TABL_TECHNICS-LANGUAGE = SY-LANGU.

TABL_TECHNICS-TABLCAT = TABKAT.

TABL_TECHNICS-TABLCLASS = TABART.

TABL_TECHNICS-BUFFERING = PUFFERUNG.

TABL_TECHNICS-KEYFIELDNO = SCHFELDANZ.

TABL_TECHNICS-LOGGING = PROTOKOLL.

TABL_TECHNICS-STORETYPE = SPEICHPUFF.

TABL_TECHNICS-MODUSER = 'RAVIP'.

TABL_TECHNICS-MODDATE = SY-DATUM.

TABL_TECHNICS-MODTIME = SY-UZEIT.

TABL_TECHNICS-TRANSPFLAG = TRANSPFLAG.

TABL_TECHNICS-TRANSLATE = UEBERSETZ.

******Here you pass all the fields

TABL_FIELDS1-TABLNAME = TABNAME1.

TABL_FIELDS1-FIELDNAME = FIELDNAME.

TABL_FIELDS1-CHECKTABLE = CHECKTABLE.

TABL_FIELDS1-KEYFLAG = KEYFLAG.

TABL_FIELDS1-POSITION = POSITION.

TABL_FIELDS1-REFTABLE = REFTABLE.

TABL_FIELDS1-REFFIELD = REFFIELD.

TABL_FIELDS1-INCLNAME = PRECFIELD.

TABL_FIELDS1-NOTNULL = NOTNULL.

TABL_FIELDS1-DTELNAME = DTELNAME.

APPEND : TABL_FIELDS1.

CLEAR : TABL_FIELDS1.

CALL FUNCTION 'RPY_TABLE_INSERT'

EXPORTING

LANGUAGE = SY-LANGU

TABLE_NAME = TABLE_NAME

  • WITH_DOCU = ' '

  • DOCUTYPE = 'T'

TRANSPORT_NUMBER = TRANSPORT_NUMBER

DEVELOPMENT_CLASS = DEVELOPMENT_CLASS

TABL_INF = TABL_INF

TABL_TECHNICS = TABL_TECHNICS

TABLES

TABL_FIELDS = TABL_FIELDS[]

  • DOCU_TABLE_USER =

  • DOCU_TABLE_TECH =

EXCEPTIONS

CANCELLED = 1

ALREADY_EXIST = 2

PERMISSION_ERROR = 3

NAME_NOT_ALLOWED = 4

NAME_CONFLICT = 5

DB_ACCESS_ERROR = 6

OTHERS = 7

.

IF SY-SUBRC <> 0.

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

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

ELSE.

CLEAR TABL_TECHNICS1.

MOVE-CORRESPONDING TABL_TECHNICS TO TABL_TECHNICS1.

CALL FUNCTION 'DD_TABT_PUT'

EXPORTING

DD09L_WA = TABL_TECHNICS1

  • PRID = 0

  • PUT_STATE = 'N'

TABL_NAME = TABLE_NAME

  • EXCEPTIONS

  • ILLEGAL_VALUE = 1

  • OBJECT_INCONSISTENT = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ELSE.

CALL FUNCTION 'DD_TABL_ACTIVATE'

EXPORTING

TABNAME = TABLE_NAME

  • AUTH_CHK = 'X'

  • PRID = 0

  • IMPORTING

  • RESULT =

EXCEPTIONS

ACT_REFUSED = 1

ACT_FAILURE = 2

ACT_UNLOCK_FAILURE = 3

ILLEGAL_VALUE = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

ENDIF.

Hope this will help you.

Thanks & Regards,

Siri.

Message was edited by: Srilatha T

0 Kudos

Here is an example program using function modules which are in function group SDIF as I suggested eariler.



REPORT ZRICH_0001 .

data: xdd02v type dd02v.
data: idd03p type table of dd03p with header line.

parameters: p_struc type DDOBJNAME.

start-of-selection.

  xdd02v-TABNAME = p_struc.
  xdd02v-tabclass = 'INTTAB'.
  xdd02v-DDLANGUAGE = sy-langu.
  xdd02v-LANGDEP = sy-langu.
  xdd02v-DDTEXT  = 'This is a test structure'.

  clear idd03p.
  idd03p-TABNAME  = p_struc.
  idd03p-FIELDNAME = 'MANDT'.
  idd03p-ROLLNAME = 'MANDT'.
  idd03p-POSITION = '1'.
  append idd03p.

  clear idd03p.
  idd03p-TABNAME  = p_struc.
  idd03p-FIELDNAME = 'MATNR'.
  idd03p-ROLLNAME = 'MATNR'.
  idd03p-POSITION = '2'.
  append idd03p.


  CALL FUNCTION 'DDIF_TABL_PUT'
       EXPORTING
            NAME              = p_struc
            DD02V_WA          = xdd02v
       TABLES
            DD03P_TAB         = idd03p
       EXCEPTIONS
            TABL_NOT_FOUND    = 1
            NAME_INCONSISTENT = 2
            TABL_INCONSISTENT = 3
            PUT_FAILURE       = 4
            PUT_REFUSED       = 5
            OTHERS            = 6.

  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL FUNCTION 'DDIF_TABL_ACTIVATE'
       EXPORTING
            NAME        = p_struc
       EXCEPTIONS
            NOT_FOUND   = 1
            PUT_FAILURE = 2
            OTHERS      = 3.

  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Regards,

Rich Heilman

0 Kudos

Thanks a lot, Siri and Rich! I appreciate your support much!

Finally i solved it with the functions mentioned by Rich.

Im quiet confused about the inconsitent way of creating a strukture in the SAP System. With SE11 u create a structure

by creating a special datatype. But with the given funtions (there are a lot of them - more ore less complex) u can create a structure by creating a table -> an internal one??!? Isnt that weird? Sometimes its a one dimensional table.... sometimes its a complex datatype - great!

There is nothing more consistent than the change

Have a nice day!

0 Kudos

Yes, I agree, it threw me for a while. I wanted to create the structure from the "data element" function module.

Regards,

Rich Heilman

0 Kudos

Hi Rich, how do I have to modify the above if i want to create Z-Table ?

Clemens

Former Member
0 Kudos

@rich:

I already did, but i couldnt find a function for creating structures...

Former Member
0 Kudos

Thanks si far Siri,

everytime iam using the function 'RPY_TABLE_INSERT'

iam getting the message that i cant create a view with the given name. Any idea?

Jim

JerMarijnissen
Participant
0 Kudos

You can also have a look to function module RSDL_DB_DATASOURCE_GENERATE