Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

How long is too long for a script to run?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How long is too long for a script to run?

    I am working on a function that optionally deletes and adds records from one table to another. Running it from the IW took 27 secs to delete & pack 87 records and then add about 120. Does this seem within range? Adding tbl.batch_begin / end only shaved off about 4 secs. I haven't tried the function from a layout where the source table is already open - can I expect that might make a difference? Even 23 secs seems too long for so few records...

    Here's the script so far:

    Code:
    'Date Created: 12-Nov-2015 08:22:26 PM
    'Last Updated: 19-Nov-2015 02:59:36 PM
    'Created By  : Robin Q
    'Updated By  : Robin Q
    FUNCTION Sched_LU AS C (vdate as d = {})
    'DESCRIPTION: Populates a temp table with m_sched to get fileno for machno & shift in production template
    	dim tbl as p
    	dim tmp as p
    	dim idx as p
    	dim i as n = 1
    	dim recs as n
    	dim list as c = ""
    	dim msg as c = ""
    	dim ordr as c = ""
    	dim tblname as c
    	dim x as c
    	dim vfile as c 
    	dim vmach as c
    	dim vshift as c
    	dim fltr as c
    	t1 = toseconds(time())
    	
    '***NOTE: could limit lookup records to current prodate only?
    '	zap_it("tmpsched")
    '	xbasic_wait_for_idle()
    	
    	GETDATE:
    	if vdate = {} then
    		vdate = ctod(popup.calendar(dtoc(date()) ) )
    		if vdate = {} then
    			'user cancelled
    			goto ENDIT
    		end if		
    	end if
    	
    	fltr = convert_expression("schedate = "+s_quote(var->vdate),"V")
    	
    	tbl = table.open("m_sched")
    	tmp = table.open("tmpsched")
    	
    	'Check that m_sched records exist with machines assigned
    	if .not. exist(cdate(vdate),"m_sched","Mach1_Blnk")
    		msg = "No Production Schedule was found for this date"+crlf()
    		msg = msg+"or machines have not been assigned to employees."+crlf(2)
    		msg = msg+"Please check the Prod Schedule for this date and correct."
    		msgbox("Add Shift Schedule: "+dtoc(vdate),msg,16)
    		tblname = "m_sched"
    		ordr = "cdate(schedate)+shift+mach1"
    		goto CLOSEIT	
    	end if
    	
    	'Prompt for user selection if schedule date already exists in tmpsched
    	if exist(vdate,"tmpsched","SCHEDATE") then
    		msg = "A schedule already exists for this date."+crlf()
    		msg = msg+"Would you like to update the existing schedule"+crlf()
    		msg = msg+"or select another date to add?"+crlf(2)
    		msg = msg+"Select YES to select another date and NO to update."
    		response = msgbox("Create Shift Schedule Lookup",msg,547)
    		if response = 2 then
    			'user cancelled
    			tblname = "tmpsched"
    			ordr = "cdate(schedate)+machno"
    			goto CLOSEIT
    		elseif response = 6 then
    			vdate = {}
    			goto GETDATE
    		else
    			'user selected NO
    			goto UPDATEIT			
    		end if
    	end if
    	
    	ADDIT:	
    '	t1 = toseconds(time())	
    	'm_sched has matching records with machines assigned
    	idx = tbl.query_create("NT",fltr,"file_no")
    	recs = idx.records_get()
    	response = msgbox("Confirm m_sched filter","records found: "+str(recs),33)
    	if response = 2 then
    		tblname = "m_sched"
    		ordr = "cdate(schedate)+shift+mach1"
    		goto CLOSEIT
    	end if
    	
    	tbl.batch_begin()
    	PleaseWait(.t.,"While the records are being added")
    	tbl.fetch_first()
    	on error goto CLOSEIT
    	while .not. tbl.fetch_eof()
    		i=1	
    		for i = 1 to 6	
    			x = alltrim(str(i))
    			vfile = tbl.file_no
    			vshift = tbl.shift
    			vmach = EVAL("tbl.mach"+x)
    			if vmach <> "" then
    				tmp.enter_begin()
    					tmp.schedate = vdate
    					tmp.machno = vmach
    					tmp.shift = vshift
    					tmp.file_no = vfile
    				tmp.enter_end(.t.)			
    			end if			
    		next i
    		tbl.fetch_next()
    	end while
    	tbl.batch_end()
    	PleaseWait()
    '	t2 = toseconds(time())
    	tblname = "tmpsched"
    	ordr = "cdate(schedate)+machno"
    	goto CLOSEIT
    	
    	UPDATEIT:	
    	'delete the tmpsched records then re add - easier than changing!
    	tmp.delete_range(fltr)
    	recs = tmp.records_deleted()
    	xbasic_wait_for_idle(.15)
    	tmp.pack()
    	xbasic_wait_for_idle(.15)
    	msgbox("Deleted Records","Removed deleted records: "+str(recs),0)
    	goto ADDIT
    	
    	CLOSEIT:
    	tbl.close()
    	tmp.close()
    	response = msgbox("View Records","Would you like to see the table?",292)
    	if response = 7 then
    		goto ENDIT
    	else				
    		A5_OPEN_DEFAULT_BROWSE(tblname,"",ordr) 
    	end if
    	
    	ENDIT: 
    	t2 = toseconds(time())
    	Tln("Sched_LU Seconds elapsed - ADDIT",str(t2-t1))
    	Sched_LU=dtoc(vdate)	    
    	end
    END FUNCTION
    tbl_data.jpg
    Last edited by MoGrace; 11-19-2015, 10:13 PM.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

    #2
    Re: How long is too long for a script to run?

    Robin,

    My first thought would be to move some of the code above the for/next loop. vfile and vshift only need to be assigned once per record.
    Alternatively, just apply the input values directly to the temp table - tmp.shift = tbl.shift and tmp.file_no = tbl.file_no.

    Might also be worth experimenting by removing the table pack to see if this is slowing things down.

    Comment


      #3
      Re: How long is too long for a script to run?

      Hi Jon,
      That's a good point about not mapping the fields to variables. I was initially going to use enter_record() instead of enter_begin(). Also I can pack the table later, it just seemed good to do it with the delete. I'll try it and let you know.

      Edit:
      I added the batch_begin() back, tried without the pack() then decided to keep it but removed the 2nd xbasic_wait_for_idle() and mapped the fields to fields and got the script down to 14 secs - which seems tolerable. If I remove 2 of the confirmation prompts to the trace window instead, it should be even better.
      Thanks!

      Addendum: Changing the 2 confirmation prompts brought the time down to 8 secs for deleting and re-adding 87 records. I probably don't even need the PleaseWait() now!
      Last edited by MoGrace; 11-20-2015, 01:13 PM.
      Robin

      Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

      Comment


        #4
        Re: How long is too long for a script to run?

        Can you make a set that defines the relationship and then loop through the set?
        Al Buchholz
        Bookwood Systems, LTD
        Weekly QReportBuilder Webinars Thursday 1 pm CST

        Occam's Razor - KISS
        Normalize till it hurts - De-normalize till it works.
        Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
        When we triage a problem it is much easier to read sample systems than to read a mind.
        "Make it as simple as possible, but not simpler."
        Albert Einstein

        http://www.iadn.com/images/media/iadn_member.png

        Comment


          #5
          Re: How long is too long for a script to run?

          Hi Al,
          I don't understand how a set would help if the records in the tmp table don't exist yet.
          Robin

          Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

          Comment


            #6
            Re: How long is too long for a script to run?

            Originally posted by MoGrace View Post
            Hi Al,
            I don't understand how a set would help if the records in the tmp table don't exist yet.
            It's difficult to follow the process. A lot of looping going on.

            I try to minimize looping of possible.

            Also I use operations when I can to get better performance than xbasic read writes.

            Operations use C++ to run and are much faster if they can do what you want.
            Al Buchholz
            Bookwood Systems, LTD
            Weekly QReportBuilder Webinars Thursday 1 pm CST

            Occam's Razor - KISS
            Normalize till it hurts - De-normalize till it works.
            Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
            When we triage a problem it is much easier to read sample systems than to read a mind.
            "Make it as simple as possible, but not simpler."
            Albert Einstein

            http://www.iadn.com/images/media/iadn_member.png

            Comment


              #7
              Re: How long is too long for a script to run?

              Using operations on a 950,000 record table
              can delete 200 records and add 400 more from another table in just a very few seconds like Al alluded to.

              Alpha is built on c++ and some of their stuff is built using c++ to make some things just plain faster by many times.
              Dave Mason
              [email protected]
              Skype is dave.mason46

              Comment


                #8
                Re: How long is too long for a script to run?

                Re using an operation: would it matter timewise if I add the xbasic for the op to the script or run as a saved op? For the xbasic - would my variables have to be dimmed as shared instead of local?
                Robin

                Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                Comment


                  #9
                  Re: How long is too long for a script to run?

                  Originally posted by MoGrace View Post
                  Re using an operation: would it matter timewise if I add the xbasic for the op to the script or run as a saved op? For the xbasic - would my variables have to be dimmed as shared instead of local?
                  Probably more flexible to put the Xbasic in the script. Local or shared should be ok with local.
                  Al Buchholz
                  Bookwood Systems, LTD
                  Weekly QReportBuilder Webinars Thursday 1 pm CST

                  Occam's Razor - KISS
                  Normalize till it hurts - De-normalize till it works.
                  Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                  When we triage a problem it is much easier to read sample systems than to read a mind.
                  "Make it as simple as possible, but not simpler."
                  Albert Einstein

                  http://www.iadn.com/images/media/iadn_member.png

                  Comment


                    #10
                    Re: How long is too long for a script to run?

                    Robin,
                    I create a lot of operations and once they are like I need them, I view the xbasic for each to be used in a udf. I generally use a script to run the udf's in the order desired. Sometimes the script does other things as well.
                    Hope that helps you. Appending 68 blank tables with up to 950,000 records each from tables on a server takes about 1.07 minutes and that includes a number of other operations at the same time.
                    Dave Mason
                    [email protected]
                    Skype is dave.mason46

                    Comment


                      #11
                      Re: How long is too long for a script to run?

                      Writing the append in Xbasic does work better when variables are involved and it runs very fast now.

                      Now all I need to do to make this routine perfect is anticipate the user errors that might occur. Mostly from entering the wrong data from either selecting the wrong date in the beginning or entering a wrong schedule altogether. Or perhaps not running the routine in the right order. This is no doubt the hardest part, so I am trying to break my own script to see what might go wrong...and figure out a recovery.

                      My goal is to make the data entry as automatic as possible since the data is gathered from manual records that themselves may be wrong. The user has to be able to find those errors easily and make corrections else the analytical reports will be useless.

                      However 'easy' to me is probably not so easy to my user...whose main 'computer' experience is from using a tablet or a smartphone!
                      Last edited by MoGrace; 11-21-2015, 04:09 PM.
                      Robin

                      Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                      Comment

                      Working...
                      X