How to insert records in a physical file using input subfile

80 pts.
Tags:
AS/400
AS/400 Records
AS/400 Subfiles
COBOL/400
Physical File
have to insert records to a physical file ,the input records should be taken from an input subfile

Answer Wiki

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

I hav a diffficulty in inserting records to PF ,The input records are read from an input subfile……But while executing the code its entering to a loop.am pasting the COBOL code and the DDS here…can anybody look into this and help me out 2 find the problem

FILE-CONTROL.
SELECT DISP-FILE ASSIGN WORKSTATION-SFLDSP1-SI
ORGANIZATION IS TRANSACTION
ACCESS MODE IS DYNAMIC
RELATIVE KEY IS WS-SUBFILE-RRN
FILE STATUS IS WS-FILE-STATUS
CONTROL-AREA IS WS-SCREEN-CONTROL-AREA.

SELECT EMP-FILE ASSIGN DATABASE-EMPPF1
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
FILE STATUS IS WS-FILE-STATUS
RECORD KEY IS EXTERNALLY-DESCRIBED-KEY.

DATA DIVISION.
FILE SECTION.

FD DISP-FILE LABEL RECORDS ARE OMITTED.
FILE SECTION.

FD DISP-FILE LABEL RECORDS ARE OMITTED.
01 DISP-FMT.
COPY DD-ALL-FORMATS OF SFLDSP1.

FD EMP-FILE LABEL RECORDS ARE STANDARD.
01 EMP-RCD-FMT.
COPY DDS-ALL-FORMATS OF EMPPF1.

WORKING-STORAGE SECTION.

01 SF090AC1-IN.
* COPY DDS-EMPREC-I OF SFLDSP.
*01 SF090AC1-OUT.
* COPY DDS-EMPREC-O OF SFLDSP.

*01 SFLCTL1-IN.
* COPY DDS-SFLCTL-I OF SFLDSP.
*01 SFLCTL1-OUT.
* COPY DD-SFLCTL-O OF SFLDSP.

01 WS-SCREEN-CONTROL-AREA.
05 WS-KEY-PRESSED PIC XX.
88 ENTER-KEY VALUE “00″.
88 FUNCTION-KEY1 VALUE “01″.
88 FUNCTION-KEY3 VALUE “03″.
88 FUNCTION-KEY5 VALUE “05″.
88 FUNCTION-KEY12 VALUE “12″.
88 ROLL-UP VALUE “90″.
88 ROLL-DOWN VALUE “91″.

01 WS-SCREEN-INDICATORS.
05 WS-SCR-INDICATOR PIC 1 OCCURS 99 TIMES INDICATOR 1.
88 INDICATOR-OFF VALUE B”0″.
88 INDICATOR-ON VALUE B”1″.

01 WS-INDICATORS-USED.
05 SFL-DISPLAY PIC 99 VALUE 20.
05 SFL-END PIC 99 VALUE 24.
05 SFL-CLEAR PIC 99 VALUE 23.
05 SFL-INITIALIZE PIC 99 VALUE 22.
05 FK-EXIT PIC 99 VALUE 03.
01 PROGRAM-NUMBER PIC X(10)
VALUE “SFLDSP “.
01 I-O-AREA PIC X(228)
VALUE SPACES.

01 WS-REC-VALIDATE PIC X.
88 NO-MORE-REC VALUE ‘Y’.
88 MORE-REC VALUE ‘N’.

01 WS-WORK-FIELDS.
05 WS-SUBFILE-RRN PIC 9(04).
05 WS-FILE-STATUS PIC X(02).

01 WS-EPNUM PIC 9(5) COMP-3.
01 WS-EPNAME PIC X(10).
01 WS-EPSAL PIC 9(5) COMP-3.

PROCEDURE DIVISION.
MAIN-PARA-SECTION.
MAIN-P.
PERFORM INTIALIZATION-PARA.
* PERFORM DISPLAY-SCREEN.
* PERFORM EXIT-PARA.

