58
AS400 Training (Native Programming Environment) Prepared by: Andy Ng

AS400 Training Part I_Version 1.1

  • Upload
    rasasp

  • View
    67

  • Download
    8

Embed Size (px)

DESCRIPTION

AS400 Training Part I_Version 1.1

Citation preview

Page 1: AS400 Training Part I_Version 1.1

AS400 Training (Native Programming Environment)

Prepared by: Andy Ng

Page 2: AS400 Training Part I_Version 1.1

April 21, 2023 2

Agenda

Day 1IntroductionNavigation through the i5/OS Main MenuFileLibraryLibrary ListHow to Create FilesQuick Intro to IFSExercises for Day 1

Day 2Review Session and Answers from Day 1Brief Relationship of Objects DiscussedSource Editing Utility (SEU) Exercises for Day 2

Page 3: AS400 Training Part I_Version 1.1

April 21, 2023 3

Agenda

Day 3Review Session and Answers from Day 2Command StructureQuick Glance at Some Useful CommandsExercises for Day 3

Day 4Review Session and Answers from Day 3Programming Example and Use of DebuggerExercises for Day 4

Day 5Review Session and Answers from Day 4Crash Course on CL programmingExercise for Day 5Review Session for Day 5

Page 4: AS400 Training Part I_Version 1.1

April 21, 2023 4

Learning Objectives

By the end of these sessions you will be able to:

Have some basic ideas on AS400 native programming environmentUnderstand the major object categories in AS400Able to use some AS400 commands Able to create data files and programsHave basic concepts on IFSKnows how to run a program and verify the resultKnows how to use the DebuggerKnows more in CL programming

Page 5: AS400 Training Part I_Version 1.1

April 21, 2023 5

Introduction

AS400 is a family of mid-range business computing systems

Exclusively use the IBM Operating System/400 (OS/400)

Offers relatively higher performance (e.g. up to 300GB/second

process bandwidth with the Power 6 Chip)

Built-in database (DB2/400)

Support multi-programming languages

Page 6: AS400 Training Part I_Version 1.1

April 21, 2023 6

Navigation through i5/OS Menu

Page 7: AS400 Training Part I_Version 1.1

April 21, 2023 7

Navigation through i5/OS Menu … Continue

Select Option 4.1.1 then fill in the information …

Page 8: AS400 Training Part I_Version 1.1

April 21, 2023 8

Navigation through i5/OS Menu … Continue

Select Option 5 to display the file content …

Page 9: AS400 Training Part I_Version 1.1

April 21, 2023 9

Navigation through i5/OS Menu … Continue

Press Enter to continue …

Page 10: AS400 Training Part I_Version 1.1

April 21, 2023 10

Navigation through i5/OS Menu … Continue

Here you are …

Page 11: AS400 Training Part I_Version 1.1

April 21, 2023 11

Navigation through i5/OS Menu … Continue

Try out with 4.2.1 similar to the above steps for a Library …

Page 12: AS400 Training Part I_Version 1.1

April 21, 2023 12

Navigation through i5/OS Menu … Continue

Select 4.2.70.24.4, then press Enter to display the Library List…

Page 13: AS400 Training Part I_Version 1.1

April 21, 2023 13

File

An object, of type *FILE, that contains data in the form of a database, device data, or a group of related records that are handled as a unit.

Physical File Contains actual data stored on the system. It has a fixed-length record format. There are 2 kinds of physical files, i.e. Source and Data Physical File.

Logical File Contains no actual data, but provides a different method of viewing the data of an accompanying data physical file(s) which it internally references like an Index

Member Subsets (Grouped Data Records) of File Objects

Page 14: AS400 Training Part I_Version 1.1

April 21, 2023 14

Library

An object, of type *LIB, that contains a group of objects.

Every object is contained in a library

Similar to the "root" or top-level directory on Unix, MS-DOS

Cannot "contain" other libraries (with the exception of QSYS)

All IBM-supplied library names begin with the letter "Q" or "#"

There are basically 3 types of libraries – QSYS, System Supplied

and User-Created

Page 15: AS400 Training Part I_Version 1.1

April 21, 2023 15

Library List

