Problem with Update Trigger Event

30 pts.
Tags:
as400/DB2 - Trigger - Comit
I'm writing  an ILE COBOL Program

WORKING-STORAGE SECTION.

01  STATUS-ERR1                 PIC XX. 01  STATUS-ERR2                 PIC XX.

 01 OLDFILE-REC.                                               COPY DD-ALL-FORMATS OF FILE1.                          05  BEN-REC-OFFSET              PIC 9(8)  BINARY.          *                                                            01 NEWFILE-REC.                                               COPY DD-ALL-FORMATS OF FILE1.                          05  NEW-REC-OFFSET              PIC 9(8)  BINARY.          *                                                            01  FEEDBACK-STUFF              PIC X(1000) VALUE SPACES. 

LINKAGE SECTION.                                  01  PARM-1-AREA.                                    03 FILE-NAME                  PIC X(10).          03 LIB-NAME                   PIC X(10).          03 MEM-NAME                   PIC X(10).          03 TRG-EVENT                  PIC X.              03 TRG-TIME                   PIC X.              03 CMT-LCK-LVL                PIC X.              03 FILLER                     PIC X(03).          03 DATA-AREA-CCSID            PIC 9(08) BINARY.   03 FILLER                     PIC X(08).           

  03 DATA-OFFSET.                                          05 BEN-REC-OFF              PIC 9(08) BINARY.          05 BEN-REC-LEN              PIC 9(08) BINARY.          05 BEN-REC-NULL-MAP         PIC 9(08) BINARY.          05 BEN-REC-NULL-LEN         PIC 9(08) BINARY.          05 NEW-REC-OFF              PIC 9(08) BINARY.          05 NEW-REC-LEN              PIC 9(08) BINARY.          05 NEW-REC-NULL-MAP         PIC 9(08) BINARY.          05 NEW-REC-NULL-LEN         PIC 9(08) BINARY.          05 FILLER                   PIC X(16).              03 RECORD-JUNK.                                          05 BEN-RECORD               PIC X(288).                05 BEN-NULL-MAP             PIC X(04).                 05 NEW-RECORD               PIC X(288).                05 NEW-NULL-MAP             PIC X(04).          

01 PARM-2-AREA.                             03 TRGBUFL                    PIC X(02).

PROCEDURE DIVISION USING PARM-1-AREA, PARM-2-AREA.

 COMPUTE BEN-REC-OFFSET = BEN-REC-OFF + 1     UNSTRING PARM-1-AREA INTO OLDFILE-REC         WITH POINTER BEN-REC-OFFSET                                                            COMPUTE NEW-REC-OFFSET = NEW-REC-OFF + 1     UNSTRING PARM-1-AREA INTO NEWFILE-REC         WITH POINTER NEW-REC-OFFSET             

OLDFILE-REC

25511007101    3820CV25511007101    25511007101    CBI00X300 002 DPP4B         ■MY■■■■ ■                 ■      NOV2■°j"■ ■/ N54077    QPADEV000VRBTUSRPD  ■°j"■ÈÄi■AY■■■■                          ■°j"■°j"MIGRATED             ■■■■■■é■■NOV2         LG1   OG1         LFA                    ■|'          

NEWFILE-REC

25511007101    3820CV25511007101    25511007101    CBI00X300 002 DPP4B         ■MY■■■■ ■                 ■      NOV2■°j"■ ■/ N54077    QPADEV000VRBTUSRPD  ■°j"■ÈÄi■AY■■■■                          ■°j"■°j"MIGRATED             ■■■■■■é■■                                                                '           

Without changing any value, I simply updated the file

When I checked inside the program in Debug, NEWFILE-REC is wih some truncated value

(NOV2         LG1   OG1         LFA                    ■|) This Portion is missing at the end

Can some body help me out.. what may be the reason

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    It's hard to be sure without more information, but these fields are not defined correctly:
           05 FILLER                   PIC X(16).
        03 RECORD-JUNK.
           05 BEN-RECORD               PIC X(288).
           05 BEN-NULL-MAP             PIC X(04).
           05 NEW-RECORD               PIC X(288).
           05 NEW-NULL-MAP             PIC X(04).
    First, the FILLER item might or might not be X(16). There is no good way to know what its size is going to be when your program runs in the future. There is no definition available for it. Its size is undefined. There is no reason to define it at all. The BEN-RECORD, BEN-NULL-MAP, NEW-RECORD and NEW-NULL-MAP fields should all be 01-level items, not defined as sub-fields of the PARM-1-AREA structure. Those fields have addresses that are determined by their offsets. They are not at fixed positions in the structure. The purpose of the offset fields is to adapt to future differences in record sizes or in the behavior of DB2. The database might act differently after upgrades or PTFs. By only using the offsets, you are protected from future changes. Since they don't have fixed positions, you can't reliably define PARM-1-AREA as a fixed-length structure. You don't know how long it is. And because of that, you can't use it as the source for your UNSTRING statement. With the offsets as your UNSTRING POINTER values, you are starting at the right memory address. However, the UNSTRING may stop too soon because your definition of PARM-1-AREA may be too short. The result would be just what you showed in your question -- a value in NEWFILE-REC that is truncated. Change the BEN-RECORD, BEN-NULL-MAP, NEW-RECORD and NEW-NULL-MAP fields to be 01-level items in your LINKAGE SECTION. Before you access any of those four fields, set its address to be the ADDRESS OF PARM-1-AREA, then set the ADDRESS OF the field UP BY the associated offset. You can then access each field directly. If you want to copy NEW-RECORD into NEWFILE-REC, just use MOVE. The UNSTRING isn't needed when you get the linkage item pointed at the right address and offset. You might also use COPY DD-ALL-FORMATS to define the BEN-RECORD and NEW-RECORD fields. You shouldn't use a PIC clause for those since the size might change in the future. And technically you shouldn't use DD-ALL-FORMATS unless you actually want all formats. For a database file, there is only one format, so it's not a big deal. It won't really matter in your program, but consider a more explicit format of COPY. Now, you can ignore almost everything that I wrote above if you wish. Instead, what you can do is start a debug session and cause your trigger to run. Look at the actual values in PARM-1-AREA to figure out if your FILLER item really is 16 bytes long. If BEN-RECORD needs to start somewhere else, then change PIC X(16) to be the correct size for your program and your files. Then look at BEN-NULL-MAP, NEW-RECORD and NEW-NULL-MAP fields to see if each one has the correct value. If any is wrong, add a new FILLER field in front of it to adjust its starting position to the right location. When each is positioned properly, they should all show correct values in debug. You might need to recompile and run in debug multiple times as you do the adjustments. I can't tell about your BEN-NULL-MAP and NEW-NULL-MAP fields. If your file only has four fields, they should be okay. Otherwise, X(04) should be changed for both of them. If you can set correct FILLER fields, the length of PARM-1-AREA will be correct and your UNSTRING should grab the right bytes by using the POINTER clause with the offset fields. So, you have two ways to go. You can use "soft coding" or you can use the hard-coding method that you're trying to do now. It looks like you took the code straight out of the Stored Procedures, Triggers, and User-Defined Functions Redbook. The examples in that manual are for the files used in those examples and for the versions of DB2 used at that time. When you write your own triggers, you might need to make numerous changes. I would use a "soft coding" method. You can use hard-coding, but be aware that you might have to change the code in the future. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following