Tuesday, July 28, 2009

(Q&A) What is the Difference if I do the RESET or not?

(From : Oyie)

The CONNECT RESET statement is used to connect to a local database, you can use this if your AS/400 is not yet connected to any SQL servers. By default AS/400 is connected locally, therefore you don't need to execute CONNECT RESET in your program.

Example:
Try using DISCONNECT CURRENT to disconnect to your database, then issue CONNECT RESET to re-establish database connection.

C/EXEC SQL
C+ DISCONNECT CURRENT
C/END-EXEC

C/EXEC SQL
C+ CONNECT RESET
C/END-EXEC


Read More...

Monday, July 27, 2009

(Q&A) Can I connect to another AS400 file with embedded SQL in RPGLE?

(From : Anonymous)

If you are going to connect to a local database you can use CONNECT RESET SQL statement, but if you want to connect to another database/machine, you can connect to the desired machine by replacing the RESET parameter with the name of the remote database.

Read More...

Monday, July 20, 2009

(AS/400 For Dummies) Source Physical Files

Within the course we will be dealing with 3 kinds of files that contain members. Source Physical Files, Physical Files and Logical Files. Let's discuss first their differences. Physical files are files that contain data, Source Physical Files contain program sources, Logical Files do not contain data or program sources, it is a file that provides a view of the data stored into the Physical file.

In this chapter we will learning on how to create source physical file and on how to create source physical file members.

We need to create the following source physical files:
1) QDDSSRC - SRC-PF for Physical Files and Logical Files
2) QDSPSRC - SRC-PF for Display Files
3) QPRTSRC - SRC-PF for Printer Files
4) QRPGSRC - SRC-PF for RPG Program
5) QCLSRC - SRC-PF for CL Program
6) QRPGLESRC - SRC-PF for RPG ILE Program
7) QCLLESRC - SRC-PF for CL ILE Program

1-5 will have lengths of 92 while 6 and 7 will have 112.

Let's create QDDSSRC. On the command line type CRTSRCPF then press F4 key. Your screen should be like this:












Under the FILE parameter type QDDSSRC, then for the LIBRARY type the name of the library that you have created, in my case it's MYLIBRARY. For the LENGTH it should be 92, then for the DESCRIPTION type "PF and LF Sources". Your screen should look like this:












Then press ENTER key. You have now crreated your first SRC-PF. You can do the same method for the remaining 6 SRC-PFs, for items 6 and 7 don't forget to change the lenght to 112.


You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial

Read More...

Friday, July 17, 2009

(AS/400 For Dummies) Creating Your First Library

Now that you are somewhat familiar with the AS/400 environment, let us try to create your personal library.

In the command line just type CRTLIB then press F4 key. Your screen should look like this:













We just need to supply the following parameters: Library (LIB), Library Type (TYPE) and Text Description (TEXT).
a) LIB, input the desired library name.
b) TYPE, input *TEST, since this is just a test library.
c) TEXT, input the description of your library.

See sample inputted parameter values:













After you are done setting up the parameters just press ENTER key. You now have created your first library.

You can also create the library using this command (w/o prompt screen):
CRTLIB LIB(MYLIBRARY) TYPE(*TEST) TEXT('My First Library')

You can check if the library was successfully created by using WRKOBJ command.
WRKOBJ OBJ(MyLibrary)


You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial

Read More...

Thursday, July 16, 2009

(AS/400 For Dummies) Programming Development Manager (PDM)

Now, let's start talking about PDM. PDM is a part of application development tools which helps us work with libraries, objects and members. With PDM we can do library, object and member manipulation using a menu type interface, this is very useful for AS/400 beginners.

Here are some of PDM functions:
1) Work with libraries.
2) Work with objects.
3) Work with members.
4) Work with user defined options.

We can start using PDM menu by typing STRPDM on the command line then press ENTER key. Your screen would look like this:












Options 1-3 can be done using the following shortcut commands.
1)WRKLIBPDM - for library manipulation.
2)WRKOBJPDM - for object manipulation.
3)WRKMBRPDM - for member manipulation.

For the 3 commands, we can notice that WRKxxxPDM is common. For "xxx" we can substitute LIB (for library), OBJ (for object) and MBR (for member).

To manipulate library/object/member you can use the top options list as your reference for desired action. Options list is located here (inside the red box):












