Showing posts with label RPGILE. Show all posts
Showing posts with label RPGILE. Show all posts

Sunday, August 9, 2009

RPGIV : After Update Trigger


DB2 Example: After Update Trigger

*========================================================*
* This program is intended to illustrate an after update *
* trigger that simulates an update cascade. *
* *
* *
* CRTSQLRPGI OBJ(CORPDATA/TRG03) SRCFILE(MJASRC/RPG) *
* COMMIT(*NONE) OUTPUT(*PRINT) *
* OPTION(*XREF *NOGEN) DBGVIEW(*SOURCE) *
* USRPRF(*OWNER) DYNUSRPRF(*ONER) *
* *
* CRTBNDRPG PGM(CORPDATA/TRG03) SRCFILE(QTEMP/QSQLTEMP1) *
* DFTACTGRP(*NO) ACTGRP(*CALLER) *
* DBGVIEW(*SOURCE) ALWNULL(*YES) *
* USRPRF(*OWNER) *
* *
* ADDPFTRG FILE(CORPDATA/DEPARTMENT) *
* TRGTIME(*AFTER) TRGEVENT(*UPDATE) *
* PGM(CORPDATA/TRG03) ALWREPCHG(*YES) *
* *
* *
*========================================================*
*
*========================================================*
* Definition of the structure passed as the first *
* parameter from database to the trigger program. *
* The include is used so that any additional fields *
* in the interface template in the future will be *
* brought into the program if it is recompiled. *
* *
* The includes in the QSYSINC library must be on *
* your system to compile this program. Option 13 of *
* the OS/400 install will install them. *
* *
*========================================================*
D/COPY QSYSINC/QRPGLESRC,TRGBUF
*
*========================================================*
* This is an overlay used to set addressability *
* to the various sections of the interface buffer *
* such as the before and after record images. *
*========================================================*
D INTARR S 1A BASED(INTPTR) DIM(32767)
D INTPTR S *
*
*========================================================*
* Definition of the trigger buffer length passed as *
* the second parameter from database to the trigger *
* program. *
*========================================================*
D PARM2 DS
D LENG 1 4B 0
*
*========================================================*
* These pointers are used to point to the before *
* and after images. The before and after images *
* are passed in the first parameter structure. *
*========================================================*
D BIMAGE S *
D AIMAGE S *
*
*========================================================*
* These based structures provide the subfields of *
* the record images. Externally defined data *
* structures are used so a recompile of the *
* program will always pick up the latest field *
* defintions. *
*========================================================*
D BEMP E DS EXTNAME(DEPARTMENT)
D BASED(BIMAGE)
D PREFIX(B)
D AEMP E DS EXTNAME(DEPARTMENT)
D BASED(AIMAGE)
D PREFIX(A)
*
*========================================================*
* Error output from QMHSNDPM *
*========================================================*
D/COPY QSYSINC/QRPGLESRC,QUSEC
D RTNDTA 17 56
*
*========================================================*
* Parameters for QMHSNDPM *
*========================================================*
D FLDS DS
D MSGLEN 1 4B 0
D PGMSTK 5 8B 0
D RTVLEN 9 12B 0
D MSGQLEN 13 16B 0
D PGMWTT 17 20B 0
D LASTOPEN 21 21A
*
*========================================================*
* If an error occurs, the trigger program should send an *
* error to database to indicate that the operation has *
* failed. To send an escape message, use the QMHSNDPM *
* API. We must send the message to the call stack entry *
* that comes immediately before the trigger program. *
* The first call stack entry in an ILE RPG trigger *
* program is the PEP. Below, we have defined the *
* name of the PEP for this ILE trigger program. *
*========================================================*
D MSGQNAM C CONST('_QRNP_PEP_TRG02')
*
*========================================================*
* Place the name of your message file in the first 10 *
* characters, padding with blanks to the 10th character. *
* Place the library name in the second 10 characters *
* padding with blanks. *
*========================================================*
D MSGFNAME C CONST('MSGF MJATST ')
D LEN C CONST(15)
D MODNAME C CONST('*NONE *NONE ')
*
C *ENTRY PLIST
C QDBTB PARM QDBTB
C PARM2 PARM PARM2
*
*========================================================*
* This is the parameter list of QMHSNDPM. *
*========================================================*
C PLIST1 PLIST
C PARM MSGID 7
C PARM MSGF 20
C PARM MSGDTA 25
C PARM MSGLEN
C PARM MSGTYP 10
C PARM MSGQUE 19
C PARM PGMSTK
C PARM MSGKEY 4
C PARM QUSEC
C PARM MSGQLEN
C PARM CSEQUAL 20
C PARM PGMWTT
*========================================================*
* Set the basing pointers for the interface *
* structure and the before and after images *
*========================================================*
C EVAL INTPTR = %ADDR(QDBTB)
C EVAL BIMAGE = %ADDR(INTARR(QDBORO+1))
C EVAL AIMAGE = %ADDR(INTARR(QDBNRO+1))
*
*========================================================*
* Only open or perform an update if the manager *
* number has changed. *
*========================================================*
C AMGRNO IFNE BMGRNO
*
*========================================================*
* Update the employee record. Note that SQL will keep *
* any of the used ODPs open. *
* Also SQL is able to use a specific isolation level *
* either by using the SET TRANSACTION statement or *
* by statement level isolation levels. *
*========================================================*
C QDBCLL IFEQ '0'
C/EXEC SQL UPDATE CORPDATA/EMPLOYEE SET WORKDEPT = :ADEPTNO
C+ WHERE EMPNO = :AMGRNO WITH NC
C/END-EXEC
C ELSE
C QDBCLL IFEQ '1'
C/EXEC SQL UPDATE CORPDATA/EMPLOYEE SET WORKDEPT = :ADEPTNO
C+ WHERE EMPNO = :AMGRNO WITH UR
C/END-EXEC
C ELSE
C QDBCLL IFEQ '2'
C/EXEC SQL UPDATE CORPDATA/EMPLOYEE SET WORKDEPT = :ADEPTNO
C+ WHERE EMPNO = :AMGRNO WITH CS
C/END-EXEC
C ELSE
C QDBCLL IFEQ '3'
C/EXEC SQL UPDATE CORPDATA/EMPLOYEE SET WORKDEPT = :ADEPTNO
C+ WHERE EMPNO = :AMGRNO WITH RS
C/END-EXEC
C ELSE
C/EXEC SQL UPDATE CORPDATA/EMPLOYEE SET WORKDEPT = :ADEPTNO
C+ WHERE EMPNO = :AMGRNO WITH RR
C/END-EXEC
C ENDIF
C ENDIF
C ENDIF
C ENDIF
*
*========================================================*
* If the SQL operation is unsuccessful for *
* some reason return a message to the application to *
* make the update fail. *
*========================================================*
C SQLCOD IFLT 0
*
*========================================================*
* Place the appropriate message ID here. *
*========================================================*
C MOVEL 'TRG0001' MSGID
C MOVEL MSGFNAME MSGF
C MOVE ' ' MSGDTA
C Z-ADD 25 MSGLEN
C MOVEL(P) '*ESCAPE' MSGTYP
C MOVEL(P) MSGQNAM MSGQUE
C MOVEL(P) MODNAME CSEQUAL
C MOVE ' ' MSGDTA
C Z-ADD 1 PGMSTK
C Z-ADD LEN MSGQLEN
C MOVE ' ' MSGKEY
C Z-ADD 66 QUSBPRV
C Z-ADD 0 QUSBAVL
C MOVE ' ' QUSEI
C MOVE ' ' QUSERVED
C MOVE ' ' RTNDTA
C CALL 'QMHSNDPM' PLIST1
C ENDIF
C ENDIF
*
C RETURN

