ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Triggers in A400

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Triggers in A400

    Hi,
    I have doubts in trigger in as400.Below is the Trigger Buffer for RPG
    D*
    D* Data structures for Trigger Buffer
    D* and Trigger Buffer Length
    D*
    D* Trigger Buffer
    D*
    DTrgBuffer DS
    D TFileName 10
    D TLibName 10
    D TMemName 10
    D TTrgEvent 1
    D TTrgTime 1
    D TCommitLock 1
    D TFiller1 3
    D TCCSID 10I 0
    D TRelRecNbr 10I 0
    D TFiller2 10I 0
    D TOldRecOff 10I 0
    D TOldRecLen 10I 0
    D TOldNullOff 10I 0
    D TOldNullLen 10I 0
    D TNewRecOff 10I 0
    D TNewRecLen 10I 0
    D TNewNullOff 10I 0
    D TNewNullLen 10I 0
    D*
    D* Trigger Buffer Length
    D*
    DTrgBufferLen S 10I 0
    to get the old/new data pointer we use below....
    CL0N01Factor1+++++++Opcode&ExtExtended-factor2+++++++++++++++++++++++++++
    C Eval OldRecPtr = %ADDR(TrgBuffer) + TOldRecOff
    C Eval NewRecPtr = %ADDR(TrgBuffer) + TNewRecOff
    C*
    C Eval OldNullPtr = %ADDR(TrgBuffer) + TOldNullOff
    C Eval NewNullPtr = %ADDR(TrgBuffer) + TNewNullOff
    Hence my doubts are :-
    1. what is TOldRecOff and TOldRecLen.
    2. what is the difference between %ADDR(TrgBuffer) and TOldRecOff .Actually what we are doing in above code.
    3. Is it necessary to use null capable fields if yes why.


  • #2
    Originally posted by Iceberg View Post
    Hi,
    I have doubts in trigger in as400.Below is the Trigger Buffer for RPG
    Code:
    D*  Data structures for Trigger Buffer
    D*  and Trigger Buffer Length
    D*
    D*  Trigger Buffer
    D*
    DTrgBuffer        DS
    D TFileName                     10
    D TLibName                      10
    D TMemName                      10
    D TTrgEvent                      1
    D TTrgTime                       1
    D TCommitLock                    1
    D TFiller1                       3
    D TCCSID                        10I 0
    D TRelRecNbr                    10I 0
    D TFiller2                      10I 0
    D TOldRecOff                    10I 0
    D TOldRecLen                    10I 0
    D TOldNullOff                   10I 0
    D TOldNullLen                   10I 0
    D TNewRecOff                    10I 0
    D TNewRecLen                    10I 0
    D TNewNullOff                   10I 0
    D TNewNullLen                   10I 0
    D*
    D*  Trigger Buffer Length
    D*
    DTrgBufferLen     S             10I 0
    to get the old/new data pointer we use below....
    Code:
    C                   Eval      OldRecPtr  = %ADDR(TrgBuffer) + TOldRecOff
    C                   Eval      NewRecPtr  = %ADDR(TrgBuffer) + TNewRecOff
    C*
    C                   Eval      OldNullPtr = %ADDR(TrgBuffer) + TOldNullOff
    C                   Eval      NewNullPtr = %ADDR(TrgBuffer) + TNewNullOff
    Hence my doubts are :-
    1. what is TOldRecOff and TOldRecLen.
    2. what is the difference between %ADDR(TrgBuffer) and TOldRecOff .Actually what we are doing in above code.
    3. Is it necessary to use null capable fields if yes why.
    1. TOldRecOff is the offset to the old record. TOldRecLen is the length of the old record.

    2. This code (Eval OldRecPtr = %ADDR(TrgBuffer) + TOldRecOff) sets a pointer to the data for the old record. The trigger parameter starts with the header information in your data structure, and it is followed by the old and new record data and the old and new null-map data. This extra data can be in any order, so the various offsets are used to locate the data. %ADDR(TrgBuffer) is the address of the beginning of the parameter, and by adding TOldRecOff (old record offset) to it, OldRecPtr will be the address of the old record data.

    3. It is not necessary to use null-capable fields in your files. If you do have null-capable fields in your file, your trigger program may have to work with the null-map information.

    By the way, use [ code ] tags around your code, rather than [ table ] tags. (I got the original version of your source by using right-click->View Page Source in the browser.)

    Comment


    • #3
      But what do u mean by offest here actually

      Comment


      • #4
        An offset is a count of bytes from the start of a space in memory to the part where the needed data begins. Offsets are used throughout computer programming, they are not unique to triggers.

        In your case, the TOldRecOff is a variable sent to you by the database engine. It is saying "This is the position in the computers memory where the old record offset is stored" For example, if it sends you a value of 1000, it means that the old record offset is 1000 bytes after the start of the trigger buffer. So if you take the address of the trigger buffer and add the TOldRecOff, you get the actual position in the computer's memory where the data is stored.

        Comment


        • #5
          U mean offset is count of bytes from the start from trigger buffer to the start of old record. Here i.e 1000. Hence by adding this (1000) to address of trigger buffer we can get the start address of old record right?

          Comment


          • #6
            Yes.

            Comment


            • #7
              thanx scott

              Comment

              Working...
              X