Thanks gagan for your answer,i'm new to as400,i don't know
embedded sql in rpg.can you send me the coding for the below
mentioned question in embedded sql rpg.
how to retrieve particular field records from a physical
file,say i have a physical file called 'employee' in it i
have to retrieve the records of a field 'admin' present in
pf 'employee' using rpg,but i should not use logical file
or openquery file.

Answer Posted / harshad r suryawaunshi

1. Declare cursor first - It will select all the record
available in the filed 'ADMIN'

c/exec sql
c+ declare cr1 cursor for
c+ select ADMIN from EMPLOYEE
c/end-exec

2. Open the cursor - its like seting the pointer on the
first record

c/exec sql
c+ open cr1
c/end-exec

3. Fetch the cursor - its like reading the records in the
cursor. NAME is the field defined in the program which
attributs are same as per field ADMIN.

c/exec sql
c+ fetch cr1 into :name
c/end-exec

This code u can execute in Do loop to read all the records.
The complete coding would look like this

c/exec sql
c+ fetch cr1 into :name
c/end-exec

C dow sqlcod <>100
C
C name dsply
c/exec sql
c+ fetch cr1 into :name
c/end-exec

C enddo

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do u design a physical file, when you have 2 Unique fields like for eg in A student file student ID and student examination no both are unique

546


What are the types of identifiers?

564


Set on command is used for closed all opened files , initialize var and release resource , return cmd is used for return to calling program but my req. Is dnt close opened files and resource must released while doing transactions , how can i do this...?

1457


is this a rpg channel?

669


Interviewer asked me write down DDS for load all subfile .can anybody write dds

1009






How Chain operation copies the record's data to the input buffer for the program?

1072


how do I declare a table or array in rpg iv?

728


1. If there are two programs using same file and 2 users are using the file at the same time and what can be done to allow them both to access? 2. How can remove lock from the file for accessing it by both users?

476


how does the rpg element work?

711


explain sflclr, sflend, sfldlt, and sflcsrrrn?

880


Assume 2 users are using the same file and first user updates some record in the file. Will the 2nd user will be able to see the updated record or not?

507


what is kids-rpg?

660


What is the difference between iter and do?

663


during execution, an rpg/400 program automatically follows a sequence of operations for each record that is processed. The built-in program cycle includes the following logical steps.

749


How to call one program from another program in RPG? please help me with the code

1250