INTIALIZATION-PARA SECTION.
INTIALIZATION-P.
OPEN I-O DISP-FILE.
OPEN I-O EMP-FILE.
INITIALIZE WS-KEY-PRESSED
WS-SCREEN-INDICATORS
WS-WORK-FIELDS
EMP-RCD-FMT.
SET INDICATOR-ON (SFL-CLEAR) TO TRUE
SET INDICATOR-OFF (SFL-DISPLAY) TO TRUE
WRITE DISP-FMT
FORMAT IS “SFLCTL”
INDICATORS ARE WS-SCREEN-INDICATORS.

MOVE 0 TO WS-SUBFILE-RRN.
* SET INDICATOR-OFF (SFL-END) TO TRUE
* MOVE 1 TO CSRPSN.
SET INDICATOR-ON (SFL-END) TO TRUE.
SET INDICATOR-ON (SFL-DISPLAY) TO TRUE.
PERFORM WITH TEST BEFORE
UNTIL INDICATOR-ON(FK-EXIT)

* MOVE 1 TO WS-SUBFILE-RRN.
WRITE DISP-FMT
FORMAT IS “SFLCTL”
INDICATORS ARE WS-SCREEN-INDICATORS

READ DISP-FILE
FORMAT IS “SFLCTL”
INDICATORS ARE WS-SCREEN-INDICATORS
END-READ
IF NOT INDICATOR-ON(FK-EXIT)
PERFORM READINPUT
END-IF
END-PERFORM.
PERFORM EXIT-PARA.
READINPUT SECTION.
READINPUT1.
READ SUBFILE DISP-FILE
NEXT MODIFIED RECORD FORMAT IS ‘SFLCTL’

AT END

SET NO-MORE-REC TO TRUE

NOT AT END
MOVE EMPNO TO WS-EPNUM
MOVE EMPNAME TO WS-EPNAME
MOVE EMPSAL TO WS-EPSAL
MOVE WS-EPNUM TO EPNUM
MOVE WS-EPNAME TO EPNAME
MOVE WS-EPSAL TO EPSAL
* ADD 1 TO WS-SUBFILE-RRN

* ADD 1 TO
END-READ.
EXIT-PARA SECTION.
EXITP.
CLOSE DISP-FILE
EMP-FILE
STOP RUN.

DDS

A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS
A*%%EC
A DSPSIZ(24 80 *DS3)
A INDARA
A R EMPREC SFL
A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS
A* @RRN 4S 0I 8 7ALIAS(SUBFILE_RRN)
A EMPNO 5 0I 9 11
A EMPNAME 10A I 9 26
A EMPSAL 5 0I 9 48
A R SFLCTL SFLCTL(EMPREC)
A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS
A CA03(03 ‘Exit’)
A CA12(12 ‘Cancel’)
A OVERLAY
A 20 SFLDSP
A N23 SFLDSPCTL
A 22 SFLINZ
A 23 SFLCLR
A 24 SFLEND(*MORE)
A SFLSIZ(9999)
A SFLPAG(0010)
A CRSR 5S 0H
A 1 2DATE
A EDTCDE(Y)
A 1 72TIME
A 2 30′Employee Report’
A 2 1USER
A 3 30′—————-’
A 7 11′Emp no’
A 7 26′Emp Name’
A 7 48′Emp Salary’

