ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Code to delete file contents in RPGLE?

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

  • #16
    Re: Code to delete file contents in RPGLE?

    Subfiles aren't keyed files - you can use SETLL to get to a record by specifying a record # - but not by key. You will have to keep track of record #'s separately or cycle through the record until you find the record you're looking for.

    Comment


    • #17
      Re: Code to delete file contents in RPGLE?

      but I wanna delete also from physical file. Subfile is just editor.
      So how it will look like in this case?

      Comment


      • #18
        Re: Code to delete file contents in RPGLE?

        If the file isn't keyed or no LF you could either create a Logical File (LF) with that key that matches the key value(s) specified in the subfile - or use embedded SQL to delete the record. In RPG the easiest way to delete a record is to CHAIN to the record and then DELETE it.

        Comment


        • #19
          Re: Code to delete file contents in RPGLE?

          Keep in mind that you can put keys in the subfile as hidden fields - they do not necessarily have to be the basis the user has to mark the records to be deleted. You would just use the key values stored in that subfile record.

          Comment


          • #20
            Re: Code to delete file contents in RPGLE?

            Originally posted by michal2442 View Post
            but I wanna delete also from physical file.
            Are you asking how to delete a line from a subfile while also deleting a related row from a PF in the same program cycle? It's not too hard effectively to do both in the same cycle. But if it's what you are asking, it's possibly better not to remove the subfile row but to change its color attribute or similar.

            Please clarify what you are asking.
            Tom

            There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

            Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

            Comment


            • #21
              Re: Code to delete file contents in RPGLE?

              Yes, in my editor i wanna type option for delete near row I want to erase and then also row in PF is also deleted.

              So maybe delete row from PF and then reload subfile to not have deleted row on screen ?

              Comment


              • #22
                Re: Code to delete file contents in RPGLE?

                The ILE RPG User Guide in the Information Center shows table 53 in the Valid WORKSTN File Operations topic. You can see that WORKSTN files defined as 'C'ombined 'F'ull-procedural on the F-spec do not allow DELETE statements. That is, you can't code a DELETE operation for a subfile record.

                One alternative is to process the subfile and delete all database records that match subfile records, then reload the subfile without any rows for the deleted records. The reload might be done simply by again calling the procedure that loaded the subfile the first time.

                An alternative is to process the subfile and delete the PF records, but simply UPDATE the subfile record to indicate that the related PF record was deleted. The indication might be by changing a color attribute, by making some or all fields in the row to be non-display or by changing the content of a STATUS field. It might also be done by protecting the option field so that it's no longer input-capable for the user or any combination of effects.

                I suppose other possibilities exist, but I haven't ever needed to use any.
                Tom

                There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                Comment


                • #23
                  Re: Code to delete file contents in RPGLE?

                  In most of the applications I've written, you want to allow the user to make many changes to the subfile, and not commit any of the changes to disk until the program has done all of it's error checking, and the user has had a chance to look over all of his changes, etc. The user typically has the option to cancel all of his changes before finally committing them to disk.

                  So, you don't typically just delete the database record at the moment when the user chooses the delete option. Instead, you blank out the record, or change it's color, or something like that (as Tom said.)

                  When they finally have decided to commit all of their changes to disk, you spin through the subfile and delete the ones that have been marked to be deleted, update the ones that have been changed, and so forth.

                  If you do want to delete them immediately, then simply deleting the database record and re-loading the subfile can be a very simple and effective way to do that. (Especially if it's a relatively small subfile.) But do take care with this -- make sure it's hard for the user to delete something accidentally (if there's no way to abort it) A simple typo could be a major problem if it deletes an important record.

                  Comment

                  Working...
                  X