× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Not seeing all of the relevant source makes debug a bit difficult, but one
question I have is where this "magic" number '96' comes from when setting
NewStart and OrgStart. In any case, here's some sample code that I threw
together and which appears to work.

First I created the file BVINING/TESTFILE using the following definition:

A R RECORD

A MYKEY 3P 0

A MYDATA 10A

A K MYKEY



I then created the trigger program BVINING/MYTRG using the following source
(note that this program does NOT implement checks that I would normally
include such as 1) am I being called at the "right" time, 2) am I being
called for the "right" file, etc):


h dftactgrp(*no)



dmyTrg pr

d TrgBfr likeds(QDBTB)

d LenTrgBfr 10i 0 const



dmyTrg pi

d TrgBfr likeds(QDBTB)

d LenTrgBfr 10i 0 const



d ORcdPtr s *

d ORcd s 32766a based(ORcdPtr)



d NRcdPtr s *

d NRcd s 32766a based(NRcdPtr)



/copy qsysinc/qrpglesrc,trgbuf



/free



ORcdPtr = %addr(TrgBfr) + TrgBfr.QDBORO;

NRcdPtr = %addr(TrgBfr) + TrgBfr.QDBNRO;



dsply ('Value before update: ' + %subst(ORcd: 3 :10));

dsply ('Value after update: ' + %subst(NRcd :3 :10));



%subst(NRcd :3 :10) = 'MyTrgChg';

dsply ('Value after trigger: ' + %subst(NRcd :3 :10));



*inlr = *on;

return;



/end-free



CrtBndRpg Pgm(BVining/MyTrg)



The use of '3' and '10' in the previous %subst operations is to represent
the respective starting offset (base 1) and length of MyData within the
TESTFILE Record.


I then added the MYTRG trigger program using the command:


AddPFTrg File(BVining/TestFile) TrgTime(*Before) TrgEvent(*Update)

Pgm(BVining/MyTrg) AlwRepChg(*Yes)


For convenience I then used SQL to insert and update a record in
BVINING/TESTFILE (you can use whatever mechanism to add and update that's
handy for your environment):



StrSQL


Insert into BVining/TestFile values(1, 'First')



Update BVining/TestFile

set MyData = 'Second'

where MyKey = 1


I then SQL to determine the value in the record, which was 'MyTrgChg'
(DSPPFM can also be used to show the value that was written):



Select * from BVining/TestFile



....+....1....+..

MYKEY MYDATA

1 MyTrgChg

******** End of data ********



And, due to the DSPLYs in MyTrg, also found the following messages:


DSPLY Value before update: First

DSPLY Value after update: Second

DSPLY Value after trigger: MyTrgChg

I hope this helps,
Bruce

On Fri, May 2, 2014 at 4:41 PM, Jack Prucha <Jack.Prucha@xxxxxxx> wrote:

We're missing something here. Rpgle on 7.1. I'm working with another
programmer on his pgm.

Created trigger with
ADDPFTRG FILE(AUTUSERS) TRGTIME(*BEFORE) TRGEVENT(*UPDATE)
PGM(AUTUSERE00) RPLTRG(*YES) ALWREPCHG(*YES)

Data is moved from buffer to a ds:

NewStart = NewRcdOff - 96 + 1;
OrgStart = OrgRcdOff - 96 + 1;

NewFileDS = %Subst( DataRcds : NewStart : NewRcdLen );
OrgFileDS = %Subst( DataRcds : OrgStart : OrgRcdLen );

Everything lines up in the DSs so the pointers and %subst seems to have
worked.

New (actually changed) record is copied to another DS

NewFileSav = NewFileDS;

Some changes are made and applied to NewFileSav. Then that ds moved back
into trigger new or after part of buffer:

%Subst( DataRcds : NewStart : NewRcdLen ) = NewFileSav;

In debug, I can see the changed data in datarcds, but it's not being
applied to the record when the trigger ends. Only my original changes that
fired the trigger.

I've looked in the redbook (changed the addpftgr to alwrepchg(*yes)).
Googled this. Any other suggestions?


TIA
Jack

This email, including any documents, files, or previous email messages
attached to it, has been sent from an email account of College Foundation
Inc., (CFI) and may contain confidential, proprietary, or legally
privileged information belonging to CFI. If you are not the intended
recipient, any dissemination, distribution, or copying of this email or its
attachments is strictly prohibited. If you have received this email in
error, please immediately notify the sender by email and destroy the
original email and any attachments.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.