Reference from JimmyOctane at Code400


Read more!

Trigger AS/400

This template deals with triggers on physical files.The triggered file itself need not be referenced here unless you have need to access it beyond the record that caused the trigger to be pulled.





/TITLE TRIGGER ** Trigger program shell **

* Pete Hall
* http://www.inwave.com/~peteh/

* Replace (PFile) with physical file name
* Replace (AFile) with ancillary file name

* ---------------------------------------------
* Ancillary files
* ---------------------------------------------
F(AFile) UF A E K DISK Commit(RunCommit) UsrOpn

* ------------------------------------------
* Entry Parameters
* ---------------------------------------------
DBuffer DS 32767
D PFName 10
D PFLibrary 10
D PFMember 10
D TrgEvent 1
D TrgTime 1
D TrgCmtLvl 1
D 3
D TrgCCSID 7B 0
D 8
D OrOffset 7B 0
D OrRcdLen 7B 0
D OrNBMapOfs 7B 0
D OrNBMapLen 7B 0
D NwOffset 7B 0
D NwRcdLen 7B 0
D NwNBMapOfs 7B 0
D NwNBMapLen 7B 0
D DataSpace 1 32767
D Bytes 1 Overlay(DataSpace) Dim(32767)

DBufferLen S 7B 0
* ---------------------------------------------
* Original Record
* ---------------------------------------------
D@OrRecord S * Inz(*Null)