For example, you want to copy DEMO library, you can type "3" on the option field located at the leftmost portion of the list of libraries, then press ENTER key, now you will be prompted to enter new library name, after inputting the new name you can now press ENTER again.


You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial

Read More...

Tuesday, July 14, 2009

(AS/400 For Dummies) AS/400 Libraries

In AS400, libraries are very important to one's AS/400 job. Each AS/400 job has it own library lists. A library list is an ordered list of library names. It identifies the libraries that a user can use within a job and it also sequentially orders library priority.

By default, user only have the following system defined libraries to work on.

QSYS
QSYS2
QHLPSYSQUSRSYS
QGPL
QTEMP

We can use ADLIBLE or EDTLIBL to add user defined libraries.

Here's a list of commands that we can use to manipulate libraries.
1) DSPLIBL - it displays current library list.

























2) CHGLIBL - it is used to change user portion of the current job's library list.
























3) ADDLIBLE - adds single library to user portion of the library list.
























4) RMVLIBLE - removes single library from the user portion of the library list.
























5) EDTLIBL - It displays current library list and it also allows the user to make changes in the user portion of the library list.























You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial

Read More...

Monday, July 13, 2009

(AS/400 For Dummies) OS/400

OS/400

- AS/400's operating system. It is designed to cater multi-user and multi programming machine. It allows simultaneous program execution and program processing. The importance of understanding this will be helpful later in the course.


OS/400 Functions:

a) Programming
-Different programming utilities are available for developers. Such utilities are as follows: Source Entry Utility (SEU), Screen Design Aid (SDA), Report Layout Utility (RLU), Data File Utility (DFU), Query Utilities, Structured Query Language (SQL), etc. These utilities are very helpful in creating programs.

b) Data Management
-OS/400 offers data file maintenance. It allows both physical files and logical files data management.

d) Spooling Functions
-The OS also comes with printing queue functions, this is very important in a multi-user environment.

e) Work Management
-It allow administrators to manage job within the system. It's also very helpful in resources allocation and maintenance.

f) Security Functions
-OS/400 contains numerous access control features that makes AS/400 a very secured machine.


Common OS/400 Object Types:

1) Libray (*LIB)
-Libraries are logical spaces that holds objects. This is the place where you place your files, programs, out queues, job queues, etc. If you will compare it to PC it's like a directory. But unlike "directories", libraries can not contain another library whithin itself.

2) File (*FILE)
-Files are the ones holding the data, either permanent or temporary data. It can be one of the following; Physical File, Logical File, Display File, Printer File, Source Physical File, etc.

3) Program (*PGM)
-Executable programs. It is the object produced after compiling you program source.


OS/400 Commands:

OS/400 command is consist of command name and parameters. Command name is the instruction on what the user wants to do. Parameters are the details of the command operation.

Command names are in a simple VERB/NOUN construction, the the verb usually contains 3 character.
Examples:
1) DLT is for Delete Function
2) CHG is for Change Function
3) RNM is for Rename Function

Noun defines the object you want to access.
Examples:
1) F is for File
2) PF is for Physical File
3) OBJ is for Object.

Let's try to issue a command using the VERB and NOUNE combination.
a) To delete a file the command name should be: DLTF
b) To transfor object from one library to another the command name should be: MOVOBJ
c) To rename an obect the command name should be: RNMOBJ

To supply parameters, simply type the command name in the command line then press "F4" key, OS/400 will prompt user for required parameters.


You Might Also Want To Visit The Following Tutorial Posts:
AS/400 For Dummies
AS/400 Tutorial
SQL/400 Tutorial
Query/400 Tutorial

Read More...

(Q&A) Why do we hit a session device error?

(From : Anonymous)

There are three types of AS/400 session device error:

1. Permanent device or session error on I/O operation

A major return code of 81 indicates a serious error that affects the device or session.

These errors include hardware failures that affect the device, communications line, or communications controller. It also includes errors because of a device being disconnected or powered off unexpectedly, and abnormal conditions that are discovered by the device and reported back to the system. Both the minor return code and the accompanying message provide more specific information about the cause of the problem.

Depending on the file type, the program must either close the file and open it again, release the device and acquire it again, or acquire the session again. To reset an error condition in a shared file by closing it and opening it again, all programs sharing the open data path must close the file. In some cases, the message might instruct you to reset the device by varying it off and on again. It is unlikely that the program will be able to use the failing device until the problem causing the error is found and corrected, but recovery within the program might be possible if an alternate device is available.