Discuss This Question: 10  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
  • TomLiotta
    What are you having trouble with? Subfile concepts? Subfile specifications? Display file creation? DDS? Programming in COBOL? Accessing the system? Programming? Tom
    125,585 pointsBadges:
    report
  • Rr1234
    Hi Tom, Thanks for looking into my Question.Am a beginner in AS400. I have done load all subfile program for displaying 10 records from a PF.Now i would like to knw wat are the changes to be done in dat program for inserting records to the PF .The records should be read from an input subfile.I would like to know how to create the display file for this input subfile and the changes to be done inDDS
    80 pointsBadges:
    report
  • philpl1jb
    I thought I had a handle on this, until I read your last sentence .. not sure where this is going. "I would like to know how to create the display file for this input subfile and the changes to be done inDDS" Changes to the RPG might look like this, if all the fields in the subfile and PF has the same names READC MySubF Dow Not %EOF Write MyPF READC MySubF Enddo
    49,940 pointsBadges:
    report
  • Rr1234
    Thanks !!! I would lik 2 knw about the the indicators to be set and the READ SUBFILE NEXT MODIFIED statement .
    80 pointsBadges:
    report
  • Rr1234
    Can U pls send code in COBOL
    80 pointsBadges:
    report
  • Rr1234
    I hav a diffficulty in inserting records to PF ,The input records are read from an input subfile......But while executing the code its entering to a loop.am pasting the COBOL code and the DDS here...can anybody look into this and help me out 2 find the problem FILE-CONTROL. SELECT DISP-FILE ASSIGN WORKSTATION-SFLDSP1-SI ORGANIZATION IS TRANSACTION ACCESS MODE IS DYNAMIC RELATIVE KEY IS WS-SUBFILE-RRN FILE STATUS IS WS-FILE-STATUS CONTROL-AREA IS WS-SCREEN-CONTROL-AREA. SELECT EMP-FILE ASSIGN DATABASE-EMPPF1 ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC FILE STATUS IS WS-FILE-STATUS RECORD KEY IS EXTERNALLY-DESCRIBED-KEY. DATA DIVISION. FILE SECTION. FD DISP-FILE LABEL RECORDS ARE OMITTED. FILE SECTION. FD DISP-FILE LABEL RECORDS ARE OMITTED. 01 DISP-FMT. COPY DD-ALL-FORMATS OF SFLDSP1. FD EMP-FILE LABEL RECORDS ARE STANDARD. 01 EMP-RCD-FMT. COPY DDS-ALL-FORMATS OF EMPPF1. WORKING-STORAGE SECTION. 01 SF090AC1-IN. * COPY DDS-EMPREC-I OF SFLDSP. *01 SF090AC1-OUT. * COPY DDS-EMPREC-O OF SFLDSP. *01 SFLCTL1-IN. * COPY DDS-SFLCTL-I OF SFLDSP. *01 SFLCTL1-OUT. * COPY DD-SFLCTL-O OF SFLDSP. 01 WS-SCREEN-CONTROL-AREA. 05 WS-KEY-PRESSED PIC XX. 88 ENTER-KEY VALUE "00". 88 FUNCTION-KEY1 VALUE "01". 88 FUNCTION-KEY3 VALUE "03". 88 FUNCTION-KEY5 VALUE "05". 88 FUNCTION-KEY12 VALUE "12". 88 ROLL-UP VALUE "90". 88 ROLL-DOWN VALUE "91". 01 WS-SCREEN-INDICATORS. 05 WS-SCR-INDICATOR PIC 1 OCCURS 99 TIMES INDICATOR 1. 88 INDICATOR-OFF VALUE B"0". 88 INDICATOR-ON VALUE B"1". 01 WS-INDICATORS-USED. 05 SFL-DISPLAY PIC 99 VALUE 20. 05 SFL-END PIC 99 VALUE 24. 05 SFL-CLEAR PIC 99 VALUE 23. 05 SFL-INITIALIZE PIC 99 VALUE 22. 05 FK-EXIT PIC 99 VALUE 03. 01 PROGRAM-NUMBER PIC X(10) VALUE "SFLDSP ". 01 I-O-AREA PIC X(228) VALUE SPACES. 01 WS-REC-VALIDATE PIC X. 88 NO-MORE-REC VALUE 'Y'. 88 MORE-REC VALUE 'N'. 01 WS-WORK-FIELDS. 05 WS-SUBFILE-RRN PIC 9(04). 05 WS-FILE-STATUS PIC X(02). 01 WS-EPNUM PIC 9(5) COMP-3. 01 WS-EPNAME PIC X(10). 01 WS-EPSAL PIC 9(5) COMP-3. PROCEDURE DIVISION. MAIN-PARA-SECTION. MAIN-P. PERFORM INTIALIZATION-PARA. * PERFORM DISPLAY-SCREEN. * PERFORM EXIT-PARA. INTIALIZATION-PARA SECTION. INTIALIZATION-P. OPEN I-O DISP-FILE. OPEN I-O EMP-FILE. INITIALIZE WS-KEY-PRESSED WS-SCREEN-INDICATORS WS-WORK-FIELDS EMP-RCD-FMT. SET INDICATOR-ON (SFL-CLEAR) TO TRUE SET INDICATOR-OFF (SFL-DISPLAY) TO TRUE WRITE DISP-FMT FORMAT IS "SFLCTL" INDICATORS ARE WS-SCREEN-INDICATORS. MOVE 0 TO WS-SUBFILE-RRN. * SET INDICATOR-OFF (SFL-END) TO TRUE * MOVE 1 TO CSRPSN. SET INDICATOR-ON (SFL-END) TO TRUE. SET INDICATOR-ON (SFL-DISPLAY) TO TRUE. PERFORM WITH TEST BEFORE UNTIL INDICATOR-ON(FK-EXIT) * MOVE 1 TO WS-SUBFILE-RRN. WRITE DISP-FMT FORMAT IS "SFLCTL" INDICATORS ARE WS-SCREEN-INDICATORS READ DISP-FILE FORMAT IS "SFLCTL" INDICATORS ARE WS-SCREEN-INDICATORS END-READ IF NOT INDICATOR-ON(FK-EXIT) PERFORM READINPUT END-IF END-PERFORM. PERFORM EXIT-PARA. READINPUT SECTION. READINPUT1. READ SUBFILE DISP-FILE NEXT MODIFIED RECORD FORMAT IS 'SFLCTL' AT END SET NO-MORE-REC TO TRUE NOT AT END MOVE EMPNO TO WS-EPNUM MOVE EMPNAME TO WS-EPNAME MOVE EMPSAL TO WS-EPSAL MOVE WS-EPNUM TO EPNUM MOVE WS-EPNAME TO EPNAME MOVE WS-EPSAL TO EPSAL * ADD 1 TO WS-SUBFILE-RRN * ADD 1 TO END-READ. EXIT-PARA SECTION. EXITP. CLOSE DISP-FILE EMP-FILE STOP RUN. DDS A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS A*%%EC A DSPSIZ(24 80 *DS3) A INDARA A R EMPREC SFL A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS A* @RRN 4S 0I 8 7ALIAS(SUBFILE_RRN) A EMPNO 5 0I 9 11 A EMPNAME 10A I 9 26 A EMPSAL 5 0I 9 48 A R SFLCTL SFLCTL(EMPREC) A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS A CA03(03 'Exit') A CA12(12 'Cancel') A OVERLAY A 20 SFLDSP A N23 SFLDSPCTL A 22 SFLINZ A 23 SFLCLR A 24 SFLEND(*MORE) A SFLSIZ(9999) A SFLPAG(0010) A CRSR 5S 0H A 1 2DATE A EDTCDE(Y) A 1 72TIME A 2 30'Employee Report' A 2 1USER A 3 30'----------------' A 7 11'Emp no' A 7 26'Emp Name' A 7 48'Emp Salary'
    80 pointsBadges:
    report
  • TomLiotta
    After you paste code from a program, select the pasted code and click the {code} button at the top of the entry area. It makes code more readable; and for something like DDS, it's almost necessary. Tom
    125,585 pointsBadges:
    report
  • Rr1234
    PLS send a sloution ASAP......dispaly file itself not coming while executing......
    FILE-CONTROL.
    SELECT DISP-FILE ASSIGN WORKSTATION-SFLDSP1-SI
    ORGANIZATION IS TRANSACTION
    ACCESS MODE IS DYNAMIC
    RELATIVE KEY IS WS-SUBFILE-RRN
    FILE STATUS IS WS-FILE-STATUS
    CONTROL-AREA IS WS-SCREEN-CONTROL-AREA. 
    
    SELECT EMP-FILE ASSIGN DATABASE-EMPPF1
    ORGANIZATION IS INDEXED
    ACCESS MODE IS DYNAMIC
    FILE STATUS IS WS-FILE-STATUS
    RECORD KEY IS EXTERNALLY-DESCRIBED-KEY. 
    
    DATA DIVISION.
    FILE SECTION. 
    
    FD DISP-FILE LABEL RECORDS ARE OMITTED.
    FILE SECTION. 
    
    FD DISP-FILE LABEL RECORDS ARE OMITTED.
    01 DISP-FMT.
    COPY DD-ALL-FORMATS OF SFLDSP1. 
    
    FD EMP-FILE LABEL RECORDS ARE STANDARD.
    01 EMP-RCD-FMT.
    COPY DDS-ALL-FORMATS OF EMPPF1. 
    
    WORKING-STORAGE SECTION. 
    
    01 SF090AC1-IN.
    * COPY DDS-EMPREC-I OF SFLDSP.
    *01 SF090AC1-OUT.
    * COPY DDS-EMPREC-O OF SFLDSP. 
    
    *01 SFLCTL1-IN.
    * COPY DDS-SFLCTL-I OF SFLDSP.
    *01 SFLCTL1-OUT.
    * COPY DD-SFLCTL-O OF SFLDSP. 
    
    01 WS-SCREEN-CONTROL-AREA.
    05 WS-KEY-PRESSED PIC XX.
    88 ENTER-KEY VALUE “00″.
    88 FUNCTION-KEY1 VALUE “01″.
    88 FUNCTION-KEY3 VALUE “03″.
    88 FUNCTION-KEY5 VALUE “05″.
    88 FUNCTION-KEY12 VALUE “12″.
    88 ROLL-UP VALUE “90″.
    88 ROLL-DOWN VALUE “91″. 
    
    01 WS-SCREEN-INDICATORS.
    05 WS-SCR-INDICATOR PIC 1 OCCURS 99 TIMES INDICATOR 1.
    88 INDICATOR-OFF VALUE B”0″.
    88 INDICATOR-ON VALUE B”1″. 
    
    01 WS-INDICATORS-USED.
    05 SFL-DISPLAY PIC 99 VALUE 20.
    05 SFL-END PIC 99 VALUE 24.
    05 SFL-CLEAR PIC 99 VALUE 23.
    05 SFL-INITIALIZE PIC 99 VALUE 22.
    05 FK-EXIT PIC 99 VALUE 03.
    01 PROGRAM-NUMBER PIC X(10)
    VALUE “SFLDSP “.
    01 I-O-AREA PIC X(228)
    VALUE SPACES. 
    
    01 WS-REC-VALIDATE PIC X.
    88 NO-MORE-REC VALUE ‘Y’.
    88 MORE-REC VALUE ‘N’. 
    
    01 WS-WORK-FIELDS.
    05 WS-SUBFILE-RRN PIC 9(04).
    05 WS-FILE-STATUS PIC X(02). 
    
    01 WS-EPNUM PIC 9(5) COMP-3.
    01 WS-EPNAME PIC X(10).
    01 WS-EPSAL PIC 9(5) COMP-3. 
    
    PROCEDURE DIVISION.
    MAIN-PARA-SECTION.
    MAIN-P.
    PERFORM INTIALIZATION-PARA.
    * PERFORM DISPLAY-SCREEN.
    * PERFORM EXIT-PARA. 
    
    INTIALIZATION-PARA SECTION.
    INTIALIZATION-P.
    OPEN I-O DISP-FILE.
    OPEN I-O EMP-FILE.
    INITIALIZE WS-KEY-PRESSED
    WS-SCREEN-INDICATORS
    WS-WORK-FIELDS
    EMP-RCD-FMT.
    SET INDICATOR-ON (SFL-CLEAR) TO TRUE
    SET INDICATOR-OFF (SFL-DISPLAY) TO TRUE
    WRITE DISP-FMT
    FORMAT IS “SFLCTL”
    INDICATORS ARE WS-SCREEN-INDICATORS. 
    
    MOVE 0 TO WS-SUBFILE-RRN.
    * SET INDICATOR-OFF (SFL-END) TO TRUE
    * MOVE 1 TO CSRPSN.
    SET INDICATOR-ON (SFL-END) TO TRUE.
    SET INDICATOR-ON (SFL-DISPLAY) TO TRUE.
    PERFORM WITH TEST BEFORE
    UNTIL INDICATOR-ON(FK-EXIT) 
    
    * MOVE 1 TO WS-SUBFILE-RRN.
    WRITE DISP-FMT
    FORMAT IS “SFLCTL”
    INDICATORS ARE WS-SCREEN-INDICATORS 
    
    READ DISP-FILE
    FORMAT IS “SFLCTL”
    INDICATORS ARE WS-SCREEN-INDICATORS
    END-READ
    IF NOT INDICATOR-ON(FK-EXIT)
    PERFORM READINPUT
    END-IF
    END-PERFORM.
    PERFORM EXIT-PARA.
    READINPUT SECTION.
    READINPUT1.
    READ SUBFILE DISP-FILE
    NEXT MODIFIED RECORD FORMAT IS ‘SFLCTL’ 
    
    AT END 
    
    SET NO-MORE-REC TO TRUE 
    
    NOT AT END
    MOVE EMPNO TO WS-EPNUM
    MOVE EMPNAME TO WS-EPNAME
    MOVE EMPSAL TO WS-EPSAL
    MOVE WS-EPNUM TO EPNUM
    MOVE WS-EPNAME TO EPNAME
    MOVE WS-EPSAL TO EPSAL
    * ADD 1 TO WS-SUBFILE-RRN 
    
    * ADD 1 TO
    END-READ.
    EXIT-PARA SECTION.
    EXITP.
    CLOSE DISP-FILE
    EMP-FILE
    STOP RUN. 
    
    DDS
    
    A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS
    A*%%EC
    A DSPSIZ(24 80 *DS3)
    A INDARA
    A R EMPREC SFL
    A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS
    A* @RRN 4S 0I 8 7ALIAS(SUBFILE_RRN)
    A EMPNO 5 0I 9 11
    A EMPNAME 10A I 9 26
    A EMPSAL 5 0I 9 48
    A R SFLCTL SFLCTL(EMPREC)
    A*%%TS SD 20101103 082611 A911809 REL-V5R4M0 5722-WDS
    A CA03(03 ‘Exit’)
    A CA12(12 ‘Cancel’)
    A OVERLAY
    A 20 SFLDSP
    A N23 SFLDSPCTL
    A 22 SFLINZ
    A 23 SFLCLR
    A 24 SFLEND(*MORE)
    A SFLSIZ(9999)
    A SFLPAG(0010)
    A CRSR 5S 0H
    A 1 2DATE
    A EDTCDE(Y)
    A 1 72TIME
    A 2 30′Employee Report’
    A 2 1USER
    A 3 30′—————-’
    A 7 11′Emp no’
    A 7 26′Emp Name’
    A 7 48′Emp Salary’
    80 pointsBadges:
    report
  • JohnN
    In your code I can see nowhere that you create the display subfile records
    Write Subfile DISP-FMT FORMAT "EMPREC" INDICATORS........
    Without this the program has nothing to show on the screen!
    50 pointsBadges:
    report
  • Rr1234
    how to get error messages on subfile.......how to clear and write back the sub file screen once inputs has given
    80 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