DOrRecord E DS ExtName((PFile)) Prefix(OR_)
D Based(@OrRecord)

* ---------------------------------------------
* New Record
* ---------------------------------------------
D@NwRecord S * Inz(*Null)

DNwRecord E DS ExtName((PFile)) Prefix(NW_)
D Based(@NwRecord)

* ---------------------------------------------
* Constant Definitions
* ---------------------------------------------
* Commit Levels
DCL_NONE C '0'
DCL_CHG C '1'
DCL_CS C '2'
DCL_ALL C '3'

* Null byte status
DNB_NOTNULL C '0'
DNB_NULL C '1'

* Trigger events
DTE_INSERT C '1'
DTE_DELETE C '2'
DTE_UPDATE C '3'

* Trigger times
DTT_AFTER C '1'
DTT_BEFORE C '2'
C *ENTRY plist
C parm Buffer
C parm BufferLen


* ---------------------------------------------
* Main-line Procedure
* ---------------------------------------------

* Assign the record templates to their data space
C eval @OrRecord = %Addr(Bytes(OrOffset+1))
C eval @NwRecord = %Addr(Bytes(NwOffset+1))

* Execute the correct procedure based on trigger event
C TrgEvent caseq TE_INSERT DoInsert
C TrgEvent caseq TE_DELETE DoDelete
C TrgEvent caseq TE_UPDATE DoUpdate
C endcs
C return

* ---------------------------------------------
* Process a delete event
* ---------------------------------------------
CSR DoDelete BEGSR


CSR ENDSR

* ---------------------------------------------
* Process an insert event
* ---------------------------------------------
CSR DoInsert BEGSR


CSR ENDSR

* ---------------------------------------------
* Process an update event
* ---------------------------------------------
CSR DoUpdate BEGSR


CSR ENDSR

* ---------------------------------------------
* Program Initialization
* ---------------------------------------------
CSR *INZSR BEGSR

C if TrgCmtLvl > CL_NONE
C move *ON RunCommit
C endif
* > if TrgCmtLvl > CL_NONE
C open

CSR ENDSR

Reference from Pete Hall's web site .


Read more!

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!

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!

RPG Language Evolution



RPG II was introduced with the System/3 series of computers. It was later used on System/32, System/34, and System/36, with an improved version of the language. International Computers Ltd also produced a version on its VME/K operating system

RPG III was created for the System/38 and its successor the AS/400 (a mid-range machine). RPG III significantly departed from the original language, providing modern structured constructs like IF-ENDIF blocks, DO loops, and subroutines.

DE/RPG or Data Entry RPG was exclusively available on the IBM 5280 series of data-entry workstations in the early 80s. It was similar to RPG III but lacking external Data Descriptions (DDS) to describe data(files) like on the System/38 and its successors. Instead, the DDS part had to be included into the RPG source itself.

RPG/400 with a much cleaner syntax, and tighter integration with the integrated database. This language became the mainstay of development on the AS/400, and its editor was a simple line editor with prompt templates for each specification (type of instruction).

RPG IV (aka RPGLE, aka RPG/ILE) was released in 1994 and the name, officially, was no longer an initialism. RPG IV offered a greater variety of expressions within its new Extended Factor-2 Calculation Specification.


Read more!

Wednesday, September 19, 2007

The RPG for Scroll Bar & Mouse






