midrange.com code scratchpad |
Name:
itmCount (Dennis Lovelady)
|
Scriptlanguage:
Plain Text
|
Tabwidth:
4
|
Date:
06/16/2010 05:57:18 pm
|
IP:
Logged
|
|
Description:
itmCount simply counts matching keys until a new key is
passed. Its only known use is to prove whether SQL data
SELECT itmCount(key)
...
FROM someFile ...
|
Code:
- H OPTION(*NOSHOWCPY:*NOEXPDDS:*NODEBUGIO:*SRCSTMT)
- H DATFMT(*ISO) TIMFMT(*ISO) DEBUG
- H CVTOPT(*VARCHAR:*NODATETIME)
- H THREAD(*SERIALIZE)
- H BndDir('QC2LE') NoMain
-
- // CRTSQLRPGI OBJ(mylib/SQLTEST) SRCFILE(mylib/PGMSRC)
- // SRCMBF(SQLTEST) OBJTYPE(*MODULE)
- // REPLACE(*YES)
-
- // CRTSRVPGM mylib/SQLTEST EXPORT(*ALL)
-
- // -- in SQL --
- // CREATE FUNCTION mylib/ITMCOUNT(VARCHAR(10))
- // RETURNS DECIMAL(5,0)
- // RETURNS NULL ON NULL INPUT
- // LANGUAGE RPGLE
- // EXTERNAL NAME 'mylib/SQLTEST(itmCount)'
- // NOT DETERMINISTIC
- // NO EXTERNAL ACTION
- // PARAMETER STYLE GENERAL
- // ALLOW PARALLEL
- // NOT FENCED
-
-
- D itmCount PR 5P 0 ExtProc('itmCount')
- // itmCount simply counts matching keys until a new key is
- // passed. Its only known use is to prove whether SQL data
- // SELECT itmCount(key)
- // ...
- // FROM someFile ...
- D key 10 Const Varying
-
-
-
- P itmCount B Export
- D itmCount PI 5P 0
- D key 10 Const Varying
-
- D statCount S Static Inz Like(itmCount)
- D prevkey S Static Inz Like(key)
-
- /Free
- If key = prevKey ;
- statCount += 1 ;
- Else ;
- statCount = 1 ;
- EndIF ;
- prevKey = key ;
- Return statCount ;
-
- /End-free
-
- P itmCount E
-
|
|
|