Some of the minor return codes in this group are the same as those for the 82 major return code. Device failures or line failures might occur at any time, but an 81 major code occurs on an I/O operation. This means that your program had already established a link with the device or session. Therefore, the program can transfer some data, but when the program starts from the beginning when it starts again. A possible duplication of data might result.

Message numbers accompanying an 81 major code might be in the range that indicates either an I/O or a close operation. A device failure on a close operation might be the result of a failure in sending the final block of data, rather than action specific to closing the file. An error on a close operation can cause a file to not close completely. Your error recovery program should respond to close failures with a second close operation. The second close will always complete, regardless of errors.

2. Device or session error on open or acquire operation

A major return code of 82 indicates that a device error or a session error occurred during an open or acquire operation. Both the minor return code and the accompanying message will provide more specific information regarding the cause of the problem.

Some of the minor return codes in this group are the same as those for the 81 major return code. Device or line failures might occur at any time, but an 82 major code indicates that the device or session was unusable when your program first attempted to use it. Thus no data was transferred. The problem might be the result of a configuration or installation error.

Depending on the minor return code, it might be appropriate for your program to recover from the error and try the failing operation again after some waiting period. You should specify the number of times you try in your program. It might also be possible to use an alternate or backup device or session instead.

Message numbers accompanying an 82 major code might be in the range that indicates either an open or acquire operation. If the operation is an open operation, it is necessary to close the partially opened file and reopen it to recover from the error. If the operation is an acquire operation, it might be necessary to do a release operation before trying the acquire operation again. In either case, specify a wait time for the file that is long enough so that the system can recover from the error.

3. Recoverable device or session errors on I/O operation

A major return code of 83 indicates that an error occurred in sending data to a device or receiving data from the device. Recovery by the application program is possible. Both the minor return code and the accompanying message provide more specific information regarding the cause of the problem.

Most of the errors in this group are the result of sending commands or data that are not valid to the device, or sending valid data at the wrong time or to a device that is not able to handle it. The application program can recover by skipping the failing operation or data item and going on to the next one, or by substituting an appropriate default. There might be a logic error in the application.

The most common one is type 2, wherein you are trying to write an empty subfile. To find out the details of the encountered error, check the session's joblog by using DSPJOBLOG command then press ENTER, F10, PAGEUP, point your cursor to the error then hit F1.
Read More...

Friday, July 10, 2009

(FAQ) How To Convert Numeric To Character Format In AS/400 RPG-ILE.

We can convert numeric to character format in two ways; using BIF %CHAR and %EDITC.

1. %CHAR(expression{:format})

%CHAR converts the value of the expression from graphic, UCS-2, numeric, date,time or timestamp data to type character. The converted value remains unchanged,
but is returned in a format that is compatible with character data.

Sample:






a. To format the time and date with the default formats, use this:

result = ’It is ’ + %CHAR(time) + ’ on ’ + %CHAR(date)

b. To format the time and date with specific formats, use this:

result = ’It is ’ + %CHAR(time : *hms:) + ’ on ’ + %CHAR(date : *iso)

c. You can use %subst with the %char result if you only want part of the result:

result = ’The time is now ’ + %SUBST (%CHAR(time):1:5) + ’.’

d. Use %CHAR to convert a graphic value to character so it can be concatenated with a character value:

result = ’The customer’’s name is ’ + %CHAR(Name) + ’.’

e. Use %CHAR to convert a number to character format:

result = ’You have ’ + %char(points) + ’ points.’


2. %EDITC(numeric : editcode {: *ASTFILL | *CURSYM | currency-symbol})

This function returns a character result representing the numeric value edited
according to the edit code. In general, the rules for the numeric value and edit
code are identical to those for editing numeric values in output specifications. The
third parameter is optional, and if specified, must be one of:

a. *ASTFILL
Indicates that asterisk protection is to be used. This means that leading
zeros are replaced with asterisks in the returned value. For example,
%EDITC(-0012.5 : ’K’ : *ASTFILL) returns ’***12.5-’.

b. *CURSYM
Indicates that a floating currency symbol is to be used. The actual symbol
will be the one specified on the control specification in the CURSYM
keyword, or the default, ’$’. When *CURSYM is specified, the currency
symbol is placed in the the result just before the first significant digit. For
example, %EDITC(0012.5 : ’K’ : *CURSYM) returns ’ $12.5 ’.

