× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



phon_P is telDS_P - I made mistake while I was creating example...



Igor.Beslic@xxxxxxxxxxxx 
Sent by: rpg400-l-bounces+igor.beslic=volksbank.hr@xxxxxxxxxxxx
13.10.2004 15:55
Please respond to
RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>


To
rpg400-l@xxxxxxxxxxxx
cc

Subject
exported Data structures and files






Hi I have question abouth data structures and EXPORT keyword...
I have 3 modules writerMOD, formatMOD, mainMOD and 2 DataStructures that 
should be accessable from writerMOD and formatMOD.

prototypes and DS definitions are in one source member

*********************************************************
***prjctProto source
*********************************************************
D nameDS  DS
D  Lab1         14A INZ('Name of user: ')
D  User         10A

D phoneDS DS    %BASED(telDS_P)
D  Fld1         14A
D  Fld2         20A

 *DS is automaticly loaded performing read of FILEt1
D phon1DS DS
D  Lab2         14A INZ('Telephone No: ')
D  TelNo1       20A
 *DS is automaticly loaded performing read of FILEt2
D phon2DS DS
D  Lab3         14A INZ('Telephone No: ')
D  TelNo2       20A

DwriteLine   PR
D               2S 0 VALUE

DdefineName  PR
D               5A   VALUE

DdefinePhone PR
D               5A   VALUE
D               1A   VALUE

mainMOD reads input file and decides what Names will be written
**********************************************************
***mainMOD source
**********************************************************
F mainFileIF  E          DISK
/copy prjctProto
.
.
.
C     read  mainRF
C     CALLP defineName(UsrID)
C     CALLP definePhone(UsrID:phoneID)
.
.
.


writerMOD copies data from data structures nameDS and telephoneDS in to 
txtLine and
write txtLine to stmf.
********************************************************
***writerMOD source
********************************************************
HNOMAIN
F FileUser IF  E  K DISK 
F FileT1   IF  E  K DISK 
F FileT2   IF  E  K DISK 
/copy prjctProto
PwriteLine B            EXPORT
DwriteLine PI
D lineID       2S 0 VALUE
D txtLINE S  100A
 /free
  Select;
        when lineID=LINE_USER; 
                txtLINE=nameDS; 
        when lineID=LINE_PHONE;
                txtLine=phoneDS;
        .
        . 
        .
  EndSl;
  //the rest of code writes the line
 /end-free
PwriteLine E

formatMOD contains subprocedures that fill nameDS and telephoneDS with 
desired data
***********************************************************
***formatMOD source
***********************************************************
HNOMAIN
F FileUser IF  E  K DISK  USROPN
F FileT1   IF  E  K DISK   USROPN
F FileT2   IF  E  K DISK   USROPN
/copy prjctProto
PdefineName  B          EXPORT
D defineName PI
D  user         5A VALUE
 *after this operation nameDS is filled with data
 /FREE
  OPEN FileUser
  chain user fileUserRF;
  WriteLine(LINE_USER);
 CLOSE FileUser
 /END-FREE
pdefineName  E

PdefinePhone  B                 EXPORT
D definePhone PI
D  user         5A VALUE
D  phone1       1A VALUE
 *after this operation nameDS is filled with data
 /FREE
  OPEN FILEt1;
  OPEN FILEt2;
  if phone1='Y'
        chain user fileT1RF;
        phon_P=%ADDR(phon1DS);
  else;
        chain user fileT2RF;
        phon_P=%ADDR(phon2DS);
  EndIf;
  writeLine(LINE_PHONE);
  CLOSE FILEt1;
  CLOSE FILEt2;
 /END-FREE
pdefinePhone  E

well, problem is in telephoneDS which is defined in prototype copy member 
with
D phoneDS DS    %BASED(telDS_P)

I have primary and secondary phone number difined in separate files, so I 
use phon1DS to be automaticly loaded on chain to FileT1 and phon2DS on 
chain to FileT2.But when execution comes to phon_P=%ADDR(phon1DS); in 
formatMOD there is issued memory not referenced prior Error.

Well I put out statements which define phon1DS and phon2DS from prototype 
member and enter it directly in formatMOD and writerMOD (definitions are 
present in 2 modules now) and program that is compiled from that three 
modules works fine!!

I wonder what's the reason of error and is there any better solution if I 
use EXPORT keyword on data structures. Maybe there is something with files 

definition (fields TelNo1, TelNo2 and User are members of FileUser, Filet1 

and Filet2)??

My final goal is to have all ds defined in one module (formatMod for 
example) or in one place but that they are still accessable from writter.

You maybe wonder why I'm using Based keyword and %addr(), why I don't just 

eval phoneDS=phon1DS but it's long story...

Help if you can and
Best regards!!

Igor Bešlić, dipl. ing. rač. 
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.