User:Heiko

From Try-AS/400
Jump to navigation Jump to search

About

This is Heikos personal page, in which he maybe shares some private information or collects bits for new articles.

Personal information

Heiko has been in IT since the 90s, but never worked with an AS/400...until 2019. He'll document his first steps in the hope they will be useful to others.

Ideas for new articles

Project Hello World

Preparations

Things you need:

Creating a physical file to hold the sources

Every user has a personal library, like a home in an Linux environment. Since a user can have and use multiple libraries, the current (=default for all operations) is stored in *CURLIB[1]. Because the value of *CURLIB can be changed by the screen you are currently working in, all following commands will contain my personal library name HKRETSCHME. If you are sure *CURLIB is set correctly, you can omit the library.

This command creates a physical file named HELLO01:

CRTSRCPF FILE(HKRETSCHME/HELLO01) RCDLEN(112) TEXT('Project Hello World')

But I prefer to do this in more steps, which I'd recommend to every beginner (By the way: don't bother using cases, the AS/400 won't either. Using capital commands and names just makes it more readable in this article.):

CRTSRCPF

If you don't give any parameters for this command, you will be asked. This works great for CRTSRCPF, but in general, OS/400 will only ask for necessary arguments. Some commands, like CHGUSRPRF will just do nothing. This always works:
Enter the command you want to execute and then hit F4.

HelloWorld01CRTSRCPF.png

A small detour: Physical Files?

Heiko struggled a lot with this and thinks a small introduction is necessary:

  • Libraries: Every user has his own personal library, think of it like a Linux home directory. Details
  • Physical Files: Of course this is no physical file and you can't touch it. And don't think of if (like I as a german[2] do) as one file (f.e. /etc/passwd), it's more like an collection of informations, like you might know from MacOS resources.
  • Members: A member is a file in an physical file, like a book in a filing box. Members of a physical file share the given structure of the PF. Record structure, field lengths, etc.

A more visal approach of explaining:
PhysicalFileOrWhat.png

The Library is the room you keep your Physical Files (like filing boxes) in. The Physical Files contain Members (like books) but must be the same size (okay, a crude explanation for the "must share structure" approach).

  • You can have as much rooms, filing boxes and books as you want.
  • But you can't put rooms in rooms, boxes in boxes or books in books[3].
  • The AS/400 has no tree-like storage structure, it is just a list (of Libraries) with a limited depth (Physical Files and Members) to unfold:
    PhysicalFileList.png

Creating the database

The procedure is as follows:

  • create a text file describing the database
  • compile it into a database

Creating the DDS

The textual description of a database is called DDS. You can learn more here about DDS and here about the DDS format and database fields.

  • Input this to work with our just created Source Physical File:
    Hello01wrkmbrpdm01.png
    wrkmbrpdm file(hkretschme/hello01)
  • Hit F6 to create a new member:
    Hello01wrkmbrpdm01a.png
  • This will run STRSEU:
    (Input member name and type PF)
    Hello01wrkmbrpdm02.png
  • Which brings you to SEU:
    (Enter text as shown)
    File:Hello01wrkmbrpdm03.png
    Here's what it means:
        ***************** Datenanfang *******************************************************************************************
0001.00      A          R MESSAGES                                                                               191001           means: Add Record named MESSAGES
0002.00      A            TEXT          42A                                                                      191001           means: Add field named TEXT with 42 bytes of Ascii.
        ******************Datenende *********************************************************************************************
  • Enter Y (here: J) to save the member.
    Hello01wrkmbrpdm04.png
    After saving, check the lower lines for messages. If there is a synthax error, return to SEU and check every line.
    Hint: Use F4 for assistance while coding!

Creating the database physical file

  • While working with PDM, enter 14 to compile the database.
    Hello01wrkmbrpdm05.png
  • The compiling will be queued…
    Hello01wrkmbrpdm06.png
  • …and you have to check with DSPMSG whether it was successful or not[4]

Hint: Checking my messages with DSPMSG only showed me it wouldn't compile. No error message or any other useful information. If you run into trouble, double check your DDS in SEU, using F4 on every single line. And remember the AS/400 is picky. Even an empty line is enough cause to abort compilation.

  • If compilation worked out, you can see your compiled database physical file here:
    wrklib + <F4>
  • Enter 5 to show contents of your library
  • And here it is:
    Hello01wrkmbrpdm10.png
    It is named HELLO, named after the DDS Member we compiled[5].

