2

In 4gl, the statement DEFINE IO_AFPOPF1 RECORD LIKE AFPOPF1.* means all content of table AFPOPF1 assigned to IO_AFPOPF1 variable. If AFPOPF1 table changes, IO_AFPOPF1 also changes automatically.

Can I do the same function in Java? Now I just define a class that store all the content of table AFPOPF1. If AFPOPF1 changes, I must add or delete fields in my class. For example code below:

public class Afpopf1 {
    private int var1;
    private int var2;

    public Afpopf1(int var1,int var2) { this.var1=var1; this.var2=var2;}
    public int getVar1() { return var1; } 
    public int getVar2() { return var2; }
}
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
user1774492
  • 71
  • 2
  • 3
  • In Java, there's no way to map a class fully with a database table like 4gl does with record declaration. You must change your classes manually. In the other hand, there is [JPA](http://en.wikipedia.org/wiki/Java_Persistence_API), an ORM that helps you bind the classes with your tables. – Luiggi Mendoza Oct 27 '12 at 14:14
  • @LuiggiMendoza Why not post that as an answer? – Duncan Jones Oct 27 '12 at 15:04
  • @DuncanJones because it doesn't solve OP's problem. – Luiggi Mendoza Oct 27 '12 at 15:39
  • 2
    @LuiggiMendoza AFAIK there *is* no way to do this in Java, so your answer is valid. You also link to some useful resources. Up to you though :-) – Duncan Jones Oct 27 '12 at 15:41
  • I think you might do best to write a (Java) program that, given a database and table name, generates the corresponding class according to the rules you want. You can then run this program to generate the class definition before compiling the rest of the Java code. – Jonathan Leffler Oct 28 '12 at 06:02
  • @JonathanLeffler ORMs in Java do that for you :). – Luiggi Mendoza Oct 29 '12 at 00:24

0 Answers0