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: 

Synchronizing Two Custom Z Tables Using Abap Program

Former Member
0 Kudos

Hi,

    My requirement is Synchronizing two custom z tables using abap program me.

I have vendors in two tables, i have to select the common vendors from first which are existing in second  table also.

In first table each vendor can have more than one supplier types in one field only. In second table these supplier types are divided into

different fields.

     My requirement is I have to check supplier types in first table and i have to pass X to corresponding supplier types in second table vendor.

I have to pass X value for each depending in Second table depending upon supplier type in first table.

. How to do it can any one suggest with code.

Thanks in Advance,

Vivek

<subject edited by moderator>

Message was edited by: Manish Kumar

4 REPLIES 4

aarif_baig
Active Participant
0 Kudos

Hi Vivek,

              So you have vendors in both tables, Is vendor a key field in 2nd table if yes.

Then you can pass vendor from 1st table to 2nd table and fetch data, once you have the data from the 2nd table you need to use do varying it will help you in reading all the columns as you mentioned the value is sitting in different columns just see the sample code below, check that supplier type is not initial and read the value of supplier type

check below link for reference

http://help.sap.com/abapdocu_70/en/ABAPDO_VARYING.htm


hope this helps.

paul_bakker2
Active Contributor
0 Kudos

Hi,

  If I have understood your requirements (which was not easy, because they are not clearly written), you want to loop at table A and update the matching entries in table B, based on the data in table A.

loop at lt_a into ls_a.

   loop at lt_b assigning <fs_b>

      where key = ls_a-key

    [ update <fs_b> based on the values in ls_a ]

  endloop.

endloop.

Is this correct? I can't see anything complicated there - do you have a specific question?

cheers

Paul


VenkatRamesh_V
Active Contributor
0 Kudos

Hi Vivek,

Hope it helpful.

Check the both tables primary keys.

declare two internal tables for first and second tables.

Use parallel cursor to append the final internal table In case of performance  Issue.

Regards,

Venkat.

former_member306787
Active Participant
0 Kudos

Hi,

Imho, you need to get (meaning, extract into separate fields) the different supplier types from Table1 first. Your key for Table1 is the vendor no, which is also the key in Table2 (or the key for Table2 is Vendor no & Type).

For better performance, better select multiple/all required entries from Table1 instead of doing a select endselect.

Depending on the format of the vendortypes in Table1, put them in a new itab (for our purpose named Table1New where vendor no & type are the only 2 fields. For example, if the type length is fixed to 2 chars, or divided by space,... use your coding accordingly.

Next step is to select all vendor no's in Table2 which you have selected in Table1. If in Table2, the vendor no is the only key (and the all vendor types are filled in a single record), then loop check the vendor types from Table1New against the types in Table2.

If the key of Table2 is vendor no & vendor type, then do a read table for the key.

The logic in pseudo-code:

Select from Table1 into table. If you'd like to limit the selection size, add package size statement.

     extract the vendor types in to itab Table1New.

    

     Select the vendor & types from Table2 by using the for all entries option (better performance).

     loop at Table1New

          check in Table2:

               if the unique key is vendor no: check all fields for the vendor type from Table1New

               if the unique key combo is vendor no & type: check by using a read table.

          If not found => add entry to Table2

     endloop.

endselect Table1 (when using package size)

I guess the most difficult step is to extract the types from Table1 into separate fields, all the rest seems straight forward. Please keep in mind the itab type definitions for a better performance.

Good luck!

Best regards,

Zhou