1.Write code to read the records from a file and load an
array of size 99? Make sure that you take care of all the
error conditions?

Answers were Sorted based on User's Feedback



1.Write code to read the records from a file and load an array of size 99? Make sure that you take..

Answer / rosh

Fpf1 if e k disk

D Max s 2p 0 inz(99)
d Lowrec s 2p 0 inz

Read(e) PF1
Dow not %EOF(PF1)
IF Lowrec <= Max
Move record to array(Lowrec)
eval Lowrec = Lowrec + 1
else
Leave
Endif
Read(e) Pf1
ENDDO

Is This Answer Correct ?    1 Yes 1 No

1.Write code to read the records from a file and load an array of size 99? Make sure that you take..

Answer / sachin

IDENTIFICATION DIVISION.
PROGRAM-ID.PGM1.
ENVIRONMENT DEVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT FILE1 ASSIGN TO DD1
FILE STATUS IS FS1.
DATA DIVISION.
FILE-SECTION.
FD FILE1.
RECORDING MODE IS FB.
LABLES ARE STANDARD.
01 WS-INPUT PIC X(80).

WORKING-STORAGE SECTION.
01 WS-ARRAY.
02 WS-NAME OCCURS 99 TIMES.

01 SWITCHES.
02 WS-EOF-SWITCH PIC X(1)
88 WS-EOF VALUE 'Y'
88 WS-NOT-EOF VALUE 'N'
PROCEDURE DIVISION.
MAIN-PARA.

PERFORM 1000-INITIALIZATION THRU 1000-EXIT.
PERFORM 2000-READ-FILE1 THRU 2000-EXIT
UNTIL WS-EOF.
PERFORM 3000-MAIN-PROCESS THRU 3000-EXIT
STOP RUN.

1000-INITIALIZATION.
INITIALIZE VARIABLES.
OPEN INPUT FILE1.

1000-EXIT
EXIT.

2000-READ-FILE.

READ FILE AT END MOVE 'Y' TO WS-EOF-SWITCH
NOT AT END
CONTINUE
END-READ.

2000-EXIT.
EXIT.

3000-MAIN-PROCESS.
PERFORM VARYING I FROM 1 BY UNTIL WS-EOF
MOVE INPUT-REC TO WS-ARRAY(I)
PERFORM 2000-FILE-READ THRU 2000-EXIT
END-READ.
3000-EXIT.
EXIT.

4000-CLOSE-PARA.
CLOSE FILE1.

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More RPG400 Interview Questions

How to add 2 new fields in a file? How many ways are there in as400?

2 Answers  


How to write record if no field or the field are different in physical file in rpgle ?

0 Answers  


I want my simple Green screen should refersh every 1 min ,How can I do it..? Please share the logic

2 Answers  


I know chain keyword retreive records randomly but how chain keyword exactly works internally????

4 Answers  


what procedure should we use to find whether the following operations are successful or not setll setgt chain read reade readp pls tell with example i'm not lazy to read the manual or not lazy to do anything.but sometimes i cannot understand the things given in manual in high level english its little bit complicated for me,i can't understand their way of writing thats why i ask these questions here and find the solution in simple words that i can understand thats the real reason sir.sorry if i had hurt you or disturbed you.please understand my situation.

5 Answers   iGate,


how do I do concatenation in rpg iv, like I do in cl?

1 Answers   IBM,


what is the necessary command needed before OPNQRYF and why?

5 Answers  


Im traying to get out put of this below mention simple logic code.But im geting out of different.(im trying with my laptop trhough my company server. DCL &FIELD1 *CHAR 10 VALUE('TCS AS/400') DCL &FIELD2 *CHAR 10 CHGVAR(%SST(&FIELD2 1 10))(%SST(&FIELD1 10 1) Can you tell me the value of field2 after excuted of CHGVAR command.

2 Answers  


can we use cl programming to update or delete physical files

12 Answers  


are there any useful c runtime apis that I can call from rpg iv?

0 Answers   IBM,


When PGMA calls PGMB for the first time PGMB executes the *INZSR. PGMB uses the RETRN operation to return to PGMA. When PGMA call PGMB the second time is the *INZSR executed?

5 Answers   Mphasis,


Hi, I am getting the error in RPG (All Record Formats for externally-described file ABCD ignored or dropped due to error; file ignored.) Please suggest any

2 Answers   Satyam,


Categories