This is my Physical file 'EMPS' existing in library "TAMIL1"
and its record format is 'EMPRCD"
a)its source is

R EMPRCD
ENO 4 0
ENAME 10
EADD 10

b)The records present in EMPS are as follows

ENO ENAME EADD

0001 tamil coimbatore
0002 kumar bangalore
0003 sunder bangalore
0004 arunkumar chennai
0005 pandi hyderabad
0006 santhosh hyderabad
0007 sasi salem
0008 kalai chennai
0009 suresh hyderabad
0010 vijay bangalore
0011 Arul chennai
0012 velu chennai
0013 khan bangalore
0014 praba chennai
0015 praba.p coimbatore
0016 anand ooty
0017 raja erode
0018 sankar erode
0019 vadivel namakkal
0020 anbu chennai
0021 Ajith mumabi

c)now i want to select the 'ENAME' field records starting
with 'S'
for that i have created a RPG program
its source code is

PGM
DCLF FILE(TAMIL1/EMPS)
DCL VAR(&MYENO) TYPE(*CHAR) LEN(4)
OVRDBF FILE(EMPS) SHARE(*YES)
OPNQRYF FILE((TAMIL1/EMPS)) QRYSLT('ENAME *EQ
%WLDCRD("S *")')
READ: RCVF RCDFMT(EMPRCD)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
CHGVAR VAR(&MYENO) VALUE(&ENO)
SNDUSRMSG MSG(&MYENO)
SNDUSRMSG MSG(&ENAME)
SNDUSRMSG MSG(&EADD)
GOTO READ
END: CLOF OPNID(EMPS)
DLTOVR FILE(EMPS)
ENDPGM

Is this coding correct sir,the program gets compiled,and if
i call it it says query running but records are not
displayed.please help me out

Answers were Sorted based on User's Feedback



This is my Physical file 'EMPS' existing in library "TAMIL1" and its record fo..

Answer / katiyar

Looks like your answer is correct, Just little modification
as per my understanding and as per your requirement.
--------------------------------------------------------
PGM
DCLF FILE(TAMIL1/EMPS)
OVRDBF FILE(TAMIL1/EMPS) SHAR(*YES)
OPNQRYF FILE((TAMIL1/EMPS)) QRYSLT('ENAME *EQ + %WLDCRD
("S*")')

/*--To See the result in file, Use following commands--*/

CPYFRMQRYF FROMOPNID(TAMIL1/EMPS) TOFILE(TAMIL1/TESTPF1) +
MBROPT(*REPLACE) CRTFILE(*YES)

RUNQRY QRYFILE((TAMIL1/TESTPF1))


READ: RCVF RCDFMT(EMPRCD)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))

/*---To See the result, Use following commands----*/

SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&ENAME) +
TOPGMQ(*EXT)
SNDUSRMSG MSG(&ENAME) TOUSR(&USERNAME)

****Provide your User Profile Name in TOUSR = &USERNAME
/*-------------------------------------------------*/
SNDUSRMSG MSG(&ENAME)
GOTO READ
END: CLOF OPNID(EMPS)
DLTOVR FILE(EMPS)
ENDPGM

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
I am sure, this will help you.

Is This Answer Correct ?    6 Yes 0 No

This is my Physical file 'EMPS' existing in library "TAMIL1" and its record fo..

Answer / katiyar

Your Answer is totally correct. Just little modification.
Add Commented Code as same mentioned below in above code.
--------------------------------------------------------
PGM
DCLF FILE(TAMIL1/EMPS)
OVRDBF FILE(TAMIL1/EMPS) SHAR(*YES)
OPNQRYF FILE((TAMIL1/EMPS)) QRYSLT('ENAME *EQ + %WLDCRD
("S*")')

/*--To See the result, Use following commented commands--*/

/* CPYFRMQRYF FROMOPNID(TESTPF) TOFILE(KATIYAR1/TESTPF1) +
MBROPT(*REPLACE) */
/* RUNQRY QRYFILE((TESTPF1)) */

/*------------------------------------------------------*/
READ: RCVF RCDFMT(EMPRCD)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
/*---------------------------------------------------*/
SNDPGMMSG MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA(&ENAME) +
TOPGMQ(*EXT)
SNDUSRMSG MSG(&EMPNM) TOUSR(&USERNAME)

****Provide your User Profile Name in TOUSR = &USERNAME
/*-------------------------------------------------*/
SNDUSRMSG MSG(&ENAME)
GOTO READ
END: CLOF OPNID(EMPS)
DLTOVR FILE(EMPS)
ENDPGM


Hope this helps you.

Is This Answer Correct ?    4 Yes 0 No

This is my Physical file 'EMPS' existing in library "TAMIL1" and its record fo..

Answer / roshan


the %WLDCRD keyword is case sensitive,

Your are entering the 'S' with capital latter in %WLDCRD
keyword and records present in file are start with
samll 's', becouse of that records are not selected in open
query command.

Thanks
Roshan

Is This Answer Correct ?    2 Yes 0 No

This is my Physical file 'EMPS' existing in library "TAMIL1" and its record fo..

Answer / vicky

BRO ITS CL PROGRAM NOT RPG

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More RPG400 Interview Questions

Suppose we have 10 records with same name and we are reading using READE,after 4 record i have to use CHAIN what is the output

3 Answers  


Why did we give STRSRVJOB while debugging batch program

3 Answers   HBL Power Systems,


Can we create 300 logical files based on a single physical file using the CRTLF command only once?.

8 Answers  


how can we can we the data decimal error?how can we open such file in support

1 Answers  


how to find whether a date format is valid or not in RPG400 not in RPGILE.Can you please write the coding for this sir,i'm new to AS400.Please help.

1 Answers  






Assume my file has 100 records and I want to see only first 10 records. Is this possible through lf?

1 Answers  


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,


what is a rpg?

0 Answers   IBM,


can i use unique key in LF

3 Answers   TCS,


How do I link an existing logical file to it's Physical File without recompiling?

2 Answers  


Hi guys, anybody know How RPG/400 code can be converted to RPG IV code with a single command?

1 Answers  


how do I preserve and clean the array?

0 Answers   IBM,


Categories