c. currency-symbol
Indicates that floating currency is to be used with the provided currency
symbol. It must be a 1-byte character constant (literal, named constant or
expression that can be evaluated at compile time). For example,
%EDITC(0012.5 : ’K’ : ’X’) returns ’ X12.5 ’.

List of Edit Codes:


X – (obsolete; but it does retain leading zeros!)
Y – Slash insertion for date
Z – Zero suppresses leading zeros (no decimals, negatives)


Sample:




Read More...

Thursday, July 9, 2009

(Tips) Renaming Program Indicators AS/400 RPG

Naming your numeric indicators used in screen displays or printer files is an effective way to make your programs more readable and understandable, but did you know there are two ways it can be done? The first method is associating a data structure using the INDDS keyword, and the second method is by address association using the BASED keyword.

The first method uses the INDDS keyword which references a data structure. Within the data structure you give each indicator you use a unique name. So instead of saying IF *IN99 = *ON, you can say IF ERROR = *ON. This provides someone who has never been in the program before a better understanding of what the test is, instead of having to hunt down every occurrence of the indicator and figure it out from there.












The keyword INDDS references a data structure named Indicators. The data structure is a length of 99, but you don't need to specify every indicator, only the ones you're using. Additionally, the keyword INDARA needs to be present in the display or printer file you're referencing. The data structure can be referenced by more than one display and/or printer file within the program. You can also create separate ones for each. The second method uses the BASED keyword. It is similar to the first method except it does not require changes to the file specifications or either the display or printer files; all the changes are in the data structure, like so:







Here, the built-in function %ADDR references the Indicator array, and BASED references the data structure you provide. A difference between the two methods is that the first method can refer to a different data structure for each display and/or printer file you use, whereas the second one would apply to all. Here's an added tip, regardless of which method you use. You are not restricted to one name for each indicator. It is possible to supply multiple names for each. For example if indicator 50 is used to condition a field on two different screens, each with a different meaning, you can specify something like this within the data structure:



This way you're not stuck using a name in another part of the program that isn't the intended meaning. A word of caution however, as when you condition one of the named indicators above, it affects both when they're sharing the same indicator within a data structure. As long as this is kept in mind when designing the program, you'll be OK.
Read More...

Wednesday, July 8, 2009

(iSeries Blunders) Part III

December 14th, 2005 by ReiVi
Source : http://techblog.livingatrandom.com

There was this one time that I was at a client site doing some programming work. I noticed that one of the system operators was removing and then re-inserting a cartridge from the AS/400’s tape drive. He would walk back to the main console and type something. Shaking his head he would go through the entire process again.

After a few more minutes, I heard him mutter what sounded like a mixture of a curse and thank you.

I couldn’t take it anymore, so I asked him what happened.

Apparently, he was trying to initialize the tape in preparation for a backup. Whenever he typed the INZTAP command on the console, it would return an error that there was no tape in the drive. He removed and re-inserted the tape. He even tried using brand new tapes to no avail. Finally, he decided to signoff of the AS/400. Just before signing back-in, he noticed that he was connected to the remote AS/400 all that time.

He was very thankful that there was no tape on the remote (production environment) AS/400. If there’d been one — and it contained important data — he would have unknowingly erased it’s contents.

Lesson learned: If you work for a company that has multiple AS/400’s — whether local or remote — make sure that you are connected to the correct machine before doing anything.
Read More...

(iSeries Blunders) Part II

August 22nd, 2005 by ReiVi
Source : http://techblog.livingatrandom.com

Have you ever worked on two programs at the same time? You are coding this current requirement when a user comes up to you from behind and blurts out, “Can you fix this? We just need an additional column on the report. My boss needed it yesterday.” Sound familiar? Knowing that it won’t take you an hour to do the modification, you agree.

Now, the thing here is, you are using a dumb terminal. Since you don’t want to exit your current task and mess up all the library list settings and stuff, you decide to use the dumb terminal next to it. You open the code up in SEU and start coding.

All of a sudden, you remembered the user never gave you the change request form. Your boss gave everyone a briefing on the subject just the other day. Setting, the keyboard aside, you call the user and request for the necessary paperwork.

