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: 

Copying data of one table to another

tharaka_fernando
Contributor
0 Kudos
133

Hi All Gurus,

Below is my requirement,

I get below values from ANEK table.

SELECT bukrs anln1 anln2 budat tcode FROM anek
    INTO TABLE t_anek WHERE bukrs IN s_co_cod AND
                            anln1 IN s_ast_nm AND
                            tcode IN ('CJ88' , 'KO88', 'KO8G', 'AIAB', 'ABUMN', 'ANZON', 'F-92', 'ABAVN') AND
                            budat IN s_post_dt.

Then I go to ANEP table to get below values.

SELECT bukrs anln1 anln2 gjahr afabe belnr buzei anbtr FROM anep
    INTO corresponding fields of table t_data FOR ALL ENTRIES IN t_anek WHERE
    bukrs = t_anek-bukrs AND
    anln1 = t_anek-anln1 AND
    anln2 = t_anek-anln2 AND
    gjahr = p_fs_yr AND
    afabe = 01.

This is working very fine. But my point is when I'm getting DATA from ANEP to t_data table I get all the values which had in T_ANEK internal table except budat tcode.

Is there a method to get these to t_data internal table without looping the T_ANEK table & get data from ANEP & append all these to t_data

OR

Without an Inner Join (ANEK,ANEP) ?

Any ABAP Performance Tunning Method to join these two internal table ...?

2 REPLIES 2

Former Member
0 Kudos
56

Hi,

To join ANEK and ANEP use view ANEKPV already exist in ABAP dictionary.

regards,

Karim

Former Member
0 Kudos
56

Hi,

one possibity is to use inner join. If you want to avoid this for some reasons, you can do it similar to this:

TYPES: BEGIN OF ts_anek,
        bukrs TYPE bukrs,
        anln1 TYPE anln1,
        anln2 TYPE anln2,
        gjahr TYPE gjahr,
        lnran TYPE lnran,
        budat TYPE budat,
        tcode TYPE tcode,
       END OF ts_anek.

TYPES: BEGIN OF ts_data,
        bukrs	TYPE bukrs,
        anln1	TYPE anln1,
        anln2	TYPE anln2,
        gjahr	TYPE gjahr,
        lnran	TYPE lnran,
        afabe	TYPE afabe_d,
        zujhr	TYPE dzujhr,
        zucod	TYPE dzucod,
        budat TYPE budat,
        tcode TYPE tcode,
       END OF ts_data.

DATA: t_anek TYPE HASHED TABLE OF ts_anek WITH UNIQUE KEY bukrs anln1 anln2 gjahr lnran,
      t_data TYPE STANDARD TABLE OF ts_data,
      gs_anek TYPE ts_anek.

FIELD-SYMBOLS: <gs_data> TYPE ts_data.

START-OF-SELECTION.

  SELECT bukrs anln1 anln2 budat tcode FROM anek
      INTO TABLE t_anek WHERE tcode IN ('CJ88' , 'KO88', 'KO8G', 'AIAB', 'ABUMN', 'ANZON', 'F-92', 'ABAVN').

  SELECT bukrs anln1 anln2 gjahr afabe belnr buzei anbtr FROM anep
      INTO CORRESPONDING FIELDS OF TABLE t_data FOR ALL ENTRIES IN t_anek WHERE
      bukrs = t_anek-bukrs AND
      anln1 = t_anek-anln1 AND
      anln2 = t_anek-anln2 AND
      afabe = 01.

"Get additional data from header
  LOOP AT t_data ASSIGNING <gs_data>.
    READ TABLE t_anek INTO gs_anek WITH KEY bukrs = <gs_data>-bukrs
                                            anln1 = <gs_data>-anln1
                                            anln2 = <gs_data>-anln2
                                            gjahr = <gs_data>-gjahr
                                            lnran = <gs_data>-lnran
                               TRANSPORTING bukrs tcode.
    <gs_data>-bukrs = gs_anek-bukrs.
    <gs_data>-tcode = gs_anek-tcode.
  ENDLOOP.

Loop itself is quite fast and also reading from a hashed table with fully specified key. Try it and let me know if this is a solution for you.

Regards

Adrian