Similar in concept to the "PATH" in Unix and MS-DOS. It specifies which libraries are to be searched and the order in which they are searched when the system looks for an object.

A library list is identified by the value *LIBL

Default library list is automatically created by OS/400 for each job started by a user

Your default library is automatically included in your library list

Use DSPLIBL/EDTLIBL to show and edit your library list

*CURLIB, means the current library

Handy for Testing

Page 16: AS400 Training Part I_Version 1.1

April 21, 2023 16

Day 1 Exercises … (Part A)

Navigate via the i5/OS Main Menu to CREATE Library with the name same as your user ID suffixed “X” (with Library Type *TEST)

Use the Main Menu again to DISPLAY your Current Library

Use the Main Menu to DISPLAY you Library List, write down the entries in Sequence

Use the Main Menu to CHANGE your Current Library to the Library you created above

Use the Main Menu to DISPLAY your Library List now, what is the difference?

Use the Main Menu to EDIT your Library List, see if you can change the the Order, ADD or DELETE individual Library Entries

Explore other OPTIONS with WRKLIB, make use of F1 and F4 Function Keys. How can you display all the libraries in your machine?

Page 17: AS400 Training Part I_Version 1.1

April 21, 2023 17

How to Create Files

Creating a Source Physical File (Menu Option 4.1.60.3.10)

Page 18: AS400 Training Part I_Version 1.1

April 21, 2023 18

How to Create Files … Continue

Creating a Program Source File Member

WRKMBRPDM (providing the Source File Name) Use F6 Function Key STRSEU (Filling in required parameters)

Page 19: AS400 Training Part I_Version 1.1

April 21, 2023 19

How to Create Files … Continue

Creating a DDS File for a Physical Data File

Page 20: AS400 Training Part I_Version 1.1

April 21, 2023 20

How to Create Files … Continue

Creating a DDS File for a Logical Data File

Page 21: AS400 Training Part I_Version 1.1

April 21, 2023 21

How to Create Files … Continue

Compiling and Creating a Physical Data File

Page 22: AS400 Training Part I_Version 1.1

April 21, 2023 22

How to Create Files … Continue

Compiling and Creating a Logical Data File

Page 23: AS400 Training Part I_Version 1.1

April 21, 2023 23

Quick Intro to IFS

Some Highlights

Stands for Integrated File System for AS400

A part of OS/400 that supports Input/Output stream of Data Management (i.e. Data are treated as stream of bytes instead of fix-length records)

Support emerging and future form of information processing (familiar/similar environment for Unix/Window users)

Separate File Systems with different capabilities to handle different types of file management such as NFS for File Network System, QNTC for NT Server File System and QSYS.LIB for AS400 Library Structure etc.

A hierarchical directory structure to organize objects

Can interact with any of the file systems through a common interface

Page 24: AS400 Training Part I_Version 1.1

April 21, 2023 24

Quick Intro to IFS … Continue

Pathname tells the Server how to locate an object. – sequence of

directories and object names separated by “/” (LINK in IFS)

The “root” (/) File System – takes full advantage of Stream File support

and hierarchical directory structure of IFS

The “/tmp” - sub-directory of “root” provided by IFS is used to store

temporary files from applications

There are also other sub-directories provided by IFS such as “/home”,

“etc”, “usr” and “usr/bin”.

Page 25: AS400 Training Part I_Version 1.1

April 21, 2023 25

Quick Intro to IFS … Continue

Accessing IFS

Use GO DATA command to invoke menu

Select Option 5 (Integrated File System)

You can then manipulate directories, links and objects via different options from the sub-menu (equivalent to Option 4.5.2 from Main Menu)

Use Option 1 (Work with Object Link) then Option 5 (Display) to navigate through the “root” Directory. Can also use the command WRKLNK

Once mapped to a network drive, IFS directories and objects can also be accessed in a PC environment

Page 26: AS400 Training Part I_Version 1.1

April 21, 2023 26

Quick Intro to IFS … Continue

Commands for Copying in IFS

CPYTOSTMF and CPYFRMSTMP (only allows one field records)

CPYTOIMPF and CPYFRMIMPF (with FDF or delimiters)

Page 27: AS400 Training Part I_Version 1.1

