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

Find by Index Method

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

  • Find by Index Method

    Hi,

    I am trying to find the "StateTaxId" from "StateTax" table with current Employee record condition which state name and date.

    This is an error coding.
    Code:
    dim tEmp as p
    dim iEmp as p
    dim vRecEmp as n
    dim vEmpDepend as n
    dim vEmpState as c
    
        tEmp=table.open("emp")
        iEmp = tEmp.index_primary_put("Emp_Id_U")
        vRecEmp = tEmp.fetch_find(vEmpId)
        if (vRecEmp > 0) then
    	    vEmpDepend = tEmp.Dependency   'Replaced with lookup("Emp","Emp_id="+quote(Payroll_days->emp_id),"Dependency")
    	    vEmpState =  tEmp.Taxfile_state
    	   
       
    'Read the State tax table which matched with above Emp condition and find the State_id 
    		dim tState as p
    		dim iState as p
    		dim vStTaxId as c
    		dim vRecState as n
    		dim vFilterSt as c
    
            tState=table.open("tax_state")
            [COLOR="Red"]vFilterSt ="state_name= var->vEmpState .and. cyear(Start_date)=cyear(vPaydate)"
            iState = tState.index_primary_put()
            tState.fetch_find(vFilterSt) [/COLOR]
              'After find the record, do something
    else
    end if
    My Questions are
    (1) Can I write as like above(Red color lines) ?
    (2) If I cannot use those, Should I use the "<tbl>.index_create_begin() with <tbl>.index_create_end() scripts in order to use Index find method?
    (3) Is Query find method better than Index find method in this case?

  • #2
    Re: Find by Index Method

    Code:
    vFilterSt ="state_name= "+quote(var->vEmpState)+" .and. cyear(Start_date)="+cyear(vPaydate)
    Example substitution...

    Code:
    'sample variables
    vEmpState = "MA"
    vPaydate = {04/03/2010}
    
    ? "state_name= var->vEmpState .and. cyear(Start_date)=cyear(vPaydate)"
    = "state_name= var->vEmpState .and. cyear(Start_date)=cyear(vPaydate)"
    
    ? "state_name= "+quote(var->vEmpState)+" .and. cyear(Start_date)="+cyear(vPaydate)
    = state_name= "MA" .and. cyear(Start_date)=2010
    Last edited by Stan Mathews; 04-07-2010, 10:49 AM.
    There can be only one.

    Comment


    • #3
      Re: Find by Index Method

      Good morning Stan,

      Thank you for your advise.

      I have an error message as "Conflicting expression data types"

      Is it because the "vFilterSt" type?
      I currently used a "C" type for this filed.

      Comment


      • #4
        Re: Find by Index Method

        Nope, I wasn't paying attention to the cyear() being character.

        Code:
        vFilterSt ="state_name= "+quote(var->vEmpState)+" .and. cyear(Start_date)="+[COLOR="Red"]quote([/COLOR]cyear(vPaydate)[COLOR="red"])[/COLOR]
        There can be only one.

        Comment


        • #5
          Re: Find by Index Method

          Stan,

          After added the Quote() or changed s_quote(), I still got an Error message which "Conflicting ...data types"

          Comment


          • #6
            Re: Find by Index Method

            I completely missed the point.

            You can't use .fetch_find() unless you have an index in effect on state and cyear(startdate). If you did have such an index you don't pass it a filter expression, you pass it values.

            You probably should use

            Code:
            tState=table.open("tax_state")
            vFilterSt ="state_name= "+quote(var->vEmpState)+" .and. cyear(Start_date)="+quote(cyear(vPaydate))"
            tState.query_create("N",vFilterSt)
            'After querying for the record, do something
            There can be only one.

            Comment


            • #7
              Re: Find by Index Method

              John,

              Code:
                 vFilterSt ="state_name= var->vEmpState .and. cyear(Start_date)=cyear(vPaydate)"
                      iState = tState.index_primary_put()
                      tState.fetch_find(vFilterSt)
              the "index_primary_put()" needs to have an index tag name in the parens;
              ie:
              Code:
                 
                      iState = tState.index_primary_put("State_name")
              where state_name is a defined index for the state tax table.

              Your fetch_find would then be
              Code:
                 vFilterSt ="var->vEmpState +cyear(vPaydate)"
                              tState.fetch_find(vFilterSt)
              Last edited by Tom Henkel; 04-07-2010, 01:31 PM. Reason: Ignore this one, Hit "enter" erroneously...

              Comment


              • #8
                Re: Find by Index Method

                John,

                Code:
                   vFilterSt ="state_name= var->vEmpState .and. cyear(Start_date)=cyear(vPaydate)"
                        iState = tState.index_primary_put()
                        tState.fetch_find(vFilterSt)
                the "index_primary_put()" needs to have an index tag name in the parens otherwise it is in record number order.
                ie:
                Code:
                   
                        iState = tState.index_primary_put("State_name")
                where state_name is a defined index for the state tax table
                ordered by state_name+cyear(Start_date)

                Your fetch_find would then be
                Code:
                                vFilterSt =var->vEmpState +cyear(vPaydate)
                                tState.fetch_find(vFilterSt)
                Tom

                Comment


                • #9
                  Re: Find by Index Method

                  Good morning

                  Tom and Stan, Thank you for your help.
                  I understood the Filter Coding rule now. I had the trouble understanding the index and query filter.

                  This is an interactive for test
                  Code:
                  dim fdr as c
                  vfdrid ="federal"
                  vfdrTaxable =982.45
                  
                  fdr = "taxfdr_id= "+quote(vFdrId)+" .and. min_income<="+s_quote(vFdrTaxable)+".AND. max_income>="+s_quote(vFdrTaxable)
                  ?fdr
                  = taxfdr_id= "federal" .and. min_income<=982.45.AND. max_income>=982.45
                  This code is fine to me so I applied on my script.
                  Code:
                  'Lookup Federal Bracket tax table 
                  dim tFdrBrk as p
                  dim vFilterFdrbrk as c
                  dim qryFdrbrk as p
                  dim vRecFdrbrk as n
                  dim vFdrBrkid as c
                  Dim vFdrBrkRate as n
                  Dim vFdrBrkPls as n
                  dim vFdrBrkExc as n          	  
                          tFdrBrk = table.open("tax_fdr_brackets")
                          vFilterFdrbrk = "taxfdr_id= "+quote(vFdrId)+" .and. min_income<="+s_quote(vFdrTaxable)+".AND. max_income>="+s_quote(vFdrTaxable)
                          [COLOR="Red"]qryFdrbrk = tFdrBrk.query_create("n",vFilterFdrbrk)[/COLOR]
                          vRecFdrBrk =tFdrBrk.records_get()
                  but I ran the debug it, I got an error message as "No such filed". What is wrong on this red color line script?

                  Comment


                  • #10
                    Re: Find by Index Method

                    I don't see where vFdrTaxable is dimmed.

                    Also best practice is to specify var-> when using them in filters. That way there is no ambiguity about what is a field name vs a variable name.



                    Code:
                    vFilterFdrbrk = "taxfdr_id= "+quote([COLOR="Red"]var->[/COLOR]vFdrId)+" .and. min_income<="+s_quote([COLOR="red"]var->[/COLOR]vFdrTaxable)+".AND. max_income>="+s_quote([COLOR="red"]var->[/COLOR]vFdrTaxable)
                    There can be only one.

                    Comment


                    • #11
                      Re: Find by Index Method

                      Stan,

                      Here, I called "vFdrTaxable" above the "Fdr_brk" script.
                      Is "if .. else .. end if" clause broken the link(??)?

                      Code:
                      'Federal TaxTable lookup  
                      dim tFdr as p
                      dim vFilterFdr as c
                      dim qryFdr as p
                      dim vRecFdr as n
                       
                      Dim vFdrId as c
                      dim vFdrallow as n    
                      dim vFdrDeduct as n    
                      Dim vSstRate as n
                      dim vMdcRate as n
                      [COLOR="RoyalBlue"]dim vFdrTaxable as n[/COLOR] [COLOR="Red"]<--- Here[/COLOR]
                       
                              tFdr = table.open("tax_fdr")
                              vFilterFdr = "File_status ="+quote(vEmpStatus)+" .and. File_period="+quote(vEmpFile)+".and.  cyear(Start_date)="+quote(cyear(vPaydate))
                              qryFdr = tfdr.query_create("n",vFilterFdr)
                              vRecFdr =tFdr.records_get()
                                 If (vRecFdr > 0) then
                                 	  vFdrId = tFdr.Txfdr_id
                                 	  vFdrallow = tFdr.Allowance
                                 	  vSstRate = tFdr.Social_tax
                                 	  vMdcRate = tFdr.Medicare_tax
                                 	  'calculate the Allawance Deduct and make a Taxable Amout
                                 	       vFdrDeduct = round(vEmpDepend * vFdrallow,2)
                                 	       [COLOR="RoyalBlue"]vFdrTaxable = (vEmpEarn - vFdrDeduct)[/COLOR]
                                  else
                                  end if  
                                
                      'Lookup Federal Bracket tax table 
                      dim tFdrBrk as p
                      dim vFilterFdrbrk as c
                      dim qryFdrbrk as p
                      dim vRecFdrbrk as n
                      dim vFdrBrkid as c
                      Dim vFdrBrkRate as n
                      Dim vFdrBrkPls as n
                      dim vFdrBrkExc as n          	  
                              tFdrBrk = table.open("tax_fdr_brackets")
                              vFilterFdrbrk = "taxfdr_id= "+quote(var->vFdrId)+" .and. min_income<="+s_quote(var->vFdrTaxable)+".AND. max_income>="+s_quote(var->vFdrTaxable)
                              qryFdrbrk = tFdrBrk.query_create("n",vFilterFdrbrk)
                              vRecFdrBrk =tFdrBrk.records_get()
                              if (vRecFdrbrk > 0 ) then
                              	vFdrBrkId = tFdrBrk.Txfdrbracket_id
                      		    vFdrBrkRate = tFdrBrk.Withhold_rate
                      		    vFdrBrkPls = tFdrBrk.Plus_tax
                      		    vFdrBrkExc = tFdrBrk.Wage_excess 
                      		
                      			'Calculate the Federal Tax Rate 
                      			dim vFicaAmt as n
                      			dim vFwhtAmt as n 
                      			dim vFwhtBase as n
                      			    vFWHTBase=round(vFdrTaxable - vFdrBrkExc,2)
                      			    vFwhtAmt= round((vFwhtbase * (vFdrBrkRate/100)+ vFdrBrkPls),2)
                      			    vFicaAmt= round(vEmpEarn*((vSstRate + vMdcRate)/100),2)  
                      	    else
                      		end if 
                      		ui_msg_box("Result for FWH" +vEmpId,"FWH tax is  "+vFwhtAmt)
                      		ui_msg_box("Result for FICA" +vEmpId,"FICA tax is "+vFicaAmt)

                      Comment


                      • #12
                        Re: Find by Index Method

                        It could cause a problem since the vFdrTaxable as n will default to zero if vRecFdr = 0.

                        Did you make the suggested change using var->?
                        There can be only one.

                        Comment


                        • #13
                          Re: Find by Index Method

                          Yes, I tried the "var->" , deleted "if..else..end" and relocated other dim clauses, Stan.

                          I attached the error and tax_Fdr_brackets table screen shots for additional info.

                          Comment


                          • #14
                            Re: Find by Index Method

                            Code:
                            vFilterFdrbrk = "taxfdr_id= "+quote(var->vFdrId)+" .....
                            should be

                            Code:
                            vFilterFdrbrk = "txfdr_id= "+quote(var->vFdrId)+" ......
                            The error was telling you there is no

                            taxfdr_id

                            field in tax_fdr_brackets.
                            There can be only one.

                            Comment


                            • #15
                              Re: Find by Index Method

                              Stan,

                              Thank you for your point.
                              It works well now.

                              Comment

                              Working...
                              X