While waiting for the change request to arrive, you decide to go back to your original task. Reaching for the keyboard, you start to type. But nothing happens. You hit the reset key. Still nothing. In desperation you start hitting random keys with your fingers like you are touch typist gone mad! Nothing’s happening.

“Oh no! I haven’t even saved my work yet! That’s almost a half-day’s work!”, you murmur to yourself.

As you hang your head, you glance at the other terminal and notice that the screen is garbled. What used to be code is now a jumbled mess of letters and numbers!

“What happened?”, you ask yourself in horror.

Tracing the cable of the keyboard you are using, you realize that you were using the keyboard for the other terminal!

“This has got to be the worse day in my life. Now I messed up two program codes!”

With a prayer you press F5 to refresh the screen.

The jumbled screen refreshes and you see your code, you say a short prayer thanking the heavens for your good fortune. Just then the user arrives with the change request.
Read More...

(iSeries Blunders) Part I

August 20th, 2005 by ReiVi
Source : http://techblog.livingatrandom.com

Since this is my first article, I decided to look back at my career. Starting out in 1996 with a small IT company, I was a fresh graduate and like other graduates, I had no idea what an AS/400 (which is what they called the iSeries back then) was. Naturally, I was pretty excited. When I say this big refrigerator in the middle of the room, I said to myself, “Cool! I get to program using a mainframe!” The other trainees and I were told later that day however, that it was a midrange.

“Huh? A mid-what?”

Since our exposure in college was focused on PC’s and DOS (Yeah, yeah, yeah. It was that long ago), we only had a rough idea of what other platforms were. Heck, we thought mainframes belonged to musuems even then. The dumb terminals that were assigned to us were really big…about the size of a microwave oven.

Eventually, the other trainees and I went through…well…training. We were all coding happily one day when one of us suddenly had an endless loop in a piece of code. No problem! Just press Ctrl-C or Ctrl-Break. But how? There isn’t even a Ctrl key!

Since it was almost time to go home anyway, we all suggested to our colleague, “Just turn the terminal off and we’ll go home. You can find the bug tomorrow.”

Imagine our suprise when we were all called down to our boss’ office the following day. We found out the hard way that turning the terminal off doesn’t necessarily end the job. We all were given a long lecture on how to use the System-Request key.
Read More...

(Tips) Uses of OVERLAY Op-Code AS/400 RPG ILE

The OVERLAY keyword overlays the storage of one subfield with that of another
subfield, or with that of the data structure itself. This keyword is allowed only for
data structure subfields.

Usage:
OVERLAY(name{:pos | *NEXT})

The Name-entry subfield overlays the storage specified by the name parameter at
the position specified by the pos parameter. If pos is not specified, it defaults to 1.

Examples:
A. Storage Allocation of Subfields with Keywords DIM and OVERLAY











B. Storage Allocation of Subfields with Keywords DIM and OVERLAY










C. Defining Subfield Overlay Positions with *NEXT








Read More...

Tuesday, July 7, 2009

(Tips) Coding AS/400 RPG ILE Arrays

Here are samples on how to code arrays in RPG.
Definition Specifications for Different Types of Arrays:




Read More...

(Tips) Useful AS/400 RLU Commands

The following line commands are available in RLU, in addition to most SEU line commands:

DR - Define Record Format
CL - Change Line Type
SD - Create Sample Data
VF - View Field Line
NP - New Page
DC - Define Constants
DF - Define Fields
CF - Center Fields
SP - Space Fields Evenly

Read More...

Monday, July 6, 2009

(FAQ) How To Know Which AS/400 RPG Programs Are Using Specific Objects

It is very important for us to know which programs are using specific objects. For example you have updated a file, added/deleted some fields or changed field lengths. We need to know which programs need to be recompiled. We can use DSPPGMREF (Display Program Reference) command to create a file that maps all objects to all programs.

Command:
DSPPGMREF PGM(*ALL) OUTPUT(*OUTFILE) OBJTYPE(*ALL) OUTFILE(MYLIB/MYFILE)

Now you have created a file MYFILE in library MYLIB that contains list of programs with objects referenced to them.

To know which program uses MYPF file we can use SQL to retrieve it.

Command:
STRSQL

SELECT * FORM MYLIB/MYFILE
WHERE WHFNAM = 'MYPF'

Note:
WHFNAM is the object referencing to the program.


Read More...

(FAQ) AS/400 Journal Restrictions

