ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Code to delete file contents in RPGLE?

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

  • Code to delete file contents in RPGLE?

    Hi

    I have a physical file with three fields (say f1 f2 and f3). I am developing a program that should delete some of the records in this file depending on the value of f2 each time the program is run. Not sure how to do this.

    Any advice?

    Many thanks in advance.

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

    if you can use embedded SQL it's trivial...
    Code:
    /free
          exec sql
             delete from myfile where f2 = 'WHATEVER';
          *inlr=*on;
          return;
    other than that just read through the file and do:
    Code:
    if f2 = 'WHATEVER';
      delete myrcdfmt;
    endif;
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Can you post us the code you have written so far... Because of the simple nature of this question I would guess you are taking a class. The study guides for this lesson should have some basic guidelines from the instructor as to the method he/ she would like to see. By showing us this we can better help you give back the expected answer.

      Welcome to code400

      Jamie
      All my answers were extracted from the "Big Dummy's Guide to the As400"
      and I take no responsibility for any of them.

      www.code400.com

      Comment


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

        Thanks Jamie I will just go with the SQL. Also unfortunately I am not taking a class and it is a bit more serious that that but am a bit slow with RPG.

        Ramin

        Comment


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

          I did not want to use SQL initially but then could not find a reason as in why not. I will just use SQL.

          Thanks

          Comment


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

            If RPG is "required", then SQL is a good way to go. You might also simply run a CLRPFM command over the file.

            Tom
            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


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

              Originally posted by tomliotta View Post
              You might also simply run a CLRPFM command over the file.
              CLRPFM would clear the entire file, not just "some records depending on the value of f2".

              Comment


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

                Ah, yes.I read the whole question the first time through the thread; but I neglected to re-read everything after simply seeing the thread title later. CLRPFM is not appropriate.

                I need to make it a habit with this forum to check the beginning after jumping to the latest post.

                Tom
                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


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

                  Rules to live by Tom - "Coffee before Coding"
                  Greg Craill: "Life's hard - Get a helmet !!"

                  Comment


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

                    Sorry, not a good rule for me. It needs to be "Coffee before, during and after Coding!"

                    {See my avatar.}

                    Tom
                    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


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

                      Instead of using Sql in Rpgle for the deletion. Use delete opcode to delete the specific record you want to delete from file

                      Steps to delete

                      f2 chain filename
                      if %found
                      delete file record format
                      Endif


                      if ur file has duplicate values of f2 then go the below process

                      F2 setll filename
                      F2 read filename
                      dow not %eof
                      delete file record format
                      F2 read filename
                      Enddo

                      Comment


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

                        FWIW if you're expecting a significant amount of records to purge SQL will perform better than RLA
                        I'm not anti-social, I just don't like people -Tommy Holden

                        Comment


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

                          dileep.gare - you don't need the chain and read when deleting as you can use a search argument directly with the delete op-code. The below will delete all records with a key of F2 from the file.

                          dou not %found(filename);
                          delete F2 filename;
                          enddo;

                          Comment


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

                            Hi,

                            That's why we like this form, this forum guide with valuable information do work more efficiently.

                            Thanks SCOTT for your valuable information and guiding me in easiest solution to work on.

                            Thanks
                            dileep

                            Comment


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

                              and how to delete row using RPG, when I wanna look not for key, but another field, 'field2' (i wanna delete it from screen - i have subfile)?
                              can I use setll for not-key field?
                              example:
                              Code:
                              field1(key)     field2
                              first              email1 
                              first              email2
                              first              email3
                              ....

                              Comment

                              Working...
                              X