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 do you get last value from Child table?

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

    how do you get last value from Child table?

    Hi All,

    I realized that the Tablemax() did not work with Logical field type.
    The result of tablemax() is "F", no matter what is the field value because it will get the "Largest Value"

    So I wrote a script
    Code:
    'FUNCTION Insurlog_Isprinted AS L (vProjectId AS C )
    dim tbl as p
    tbl = table.open("insur_logs",FILE_RO_SHARED)
    tbl.index_primary_put("project_id")
    rcd = tbl.fetch_find(vProjectId)
    if rcd>0 then
    	tbl.order("log_date")
    	'tbl.fetch_first()     [COLOR="#0000FF"]<-- Deleted because with "While ... end while" loop, it is the endless[/COLOR]
    	'while .not. tbl.fetch_eof() 
    		tbl.fetch_last()  [COLOR="#FF0000"]<-- I cannot get the last record[/COLOR]
    		vIsprint = tbl.Isprinted
    	   ' Insurlog_Isprinted= tbl.Isprinted
    	   
    	'end while
    end if
    tbl.close()	
    'END FUNCTION
    But I still not able to get the last record by "date" of value.

    How do you get the last value from child table?

    #2
    Re: how do you get last value from Child table?

    I tried this with my own table:

    Code:
    FUNCTION chk_print AS L (vfileno AS C )
        dim tbl as p
        dim chkfileno as c = ""
        dim vflag as c = ""
        tbl = table.open("employee")
        tbl.order("fileno")
        rec = tbl.fetch_find(vfileno)    
        if rec < 0 then
            tbl.order("hiredate")
            'tbl.order("",".t.") 'use to get last actual record entered
         tbl.fetch_last()     
        end if
        chkfileno = tbl.fileno
        vflag = tbl.printflag
        ui_msg_box("Search For: "+vfileno,"Found: "+chkfileno+crlf()+"Printflag: "+vflag,0)
        tbl.close()
        chk_print = .t.
    END FUNCTION
    chk_print("1066") returned the fileno and printflag for that record. When I tried a number I know doesn't exist it returned the fileno of the most recent employee hired and its printflag value. My printflag field is a character field however.

    In your script if the projectid is found then you want to switch the order of the table to the last log date and see if it was printed - is that correct? My guess is there is more than one log date for a projectid? Perhaps you should filter the table - else how will you know the last log date belongs to that same projectid?
    Last edited by MoGrace; 10-21-2011, 03:57 PM.
    Robin

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

    Comment


      #3
      Re: how do you get last value from Child table?

      Robin,

      I think I have to change the Field type to Character
      Thank you

      Comment


        #4
        Re: how do you get last value from Child table?

        Robin,

        After I deleted the <tbl>.order() function, the found record moved to last record. I think the <tbl>.order ignored the found records and ordered all of table records, not only found records.

        So after I deleted the <tbl>.order() after "Filter" the records from my scripts, I can move and save at the last record of tables with Query method but If I use the "Fetch" method, I can not save it to last record of tables.

        Can you tell me what is wrong with my "Fetch" scripts?

        LastRcd.zip

        Comment


          #5
          Re: how do you get last value from Child table?

          Given your sample what do you think is "last record of tables."

          I see it as project_id 08-1708, because the table is ordered by project_id and that is the last (highest) project_id.

          I think the <tbl>.order ignored the found records and ordered all of table records, not only found records.
          Correct, tbl.order() sets the order of the records in a table. It doesn't care what other activities might have preceeded it.

          Can you tell me what is wrong with my "Fetch" scripts?
          You seem to be under the impression that tbl.fetch_find() somehow limits the available selection of records. Not so.
          The <TBL>.FETCH_FIND() method retrieves the first record in the table or set referenced by <TBL> with a primary index key equal to the Matching_Expression parameter.
          If a matching record is found the record pointer moves to that record. That is all. You are still free to move among all other records.
          Last edited by Stan Mathews; 10-31-2011, 01:39 PM.
          There can be only one.

          Comment


            #6
            Re: how do you get last value from Child table?

            Stan,
            That is what was confusing to me as well. Is it the last project id, the last entry date or the last record entered (regardless of project id or entry date) that is to be fetched? A little pseudo code here first would help.
            Robin

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

            Comment


              #7
              Re: how do you get last value from Child table?

              The query version of the code in the example database queries for each project_id in turn and changes field values in the last record for each project_id. The find version seems to be an attempt to do the same.
              There can be only one.

              Comment


                #8
                Re: how do you get last value from Child table?

                I have been trying to get the last record of a child table to be shown on a form and on a report.
                On the form I used a calculated value like: Last_Invoice = Last(Invoice_dlt->Invoice_nbr,GRP->Grand)
                On the report I used a calculated value like: Last_Invoice = maximum(Invoice_dlt->Invoice_Nr,GRP->Grand)

                Hope this helps.
                Jo Hulsen
                Dommel Valley Solutions
                The Netherlands

                Comment


                  #9
                  Re: how do you get last value from Child table?

                  Are the form and report based on a set or a table? Why do you use one function for the form and another for the report? (Using the AlphaSports invoice form both expressions return the same result.)
                  There can be only one.

                  Comment


                    #10
                    Re: how do you get last value from Child table?

                    Jo,

                    Thank you for your comment but We are talking about the TABLE level, not a FORM level.

                    If the DATE value is an important factor, and what ever reason the table's record number is not last record of project_id, then How do you sort / order the table records by date after found the records by project_id?

                    My "Query" method get the last record of Table's Record number after found the records by Project_id. However, the "Fetch" method does not have the same result.

                    Comment


                      #11
                      Re: how do you get last value from Child table?

                      Stan,

                      They are based on a set.
                      As to why 2 functions; I started with the form and moved on to the report. I couldn't get the Last() function to work in the report, so moved on to the Maximum() function. I have checked again, and Yes you are correct. I must have made a mistake.

                      Thanks,
                      Jo Hulsen
                      Dommel Valley Solutions
                      The Netherlands

                      Comment


                        #12
                        Re: how do you get last value from Child table?

                        How do you sort / order the table records by date after found the records by project_id?
                        John,

                        Finding is not the same as querying. The .fetch_find() method locates and moves the record pointer to the first record that matches the key value supplied. It does not restrict processing to records that match the key value. After a successful .fetch_find() using .fetch_last() moves the record pointer to the last record in the table as it is currently sorted without regard to key value.

                        Think of lining up a group of people by last name.
                        .fetch_find() allows you to quickly locate the first person in line whose last name you call.
                        .fetch_last() lets you move to the end of the line, that's all.
                        There can be only one.

                        Comment


                          #13
                          Re: how do you get last value from Child table?

                          Stan,

                          Thank you for your help. I think the <tbl>.fetch_find() with "For .. next" functions are not suitable for this case. Because, I only get one result, It should be two results.

                          I think A5 does not support the Sort or Order after found the records regardless "query" or "fetch". Am I right?

                          Comment


                            #14
                            Re: how do you get last value from Child table?

                            John,

                            There is no reason to reorder the records after the query, do it as part of the query.

                            Instead of

                            query.order="project_id"

                            use

                            query.order="project_id +cdate(log_date)"

                            then you can .fetch_last() and be on the last dated record for the project_id each time the query runs.
                            There can be only one.

                            Comment


                              #15
                              Re: how do you get last value from Child table?

                              Stan,

                              Thank you, Always...

                              query.order="project_id +cdate(log_date)"
                              which I never think about it.

                              Comment

                              Working...
                              X