*************************************************************
FGCKFM CF E WORKSTN
F SFILE(SFLA:RRNA)
FGCKF UF A E DISK INFDS(INFDS)
FGCKFL1 IF E K DISK Rename(RGCKF:RGCKF1)
F INFDS(DB1) BLOCK(*NO)
FGCKFL2 IF E K DISK Rename(RGCKF:RGCKF2)
F INFDS(DB2) BLOCK(*NO)
FGCKFL3 IF E K DISK Rename(RGCKF:RGCKF3)
F INFDS(DB3) BLOCK(*NO)
* ..................................................
D Col# S 1 0
D CTL1Saved S Like(CTL1)
D CTL2Saved S Like(CTL2)
D ColSaved S Like(Col#)

* INFDS for database file. FileSize will contain the number
* of records in the file when the file is opened.
DINFDS DS
D FILESIZE 156 159B 0

* Get the record Number, to know which record to update/process:
D DB1 DS
D DB1RRN 397 400B 0
D DB2 DS
D DB2RRN 397 400B 0
D DB3 DS
D DB3RRN 397 400B 0
* ..................................................
DRecordDataDS E DS ExtName(GCKF)
D SavedData S Like(RecordDataDs)
D ChangedData S Like(SavedData)
D CheckData S Like(SavedData)
* ..................................................
DRecord4 DS
D GNNAME
D RecNbr
D Data 300

D AR4 S 400 Dim(3000)
* ..................................................

* If file is empty:
C FILESIZE IFLE *ZEROS
C Clear RecNbr
C EXSR AddFixSR
C Else
C Z-ADD 1 RRN 4 0
C Z-ADD 1 RRNA

C If Col#=ColSaved and
C CTL1=CTL1Saved and
C CTL2=CTL2Saved
C Write FMT01
C Else
C Eval ColSaved=Col#
C Eval CTL1Saved=CTL1
C Eval CTL2Saved=CTL2

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

* Show Partial note, or not:
C IF CTL1=1
C Eval *IN42=*ON
C Else
C Eval *IN42=*OFF
C End

C Select
C When Col#=1
C Exsr FillSFL1
C
C When Col#=2
C Exsr FillSFL2
C
C When Col#=3
C Exsr FillSFL3
C
C When Col#=4
C Exsr FillSFL4
C EndSL
C EndIf
C
**
C RRNA IFGT 17
C MOVE *ON *IN91
C END
C Z-ADD RRNA NBRREC
C MOVE *ON *IN90
C WRITE FOOTR
C EXFMT FMT01
C Read Footr

C Select
C When *INKC=*ON
C Eval *INLR=*ON

* Was a column heading clicked?
C When CURFLD = 'COL1 ' or
C CURFLD = 'COL2 ' or
C CURFLD = 'COL3 ' or
C CURFLD = 'COL4 '
C Eval *IN31=*OFF
C Eval *IN32=*OFF
C Eval *IN33=*OFF
C Eval *IN34=*OFF
c Select
C When CURFLD = 'COL1 '
C Eval Col# = 1
C Eval *IN31=*ON

C When CURFLD = 'COL2 '
C Eval Col# = 2
C Eval *IN32=*ON

C When CURFLD = 'COL3 '
C Eval Col# = 3
C Eval *IN33=*ON

C When CURFLD = 'COL4 '
C Eval Col# = 4
C Eval *IN34=*ON

C EndSL

* Footer Push button Choices:
* Settings
C When F1=2
C
* Issue key:
C When F1=3
C Exsr IssueSR
* Add Key :
C When F1=4
C Clear RecNbr
C Exsr ADDFIXSR
* Exit
C When F1=5
C Eval *INLR=*ON
C
* If a choice was made, then do the required action:
C When RRNA>*ZEROS
C RRNA CHAIN SFLA 54
C EXSR ADDFIXSR

* Do either the maintain window or the note window:(PushButton 2)
C When PB2=1
C EXSR ADDFIXSR
C When PB2=2
C EXSR ADDFIXSR
C When PB2=3
C EXSR IssueSR

C EndSL
C END

* ________________________________________________________
* Add or Fix a record:
C AddFixSR BegSR
C If RecNbr > *zeros
C RecNbr Chain (N) GCKF
C Movel RecordDataDS Saveddata
C Else
C Clear FMT05
C End

C EXFMT FMT05
* If accepted:
C If NOT *INKC and NOT *INKL

C If RecNbr > *zeros
C Movel RecordDataDS ChangedData
C RecNbr Chain GCKF
C Movel RecordDataDS CheckData

C If CheckData = SavedData
C Movel ChangedData RecordDataDS
C Update(E) RGCKF
C Else
* send a mesage: the record wa changed at another work station
C End

C Else
C Write (E) RGCKF
C End

C End

C ENDSr
* _____________________________________________________________
C IssueSR BegSR
* Get name to use:

C Clear FMT05
C Exsr AddFixSR

C EndSR
* _____________________________________________________
C AddKeySR BegSR
* Get name to use:

C Clear FMT05
C Exsr AddFixSR

C EndSR
* _____________________________________________________
C SettingSR BegSR
C EndSR
* _____________________________________________________
C *INZSR BegSR
C Eval Col# = 2
C Eval *IN32=*ON
C Eval CTL1=1
C Eval CTL2=1
C Eval PB2=2

C EndSR
* ____________________________________________________________
* Write the line(s) in the subfile:
C WriteLineSR BegSR

C Movel GCKNOTE PNNO
* Show Name as pink if "!", or not:
C Eval *IN41=*Off
C If CTL2=1
* If first character of Note is "!" then turn the name pink:
C Movel GCKNOTE Test1 1
C If Test1 = '!'
C Eval *IN41=*On
C End

C Movel GCKNOTE PNNO
* Show Name as pink if "!", or not:
C Eval *IN41=*Off
C If CTL2=1
* If first character of Note is "!" then turn the name pink:
C Movel GCKNOTE Test1 1
C If Test1 = '!'
C Eval *IN41=*On
C End
C End

* Get name(s), if key(s) issued:
C WRITE SFLA
C ADD 1 RRN
C Z-ADD RRN RRNA

C EndSR
* ____________________________________________________________
* Logical on Name:
C FillSFL1 BegSR
* This uses the array filled earlier. "I" is the number of elements.
C SORTA AR4
C 3000 Sub I J 4 0
C J DOUGT 3000
C If AR4(J)>*Blanks
C MOVEL AR4(J) Record4
C MoveL Data RecordDataDS
C EXSR WriteLinesr
C END
C Eval J=J+1
C END

C EndSR
* _________________________________________________________________
* Logical on Key #
C FillSFL2 BegSR
C *LoVal Setll RGCKF1
C READ RGCKF1 58

* prepare an array so that a request for an alph listing will work:
C Move *Blanks AR4
C Z-Add 0 I 4 0

C* Fill the subfile:
C *IN58 DOWEQ *OFF
C Z-Add DB1RRN RecNbr
C EXSR WriteLinesr
* fill array:
C If GNNAME>*Blanks
C Eval I=I+1
C MoveL RecordDataDS Data
C Movel Record4 AR4(I)
C END

C READ RGCKF1 58
C END

C EndSR
* _________________________________________________________________
* Logical on Hook #:
C FillSFL3 BegSR
C *LoVal Setll RGCKF2
C READ RGCKF2 58
C* Fill the subfile:
C *IN58 DOWEQ *OFF
C Z-Add DB2RRN RecNbr
C EXSR WriteLinesr
C READ RGCKF2 58
C END

C EndSR
* _________________________________________________________________
* Logical on Building & door:
C FillSFL4 BegSR
C *Loval Setll RGCKF3
C READ RGCKF3 58
C* Fill the subfile:
C *IN58 DOWEQ *OFF
C Z-Add DB3RRN RecNbr
C EXSR WriteLinesr
C READ RGCKF3 58
C END

C EndSR
* _________________________________________________________________




DDS for the Scroll Bar & Mouse (Display file source code)

A*
A*%%EC
A DSPSIZ(27 132 *DS4)
A REF(*LIBL/GCKFL1 RGCKF)
A CHGINPDFT(HI UL)
A ERRSFL
A CF03(03 'Exit')
A CF12(12 'Exit')
A MOUBTN(*ULD ENTER)
A R SFLA SFL

A GNNAME R O 6 3
A 41 COLOR(PNK)
A GCKKEY# R O 6 34
A GCKHOOK# R O 6 45
A GCKBLDG R O 6 56
A GCKDOOR# R O 6 77
A RECNBR 5S 0O 6 89
A** PNNO 40A O 6 89
A PNNO 30A O 6 99
A N42 DSPATR(ND)
A GCKNOTE R H
A** RECNBR 5S 0H
A R FMT01 SFLCTL(SFLA)

A SFLPAG(0015)
A RTNCSRLOC(&CURREC &CURFLD)
A SFLSIZ(&NBRREC)
A OVERLAY
A SFLCSRRRN(&RRNA)
A 90 SFLDSP
A 90 SFLDSPCTL
A N90 SFLCLR
A 91 SFLEND(*SCRBAR *MORE)
A 1 3DATE
A EDTCDE(Y)
A 2 3TIME
A 1 79' Selection Criteria for this scr-
A een: '
A DSPATR(UL)
A COLOR(BLU)
A 1 34' Key Cabinets'
A COLOR(WHT)
A PB1 2Y 0B 2 80MLTCHCFLD
A CHOICE(1 'Show partial >note')
A CHCCTL(1 &CTL1)
A CHOICE(2 'Show ! as >pink')
A CHCCTL(2 &CTL2)
A CTL1 1Y 0H
A CTL2 1Y 0H
A PB2 2Y 0B 2105SNGCHCFLD
A CHOICE(1 'Maintain Note ')
A CHOICE(2 'Maintain Record')
A CHOICE(3 'Issue Key ')
A COL1 30A B 5 3DFTVAL('Name -
A ')
A DSPATR(UL)
A DSPATR(PR)
A N31 COLOR(BLU)
A 31 COLOR(GRN)
A COL2 10A B 5 34DFTVAL('Key # ')
A DSPATR(UL)
A DSPATR(PR)
A N32 COLOR(BLU)
A 32 COLOR(GRN)
A COL3 10A B 5 45DFTVAL('Hook # ')
A DSPATR(UL)
A DSPATR(PR)
A N33 COLOR(BLU)
A 33 COLOR(GRN)
A COL4 31A B 5 56DFTVAL('Door # ')
A DSPATR(UL)
A DSPATR(PR)
A N34 COLOR(BLU)
A 34 COLOR(GRN)
A 5 88'Comment... (First characters only)-
A '
A COLOR(BLU)
A DSPATR(UL)
A N42 DSPATR(ND)
A RRNA 5S 0H
A NBRREC 5S 0P
A CURREC 10A H
A CURFLD 10A H
A R FOOTR

A 24 3' -
A -
A -
A '
A DSPATR(UL)
A COLOR(BLU)
A F1 2Y 0B 26 10PSHBTNFLD
A DSPATR(PC)
A PSHBTNCHC(1 '>Enter' ENTER)
A PSHBTNCHC(2 '>Settings' ENTER)
A PSHBTNCHC(3 '>Add Key' ENTER)
A PSHBTNCHC(4 'E>xit' CF03)
A R FMT02

A WINDOW(*DFT 12 45 *NOMSGLIN)
A TEXT('Key Cabinet')
A BLINK
A OVERLAY
A WDWTITLE((*TEXT ' Maintain Key Reco-
A rd '))
A GCKKEY# R B 1 1
A GCKHOOK# R B 2 1CHECK(LC)
A GCKBLDG R B 3 1CHECK(LC)
A GCKDOOR# R B 3 21CHECK(LC)
A GCKNOTE R B 5 1CHECK(LC)
A CNTFLD(043)
A F2 2Y 0B 12 3PSHBTNFLD
A PSHBTNCHC(1 'Cancel' CF12)
A PSHBTNCHC(2 'Accept')
A 1 13'Key Number'
A 2 13'Hook Number'
A** 3 13'Door Number'
A R FMT03

A WINDOW(*DFT 8 45 *NOMSGLIN)
A TEXT('Maintain Notes ')
A BLINK
A OVERLAY
A* WDWTITLE((*TEXT ' Sample ') *BOTTOM)
A* WDWTITLE((*TEXT ' Top ') *TOP)
A WDWTITLE((*TEXT ' Maintain Notes '))
A GCKNOTE R B 1 1CNTFLD(043)
A CHECK(LC)
A F3 2Y 0B 8 3PSHBTNFLD
A PSHBTNCHC(1 'Cancel' CF12)
A PSHBTNCHC(2 'Accept')


thank you Booth Martin.


Read more!