Re: SQL question (Autoincrementing value.)
Date: 2000/02/04
Message-ID: <kxMm4.489$v74.6598_at_ord-read.news.verio.net>#1/1
Ron,
For straight COBOL, look at http://www.news400.com/index400/cobol.htm for a list of IBM's COBOL manuals, and particularly COBOL/400 User's Guide and COBOL/400 Reference. The User's guide instructs you on how to create a COBOL program, and the Reference provides the syntax.
As suggested in a previous post, you'll want to create a before insert trigger program. The DB2 for AS/400 Database Programming book will give you a kick start, and particularly chapter 17 on triggers which includes a sample "update trigger" program written in COBOL. http://publib.boulder.ibm.com/cgi-bin/bookmgr/bookmgr.cmd/BOOKS/QB3AUC00/CON TENTS#3.8 You'll figure out how to change that into your own "before insert trigger" program. But in *your* trigger program, you'll want to make a call out to a CL program which will provide you with your incremented value. You only need to create the data area once by issuing a command like
CRTDTAARA DTAARA(CTLDTA) TYPE(*DEC) LEN(7 0) VALUE(0) Then your CL program can look something like:
/* CL program to provide an incremental value */
PGM PARM(&CTLNBR) DCL VAR(&CTLNBR) TYPE(*DEC) LEN(7 0) VALUE(0) /* Loop until we have exclusive lock on the data area... */ ALC: ALCOBJ OBJ((CTLDTA *DTAARA *EXCL)) MONMSG MSGID(CPF1002 CPF1040 CPF1085) EXEC(GOTOCMDLBL(ALC))
/* Increment the data area value... */
RTVDTAARA DTAARA(CTLDTA) RTNVAR(&CTLNBR) CHGVAR VAR(&CTLNBR) VALUE(&CTLNBR + 1) CHGDTAARA DTAARA(CTLDTA) VALUE(&CTLNBR) /* Release our exclusive lock on the data area... */ DLC: DLCOBJ OBJ((CTLDTA *DTAARA *EXCL)) ENDPGM
Then your COBOL before trigger program will need to include the code snippets:
01 autoincrement-field PIC S9(7) COMP. and
CALL clprogram USING autoincrement-field. (Replace autoincrement-field and clprogram with the names of your choosing.)
Bruce
Ron Stow <ronstow_at_btinternet.com> wrote in message
news:87d369$js$1_at_neptunium.btinternet.com...
> So it seems that I will have to write a program that inserts the value! I
> am not a Cobol, RPG or C programmer, but i know a bit of VB...!! Does
> anyone have a suggestion for a book that would get me into Cobol
programming
> quickly. This would be more usefull to me as I could apply the knowledge
to
> Mainframes,that I also currently use with SAS alone. (I do a bit of SAS
as
> well!)
>
> Cheers for all the suggestions.
>
> Graeme
>
> NB. Using a Date/Time stamp won't work as I am trying to perform a join of
> the form: a.number = b.number + 1. If you reed my original message you
will
> realise that i allready have a incrementing unique date/time value. I
must
> admit the original posting was a bit long.
>
>
>
>
>
Received on Fri Feb 04 2000 - 00:00:00 CET