Monday, October 1, 2007

The RPGIV for the 3-Column Subfile



*************************************************************
* A program to select from 3 different files *
* 6/00 Booth Martin *
* *
* *
*************************************************************
FSFL3ColFM CF E WORKSTN
F SFILE(SFLA:RRN)
FFilters1P IF E DISK
FFilters2P IF E DISK
FFilters3P IF E DISK

D ReadFilters1P S 3 INZ('Yes')
D ReadFilters2P S 3 INZ('Yes')
D ReadFilters3P S 3 INZ('Yes')

* Arrays of Selected Items
D Inx S 3S 0
D Inx1 S 3S 0
D AR1 S 2 DIM(60)
D Inx2 S 3S 0
D AR2 S 2 DIM(60)
D Inx3 S 3S 0
D AR3 S 2 DIM(60)

* ..................................................

C Z-ADD 1 RRN 4 0

* Clear subfile & screen, prepare to re-fill or fill:
C Eval *IN90=*OFF
C Clear SFLA
C Write FOOTer
C Write FMT01
C EXSR FillSubfileSR

**
C RRN IFLT 11
C MOVE *ON *IN91
C END
C MOVE *ON *IN90
C WRITE FOOTer

C DoW *INLR = *Off
C EXFMT FMT01
C Read Footer

C Select

* Footer Push button Choices:
* Refresh Subfile:
C When PB1 = 1 Or *INKE = *On
C Eval ReadFilters1P = 'Yes'
C Eval ReadFilters2P = 'Yes'
C Eval ReadFilters3P = 'Yes'
C GOTO RefreshTag
* Run the job
C When PB1 = 2 Or *INKJ
C Exsr AcceptSR
C Eval *INLR = *ON
* end the job
C When PB1 = 3 or *INKC Or *INKL
C Eval *INLR = *ON

* Mouse clicked in Column 1, toggle the field
* (Note: The DDS has a mouse button click = F11. The reason for this is
* so that a regular Enter while the cursor is in a Filter field
* won't toggle the field's value. F11=*INKK)

C When FLD = 'COL1O' And *INKK
C Relrcd Chain SFLA
C If Col1o = 'Y'
C Eval Col1o = ' '
C Else
C Eval Col1o = 'Y'
C End
C Update Sfla

* Mouse clicked in Column 2, toggle the field
C When FLD = 'COL2O' And *INKK
C Relrcd Chain SFLA
C If Col2o = 'Y'
C Eval Col2o = ' '
C Else
C Eval Col2o = 'Y'
C End
C Update Sfla

* Mouse clicked in Column 3, toggle the field
C When FLD = 'COL3O' And *INKK
C Relrcd Chain SFLA
C If Col3o = 'Y'
C Eval Col3o = ' '
C Else
C Eval Col3o = 'Y'
C End
C Update Sfla

C EndSL
C END

C RefreshTag Tag
* _________________________________________________________________
C AcceptSR BegSR
* If a choice was made, then do the required action:
C Eval Inx = 1
C Eval Inx1 = 1
C Eval Inx2 = 1
C Eval Inx3 = 1

C Inx Chain SFLA

C If %Found
C DoU %EOF or Not %Found

C If Col1o = 'Y'
C Eval Ar1(Inx1) = Col1H
C Eval Inx1 = Inx1 + 1
C End

C If Col2o = 'Y'
C Eval Ar2(Inx2) = Col2H
C Eval Inx2 = Inx2 + 1
C End

C If Col3o = 'Y'
C Eval Ar3(Inx3) = Col3H
C Eval Inx3 = Inx3 + 1
C End

C Eval Inx = Inx + 1
C Inx Chain SFLA
C EndDo
C EndIf
* Sort the arrays so we can do look ups:
C Sorta AR1
C Sorta AR2
C Sorta AR3

* Write a file of records for printing the report(s):
C Exsr WriteRecordSR

C EndSR
* _________________________________________________________________
C WriteRecordSR BegSR
* This sub routine is blank. It is trivial to add whatever code is
* needed to make the filters selected be useful. The purpose of this
* exercise is to show the 3-column subfile and the toggling of the values
C EndSR
* _________________________________________________________________
C FillSubfileSR BegSR

