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: 

generate persistent class of a selfmade table which access to a text table

Former Member
0 Kudos

Hi SCN-Users,

I hope you could help me again .

My status quo:

I have a main table ZTRANSLATE_FIELD with the fields CTYPEID and PARENT_CTYPEID.

For this table I defined a text table ZTRANSLATE_TEXT to enable translation for international users. The text table contains the field CTYPEID, SPRAS and the fields CTYPENAME & CTYPEDESC which should be translatable.

The text table works fine if I log on f.e. as a english oder a german user.

So, if I start SE11 and show the content of the main table ZTRANSLATE_FIELD, it displays the complete table with the fields CTYPEID, PARENT_CTYPEID, CTYPENAME, CTYPEDESC - in the appropriate language:

[image 1]

Now my problem:

I have to define a persistent class of the table  ZTRANSLATE_FIELD to access all the attributes over ABAP/ Web Dynpro. But this main table only contents two fields CTYPEID & PARENT_CTYPEID in DDIC:

[image 2]

For the persistent class I also need to access the translatable fields CTYPENAME and CTYPEDESC, which are defined in the "external" text table ZTRANSLATE_TEXT:

[image 3]

If I save a new class over SE80 and define its "Persistence" I only could add one table, which should be the required main table ZTANSLATE_FIELD. But then there aren't shown the two fields CTYPENAME & CTYPEDESC of the linked text table, which I also need in this class:

[image 4]

So, the persistent class should look like the table content which is shown in [image 1].

How could I link these two tables, that I could define one persistent class with the fields/methods CTYPEID, PARENT_CTYPEID, CTYPENAME & CTYPEDESC - like it is shown in [image 1]?

I hope someone could help me - I'm thankful about every tip.

Greetings,

Andi

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Andi,

You basically want to define an OR (object-relationship) model for the join of the main & text tables? Afaik you can't do this.

May be create a DB view with a join on the two tables and use this in your persistence class ()

BR,

Suhas


16 REPLIES 16

SuhaSaha
Advisor
Advisor
0 Kudos

Hello Andi,

You basically want to define an OR (object-relationship) model for the join of the main & text tables? Afaik you can't do this.

May be create a DB view with a join on the two tables and use this in your persistence class ()

BR,

Suhas


0 Kudos

Hello,

I am facing the very same issue, and tried to use the DB view option, but then the persistent class mapping cannot be saved because the DB view does not allow maintenance.

And since the mapping requires both tables have the same key, I really don't know how to create a persistent class for a table with a text table...

0 Kudos

Hello Claudio,

Thanks for sharing your experience Yesterday i tried creating the OR mapping for the DB view and i could create it & let me be honest with you i didn't quite check the GET* & SET* methods.

But as per SAP documentation we can use DB tables, views & (even) structures in the OR mapping

Mapping - ABAP - Object Services - SAP Library

May be we're missing something very mundane.

BR,

Suhas

Former Member
0 Kudos

Hi Claudio,

May be this helps not in terms of solution but to understand what is the actual(better) process

http://scn.sap.com/thread/173806

Thanks

Bala Duvvuri

Former Member
0 Kudos

Hey you..

that's fine that I'm not alone with my problem.

I still didn't solve the problem yet 😕 How I could add the second table - my text table for translation - to the persistent class. Of cause the key is the same in this constallation.

Greetings,

Andi

0 Kudos

Hi Andreas,

The problem is that text tables have the SPRAS key field, which is not a key in the other table.

In order to make a persistent class for multiple tables, they must have the complete same key - at least, that is what the documentation informs and what I have sucessfully tested.

I was just wondering if ABAP would have some special function to deal with text tables for persistent classes.

Former Member
0 Kudos

Hi Claudio,

thanks for this information.

How could I set the second table (..the TextTable) to my persistent class?

Or what about generating a persistand class of a database view - some experiences!?

Thanks,

Andi

Former Member
0 Kudos

With a right-click in "Tables/Field" you could add a second table!


The tables have to have to same business key and both a GUID

Former Member
0 Kudos

Thanks for this link Claudio - but this also don't help to solve my problem.

Why couldn't I find a solution or a HowTo from SAP, or in SCN??!!

I still could not generate a persistent class of...

1) a main table and its TextTable, because the haven't got the same primary keys

2) a defined database view of the main table and its TextTable, because there are no operations allowed

I hope I'll get some help..

Former Member
0 Kudos

Hello Andreas,

Good that you atleast have the "Add Table " option. My NW system is ancient , i have not seen that feature  .

From a Theoretical point of view, I feel it is right to not link the table and its text table . Why?

You use Object Identity. ie, the Primary keys are used to uniquely identify an object instance in the DB.