Insert content into the database

  • STRSQL + F4
    • Enter the library name, in this example HKRETSCHME[6]
  • In the interactive SQL session, enter: INSERT INTO HELLO (TEXT) VALUES ('Hello World!')
  • There are many ways to display the result:
    • If you're still in STRSQL, enter: SELECT * FROM HELLO
    • On command line, try this: DSPF FILE(HKRETSCHME/HELLO)

Display the content

Create a display file

A Display File (device) is a template for displaying your content.

  • Read this and this about creating DISPLAY FILES (DSPF)
  • CRTDSPF followed by F4
    • Enter target file and library (I used: HELLODSP, HKRETSCHME), which will result in a newly created Display File named HELLODSP)
    • Enter source file, library and DDS member (in this example: HELLO01, HKRETSCHME and HELLO)
    • Press ⏎
  • Then I ran into an problem: The DSPF wasn't created and I couldn't locate the error message. Depending on your system's configuration you will find them in your Print-Queue (use WRKOUTQ!), or even printed out on a printer. In my case, a PDF is created and showed the following:

After some hours, I got it right:

   Spalten . . . :    1 100                                     Editieren                                          HKRETSCHME/HELLO01 
   SEU==>                                                                                                                   HELLODSPF
   FMT DP .....AAN01N02N03A.Name++++++RLängeDDsFZeiPosFunktionen++++++++++++++++++++++++++ ...+... 9 ...+... 0                       
       ***************** Datenanfang *******************************************************************************************  
  0001.00                                             REF(HKRETSCHME/HELLO)                                        191007             
  0002.00      A          R MESSAGES_                                                                              191007             
  0003.00      A            TEXT      R   42A  O  5  3                                                             191007             
          ******************Datenende *********************************************************************************************   

I copied the DDS Member to a new Member named HELLODSPF, changed the type to DSPF, and added the red characters. Explanation:

  • the first row to indicate this refers to a database physical file[7]
  • R to mark this field als reference[8]
  • O to mark this field als output[9]
  • 5 3 to locate the field in row 5, column 3 of the output screen[10]

If you struggle with the positions of the keywords, have a look at IBM's DDS Reference (PDF) (I used Version 4), the 708 pages are packed with great screenshots and explanations. Please note that the record is named slightly differently, with a trailing "_".

Finally, 14 to compile XOR CRTDSPF FILE(HKRETSCHME/HELLODSP) SRCFILE(HKRETSCHME/HELLO01) SRCMBR(HELLODSPF) worked out:
HelloWorldCRTDSPFOK.png

Create the program

Now it's getting clear, that the whole design follows the MVC Paradigma:

  • Database Physical File => Model
  • Display File => View
  • Program[11] => Controller

You can create programs in many languages: CL, REXX, C, COBOL and most commonly used, RPG.

Let's create a RPG:

  • WRKMBRPDM + F6



TODO: MOVE THIS TO --> Beginners Project: Hello World (using database and display file)

Project: Access database with ODBC

Create a database

I suggest you try Beginners Project: 99 Bottles Of Beer (using REXX) and Beginners Project: Hello World (using database and display file) before you try this![12]

Create a database to play with

  • This is the third project Heiko did, so his personal Library was getting a bit cluttered. Therefore, let's create a library just for this niew project:
    • CRTLIB LIB(ODBC) TEXT(Library for ODBC project)
  • CRTSRCPF FILE(ODBC/ODBCDB) RCDLEN(112) TEXT('Project ODBC and Database') to create new physical file to hold the DDS.
  • WRKMBRPDM FILE(ODBC/ODBCDB) Work with this file.
  • F6 to create new member, insert member's name and type PF:
    ODBCDB01.png
  • Enter this DDS: (Learn what the below means)
        ***************** Datenanfang *******************************************************************************************
