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