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: 

Create View - Same table is used twice

Former Member

Hi,

I would to create a DB/maintenance view, in which the same DB table should be used twice (the table is the foreign key of two separate fields of main table).

In standard database views there is option of ALIAS definition, but I haven't been find any similar option in SAP.

For example:

View of main table ZMAT_CONVERT which contain the fields MATNR_FROM, MATNR_TO.

MATNR_FROM should be linked to MARA, but MATNR_TO should also be linked to MARA.

How can this be done?

Thanks in advance,

Shai

15 REPLIES 15

Former Member
0 Kudos

Hi

Goto SE11. Selct view and specify a name. Click on Create. Select Maintenance View. Now you need to specify your table ie ZMAT_CONVERT . Click on Relationships button. The set of all relationships ie foreign key relationships appear. Select the desired table ie. MARA. Automatically it displays the list of all join conditions.

Hope this helps

Regards,

Jayanthi.K

0 Kudos

Shai wants to link MARA twice to two different MATNR fields, I don't think this is possible using the SAP data dictionary.

Thomas

Former Member
0 Kudos

Hello

I at one time tried to do like, but beside me was not got.

Former Member
0 Kudos

Thanks your for your replies.

However, as Thomas mentioned, I am asking how can I use the same table twice in my view?

(For example: I have two fields: MATNR_FROM, MATNR_TO in my main table and I would like to link both of them separately to MARA table)

0 Kudos

Hi

It's not possible to use a table twice in the same database view.

Max

0 Kudos

Hi,

I understood that it is not possible use the same table twice in a database view.

Is there any way to do it in maintenance view screen (even if some programming is requried)?

For example: Display the material description for both fields: MATNR_FROM and MATNR_TO.

Thanks,

Shai

0 Kudos

0 Kudos

Hi,

Thanks for your reply.

I have finally succeeded doing it, although it was kind of tricky:

1. First, I have created a maintenance view based on tables ZMARA_DEST and MAKT (MAKT was defined as foreign key and assigned to view tables only once).

2. Then, I have added to the View fields the field MAKT-MAKTX twice with two different view field names (For some reason, it is possible).

3. At last, I have implemented all 3 self-defined events: AA, AC, AD, for which I have copied the standard forms (get_data, read_single, compl), and made some modifications. In my case, I changed the selection method of MAKTX2 value.

Best regards,

Shai

0 Kudos

OK, thanks for posting how you solved it.

Thomas

vonglan
Active Participant

Hi,

Shai (who posted the question) has answered this himself, but it is hidden in the comments, therefore I copy it here, and add an improvement below:

"Hi,

Thanks for your reply.

I have finally succeeded doing it, although it was kind of tricky:

1. First, I have created a maintenance view based on tables ZMARA_DEST and MAKT (MAKT was defined as foreign key and assigned to view tables only once).

2. Then, I have added to the View fields the field MAKT-MAKTX twice with two different view field names (For some reason, it is possible).

3. At last, I have implemented all 3 self-defined events: AA, AC, AD, for which I have copied the standard forms (get_data, read_single, compl), and made some modifications. In my case, I changed the selection method of MAKTX2 value.

Best regards,

Shai"

ADDITION:

For step 3, I implemented just events 05 (FORM add_text) and AA (FORM read_and_add_text).

Here is my example coding:

FORM add_text.

  CHECK zieplant_ctrl_v-old_iwerk IS NOT INITIAL

    AND zieplant_ctrl_v-old_iwerk_txt = zieplant_ctrl_v-new_iwerk_txt.

  SELECT SINGLE name1

    FROM t001w

    WHERE werks = @zieplant_ctrl_v-old_iwerk

    INTO @zieplant_ctrl_v-old_iwerk_txt.

ENDFORM.



FORM read_and_add_text.

  PERFORM get_data_zieplant_ctrl_v. " standard-generated routine for reading

  LOOP AT total[] ASSIGNING <vim_total_struc>.

    zieplant_ctrl_v = <vim_total_struc>.

    PERFORM add_text.

    <vim_total_struc> = zieplant_ctrl_v.

  ENDLOOP.

ENDFORM.

0 Kudos

the abap syntax you are using did not exist in year 2009

why do you answer to a very old question ?

0 Kudos

Thank you, Edo. It helped me in 2020!

I must say I had to implement the event 05 as well for changes to existing data.

0 Kudos

Thank you Edo!

I did exactly as you posted and it worked to perfection!

vonglan
Active Participant

I just (in 2019) had the same problem as the original author

0 Kudos

good point

thanks for sharing