Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RPG/400 Data Structures

Status
Not open for further replies.

badapplebob

Programmer
May 13, 2003
12
GB
Hiya,

Could someone be kind enough to give me a basic understanding of data structures in RPG/400.
 
What kind of Data Structures?
Program data structures?
File data structures?
or user defined data structures?

RedMage1967
IBM Certifed - RPG IV Progammer
 
Are you talking about the DDS,, ie file layouts,, or talking about the DS in the input specs,,, where you define "storage areas"..
 
Hiya,

I talking about where you declare a data structure (DS) in I-Specs.

eg.
ISQ1 DS 360
I 1 360 S1
INQ2 DS 54
I 1 540N2

Could anyone give an explanation of how they are setup (ie.what the above means)
 
Been a while since I've coded in RPG/400. Doing all of my coding in RPGLE (RPG IV). In RPG IV, the data structures have been moved from the 'I' specs to the 'D' specs. What are you trying to define with the data structure. What are you using it for?

RedMage1967
IBM Certifed - RPG IV Progammer
 
I was looking at some old code and trying to decipher what it means. I'm pretty much a novice when it comes to RPG/400. Originally a COBOL programmer!!
 
You can do a lot of things with a data structure. There are some IBM supplied special data structure. One is called the Program data structure. This allows you to get specific information about the program itself. (The user who called it, error status, etc). There is also a file information data structure. This allows you to get information about a specific data file (last I/O operation, open/close status, last relative record number read, etc).
There is a different data structure for printer files that let you retieve the last line written and the current page nbr being created, to name a few things I use it for. The last data structure I use has to be used in conjunction with the DDS keyword INDARA. What this allows me to do is to define a data structure of indicators that relate to the indicators that a DSPLF or PRTF file would be using. For example, in a DSPLF, *IN03 is defined as the exit key, in the program I would code a data structure like so (this is RPG IV).
Code:
D File2Ind         DS 
   Exit                03     03N    Inz(*Off)
In the program, I wouldn't code *IN03, I would code EXIT, for example
Code:
If Exit = *On;  // f3 pressed
  Leave;
EndIf;
The other type of data structure I use is to define program variables that I need to reset to there initial values. Intead of having to write a SR to clear all of the variables, I just have to clear the data structure:
Code:
D Work            DS
D  Variable1              50    Inz(*Blanks)
D  Variable2               1S 0 Inz(0)
D  Variable3               6S 2 Inz(0)
 //--------------------------------------------
 /Free
  
   // some type of processing here

  Clear Work;

 /End-Free

What this does, when the data structure WORK is cleared, it sets all of the variables in WORK to there default clear values (Blanks for char fields, zero for numeric.).

I hope this helps.

RedMage1967
IBM Certifed - RPG IV Progammer
 
In RPG/400 there is a limit of 256 characters for a field. Using these data structures in your example, the programmer is using the data structure to create a field larger than 256 characters. I think.

RedMage is giving you the 300 level instruction when you asked for a 100 level instruction.
 
I got carried away, my bad, sorry.

RedMage1967
IBM Certifed - RPG IV Progammer
 
RedMage

I must add- I really enjoy the knowledge. I want to know what you know... and more. Thanks
 
RedMage,

Thxs for your help! Unfortunately I don't know RPG(IV) so it's all a bit of a learning process!

Cheers

BOB
 
Jack1955

There is a danger is using data structures. You cannot have a variable that your passing to another program defined in a data structure. You must define the variable as a stand alone variable. The reason is, when the 400 passes parms between programs, it passes the pointer address of the variable, not the actual value of the variable. When you define a data structure, the variables are subfields of the data structure, so if you try to pass one of the subfields, the 400 sends the pointer address of the entire data structure, which can have undesireable effects on your program. If you need more explanation, please email me at b c l e m o n s @ w b g p p m . c o m.

RedMage1967
IBM Certifed - RPG IV Progammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top