.An object with a Key as say 2190 in one table and there is an object with key 2190EN . As far

as the system is concerned  these are two seperate objects, though there maybe a Foreign key relationship between the two on one of the columns.Also, there is a 1:CN relationship , so how many text table objects does it need to instantiate?. or How many persistent objects are created? ( one for every language etc. ).

Also, the text table need not be the only table which has a foreign key relationship, there maybe other tables too, becuase at the DB level, I dont think there is a special type of foreign key for text tables.

Maybe, In the future there could a special relatonship for Text tables such as Object A(Table A) is described by Object B(table B -Text table) and a descriptor handler Interface could be attached only for Persistent objects that have a text table.

For your case, you could have the Persistent object of the text table as an attribute to the Persistent class of the Main table. Write your own initialization logic in the  Init ( ) method to initialize the persistent object for the text table and write your own custom methods for setting/getting the data. This is the easiest as far as I know.

Hope this helps. Do correct me If I am missing anything.

Thanks,

Venkat.

Message was edited by: Venkat Gowrishankar

Former Member
0 Kudos

Thank for this reply - there is much more clarity now - but I still don't know how to do 😕

I search for a HowTo or a description, how I could "add" the fields of another table (..in my case the TextTable..) to the persistente class-options of the main table.

Example:

I made two persistent classes from own DDIC-tables ATTRIBUTE_MAIN and ATTRIBUTE_TTABLE:

- CL_ATTRIBUTE_MAIN has the keyfield ATTRIBUTE_ID

- CL_ATTRIBUTE_TTABLE has the keyfields ATTRIBUTE_ID (with foreign key to the table ATTRIBUTE) and SPRAS. And this class has the other field ATTRIBUTE_NAME, which should show the language-dependent input.

How could I set the proberties of ATTRIBUTE_NAME of my CL_ATTRIBUTE_TABLE (the GET and SET-methods) as an method/attribute of the main class CL_ATTRIBUTE_MAIN.

Former Member
0 Kudos

Hello Andreas,

I would suggest the following:

1. Create an attribute in CL_ATTRIBUTE_MAIN of type ref to CL_ATTRIBUTE_TTABLE.

2. In   IF_OS_STATE~INIT Method of CL_ATTRIBUTE_MAIN, Initialize the text object attribute by passing in the key and the Language.

3. Add a set custom method to CL_ATTRIBUTE_MAIN which updates the text . Also write a get method which returns the text.

I hope this clarifies .

Thanks,

venkat.

Former Member
0 Kudos

Hi Venkat,

this helps me more, yes - thanks.

But would be nice if you could help me with the execution, also...

1.) Create attribute "ATFO_DESC" in the main-class ATTRIBUTE_FOLDER with associated type of the texttable-class:

2.) Method in IF_OS_STATE~INIT - I don't know what to write for initialization. Based on ATFO_ID and SPRAS there should be shown the language-specific ATFO_NAME and ATFO_DESC:

Is this right?

3.) The attributes ATFO_NAME and ATFO_DESC of the texttable-class "CL_TEXTTABLE_ATFO" should be shown - so "read only"/only get-method.

How has the call have to look like?

Thanks for your help,

Andreas

Former Member
0 Kudos

Hello Andreas,

You have done it right! .

That's it you need not do anything more. The Init method is called by the system  whenever a persistent object is initialized. So that's it  . Let me know if there are any other issues.

Note : Marking an attribute ( Especially an object reference )  as read only, ensures that the attribute alone is read only and not the object. That is, The method in the classes can still be called. When we  mark an attribute as read only, especially in the case of object references, we make sure that the attribute cannot be set a reference outside of the class's scope. If you want a  read only option, then you could create an interface which returns the text only. The persistent class of the text table then implements this interface. You have you attribute in the Main class as a reference of type Interface.

Hope this helps.

Thanks,

Venkat.

Former Member
0 Kudos

Okay..

in 1.) I have to define the TextTable as an attribute

...or the specific field/attribute of the TextTable - like in my post at 3.June --> ATFO_DESC with TYPE Ref CL_TEXTTABLE?

2.) In INIT I have to define all of this

...and in my Web Dynpro Code I have to call/define the functions "again":

Is this right!?

Where is my benefit, if I have to define every class, agent, ... in the Web Dynpro again!?

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

EDIT:

if I delete the Attribute and the code in ~INIT, I also get my data of the Web Dynpro-code...  😕

Former Member
0 Kudos

Hello Andreas,

In the INIT( ) method, you would intialize the text table object attribute

In the webdynpro, the following code ..

cl_atfo->atfo_ttable->get_text( )

should do the trick .

Thats it. The same applies for updating the text.

Thanks,

Venkat.