The Create Journal (CRTJRN) command creates a journal as a local journal with the specified attributes, and attaches the specified journal receiver to the journal. Once a journal is created, object changes can be journaled to it or user entries can be sent to it. The journal state of the created journal is *ACTIVE.

Restrictions:
• A journal cannot be created in the library QTEMP.
• The receiver specified must be created before issuing this command and it must be empty (that is, the receiver must not have been previously attached to a journal or have been in the process of being attached to a journal).
• This command cannot be used to create a remote journal. See the ADDRMTJRN (Add Remote Journal) command description or the Add Remote Journal (QjoAddRemoteJournal) API in the System API Reference information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter.
• If RCVSIZOPT(*MAXOPT1 or *MAXOPT2 or *MAXOPT3) is not to be in effect for the journal, the maximum threshold value that can be specified for any journal receiver being attached is 1,919,999 kilobytes.
• If the library to contain the journal is on an independent ASP then the journal receiver specified must be located on an independent ASP that is in the same ASP group as the journal's library. Likewise, if the library to contain the journal is not on an independent ASP, then the journal receiver specified cannot be located on an independent ASP.
• If the library to contain the journal is on an independent ASP then ASP(*LIBASP) must be specified.
• RCVSIZOPT(*MINFIXLEN) and FIXLENDTA cannot be used for the system security audit journal QSYS/QAUDJRN. Journal entries in the security audit journal are required to contain all possible data that could be used for auditing purposes.


Read More...

(FAQ) How To Use Commitment Control In AS/400

With Commitment Control, you ensure one of two outcomes for the file operations: either all of the file operations are successful or none of the file operations has any effect. In this way, you process a group of operations as a unit.

To use Commitment Control, you do the following:

• Use the CL commands CRTJRN (Create Journal), CRTJRNRCV (Create Journal Receiver) and STRJRNPF (Journal Physical File) to prepare for using commitment control, and the CL commands STRCMTCTL (Start Commitment Control) and ENDCMTCTL (End Commitment Control) to notify the system when you want to start and end commitment control. See the CL Reference for information on these commands.
• Specify commitment control on the file-description specifications of the files you want under commitment control.
• Use the COMMIT operation code to apply a group of changes to files under commitment control, or use the ROLLBACK operation code to eliminate the pending group of changes to files under commitment control.

Starting and Ending Commitment Control

The CL command STRCMTCTL notifies the system that you want to process files under commitment control.
The LCKLVL (Lock Level) parameter allows you to select the level at which records are locked under commitment control.
When you complete a group of changes with a COMMIT operation, you can specify a label to identify the end of the group. In the event of an abnormal job end, this identification label is written to a file, message queue, or data area so that you know which group of changes is the last group to be completed successfully. You specify this file, message queue, or data area on the STRCMTCTL command.
Before you call any program that processes files specified for commitment control, issue the STRCMTCTL command. If you call a program that opens a file specified for commitment control before you issue the STRCMTCTL command, the opening of the file will fail.
The CL command ENDCMTCTL notifies the system that your routing step has finished processing files under commitment control.

Specifying Files for Commitment Control

When a program specifies commitment control for a file, the specification applies only to the input and output operations made by this program for this file. Commitment control does not apply to operations other than input and output operations. It does not apply to files that do not have commitment control specified in the program doing the input or output operation.
When more than one program accesses a file as a shared file, all or none of the programs must specify the file to be under commitment control.

Commitment Control Operations

The COMMIT operation tells the system that you have completed a group of changes to the files under commitment control. The ROLLBACK operation eliminates the current group of changes to the files under commitment control.
If the system fails, it implicitly issues a ROLLBACK operation. You can check the identity of the last successfully completed group of changes using the label you specify in F1 of the COMMIT operation code, and the notify-object you specify on the STRCMTCTL command.
At the end of a routing step, or when you issue the ENDCMTCTL command, the OS/400 system issues an implicit ROLLBACK, which eliminates any changes since the last ROLLBACK or COMMIT operation that you issued. To ensure that all your file operations have effect, issue a COMMIT operation before ending a routing step operating under commitment control.
The OPEN operation permits input and output operations to be made to a file and the CLOSE operation stops input and output operations from being made to a file. However, the OPEN and CLOSE operations do not affect the COMMIT and ROLLBACK operations. A COMMIT or ROLLBACK operation affects a file, even after the file has been closed. For example, your program may include the following steps:
1. Issue COMMIT (for files already opened under commitment control).
2. Open a file specified for commitment control.
3. Perform some input and output operations to this file.
4. Close the file.
5. Issue ROLLBACK.
The changes made at step 3 are rolled back by the ROLLBACK operation at step 5, even though the file has been closed at step 4. The ROLLBACK operation could be issued from another program in the same routing step.
A program does not have to operate all its files under commitment control, and to do so may adversely affect performance. The COMMIT and ROLLBACK operations have no effect on files that are not under commitment control.
When multiple devices are attached to an application program, and commitment control is in effect for the files this program uses, the COMMIT or ROLLBACK operations continue to work on a file basis and not by device. The database may be updated with partially completed COMMIT blocks or changes that other users have completed may be eliminated. It is your responsibility to ensure this does not happen.