April 21, 2023 27

Day 1 Exercises … (Part B)

Explore the command CRTDTAARA, CHGDTAARA and RTVDTAARA. <Hints: AS400 Data Area is an object which has been allocated some memory. Data area can be understood to be flat file sort of object with only one record of specific length.>

Create a Data Area HELLOFLAG with 1 Character in Length and populate with value “Y”.

Create Physical Source File QDDSSRC, QCLLESRC and QCBLLELSRC in your library. <Hints: Use the default record length>

Create a DDS Source Member HELLO in Physical Source File QDDSSRC with TYPE PF. Record should have 2 bytes for key and 80 byte for message. Define the key in ascending order <Hints: a physical data file can also have key>

Create a DDS Source Member HELLO1 in Physical Source File QDDSSRC with TYPE LF. Define the key in descending order.

Compile HELLO into a Physical Data File, then compile HELLO1 into a Logical Data File basing on HELLO. <Hints: Use Option 14/F4 within WRKMBRPDM to execute the compilation. Press F18 and modify COMPILE IN BATCH to “N”. Verify the Compiled List via the SpoolFile produced>

Page 28: AS400 Training Part I_Version 1.1

April 21, 2023 28

Brief Relationships of Objects Discussed

QSYS (*LIB) [special library] | | contains | Library (*LIB) | | contains | .------------------+----^-----------------.--------. | | | | Programs (*PGM) Outqueues (*OUTQ) Files (*FILE) Other [Executable] | | objects | contains | Spooled Files | [Output intended for Printer] | | .----------------^--. | | Physical Data Logical file file (PF) (LF-DTA) | ^ contains .------^-----. Member(s) | | [Reorginized data] Source Data Physical Physical File File (PF-SRC) (PF-DTA) | | contains | | contains | | Member(s) Member(s) [Program Source] [Actual Data] ]

Page 29: AS400 Training Part I_Version 1.1

April 21, 2023 29

Source Edit Utility (SEU)

Offers full screen editor providing syntax checking

Use STRPDM to start the SEU

F3 to quit SEU

F4 to check format

Sequence numbers of records at the extreme left displays the sequence number of the record and is used for entering SEU line commands

Explore the use of F1, F3, F11, Shift F1, F2, F3 and F9 Keys

Page 30: AS400 Training Part I_Version 1.1

April 21, 2023 30

Source Edit Utility (SEU) … Continue

The following is a list of several SEU commands examples :

A After Move or copy records after this record. B Before Move or copy records before this record. C Copy Line Copy this line to a specified target. CC Block Copy Copy all lines between the boundaries formed by the two CC commands D Delete Delete the current line. Dn Delete n lines Delete the current line and the next n-1 lines. DD Block Delete Delete all lines between the two DD boundaries. I Insert a line Insert a blank line after the current record. In Insert n lines Insert n blank lines after this record. Ln Shift data n chars left Shift data in this record n character positions to the left without losing data.

M Move a line Move a line to a specified target. MM Block Move Move all records between and including the boundaries defined by the MM line commands to a specified target.

Page 31: AS400 Training Part I_Version 1.1

April 21, 2023 31

Source Edit Utility (SEU) … Continue

Some Useful Commands that can be entered on command line

FIND F CHANGE C SAVE S CANCEL CAN FILE FILE TOP T BOTTOM B

Page 32: AS400 Training Part I_Version 1.1

April 21, 2023 32

Day 2 Exercises

Use Main Menu Option 4.1.7.5 to explore and use DFU inserting a couple records into file HELLO.

<Hints: STRDFU with option 5>

Use Main Menu Option 4.1.10 to display your HELLO file and verify the data input.

Copy the File TRAINING/HELLOEX3CL into your user library’s CL Source File QCLLESRC created in earlier exercise.

Use the command STRPDM to access and Study the CL program HELLOEX3CL to see how the value of Data Area HELLOFLAG is retrieved and put into a parameter variable that pass back to the Calling Program. Add comments (use embedded /*…*/) such as your name, Date of Program Creation, Purpose of the Program etc. Practice the use of different SEU commands. Compile the program using Option 14 to make sure it’s error free.

