How to operating with Multiple Member PF in RPG ?

pts.
Tags:
AS/400
CLP
DB2 Universal Database
RPG
RPGLE
I have a multiple member physical file and I want to operate(read/update/delete) with specific member in RPG. The member name for that PF need to be set at runtime depending upon from which program this rpg program is called. I am writing the sample code that I was trying, but it ends up with compilation errors on setll and read statements. FFileA IF F 731 Disk Extfile(File) F Extmbr(Mbr) F Usropn FFile1 UF A E K Disk DFile S 10 Inz(' ') DMbr S 10 Inz(' ') c *entry plist c parm pgmname c* c eval File = 'File1' c if pgmname = 'Pgm1' c eval Mbr = 'Mbr1' c endif c if pgmname = 'Pgm2' c eval Mbr = 'Mbr2' c endif c open FileA c *loval setll FileA c read FileA c dow not %eof(FileA) c* rcdfmt is record format name of File1 c delete rcdfmt c read FileA c enddo Thanks & regards, Alok.

Answer Wiki

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

Hi Alok

The secret is to override the member name before opening the file in the RPG program. The easiest way to do this is to have a CL program that accepts the PGMNAME parameter and have that perform the override before calling the RPG program.

For example, something along the lines of:

PGM PARM(&PGMNAME)

DCL &PGMNAME *CHAR 10
DCL &MBR *CHAR 10

IF COND(&PGMNAME *EQ ‘PGM1′) THEN(DO)
CHGVAR &MBR ‘MBR1′
ENDDO
ELSE DO
IF COND(&PGMNAME *EQ ‘PGM2′) THEN(DO)
CHGVAR &MBR ‘MBR2′
ENDDO
ELSE DO
CHGVAR &MBR ‘MBR3′
ENDDO
ENDDO

OVRDBF FILE(MULTIPF) TOMBR(&MBR)
CALL PGM(RPGPGM)

ENDPGM

All the best

Jonathan

Discuss This Question: 1  Reply

 
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
    It's one thing to say that an error occurs on a particular statement. It's altogether something different to say what the error is. BTW, your program doesn't make any sense. Is there meaning to setting File = 'File1' and also having a F-spec for File1? And how are you expecting the DELETE statement to do anything if you haven't done any input or even positioning for File1? Surely you're not expecting the 'File1' and File1 to somehow mean the same thing? The compiler can't read your mind. It cannot predict what value be put into the File variable. Tom
    125,585 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