Commitment Control Locks

On the STRCMTCTL command, you specify a level of locking, either LCKLVL (*ALL) or LCKLVL (*CHG). When your program is operating under commitment control and has processed an input or output operation on a record in a file under commitment control, the record is locked by commitment control as follows:
• Your program can access the record.
• Another program in your routing step, with this file under commitment control, can read the record. If the file is a shared file, the second program can also update the record.
• Another program in your routing step that does not have this file under commitment control cannot read or update the record.
• Another program in a separate routing step, with this file under commitment control, can read the record if you specified LCKLVL (*CHG), but it cannot read the record if you specified LCKLVL (*ALL). With either lock level, the next program cannot update the record.
• Another program that does not have this file under commitment control and that is not in your routing step can read but not update the record.
• Commitment control locks are different than normal locks, depend on the LCKLVL specified, and can only be released by the COMMIT and ROLLBACK operations.
• The COMMIT and ROLLBACK operations release the locks on the records. The UNLCK operation will not release records locked using commitment control. See the CL Reference for details on lock levels.
• The number of entries that can be locked under commitment control before the COMMIT or ROLLBACK operations are required may be limited.

Commitment Control in the Program Cycle

Commitment control is intended for full procedural files, where the input and output is under your control. Do not use commitment control with primary and secondary files, where input and output is under the control of the RPG/400 program cycle. The following are some of the reasons for this recommendation:
• You cannot issue a COMMIT operation for the last total output in your program.
• It is difficult to program within the cycle for recovery from a locked-record condition.
• Level indicators are not reset by the ROLLBACK operation.
• After a ROLLBACK operation, processing matching records may produce a sequence error.


Read More...

Friday, July 3, 2009

(FAQ) What are AS/400 Data Queue APIs?

Data queues are a type of system object that you can create, to which one high-level language (HLL) program can send data, and from which another HLL program can receive data. The receiving program can be waiting for the data, or can receive the data later.

Before using a data queue, you must first create it using the Create Data Queue (CRTDTAQ) command.

The data queue APIs are:

* Clear Data Queue (QCLRDTAQ) clears all entries from a data queue.


Required Parameter Group:

1 Data queue name Input Char(10)
2 Library name Input Char(10)

Optional Parameter Group:

3 Key order Input Char(2)
4 Length of key data Input Packed(3,0)
5 Key data Input Char(*)
6 Error code I/O Char(*)

Default Public Authority: *USE


* Receive Data Queue (QRCVDTAQ) receives data from the specified data queue.

Required Parameter Group:

1 Data queue name Input Char(10)
2 Library name Input Char(10)
3 Length of data Output Packed(5,0)
4 Data Output Char(*)
5 Wait time Input Packed(5,0)

Optional Parameter Group 1:

6 Key order Input Char(2)
7 Length of key data Input Packed(3,0)
8 Key data I/O Char(*)
9 Length of sender information Input Packed(3,0)
10 Sender information Output Char(*)

Optional Parameter Group 2:

11 Remove message Input Char(10)
12 Size of data receiver Input Packed(5,0)
13 Error code I/O Char(*)

Default Public Authority: *USE

* Retrieve Data Queue Description (QMHQRDQD) retrieves information about a data queue.

Required Parameter Group:

1 Receiver variable Output Char(*)
2 Length of receiver variable Input Binary(4)
3 Format name Input Char(8)
4 Qualified data queue name Input Char(20)

Default Public Authority: *USE

Threadsafe: Yes

* Retrieve Data Queue Message (QMHRDQM) retrieves an entry from a data queue without removing the entry.

