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

collecting data from a child table in a set

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

    collecting data from a child table in a set

    Payroll report takes forever to calculate. There has to be a better way. I have 40 calculated fields that use the following custom function.

    Code:
    'Date Created: 13-May-2009 04:39:00 PM
    'Last Updated: 13-May-2009 07:31:44 PM
    'Created By  : Lee Goldberg
    'Updated By  : Lee Goldberg
    FUNCTION get_hrs AS N (vDateWrk AS D, vEmp AS C, vDOW AS C, vType AS C, vOT as l)
    	DIM tblwk as p 'worksheet
    	DIM tblwse as p 'ws_employee
    	DIM tblah as p 'additional hrs
    	DIM qrywk as p
    	DIM qryws as p
    	DIM qryah as p
    	DIM vRecCount as n
    	DIM vRecEmp as n
    	DIM vWKNum as n
    	DIM vEndDate as d	
    	
    	vDateWrk = vDateWrk + val(vDOW)
    	get_hrs = 0 
    	
    	
    	if vtype = "Reg" .or. vtype = "Units" then
    		tblwse = table.open("tblws_emp")
    		tblwk = table.open("tblwksht")
    			if vType = "Units" then 
    				qFilter = "date = ctod('"+vDateWrk+"') .and. val(left('"+tblwk.Bill_type+"',1)) = 3"
    			else if vOT = .t. .and. vType = "Reg" then
    				qFilter = "date = ctod('"+vDateWrk+"') .and. OT = .t. .and. val(left('"+tblwk.Bill_type+"',1)) < 2"
    			else if vOT = .f. .and. vType = "Reg" then
    				qFilter = "date = ctod('"+vDateWrk+"') .and. OT = .f. .and. val(left('"+tblwk.Bill_type+"',1)) < 2"
    			end if
    			
    			qrywk = tblwk.query_create("",qFilter,"")
    			
    			vRecCount = tblwk.records_get()
    			
    			if vRecCount > 0
    				tblwk.fetch_first()
    				
    				while .not. tblwk.fetch_eof()
    		
    					vWKNum = tblwk.Wksht_num
    					
    					qryFilter = "emp_code = alltrim('"+vEmp+"') .and. wksht_num = val('"+vWknum+"')"   			
    					qryws = tblwse.query_create("",qryFilter,"")
    					vRecEmp = tblwse.records_get()
    				
    					if vRecEmp > 0 then
    						tblwse.fetch_first()
    						
    						while .not. tblwse.fetch_eof()
    							if vType = "reg" then
    								get_hrs = get_hrs + tblwse.Qty
    							else if vType = "Units"
    								get_hrs = get_hrs + (tblwse.TOTAL_UNITS_PAID * (tblwse.Percentage / 100))
    							end if
    							tblwse.fetch_next()
    						end while	    
    				
    					end if
    				tblwk.fetch_next()	
    				end while		
    			end if
    			
    		tblwk.close()
    		tblwse.close()
    	else 
    		'vDateWrk = vDateWrk + val(vDOW)
    		vEndDate = vDateWrk + 6
    		'ui_msg_box("",ctod(vDateWrk) + "   " + ctod(vEndDate))
    		tblah = table.open("tbladditional_hrs_ln")
    			qFilter = "date_hrs >= ctod('"+vDateWrk+"') .and. date_hrs <= ctod('"+vEndDate+"') .and. alltrim('"+vtype+"')$type_work .and. '"+vEmp+"'$emp_code"
    			qryah = tblah.query_create("",qFilter,"")
    			vRecCount = tblah.records_get()
    			if vRecCount > 0 then
    				tblah.fetch_first()
    				while .not. tblah.fetch_eof()
    					get_hrs = get_hrs + tblah.Hrs
    					tblah.fetch_next()
    				end while
    			end if
    		tblah.close()
    	end if
    END FUNCTION
    I have the following set.
    Code:
    tblwksht
         |----------->(1:M) tblws_emp

    In order to run payroll I must first filter the tblwksht table by date. So I now have all the worksheets that were created for that day. The script runs through every worksheet and then filters the tblws_emp table by worksheet number and the desired employee. It totals the hours for that employee and then moves on to the next worksheet for that day.

    This happens 40 times over. I know it is slow because it is a detailed task but how can I collect the data more efficiently to reduce the load time on this report?
    Lee Goldberg
    Software Development and Sales
    Shore Consultants Ltd.
    [email protected]
    www.shorecon.com

    #2
    Re: collecting data from a child table in a set

    Lee,
    Why don't you have a payroll summary table that get's posted to on a one-by-one basis as the employee worksheet record is created/edited? Then have payroll run from the summary table instead of generating a summary at the time of payroll?
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

    Comment


      #3
      Re: collecting data from a child table in a set

      I thought about this approach but doesn't this defy the laws of database normalization since the data is already stored in the database. I was always taught to never duplicate data. Was I wrong to enforce this so rigidly?
      Lee Goldberg
      Software Development and Sales
      Shore Consultants Ltd.
      [email protected]
      www.shorecon.com

      Comment


        #4
        Re: collecting data from a child table in a set

        "Never" is a long time.

        There are good reasons to occasionally "break the rules". This may be one of them.

        If you don't want to keep running totals while the worksheets are being created, here's another idea for you:

        Your code spends a lot of time opening, querying, and closing tables. You can speed this up if you rearrange things.

        1) abandon the use of a function. Instead think in terms of a single script that processes all the employees and worksheets in one pass, storing the calculated results in a temporary table. This table would hold employee id's and computed results for that employee.

        2) modify the set supporting the report layout to link the temp table one to one using the employee id

        3) add the computed result from the temp table wherever needed in the report layout

        4) to populate the temp table reverse the order of your two table set and use a one to one link. Filter the set for the relevant worksheets, while sorting them by employee id. Your script would step through the filtered records one time, accumulating totals for each employee. When the script hits a record that has a different employee id, it stops and adds a new record to the temp table... the new record contains the employee id and the computed result for the employee for whom the accumulations have been occurring. Start the accumulations again for the next employee and loop through them until the employee id continues. Keep going until you hit eof

        5) the new sequence would be something like: (a) zap the temp table (b) run the script to populate the temp table (c) run the report.

        Comment

        Working...
        X