<Hints: Source Member must be of TYPE CLLE, Go into EDIT mode and explore the user of F4 Function Key. How does it help you? Also while WRKPDM, use F18 to change Compile in Batch to “N”>

Page 33: AS400 Training Part I_Version 1.1

April 21, 2023 33

Command Structures

A command is made up of two components

Verb - consists of three characters and is the "action" component

Subject - Specifies the item that the verb acts on

Some common verbs and their meanings are shown below -

ADD - Add Item CHG - Change CPY - Copy CRT - Create DLT - Delete DSP - Display item MOV - Move RMV - Remove item RST - Restore RTV - Retrieve STR - Start (a program or utility) WRK - Work with

Page 34: AS400 Training Part I_Version 1.1

April 21, 2023 34

Command Structures … Continue

Examples of verb/subject combinations are:

CHGPWD – Change Password

CRTSRCPF - Create Source Physical File

CRTLIB – Create Library

WRKMBRPDM – Work with Members using PDM*

ADDLIBLE - Add Library List Entry

SIGNOFF – Logoff Session Forget your commands? Try SLTCMD, GO CMDxxx and ? F4 for parameters, F11 for Qualifier Name (Keyword) CL command can use a combination of both positional and keyword

parameters; i.e. parameters can be omitted.

* Note: Program Development Manager (PDM) is a set of utilities under OS/400

designed to simplify the creation and development of software. It automates file

and member creation, editing, compilation and program execution, and allows

the programmer to manage their environment from a set of standard menus.

Page 35: AS400 Training Part I_Version 1.1

April 21, 2023 35

Day 3 Exercises

Find out what command you use to submit a Job

Find out what command you use to hold a Spooled File

Find out what command you use to Override a Database File <What is the use of this? Discuss with other members of you class>

Navigate through the Main Menu (Option 4.1.6.10 then press ENTER, you should be able to see Work With Query Manger Queries screen. Select Option 1 then change the Library to a database library you want to be in and press ENTER again. Input Option 1 and input a Query Name to create a Query … Explore how to run a Query from here and have the result output to a file in your library)

Use the command DSPFFD to output a data file’s structure into a file TMP in library QTEMP. Study the data in TMP file (what is your finding?) Use Main Menu Option 4.1.6.10 then press ENTER go to Work With Query Manger Queries screen. Select Option 3 then change the Library to QTEMP and press ENTER again. You should now able to display the TMP File/table via Option 5.

Create a Query that only gives Internal Field Name, Output Buffer Position, Field Type, Field Length in Bytes, Number of Digits, Decimal Positions and Field Text Description.

<Hints: You should cross-check the column headings with the last step when you display the table TMP>

Page 36: AS400 Training Part I_Version 1.1

April 21, 2023 36

Some Programming Examples and Use of Debugger

Let’s start working on a simple program first –

Create COBOL Source File QLBLSRC

Create a Source Member HELLOEX1 with TYPE *CBL

Use SEU to create a program that will print out the string “HELLO WORLD!”

Use F4 to help you format the lines as required

Compile the program as follows

Run and Test your program

Use Interactive Debugger to step through the program

Page 37: AS400 Training Part I_Version 1.1

April 21, 2023 37

Some Programming Examples and Use of Debugger … Continue

An example of the HELLOEX1 program in COBOL

Page 38: AS400 Training Part I_Version 1.1

April 21, 2023 38

Some Programming Examples and Use of Debugger … Continue

Compiling the HELLOEX1 program

Page 39: AS400 Training Part I_Version 1.1

April 21, 2023 39

Some Programming Examples and Use of Debugger … Continue

Compiling the HELLOEX1 program

Page 40: AS400 Training Part I_Version 1.1

April 21, 2023 40

Some Programming Examples and Use of Debugger … Continue

Use Debugger to run HELLOEX1Invoke the Debugger via command STRDBG then press F4

Page 41: AS400 Training Part I_Version 1.1

April 21, 2023 41

Some Programming Examples and Use of Debugger … Continue

Check you spool files for result via WRKSPLF command

Page 42: AS400 Training Part I_Version 1.1

April 21, 2023 42

Some Programming Examples and Use of Debugger … Continue

An example of CL program -