C 1 Setll Filters1P
C 1 Setll Filters2P
C 1 Setll Filters3P

C DoW ReadFilters1P = 'Yes' Or
C ReadFilters2P = 'Yes' Or
C ReadFilters3P = 'Yes'
C Exsr WriteLineSR
C Write SFLA
C Eval RRN = RRN + 1
C End

C Eval NBRREC = RRN
C EndSR
* _________________________________________________________________
* Write the line in the subfile:
C WriteLineSR BegSR

* Column 1: Status
C Eval Col1O = ' '
C Eval Col2O = ' '
C Eval Col3O = ' '

* Column 1: Filters 1
C Eval Col1 =*Blanks
C Eval Col1H =' '
C If ReadFilters1P = 'Yes'
C Read Filters1P

C If Not %EOF
C Eval Col1 = TypeID + ' ' + TYPEDS
C Eval Col1H = TypeID
C Eval Col1O = 'Y'
C Else
C Eval ReadFilters1P = 'No '
C End

C End

* Column 2: Filters2P
C Eval Col2 =*Blanks
C Eval Col2H =' '

C If ReadFilters2P = 'Yes'
C Read Filters2P

C If Not %EOF
C Eval Col2 = ST + ' ' + STATE
C Eval Col2H = ST
C Eval Col2O = 'Y'
C Else
C Eval ReadFilters2P = 'No '
C End

C End

* Column 3: FiltersP
C Eval Col3 =*Blanks
C Eval Col3H =' '

C If ReadFilters3P = 'Yes'
C Read Filters3P

C If Not %EOF
C Eval Col3 = CNTRY + ' ' + COUNTRY
C Eval Col3H = CNTRY
C Eval Col3O = 'Y'
C Else
C Eval ReadFilters3P = 'No '
C End

C End

C EndSR
* _____________________________________________________


The DSPF code of 3-Column Subfile

A DSPSIZ(24 80 *DS3)
A CHGINPDFT(HI UL)
A CSRINPONLY
A ERRSFL
A CF03(03 'Exit')
A CF05(05 'Refresh')
A CF10(10 'Run')
A CF11(11 'Toggle field')
A CF12(12 'Exit')
A MOUBTN(*ULD CF11)
A R SFLA SFL
A*
A COL1O 1A B 11 4SFLCSRPRG
A COL1 20A O 11 6DSPATR(HI)
A COL2O 1A B 11 29SFLCSRPRG
A COL2 20A O 11 31DSPATR(HI)
A COL3O 1A B 11 54SFLCSRPRG
A COL3 20A O 11 56DSPATR(HI)
A COL1H 2A H
A COL2H 2A H
A COL3H 2A H
A*
A R FMT01 SFLCTL(SFLA)
A SFLPAG(0011)
A SFLSIZ(&NBRREC)
A OVERLAY
A RTNCSRLOC(&REC &FLD)
A SFLCSRRRN(&RELRCD)
A 90 SFLDSP
A 90 SFLDSPCTL
A N90 SFLCLR
A 91 SFLEND(*SCRBAR *MORE)
A RELRCD 5S 0H
A NBRREC 5S 0P
A REC 10A H
A FLD 10A H
A 1 69DATE
A EDTCDE(Y)
A 2 69TIME
A 3 69SYSNAME
A 4 69'Filter'
A 5 69USER
A 7 4'Filter by these fields'
A DSPATR(HI)
A 10 4' Type '
A DSPATR(UL)
A COLOR(BLU)
A 10 29' State '
A DSPATR(UL)
A COLOR(BLU)
A 10 54' Country '
A DSPATR(UL)
A COLOR(BLU)
A 7 49'Select for printing = "Y"'
A 8 49'Print report = Run, or F10'
A DSPATR(BL)
A COLOR(GRN)
A 1 3' ____ _____ __ -
A ____ __ ____ __ '
A 2 3' _ /___/ ___/__ / /_ ____ _ _-
A __ / __/_ __/ / / _(_) /__ '
A 3 3' _/_ <___/ /__/ _ \/ / // / \/ -
A _ \ _\ \/ // / _ \/ _/ / / -_)'
A 4 3'/____/ \___/\___/_/\_,_/_/_/_/_/-
A /_/ /___/\_,_/_.__/_//_/_/\__/ '
A R FOOTER
A PB1 2Y 0B 23 3PSHBTNFLD
A PSHBTNCHC(1 'Refresh (F5) ' CF05)
A PSHBTNCHC(2 'Run (F10) ' CF10)
A PSHBTNCHC(3 'Cancel (F12) ' CF12)

