Wednesday, March 3, 2010

Procedures within an ILE RPG program

procedure within RPGLE program,

Something more am trying to know about procedure,subprocedure,service program. While googling sample programs and I created one procedure in program. Iam not sure about the the other concepts now. Let me hack it later.
these procedures can be used like built-in functions:-)

http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c092508410.htm


steps for creation:

(1)
A Prototype which specifies the name, return value if any, and parameters if any.

(2)
A Begin-Procedure specification (B in position 24 of a procedure specification)

(3)
A Procedure-Interface definition, which specifies the return value and parameters, if any. The procedure interface must match the corresponding prototype. The procedure-interface definition is optional if the subprocedure does not return a value and does not have any parameters that are passed to it.

(4)
Other definition specifications of variables, constants and prototypes needed by the subprocedure. These definitions are local definitions.

(5)
Any calculation specifications, standard or free-form, needed to perform the task of the procedure. The calculations may refer to both local and global definitions. Any subroutines included within the subprocedure are local. They cannot be used outside of the subprocedure. If the subprocedure returns a value, then the subprocedure must contain a RETURN operation.

(6)
An End-Procedure specification (E in position 24 of a procedure specification)

See sample program:



Rest of the code highlighted:


But default activation group(DFTACTGRP) as 'YES' throwing error while compiling, this can solveed giving as option 'NO'

not sure the reason for this ( need to investigate)
Activation group . . . . . . . . ACTGRP QILE




OUTPUT




See little about free format.... we can write direct statements separated by semicolon in between /free ...and /end-free

Please refer :

Code400.com

Friday, February 26, 2010

RPG flaw in addition

There is flaw in RPG addition , RPG programmers must have to aware of that. If you have twp variable length 2 and the sum is also length 2 then if the real result of addition has 3 digits it will truncate the left most digit rather than throwing an overflow in addition.

See the result:


output

Monday, February 22, 2010

SETLL

see in publib boulder ibm
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/books/c0925083713.htm


CHGPF http://search400.techtarget.com/tips/index/0,289482,sid3_tax2f9,00.html

When the structure of a physical file changes, most AS/400 programmers take the following steps to incorporate the change:

a. Change the DDS to reflect the new structure.

b. Make a copy of the data from the old structure file.

c. Delete any logical files based on the physical file.

d. Recompile the source and rebuild any logical files.

e. Copy the old data back to the new structure, specifying options *DROP and *MAP.

You can use the CHGPF command to achieve the same goal with less effort. When you need to recompile because of a change in file structure, follow these steps:

a. Make the necessary changes to the DDS source.

b. Type CHGPF and press F4 to display the screen below:
�������������������� Change Physical File (CHGPF)

� Type choices, press Enter.
� Physical file� . . . . . .��� ARETURNS�� Name
��� Library� . . . . . . . .����� INVLIB�� Name, *LIBL, *CURLIB
� System . . . . . . . . . .��� *LCL������ *LCL, *RMT, *FILETYPE
� Source file� . . . . . . .��� QDDSSRC��� Name, *NONE
��� Library� . . . . . . . .����� SRCLIB�� Name, *LIBL, *CURLIB

Enter the name of the physical file and the name of the library in which the file resides. Also type the source physical file name and the name of the library in which the source file resides.

c. Press Enter to display the screen below:
�������������������� Change Physical File (CHGPF)

� Type choices, press Enter.
� Physical file� . . . . . . .� ARETURNS�� Name
��� Library� . . . . . . . . .��� INVLIB�� Name, *LIBL, *CURLIB
� System . . . . . . . . . . .� *LCL������ *LCL, *RMT, *FILETYPE
� Source file� . . . . . . . .� QDDSSRC��� Name, *NONE
��� Library� . . . . . . . . .��� SRCLIB�� Name, *LIBL, *CURLIB
� Source member� . . . . . . .� *FILE����� Name, *FILE
� Source listing options . . .������������ *SRC, *NOSRC,*SOURCE...
���������������� + for more values
� Generation severity level� .� 20�������� 0-30
� Flagging severity level� . .� 0��������� 0-30
� Delete dependent logical file *NO������� *NO, *YES
� Remove constraint� . . . . .� *RESTRICT� *RESTRICT, *REMOVE
� Expiration date for member .� *NONE����� Date, *SAME, *NONE

Enter the source member name, and press Enter. This step recompiles the physical and logical files and copies data back. In fact, it does all the steps you've been doing manually.

Note that when you change the DDS to reduce a field's size or drop a field, you may receive a message warning that you may lose your data. You can ignore the message by responding to it with I(gnore).

You can use a similar technique to delete all the logical files based on a physical file. Rather than using the DSPDBR command to find all dependent logicals and then deleting them one by one, simply use the CHGPF command as described above and specify *YES for "Delete dependent logical file" on the second screen to delete all dependent files.