Page 43: AS400 Training Part I_Version 1.1

April 21, 2023 43

Some Programming Examples and Use of Debugger … Continue

An example of RPG program (Translation of the HELLOEX3 COBOL program)

Page 44: AS400 Training Part I_Version 1.1

April 21, 2023 44

Day 4 Exercises

Create a COBOL program HELLOEX2 to read all records from HELLO file and print ALL of them out one by one. <Hints: follow the example discussed>

Create a COBOL program HELLOEX3 to call CL program HELLOEX3CL. Review the value in Data Value passed back from the call; if value = “Y” then output ALL the messages from file HELLO1 in descending key sequence; otherwise exit program. <Hints: make use of the Logical File HELLO1 you created just now, include a one character parameter variable during the call of HELLOEX3CL >

Run HELLOEX2 and HELLOEX3, then verify your results. <Hints: use the CALL command>

You would also like to use the Debugger to fool around with those programs.

Page 45: AS400 Training Part I_Version 1.1

April 21, 2023 45

Crash Course on CL Programming

Some Highlights

Control Language is the primary interface of OS/400 and can be used

concurrently from multiple workstations.

A CL Program is constructed by Commands and System Functions used

in iSeries

There are over 1500 commands in total

Used extensively in iSeries to perform and automate system and

application functions

Able to Interact with programs written in other programming languages

Page 46: AS400 Training Part I_Version 1.1

April 21, 2023 46

Crash Course on CL Programming … cont

What You Will Learn …

CL Variables

Some useful CL Commands and Functions

CLP Basic Logic and Control

Monitor Message and Error Handling

File and Data Area

Passing Variables between Programs

F4 Prompting, Command Continuation and Operators

Executing SQL in CL Program

Page 47: AS400 Training Part I_Version 1.1

April 21, 2023 47

Crash Course on CL Programming … cont

CL Variables

Use DCL Command to define a CL Variable

Variable Naming Convention

CL Variable Types (*CHAR, *DEC, *INT, *LGL etc.)

CL Variable Length, Decimal Positions and Initial Value

Page 48: AS400 Training Part I_Version 1.1

April 21, 2023 48

Crash Course on CL Programming … cont

Some Useful CL Commands and Functions

PGM … ENDPGM

Examples of Commands : ADDLIBLE, CALL, CHGVAR, CHGCURLIB, CPYF, CRTDUPOBJ, DLTF, DLYJOB, DO, PARM, RNM, RTVDTAARA, RTVUSRPRF, RTVSYSVAL, SNDPGMMSG, SBMJOB, WRKOBJ

Examples of Functions : %BINARY, %SST

Use embedded /* … */ for comments

Page 49: AS400 Training Part I_Version 1.1

April 21, 2023 49

Crash Course on CL Programming … cont

CL Basic Logic Control

GOTO (With Command Labels)

IF … THEN …

DO … ENDDO DOWHILE (Top Tested Loop) … ENDDO

DOUNTIL (Bottom Tested Loop) … ENDDO

DOFOR (Require Integer Type Control Variables) … BY (Optional) … ENDDO

LEAVE (Exit Loop and Continue with command after ENDDO)

SELECT WHEN … OTHERWISE … ENDSELECT

RETURN (Same function as F3)

Page 50: AS400 Training Part I_Version 1.1

April 21, 2023 50

Crash Course on CL Programming … cont

Monitor Message and Error Handling

Use MONMSG command

Take a look via command WRKMSGF on QSYS/QCPFMSG

Use SNDPGMMSG to show errors

Page 51: AS400 Training Part I_Version 1.1

April 21, 2023 51

Crash Course on CL Programming … cont

Monitor Message and Error Handling

A simple Error Handling Routine example -

PGM DCL &msgid *CHAR 7 DCL &msgf *CHAR 10 DCL &msgflib *CHAR 10 DCL &msgdta *CHAR 100 MONMSG CPF0000 EXEC(GOTO ERROR) . . (Include normal processing here) . RETURN /* Normal end of program */ ERROR: RCVMSG MSGTYPE(*LAST) + MSGDTA(&msgdta) + MSGID(&msgid) + MSGF(&msgf) + SNDMSGFLIB(&msgflib) SNDPGMMSG MSGID(&msgid) + MSGF(&msgflib/&msgf) + MSGDTA(&msgdta) + MSGTYPE(*ESCAPE) ENDPGM

