Subfile in As400

635 pts.
Tags:
AS/400
AS/400 Subfiles
Duplicate records
OS/400
Hi below pasted is my code which i am running but i am getting an error 'Attemp to write duplicate records" DDS A*                                                         A                                      CF03(03)            A                                      DSPSIZ(24 80 *DS3)  A          R RECSFL                    SFL                 A  30                                  SFLNXTCHG           A            UPC           20   B  9  3TEXT('UPC 2ND ITEM') A  31                                  DSPATR(UL)          A*                                                         A          R RECCTL                    SFLCTL(RECSFL)      A*                                                         A                                      OVERLAY             A                                      SFLSIZ(0010)        A                                      SFLPAG(0005)        A  10                                  SFLDSP              A  12                                  SFLDSPCTL           A  11                                  SFLCLR              A  13                                  SFLINZ              A                                      SFLDROP(CF04)       A                                      SFLFOLD(CF04)       A            #RRNO          4S 0H      SFLRCDNBR           A                                  1  2DATE              A                                      EDTCDE(Y)         A                                  1 12TIME              A                                  5  3'UPC SHORT CODE. . A                                      COLOR(WHT)        A                                  8  3'UPC 2ND ITEM'    A  31                                  DSPATR(UL)        A                                      COLOR(TRQ)        A            UPCSCD         3A  I  5 24TEXT('UPC')       A          R FKEY                                        A                                       OVERLAY          A                                 23  2'F3 - EXIT'       A                                      COLOR(BLU)        RPGLE code FSIDDLF    IF   E           K DISK    INFDS(@SIDLF)                    FPSIDDPF   IF   E           K DISK                                     F                                     RENAME(PSIDDPF:@PSIDDPF)         F                                     PREFIX(P)                        FD123      CF   E             WORKSTN INFDS(@D123)                     F                                     SFILE(RECSFL:I1)                 D @D123           DS           500                                      *                                                                     D @SIDLF          DS                                                   D  #RRN                 400    402                                      *                                                                      ********* MAIN ROUTINE *******************                    *                                                                     C                   EXSR      LOAD                                     C                   SETON                                            LR  *                                                                     ******************* LOAD SUBFILE *********  *                                                                     C     LOAD          BEGSR                                               *                                                                     C     *IN03         DOWEQ     '0'                                       *                                                                     C                   WRITE     FKEY                                     C                   EXFMT     RECCTL                                   C                   Z-ADD     0             I1                         C                   Z-ADD     0             #RRNO                      C*                                                                     C     UPCSCD        SETLL     @PSIDDPF                                 C     UPCSCD        READE     @PSIDDPF                               89 C     *IN89           DOWEQ     '0'                                      C                        MOVEL       PUPC          UPC                        C                        ADD          1             I1                         C     #RRNO         IFEQ      0                                        C                        ADD       I1            #RRNO                      C                        ENDIF                                              C                        WRITE     RECSFL        <--- error here                       C*                      C     UPCSCD        READE     @PSIDDPF                               89 C                   ENDDO                                               *                                                               C                   ENDDO                                         *                                                               C                   ENDSR                                         ******** INIT ROUTINE *********************           *                                                               C     *INZSR        BEGSR                                         *                                                               C                   EXSR      SCLR                                *                                                               C                   ENDSR                                         *                                                                ******* CLEAR SUBFILE ********************           *                                                               C     SCLR          BEGSR                                        C                   Z-ADD     0             I1                4 0 C                   Z-ADD     0             #RRNO                C                   MOVE      *ON           *IN11                C                   MOVE      *OFF          *IN10                C                   MOVE      *OFF          *IN12                C                   WRITE     RECCTL   <-- Control record                          C                   MOVE      *OFF          *IN11                C                   MOVE      *ON           *IN10                C                   MOVE      *ON           *IN12                C                   MOVE      *ON           *IN31                C                   Z-ADD     5             PG                4 0 C                   DO        PG                                 C                   ADD       1             I1                   C                   ADD       1             #RRNO                C                   WRITE     RECSFL    <- subfile record                         C                   ENDDO                                         *                                                               C                   ENDSR                                         *                                                              

Software/Hardware used:
os/400

Answer Wiki

Thanks. We'll let you know when a new response is added.

It looks as if your SCLR subr leaves field #RRNO with thevalue ’5′. In your LOAD subr you test if #RRMO is equal to zero, which is not the case. Therefore you will do your looped writings with #RRNO = 5 constantly…

Good luck

DanF

SCLR you have written the 5 records to the subfile.
You must Chain to each one and update.
you may want to MOVE *blank UPC before WRITE RECSFL

It looks to me like your Z-ADD 0 to I1 and then the ADD 1 I1 are intended to make your #RRNO field contain a continually incremented record number. But when you do the ADD I1 #RRNO, you’re not just moving the value of I1 to #RRNO, you’re adding it to #RRNO, so the values in #RRNO would be 1, 3, 6, etc.
Even with that said, you only execute the ADD I1 #RRNO once, since #RRNO won’t be zero the second time through the loop. Therefore, #RRNO will not get changed, and you’ll write record 1 a second time. That would give you a duplicate record error.

Discuss This Question: 2  Replies

 
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
  • Sangay
    program is working now just had to initialize the indicators....but i am facing another type of issue. I am entering the UPC short code value in UPCSCD value but after displaying subfile values in UPC, the value in UPCSCD gets cleared. I want to retain the value even after displaying the subfile values.. Any help Thanks a ton in advance.
    635 pointsBadges:
    report
  • Sangay
    ohh. i have found that too.....the field was input capable...made it to output capable
    635 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