ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Simple Update Program HELP THE NOOB!

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

  • Simple Update Program HELP THE NOOB!

    Having recently graduated college with a degree nowhere related to programming, I was quite surprised to see this archaic seeming iSeries is my primary tool. However I have come to love this extremely robust system so much that I want to learn to program!

    I need to create a basic program that will update records in a file based on user input. For example, a user will enter two values in a display screen, obe of which will be a key field. Then the program will update two fields on the record based on the user's input.

    I am so inexplicably lost with this. ...do I do it all in RPGLE....do I need a logical file...I will take any and all guidance.

    Thanks in advance!

    -Kevin

  • #2
    Re: Simple Update Program HELP THE NOOB!

    Maybe start with the RPG Programmer's Guide http://www-01.ibm.com/support/knowle...in.htm?lang=en

    That is the 7.2 version, you will probably want to get the version that matches your system - just search the Knowledge Center. It has some examples, maybe work with those and then come back with specific questions you have and we can help.

    Comment


    • #3
      Re: Simple Update Program HELP THE NOOB!

      Your question is difficult to answer since you didn't explain what you're stuck on. Maybe some pseudocode with an overview of the process will help.

      With traditional RPG (native I/O), what you do is:

      1) Get the original key value from the user.
      2) CHAIN to the original record.
      3) Put the values on the screen, let the user make his/her changes
      4) copy the new values (from the screen) to the file. (This is only needed if you used different field names.)
      5) UPDATE the record.

      Whether or not you need a logical file really depends on whether the file structure does/doesn't match your keys.

      With SQL (the more modern way to do this stuff):
      1) Get the orignal key value from the user
      2) Use SQL SELECT FIELD1, FIELD2 FROM MYFILE WHERE KEY=:ORIGKEYVAL to get the fields.
      3) Display them on screen, let the user change
      4) use SQL UPDATE MYFILE set FIELD1=:NEWVAL, :FIELD2=:NEWVAL2 where KEY=:ORIGKEYVAL

      Does that help?

      Comment


      • #4
        Re: Simple Update Program HELP THE NOOB!

        kevin, you can download my open source subfile program from Google Code: http://code.google.com/p/rdwrites/downloads/list This is a zip file of the source code to look at on a PC: rdwrites 090715 WEBVISITOR 5250 subfile maintenance ascii source files zip. I'm on a phone and copied that from another post, but looks like the link is there. One of the programs is an update screen. You should be able to find a lot of what you might want to do in those programs.

        Comment


        • #5
          Re: Simple Update Program HELP THE NOOB!

          If you have an iSeries to work on, you potentially have a reasonably current version of the OS and some development tools. And if this iSeries is used for actual production that you might be involved with, it could be even better. The "AS/400" line has been around a long time, and lot of older systems are out there.

          Everything on the older systems can be applied to newer ones, so any knowledge isn't necessarily lost. But as with all lines from all vendors, there is a real preference for newer facilities. So, to get best help, we'll want to know the OS version/release and a basic list of compilers and development tools available to you.

          With that said, "yes and no" is the answer to your initial question. ILE RPG is a version of the most common business programming language used for the iSeries. Technically, you could indeed do it all with ILE RPG. That includes manipulating the display, handling the database functions and pretty much whatever else you can think of. In practice, though, a couple other languages would be involved.

          For example, the description of the display screens is almost always done using DDS (Data Description Specifications). This language is used for defining and describing native "files". A file would generally be a display file, a printer file or a database file. Such files on the iSeries are 'external' files that exist as 'objects' completely separate from any programs that might access them. The definitions are brought into a compiled program by coding a reference to the object. The record formats, field definitions and all attributes needed for manipulation of the object through its methods are automatically incorporated into the compiled program object.

          You might also use SQL for a more "modern" database interaction. It might be better to start with using embedded SQL rather than 'native' file access, but that's also somewhat dependent on the working environment that you have in mind.

          A logical file (LF) isn't usually needed, though it's often a 'best practice' to use one that is appropriately defined for the process rather than using a physical file (PF) directly. A LF can provide only the fields needed, or an appropriate index, or perhaps other elements that might be best. It's probably a good idea to compile one or more slightly different LFs over your PF just to get the idea of how one might be used.

          If you are experienced at all with other languages, you might prefer them to RPG. RPG is just very well suited for the business programming that runs on most iSeries systems, and it's a very competent language. If the system already makes use of RPG, it's probably your best starting point. But be very aware that might see many (many!) code examples on the system that reflect coding from 20 and more years ago. The world has changed a lot, and the language has also. New RPG programming can be unrecognizably different from older RPG code. (Seriously.)

          But quite a few other programming languages are available and might be installed on your system. Actually, there are other programming languages on your system even if none were ever installed by its administrators; but you might never use any other than probably CL (the 'Control Language').

          Anyway, "yes and no" kind of answers the question of whether it would all be done in ILE RPG. At the simple overview level, it's mostly "yes" but probably with DDS and possibly SQL exceptions.
          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


          • #6
            Re: Simple Update Program HELP THE NOOB!

            Wow, thank you all for the support!

            A few misc. bits of info that may help you help me:

            -iSeries version 6.1

            Scott M—That resource is phenomenal and I have already started reading.
            Scott Clement—I will copy in some sample below but I was unaware you could use SQL in RPG?
            Ralph—I could not find the code you linked.
            Tomliotta—I have access to our dev server which is a copy of our production server including the PDM and my own library I created for learning on. I have been working hard to earn the IS team's trust I would say I am most comfortable with SQL but still a beginner. However, since I am entirely new to this I would like to devote my time to learning the most appropriate and current methods/languages and to doing things the right way so guide me and I will listen. I know we make use of RPG, RPGLE, CL, DDS, and I'm sure many others.....I work for a very large company.

            If I were to put my "program" into SQL it would be as follows (including the noobie notes/comments:

            UPDATE FILE1;
            SET FIELD1 = 'X', FIELD2 = 'Y'
            WHERE FIELD3 < 58
            AND FIELD4 = CURDATE()
            AND FIELD5 = _________(<<<user input from display screen)

            Thank you all so much!

            Comment


            • #7
              Re: Simple Update Program HELP THE NOOB!

              kevin, don't know exactly what you mean by can't find the code. The link to my open source RPG code on Google Code has 7 download files. The fifth is the one I listed. It is a zip file. When you extract the files, they are each a program. The extension says the type of program, I think the RPG file extension is RPGLE. They are each a source code member in PDM. The last download file is the source code SAVF which could be restored to your dev box and accessed by PDM. Or the ascii files could be opened in rdi (Eclipse development editor) and saved away asas source code on your dev box. After that it is also accessible by PDM. But the ascii source code files can also be opened by any PC editor if you just want to take a look at the code.

              Let me know here if any problems or questions. I'll be glad to answer (along with all the other great help here).

              I took a look and WEBVISITRC.RPGLE is the screen update program. The code is in /free syntax so may not look like what you expect. You will want to start out writing in /free. Also I use native IO (chain, update, etc.) but you can embed SQL instead if you want. Your choice.

              Comment


              • #8
                Re: Simple Update Program HELP THE NOOB!

                The simplest version of an ILE RPG program that implements your SQL would look something like this:
                Code:
                     d myInput         s              5a
                      /free
                
                       dsply 'Enter value (5 characters)' ' ' myInput ;
                
                       Exec SQL
                         update FILE1
                            set FIELD1 = 'X', FIELD2 = 'Y'
                         where FIELD3 < 58
                           and FIELD4 = CURDATE()
                           and FIELD5 = :myInput ;
                
                         *inLR = *on ;
                         return ;
                
                      /end-free
                It's a bare beginning and not the way it'd normally be done.

                Any input from a user would normally be through a formatted display screen rather than through the DSPLY op-code. This just happens to be a very simple need, so DSPLY makes for a simple example. The value from the user should possibly be checked for a valid value. The SQL UPDATE statement would be checked for any error condition after being run.

                Various other things could (and possibly should) be done, depending on the purpose and environment. Maybe ideally this would be prototyped and perhaps even only be a *MODULE rather than the complete *PGM. Yet, this is a working example, though my table definition for FILE1 was also as simple as I could make it based on your SQL statement.

                Further, it uses embedded SQL primarily because you gave a SQL sample. It could be written instead as native file access and would look quite a bit differently. You might see if you can come up with a 'native' version.
                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

                Working...
                X