Page 52: AS400 Training Part I_Version 1.1

April 21, 2023 52

Crash Course on CL Programming … cont

File and Data Area

DCLF … CLOF (Declare and Close a File, using OPNID for multiple files), RCVF

OVRDBF and DLTOVR (replacing the file with a different file bearing the same format but having the same or some different characteristics)

CRTDTAARA, CHGDTAARA, DLTDTAARA, RTVDTAARA and DSPDTAARA

*LDA (Local Data Area - Job associated with 1024 bytes storage)

Page 53: AS400 Training Part I_Version 1.1

April 21, 2023 53

Crash Course on CL Programming … cont

Passing Values Between Programs

PGM PARM(&VAR1 &VAR2 &VAR3 … )

CALL PGM(PROGRAM1) PARM((&VAR1 &VAR2 &VAR3 … )

Order and Data Types for parameters must be matched correctly

Page 54: AS400 Training Part I_Version 1.1

April 21, 2023 54

Crash Course on CL Programming … cont

F4 Prompt, Command Continuation and Operators

Use F4 to Prompt for Parameters for a Command

Use + or – for CL Statement Continuation (Note : - includes the leading blanks of the next line)

Arithmetic Operators (+, -, *, /)

Character Operators (*CAT, *BCAT, *TCAT)

Logical Operators (*AND, *OR, *NOT)

Relational Operators (*EQ, *GT, *LT, *GE, *LE, *NE, *NG)

Page 55: AS400 Training Part I_Version 1.1

April 21, 2023 55

Crash Course on CL Programming … cont

Executing SQL in CL Program

A couple ways to achieve this

Use RUNSQLSTM (IBM recommended and provide supported, require setting up a Source SQL File Member)

Use STRQMQRY (require the creation of QUERY object)

Use QZDFMDB2 (an OS Program Object)

Others???

Page 56: AS400 Training Part I_Version 1.1

April 21, 2023 56

Day 5 Exercises

Create a CL program to perform the following functions - - Accept the Library Name and File Name of any Source File - Declare the System File QSYS/QAFDMBRL as the file you are going to open - Create a Data Area with name MBRNBR in your User Library - Use the DSPFD command to output the information of the above file to a temporary file TMP in Library QTEMP - Override the declared file QAFDMBRL to QTEMP/TMP - Retrieve the field MLNOMB and have the value populated into the newly created Data Area MBRNBR - Display the above Data Area and show the values updated <Questions> 1. Do you know what is the function of this program? Discuss with you peers. 2. Re-run your program several times with different Source File Names and verify the results. What happens when you try to run it for the second time? How do you workaround the problem? 3. Include the OPNID in you DCLF and RCVF commands. What happens when you re-compile the program? Use the compilation list to help you work out the solution to get a successful re-compilation. 4. Add codes to send Program Message via SNGPGMMSG in the format of “The number of members in File XXXXXXXXXX are nnnnnnnnnnnn”

Page 57: AS400 Training Part I_Version 1.1

April 21, 2023 57

Day 5 Exercises … continue

Create a Source Physical File QSQLSRC in your library. Add a member SQLEX2 with SQL statement to build a Data File QTEMP/TMP from any existing data file you know of.

Create a CL program to perform the following functions - - Use RUNSQLSTM to execute your SQL above. - Use CPYTOIMPF to copy the data to the a Stream File with the name same as your User ID and suffixed with “EX2.CSV” to Target Directory “/tmp”. (Stream File Code Page should be *PCASCII and Record Delimiter being &CRLF. Remember to use F9 to prompt for all parameters)

<Questions> 1. Compile and execute the program. Check if the Stream File gets created in the Target Directory. 2. Use Main Menu navigate to the Target IFS directory and display the data from the file. They should be in the .csv format with comma delimiters. 3. If your PC is configured to map to this directory, try open the file from Window Explorer to see if MS EXCEL is able to recognize and display the data properly.

Page 58: AS400 Training Part I_Version 1.1

Questions?

Thank you!