Required Parameter Group:

1 Receiver variable Output Char(*)
2 Length of receiver variable Input Binary(4)
3 Format name Input Char(8)
4 Qualified data queue name Input Char(20)
5 Message selection information Input Char(*)
6 Length of message selection information Input Binary(4)
7 Message selection information format name Input Char(8)
8 Error code I/O Char(*)

Default Public Authority: *USE

Threadsafe: Yes

* Send to a Data Queue (QSNDDTAQ) sends data to the specified data queue.

Required Parameter Group:

1 Data queue name Input Char(10)
2 Library name Input Char(10)
3 Length of data Input Packed(5,0)
4 Data Input Char(*)

Optional Parameter Group 1:

5 Length of key data Input Packed(3,0)
6 Key data Input Char(*)

Optional Parameter Group 2:

7 Asynchronous request Input Char(10)

Optional Parameter Group 3:

8 Data is from a journal entry Input Char(10)

Default Public Authority: *USE

Threadsafe: Conditional

Read More...

(FAQ) How to DEBUG in Batch Mode.

To debug in batch mode, just follow these steps:

a) Submit your program to batch. The job MUST be held. You can either hold the job queue (HLDJOBQ) or hold the individual job (HLDJOB) or specify HOLD(*YES) on the SBMJOB command.

b) WRKSBMJOB/WRKUSRJOB/WRKACTJOB and find your submitted job. Note that the SBMJOB command gives you an informational message with the job name/number. What you need is the job name, user ID and job number - the fully qualified job name. Example: 123456/BUCK/MONTHEND

c) STRSRVJOB on the held batch job.

d) STRDBG on your program. Specify UPDPROD(*YES) if needed. You'll see the source listing if you compiled with DBGVIEW(*LIST) or *SOURCE.

e) Press F12 to exit - you cannot set a breakpoint yet.

f) Release the job so that it becomes STATUS(*ACTIVE).

g) You'll see a display asking if you want to debug or continue. Press F10 to debug.

h) DSPMODSRC to see the source listing again. Alternately, press F10 to step into the first instruction.

i) Now you can add your breakpoints.

j) Press F3 until you're back to the "debug or continue" display. Press Enter to run the program with your breakpoints set.

k) When you're done, do an ENDDBG and ENDSRVJOB.
Read More...

(FAQ) How To Transfer AS400 Objects to Another Machine

These steps will help us transfer objects from one machine to another.
1) Create save file. This save file will contain the objects that we are going to transfer. This must be created on both machines.

Command: CRTSAVF FILE(MYLIBRARY/MYSAVF) TEXT('My Save File')

2) Save Objects to save file (*SAVF). You can now save your desired object to your save file.

Command: SAVOBJ OBJ(MYSRCPF) LIB(MYLIB) DEV(*SAVF) SAVF(MYLIB/MYSAVF)

3) Now you can now transfer save file (*SAVF) to the other machine using FTP.

Command: FTP RMTSYS('111.11.11.11')
- User: UserName
- Password: Password
- Binary
- Put MyLib/MySavF MyLib/MySavf
- Quit

4) After completion of FTP, you can now restore your object (from the *SAVF) to machine 2.

Command: RSTOBJ OBJ(*ALL) SAVLIB(MYLIB) DEV(*SAVF) SAVF(MYLIB/MYSAVF)

Read More...

Thursday, July 2, 2009

(FAQ) Difference Between SKIPA/SPACEA and SKIPB/SPACEB

SKIPA (Skip After) keyword in printer files
Use this file-, record-, or field-level keyword to specify that the printer device is to skip to a specific line number after it prints one or more lines. The format of the keyword is: SKIPA(skip-after-line-number)

SPACEA (Space After) keyword in printer files
Use this record- or field-level keyword to specify that the printer device is to space some number of lines after it prints one or more lines. The format of the keyword is: SPACEA(space-after-value)

SKIPB (Skip Before) keyword in printer files
Use this file-, record-, or field-level keyword to specify that the printer device is to skip to a specific line number before it prints the next line(s). The format of the keyword is: SKIPB(skip-before-line-number)

SPACEB (Space Before) keyword in printer files
Use this record- or field-level keyword to specify that the printer device is to space some number of lines before it prints the next line or lines. The format of the keyword is: SPACEB(space-before-value)
Read More...