I have been programming for nearly 30 years now. I started with BASIC on a Texas Instruments TI-99 with voice Synthesizer. https://en.wikipedia.org/wiki/Texas_Instruments_TI-99/4A
I followed that up with my very own Commodore 64 where I continued to dabble in the fine art of coding. Mostly though I spent a lot of time on line on a 300 baud modem. Oh those were the days.
Over the years I have dabbled in many different languages, but Visual Basic.NET and C# have always been my go to languages of choice when programming for the PC.
My issue is that those languages do not work with IBM on their OS400 platform. No there if you want to make this box do anything you have to learn a new language, RPG. On a few occasions in the past I looked into it and because a lack of a good simple Hello World tutorial I gave up. That is until now.
This time I had an actual need to make this box backup some files, then transfer them to the PC with FTP for backing up to the cloud. Sounds simple enough. That is if you know how to program in RPG and how to use the editor and compiler on the OS400. I did not.
Having used the AS400 and its OS for about 18 years I was familiar with getting around the box, so that helps. If this is your first time even looking at a green screen then good luck. This tutorial will get you through to a finished product but it will be a bit daunting for you. Oh lest I forget, if you screw something up while following these directions it’s on you. If you don’t know what you are doing then get someone who does. I take no responsibility for what happens and I don’t guarantee this will work for your situation.
First you must be using IBM i Release 7.3, Release 7.2 TR3, or Release 7.1 TR11. RDi Release 9.5.
This is because I am using the fully free form of coding. It’s much better than what was required before and is easier for programmers of other languages to use.
I began my search on Google, looking for help on programming the AS400. I came across a few books, but when I looked they really looked like they were for someone who already had programming experience on the AS400. I decided to save my money for now and continued my search. Then I came across the aforementioned IBM link. Viola! Hello World! I read through the first page a few times and realized this might work, but the directions where confusing and really incomplete.
For clarification lets go over the steps to create your first program for the AS400.
As an example we want to create a BACKUPPGM program in a library called BACKUP.
Logon to a session on your IBM AS400
Next create a Physical File using the CRTSRCPF. Here I name my file BACKUPPF and put it in the BACKUP library I just created.
Now we are going to create a member using PDM. Enter WRKMBRPDM on the command line and press F4.
Enter the info as you see it above and press enter. You will see the resulting screen.
Press F6 to Create a member
Enter HELLO for the Source Member, RPGLE for the Source type and give it a description. Press enter when you are done. It will take you to an editor where now you can add your code.
Now let’s write a simple Hello World program
On the first line and it must be the first line of your code enter:
This indicates we are using the free form version of code.
Next put the following:
dsply ‘Hello World’;
This is what is going to flash the Hello World on the screen.
When finished you should see something like this:
Now press F3 to get out of the editor and accept the defaults for saving the member.
Once back to the member list, you will see your HELLO member. Put a 14 next to it to compile it. Once compiled, from a command line enter: CALL BACKUP/HELLO
Congratulations, you created your first program on the AS400.
Now take it a step further and create that program for backing up some libraries.
We already have our library ( BACKUP) and our Physical File (BACKUPPF) so all we need to do now is create a new member for the backup program.
If you are not already there get back to your member list. (Enter WRKMBRPDM on the command line and press F4.)
Press F6 to create a new member and this time enter BACKUPPGM for the Source Member and RPGLE for the Source Type. Give it a description.
Once again you are back to your editor.
Here we are concerned with three commands:
CRTSAVF – This creates a Save File. This would be the file you want to save your library to.
CLRSAVF – This clears the save file if it contains any data already.
SAVLIB – Saves the specified library to the save file we created earlier.
Now technically you can simply issue the CRTSAVF from the command line and be done with it. This is because after the first time you run your program the save files will have already been created. However for clarity and simplicity I will leave them in the program.
For our example here we want to back up two libraries named HTEDTA and HTEPGM. To do this you would enter the following lines of code in your editor:
SAVLIB LIB(HTEDTA) DEV(*SAVF) SAVF(BACKUP/HTEDTA)
SAVLIB LIB(HTEPGM) DEV(*SAVF) SAVF(BACKUP/HTEPGM)
Now let me break it down for you.
This creates a save file in the library BACKUP we created earlier called HTEDTA.
This clears the save file in the library BACKUP called HTEDTA.
SAVLIB LIB(HTEDTA) DEV(*SAVF) SAVF(BACKUP/ HTEDTA)
This saves the library called HTEDTA using the device Save File to the save file called HTEDTA in the library BACKUP.
Now that you have entered all your code press F3 and save your source member.
Put a 14 next to it and compile.
To run it you can enter on the command line CALL BACKUP/ BACKUPPGM
This will now save the libraries you specified to the save files you created. From here we can now go to a PC and FTP the files down.
Open your favorite desktop file editor and enter the following:
Note: It is a good idea to use a AS400 user that only has read access to the box as you are storing these options in clear text on a PC.
Save the file as ftp_options.txt
Now create a Batch file and add this to it:
Save the batch file in the same folder as the ftp_options.txt file.
Now you can use this batch file manually by running for a command line or as part of the command in Task Scheduler.
My intent here was to combine learning to program the AS400 and backing up to the PC while adding some clarity for the new AS400 programmer.
I want to thank Drew Dunkel on Spiceworks for his work on backing up the AS400.
Also thanking IBM for the Hello World instructions.