reference from Booth Martin


Read more!

The RPGIV for the two subfile program








*************************************************************
* A program to select from 2 different subfiles *
* 11/03 Booth Martin *
* *
* *
*************************************************************
H option(*nodebugio)
FTEST00D CF E WORKSTN
F SFILE(SFLA:RRN)
F SFILE(SFLB:RRNB)
FTEST01P IF E K DISK
FTEST02P IF E K DISK

D RRN S 4S 0
D RRNB S 4S 0
D TopRec S 4s 0
D SavedStates S Like(States)
* ..................................................
C EXSR FillSubfileASR
C EXSR FillSubfileBSR

C DoW *INLR = *Off
C write (e) Header
C write (e) Footer
* set the top of subfile A:
* Here you may choose to have subfile A positioned to either:
* 1) The State chosen,
* (use RelRcd > 0)
* 2) or, the same way as SFLA was when the selection was made,
* (use TopRecIn > 0)
* 3) or, always reposition to the beginning of SFLA.
* (comment or delete this section)
C If Relrcd > 0
C eval TopRec = RelRcd
C* If TopRecIn > 0
C* eval TopRec = TopRecIn
C else
C eval TopRec = 1
C endif

C if FLD = *Blanks
C write (e) FMT02
C exfmt FMT01
C Read (e) FMT02
C Read (e) Footer
C else
C write (e) FMT01
C exfmt FMT02
C Read (e) FMT01
C Read (e) Footer
C endif

C Select
* Footer Push button Choices:
* end the job
C When *INKC or
C *INKL
C Eval *INLR = *ON

* Fill cities subfile:
C When FLD > *Blanks
C RELRCD chain (e) SFLA
C exsr FillSubfileBSR

C EndSL
C END
* _________________________________________________________________
C FillSubfileAsrBegSR
* fill SFLA
C eval RRN = 0
* Clear subfile & screen, prepare to re-fill or fill:
C Eval *IN90=*off
C Clear SFLA
C Write FMT01
C eval *IN90 = *on

C *LoVal Setll Test01P
C Read Test01P
C DoW Not %EOF(Test01P)
C Eval RRN = RRN + 1
C Write SFLA
C Read Test01p
C End

C Eval NBRREC = RRN
C RRN IFLT 5
C eval *IN91 = *on
C END

C ENDSR
* _________________________________________________________________
C FillSubfileBsrBegSR
* fill SFLB
C eval RRNB = 0

C Eval *IN80=*off
C Clear SFLB
C eval Title = ' Cities '
C Write FMT02
C eval *IN80 = *on

C if RELRCD = *zeros
C Eval CITIES = *Blanks
C Eval RRNB = RRNB + 1
C Write SFLB
C else
C RELRCD Chain (e) SFLA
C eval SavedStates = States
C Eval Title = ' ' + STATES + ' '
C STATES Setll Test02P
C Read (e) Test02P
C If States <> SavedStates or
C %EOF(Test02P)
C eval cities = 'No cities listed'
C Eval RRNB = RRNB + 1
C Write SFLB
C else
C DoW Not %EOF(Test02P) and
C States = SavedStates
C Eval RRNB = RRNB + 1
C Write SFLB
C Read Test02P
C Enddo
C endif
C endif

C Eval NBRRECB = RRNB
C RRNB IFLT 5
C eval *IN81 = *on
C END

C EndSR
* _____________________________________________________


