Application Development and Automation 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: 

Updating a ZTable

Former Member
0 Kudos
362

Hi All,

I have to update a table with 1 million + entries. My selection criteria matches 740,000 records.

I have to upload a text file in the background and based on the entries in the text file, I have to update a single column in all the matching records.I have 2 soulutions for this:

up_tab is the uploaded text file.

1. select the records into an internal table itab.

    loop at itab.

         update zabc set col1 = up_itab-col1 where....

   endloop.

2. Select all records into internal table itab.

    loop at itab.

        itab-col1 = up_itab-col1.

        modify itab.

    endloop.

    update zabc from itab.

In this scenario, which is the best and efficient way of doing this? And also please explain me in detail how to save the file on application server and use that in my program.

Thanks,

Anitha

2 REPLIES 2

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos
325

The update from syntax should be the more efficent because it works as a mass update.  That means that this single line of ABAP code will update your 740,000 records. That's a big SQL statement. I'm assuming the ABAP Optimizer has some controls to help break this up internally, but that still means that all rows must be updated before you can commit your work. This has a tendency to make me nervous. I have also seen very large updates cause resource problems and Snap-Shot Too Old Dumps (Oracle Database).

Being a control freak, I tend to give up a little bit of performance and control my updates/commits myself.  You still don't want to commit after every record because that will really slow you down. If you can, keep a counter and commit every 1000 or so records. Perhaps on an update this large you might only commit every 5,000 or 10,000. I think the difference in performance between the two examples will be a matter of a few minutes not hours.

Now as far as saving the file on the application server: I'm not sure what you are looking for there.  If you want to read a file that is already on the application server, look at the ABAP Keywords OPEN DATASET, TRANSFER, and READ DATASET in the on-line help. If you want to upload the file from the Presentation Server and store it on the application server for later processing, look at the class method CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD or the function module GUI_UPLOAD. You will then have the data in memory. From there you can use the OPEN DATASET and TRANSFER commands to write it out to the application server's file system.

0 Kudos
325

Hi Thomas,

You reply makes perfect sense. Could you point me to SAP help or documentation that goes over the difference between the two approaches to modify?

Thanks

Andre