0001.00      A          R CALLS                                                                                  191002          
0002.00      A            CALLER        42A                                                                      191002          
0003.00      A            CALLED        42A                                                                      191002          
0004.00      A            DATE            L                                                                      191002          
0005.00      A            TIME            T                                                                      191002          
0006.00      A            TIMESTAMP       Z                                                                      191002          
        ******************Datenende *********************************************************************************************
  • 14 to compile…
    ODBCDB02.png
    …I failed again. Stupid me. I can't create a new physical database file in the same place, where source physical file (with the same name!) exists.
    • Just rename the DDS member from ODBCDB to ODBCDBPF:
      ODBCDB03.png
      ODBCDB04.png
    • And try again.
    • Check with DSPMSG[13] whether the compile was successful or not. If it did, you find the new PF in the library:
      ODBCDB10.png

Insert content into the database

HIER WEITERMACHEN!

  • STRSQL + F4
    • Enter the library name, in this example ODBC[14]
  • In the interactive SQL session, enter: INSERT INTO CALLS (CALLER, CALLED, TIME, DATE, TIMESTAMP) VALUES ('Ernie', 'Bert', 2019-10-05, '23:23', '2019-10-05 23:23:42')[15]
  • There are many ways to display the result:
    • If you're still in STRSQL, enter: SELECT * FROM CALLS
    • On command line, try this: DSPF FILE(ODBC/ODBCDBPF)
    • Or use STRDFU, select option 5 and fill out the displayed form.

Articles to maintain


Sandbox

Screen mit MW-Bordmitteln

                                  Anmelden            
                                              System  . . . . . :   SLVRLAKE
                                              Subsystem . . . . :   QINTER
                                              Bildschirm  . . . :   QPADEV0004

               Benutzer  . . . . . . . . . . . .             
               Kennwort  . . . . . . . . . . . .
               Programm/Prozedur . . . . . . . .             
               Men}  . . . . . . . . . . . . . .             
               Aktuelle Bibliothek . . . . . . .             













                                       (C) COPYRIGHT IBM CORP. 1980, 2013.

Und nun Screen mit Bordmitteln und etwas HTML-Foo

Anmelden
System . . . . . : SLVRLAKE
Subsystem . . . . : QINTER
Bildschirm . . . : QPADEV0004

Benutzer . . . . . . . . . . . .
Kennwort . . . . . . . . . . . .
Programm/Prozedur . . . . . . . .
Men} . . . . . . . . . . . . . .
Aktuelle Bibliothek . . . . . . .













(C) COPYRIGHT IBM CORP. 1980, 2013.

Using (not-working) console-tag

<console> Test </console>

<console>

                                  Anmelden            
                                              System  . . . . . :   SLVRLAKE
                                              Subsystem . . . . :   QINTER
                                              Bildschirm  . . . :   QPADEV0004

               Benutzer  . . . . . . . . . . . .             
               Kennwort  . . . . . . . . . . . .
               Programm/Prozedur . . . . . . . .             
               Men}  . . . . . . . . . . . . . .             
               Aktuelle Bibliothek . . . . . . .             













                                       (C) COPYRIGHT IBM CORP. 1980, 2013.

</console>


  1. https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/rzarl/rzarlcurlib.htm
  2. Yes, as a german IT guy you think of "file" as "Datei". But "file" in english can also mean "Akte" or "Karton mit Akten". Sorry for Kauderwelsch.
  3. And as you may have guessed, you can't put rooms in boxes, boxes in books…
  4. Can anyone tell me how this is done synchronously? Performance isn't an issue any more…
  5. If we had chosen the same name for the member as for the source physical file, the PDM would have asked, if I'd want to overwrite the source physical file with the compiled database. Naming the member differently avoided this. This has the advantage that the DDS member remains for later use.
  6. Shortcut: STRSQL LIBOPT(HKRETSCHME)
  7. Beginning with column 45
  8. Column 29
  9. Column 38
  10. Row: 39-41, column: 42-44
  11. Short: PGM
  12. Heiko made this pretty brief, f.e. not every F3 or is noted.
  13. or use Compile Sources Without Queuing
  14. Shortcut: STRSQL LIBOPT(ODBC)
  15. Timestamp format: https://www.ibm.com/support/knowledgecenter/SSFMBX/com.ibm.swg.im.dashdb.sql.ref.doc/doc/r0007107.html