Reference Booth Martin.


DDS Source (Physical file source code)

Name of states file: TEST01P
A R TEST01REC
A STATES 10
A K STATES

Name of cities file: TEST02P
A R TEST02REC
A STATES 10
A CITIES 20
A K STATES
A K CITIES




DDS Source (Display file source code)

A DSPSIZ(24 80 *DS3)
A CHGINPDFT(HI UL)
A ERRSFL
A CA03(03 'Exit')
A CA12(12 'Exit')
A MOUBTN(*ULD ENTER)
A R HEADER
A 1 69DATE
A EDTCDE(Y)
A 2 69TIME
A* 3 69SYSNAME
A 3 69'SYSTEM X'
A 4 69USER
A 2 7' __ _-
A _ ___ _ __ '
A 3 7' / /_ _ __ ___ ___ __ __ / -
A / / _/(_)/ /___ ___ '
A 4 7' / __/| |/|/ // _ \ (_- / // // _-
A \ / _// // // -_)(_- '
A 5 7' \__/ |__,__/ \___/ /___/\_,_//_._-
A _//_/ /_//_/ \__//___/ '
A 6 7' -
A '
A R SFLA SFL
A STATES 10A O 2 1
A R FMT01 SFLCTL(SFLA)
A TEXT('States subfile')
A OVERLAY
A WINDOW(9 5 8 27 *NOMSGLIN)
A WDWTITLE((*TEXT ' States '))
A *DS3 SFLLIN(2)
A SFLPAG(0012)
A SFLSIZ(&NBRREC)
A* (can not use this with SFLLIN) SFLSNGCHC
A RTNCSRLOC(&REC &FLD)
A SFLCSRRRN(&RELRCD)
A 90 SFLDSP
A 90 SFLDSPCTL
A N90 SFLCLR
A 91 SFLEND(*SCRBAR *MORE)
* Use TopRecIn or RelRcd to set TopRec, which sets the position of SFLA:
A TOPREC 4S 0H SFLRCDNBR(*TOP)
A TOPRECIN 5S 0H SFLSCROLL
A RELRCD 5S 0H
A NBRREC 5S 0P
A REC 10A H
A FLD 10A H
A R SFLB SFL
A CITIES 20A O 2 2
A R FMT02 SFLCTL(SFLB)
A TEXT('Cities subfile')
A RTNCSRLOC(&RECB &FLDB)
A OVERLAY
A SFLCSRRRN(&RELRCDB)
A 80 SFLDSP
A 80 SFLDSPCTL
A N80 SFLCLR
A 81 SFLEND(*SCRBAR *MORE)
A SFLSIZ(&NBRRECB)
A SFLPAG(0006)
A WINDOW(9 45 8 26 *NOMSGLIN)
A WDWTITLE((*TEXT &TITLE))
A SFLMLTCHC
A RELRCDB 5S 0H
A NBRRECB 5S 0P
A RECB 10A H
A FLDB 10A H
A TITLE 12A P
A R FOOTER
A OVERLAY
A 23 3'F3=Exit F12=Return'
A COLOR(BLU)
A 20 46'Select as many cities as you like.'
A COLOR(BLU)
A 21 46'Use the space bar or mouse click'
A COLOR(BLU)
A 22 46'to make your selections.'
A COLOR(BLU)
A R DUMMY
A TEXT('PREVENTS PREVIOUS SCREEN FROM-
A BEING CLEARED')
A ASSUME
A 5 9' '


Read more!

Friday, September 21, 2007

AS/400 Control Language (CL)



The AS/400 control language (CL) is reminiscent of JCL and consists of an ever expanding set of command AS/400 object|objects (*CMD) used to invoke traditional AS/400 programs and/or get help on what those programs do. CL can also be used to create CL programs (congruent to Shell script|shell scripts) where there are additional commands that provide program-like functionality (GOTO, IF/ELSE, variable declaration, file input, etc.)

The vast majority of AS/400 commands were written by IBM developers to perform system level tasks like compiling programs, backing up data, changing system configurations, displaying system AS/400 object|object details, or deleting them. Commands are not limited to systems level concerns and can be drafted for user applications as well.

Commands and programs

Parameter (computer science)|Parameters (aka arguments) defined in the main procedures of all traditional AS/400 programs are hard coded lists that are be made up of parameters that can be numeric, alphanumeric, boolean, etc and the order in which Parameter (computer science)|parameters are passed is important. This is a stark difference from the Unix & DOS worlds where the parameter list in Unix Shell script|shell scripts and C programming language|C programs is a set or array of character pointers and more often than not the parameters are not positionally dependent.

The AS/400 developer's solution to this problem was the command AS/400 object|object (*CMD). While the parameters on the command can be specified in any order, each parameter is defined to be passed in a specific order to the program. The programmer can also define, among other things, the parameter's data type, unique parameter name, descriptive text (for prompting), default value (used only if the parameter isn't specified during execution), if the values are restricted to a certain set or range, if the data entered should be changed to another value before calling the program, etc.

At its most basic a command names a single program to call when the user types or prompts the command and presses the Enter key. The command takes all of the parameters typed by the user, and those not typed by the user, and builds a parameter list that it passes to the program when it's called.



Sample Code

The following is a sample of CL programming. The program interactively converts dates from julian to mdy and vice versa. Results are displayed on line 24 of the terminal. It accepts two parameters. The &IN parameter which is the date string to be converted. If a julian string it should be in the format yynnn where yy is the year number and nnn is the day number of the year. If a MDY string it must be in the format mmddyy. The second parameter is &TYP which is the type of date to be converted to. It must be 'J' (julian) or 'M' (mdy). For example: the command CALL PGM(ICVTDATC) PARM('04180' 'M') will convert the julian date 04180 to 062804 (June 28, 2004).




PGM PARM(&IN &TYP)

DCL VAR(&IN) TYPE(*CHAR) LEN(6)
DCL VAR(&OUT) TYPE(*CHAR) LEN(8)
DCL VAR(&TYP) TYPE(*CHAR) LEN(1)
DCL VAR(&MSG) TYPE(*CHAR) LEN(80)

IF COND(&TYP = J) THEN(DO)
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*MDY) +
TOFMT(*JUL) TOSEP(*NONE)
ENDDO

IF COND(&TYP = M) THEN(DO)
CVTDAT DATE(&IN) TOVAR(&OUT) FROMFMT(*JUL) +
TOFMT(*MDY) TOSEP(*NONE)
ENDDO

CHGVAR VAR(&MSG) VALUE('IN=' || &IN || ' OUT=' || +
&OUT)
SNDPGMMSG MSG(&MSG)

ENDPGM

Retrieved from "http://csiwiki/index.php?title=AS/400_Control_Language"


Read more!

Thursday, September 20, 2007

RPG IV, a Modern Language


In 2001, with the release of OS/400 V5R1, RPG IV offered even greater freedom for calculations than offered by the Extended Factor-2 Calculation Specification: a free-format text-capable source entry, as an alternative to the original column-dependent source format. The "/FREE" calculation does not require the operation code to be placed in a particular column; the operation code is optional for the EVAL and CALLP operations; and syntax generally more closely resembles that of mainstream, general-purpose programming languages.

Today, RPG IV is a considerably more robust language. Editing can still be done via the simple editor or it can be edited via PC using IBM's Websphere Development Studio (a customized implementation of Eclipse). IBM is continually extending its capabilities and adding more built-in functions (BIFs). It has the ability to link to Java objects (See IBM's RPG Reference Manual [1] ), and i5/OS APIs; it can be used to write CGI programs with the help of IBM's Cgidev2[2]web toolkit, RPG xTools [3] CGILIB and other commercial Web enabled packages. Even with the changes it retains a great deal of backward compatibility, so an RPG program written 37 years ago could run today with little or no modification.

The OS/400 was later renamed i5/OS in correspondence with the new IBM System i branding initiative. The i5/OS V5R4 [4] (Version 5 Release 4) was released in January 2006 and is currently the latest version (as of August, 2007).


Read more!