Parent/child classes vs badi or something else

Dear Experts,
I’m looking for some architectural suggestions here on the best way to implement “user exits” with classes.
Up to now, I have coded my software similar to the SAPMV45A method of having an include with subroutines USEREXIT_BEFORE_HEADER and the like.
It works okay except that the code doesn’t do a great job of encapsulation.  All data has to be global and that gets to be a pain for cleanup.
I’m wondering the best way to do this as I am not an expert at all in object oriented development.  I've only implemented BADI on a couple of occasions, found it confusing and were it not for tutorials, I wouldn't have been able to do it at all.
For example, a common flow of my RFC goes like this:
Perform userexit_initialize in program (sy-repid) if found.
Perform initialize.
Perform read_header
Perform read_items
Perform populate_header_output
Perform populate_item_output
In each of the FORM routines, I have a userexit at the end to allow custom filters or database reads as necessary.
For example:
Form read_header
  Select * from header_tab ….
  PERFORM userexit_read_header_finished in program (sy-repid) if found.
Endform.
I had hoped I could have two classes, a parent or “core” class to which I can implement only child methods as needed.
Therefore, it would be more along the lines of:
Function z_my_rfc
  Importing i_docnum
  Exporting e_header
                 Et_items
                Et_bapiret2
Call zcl_core->read_header
Call zcl_core->read_items
Call zcl_core->populate_header
Call zcl_core->populate_items
What I haven’t really been able to figure out is if I can create and distribute another class zcl_child which I can then customize at every implementation by simply adding a new method and using “super” to incorporate the logic of the zcl_core class.
I think I’ve seen that this can be done in local class development ( in an include abap program ) but I want to do this in actual classes via SE24.
Now, my other thought is that this is what BADI are for??
Periodically, I want to send my customers a transport with update ZCL_CORE class code/methods, etc. but I want to leave the ZCL_CHILD class alone.
Hopefully, I’ve conveyed my desire here and perhaps you can suggest the simplest way to support this software going forward.
Thanks in advance for your time and consideration.

Hi Ray,
Go for custom BADIs in this case. In fact, that is exactly the functionality you are looking for !
Just go through this excellent five part blog on Enhancement framework by Thomas Weiss.
What the New Enhancement Framework Is For – Its Basic Structure and Elements For Beginners
The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement
How To Define a New BAdI Within the Enhancement Framework - Part 3 of the Series
How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framework
Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework
Cheers,
Mahesh

Similar Messages

  • Parent Child classes

    Hi All,
    I have a really general question that I have not been able to solve.
    Here is my sample code:
    class parent {
    public List mylist
    public parent(){
    child c = new child(this, mylist);
    class child
    private parent p;
    private List mylist;
    private String currentLine ="";
    public child(parent p, List mylist){
    this.p=p;
    this.mylist = mylist;
    BufferedReader in new BufferedReader(new FileReader("test.txt"));
    while ((currentLine = in.readLine()) != null){
    mylist.add(currentLine);
    How do I return mylist in the child class back to the parent class? Or secondly, can I declare a List in the child class and have some way of passing it back to the parent class? I am not very familiar with the parent/child classes. If you can assist, I'd appreciate it. Thanks.

    Actually....the main problem that I have is that I am using multi threading. Right now the problem that I have is that I can't write to the same output file with multiple children threads...not sure why.
    class parent {
    PrintWriter out;
    public parent () {
    out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
    for (int i=0; i<10; i++){
    childthread ct = new childthread(this);
    public synchronized void Output (String output){
    out.write(output);
    }//end class parent
    class child extends Thread{
    parent p;
    public child (parent p) {
    this.p = p;
    public void run(){
    String thisLine = "test";
    p.Output(thisLine);
    }//end class child
    How can I get all of my 10 threads to write to the same file. Since my parent thread is the one with the output file, each time the child thread calls the p.Output and passes the String..it should printout test in my output file...but it does not. Is there any reason why?
    My output file should display "test" ten times. Please let me know what I am doing wrong...or how I can go about writing multiple threads to the same output file. Thank you.

  • Parent Child Questions

    Hi All
    Fairly new at this and am a bit confused.
    I have been given the task of cleaning up certain tables in my DB. I am running into parent / child issues.
    I want to remove all entries from Table A. When i try and delete one row it gives me a constraint violation. It tells me there is a child record out there. So i go ahead and disable that constraint, go back to table A and try the delete again. I get a different another violation telling me that there is a child record on a different table. And on and on the story goes.
    Now I could keep doing this but the schema i am working on has 1051 tables and just over 6000 constraints. So as you can see this might take me a month to sit here and do that. Not very keen on that.
    What I am after is:
    1. A program / script that will lay out all the parent child relationships for me. Coming across each one as i try and delete is painful
    Would it be possible to get something like:
    Table A
    -- Table B
    -- Table C
    Table D
    -- Table E
    -- Table G
    -- Table F
    2. All the constraints have been created with a delete rule of 'No Action'. I think the easiest thing to do would be to go to the parent table (or what I think is the parent table) and change this to on delete Cascade. From what it looks like I don't think you can do this. Does anybody know how to? Or if its possible?
    3. The third option I am thinking of is:
    Disable All the constraints on what I think is the parent table. Remove entries from the child tables. Enable the constraints.
    Now my issue here is, how do i know all of the child tables? I guess that goes back to my question 1.
    Thanks in advance. Sorry for the story.
    The lack of documentation / diagrams here is driving me nuts :)

    You can use tools like Microsoft Visio to reverse engineer the tables and their relationships.
    You can also generate a list of parent-child related tables from user_constraints.
    something like:
    SQL> SELECT TABLE_NAME,
      2         (SELECT TABLE_NAME
      3            FROM ALL_CONSTRAINTS R
      4           WHERE R.OWNER = U.R_OWNER
      5             AND R.CONSTRAINT_NAME = U.R_CONSTRAINT_NAME) PARENT_TABLE
      6    FROM USER_CONSTRAINTS U
      7   WHERE U.CONSTRAINT_TYPE = 'R'
      8  /
    TABLE_NAME                     PARENT_TABLE
    EMP                            DEPT
    SQL>

  • Seemingly unpredictable results when calling an overriden parent method on an instance of a child class casted to the parent class

    I have a parent class with a sub-vi Override.vi, and a child which overrides this sub-vi.  I create an instance of this child.  I cast this child to it's parent class and store it in an array.  Later, if I invoke the parent's 'Override.vi' on this child (casted to parent) then Labview 2013 seems to randomly choose whether to run the parent or the child override.vi.  In Labview 2011 SP1 it would always call the childs version of override.vi (which while surprising to me was very useful).  This has totally broken an application I have been developing, any insight as to how to control which override.vi is run would be helpful (re-casting to the child class isn't really an option, as there are in fact many child classes each with their own version of override.vi).

    The actual data type of the wire is irrelevant in deciding which VI to run. The only thing that is relevant is the class of the object which is actually on the wire, so casting to the parent should not be relevant. *IF* the object really is a child, then LV should always call the child's VI, just like you say it works in 2011.
    I suspect that what's happening in your case is that somewhere you're generating a parent and that's what's actually on the wire (e.g. maybe you have an error somewhere and a function outputs the default value, which is a parent). The fact that it didn't happen in 2011 doesn't mean it's a bug in 2013. It could be that something else has changed.
    In any case, it's impossible to tell whether this is a misunderstanding, a bug in your code or a bug in LV without actual code. If you can post actual code which shows this, people can help. Otherwise (if it only happens in code you don't want to publish), you should try contacting NI directly so that you can at least show them the code.
    Try to take over the world!

  • Overriding VO Impl class methods to populate parent-child VO

    Hi All,
    I need to populate parent child VOs by giving webservice calls from respective impl classes.
    Scenario : Lets say suppose i have 2 VOs as DepartmentVO and Employee VO with a viewLink on departmentId. Taking a particular instance, in Department table there are 2 rows and for each parent row we have 2 child rows in Employee.
    Webservice Structure : I have a parent Object and inside that parent object i have list of child objects
    e.g : public class DepartmentDTO{
    private List<EmployeeDTO> employeeList;
    After that i have extended Impl classes for both VOs and overriden method i.e. "executeQueryForCollection" to give a webservice call and get back response of DepartmentDTO[] with List<EmployeeDTO> inside it.
    In DepartmenntVOImpl class i have overriden "createRowFromResultSet" which populates the parent VO with the number of parent records returned from webservice.
    Code for Department impl class is :
    protected ViewRowImpl createRowFromResultSet(Object qc,
    ResultSet resultSet) {
    Iterator deptIter= getPackageClassIterator(qc);
    ViewRowImpl r = createNewRowForCollection(qc);
    DepartmentDTO curDTO = (DepartmentDTO )deptIter.next();
    populateAttributeForRow(r,
    findAttributeDef("DeptId").getIndex(),
    curDTO.geDeptId() );
    populateAttributeForRow(r,
    findAttributeDef("DeptName").getIndex(),
    curDTO.getDeptName() );
    return r;
    Similarly i have overridden "createRowFromResultSet" method in EmployeeVOImpl to populate the child VO(this need to be populated from the list object inside parent object reponse)
    Code as follows :
    protected ViewRowImpl createRowFromResultSet(Object qc,
    ResultSet resultSet) {
    Iterator empItr= getPackageClassIterator(qc);
    ViewRowImpl r = createNewRowForCollection(qc);
    DepartmentDTO curDTO1 = (DepartmentDTO )empItr.next();
    List<EmployeeDTO> list = curDTO1.getEmployeesList();
    for (EmployeeDTO curDTO : list) {
    populateAttributeForRow(r,
    findAttributeDef("EmpId").getIndex(),
    curDTO.getEmpId());
    populateAttributeForRow(r,
    findAttributeDef("EmpName").getIndex(),
    curDTO.getEmpName() );
    populateAttributeForRow(r,
    findAttributeDef("EmpLastName").getIndex(),
    curDTO.getEmpLastName() );
    populateAttributeForRow(r,
    findAttributeDef("DeptId").getIndex(),
    curDTO.getDeptId());
    return r;
    Though the code looks simple and correct but the child records are not getting populated correctly. Am not sure if the code implementation to populate parent child VOs from webservcie is correct or not.
    Would appreciate for Help or valuable Suggestions.
    -Sanjeeb

    Hi Ray,
    Go for custom BADIs in this case. In fact, that is exactly the functionality you are looking for !
    Just go through this excellent five part blog on Enhancement framework by Thomas Weiss.
    What the New Enhancement Framework Is For – Its Basic Structure and Elements For Beginners
    The new Enhancement Framework Part 2 - What Else You Need to Know Before Building an Enhancement
    How To Define a New BAdI Within the Enhancement Framework - Part 3 of the Series
    How to implement a BAdI And How to Use a Filter - Part 4 of the Series on the New Enhancement Framework
    Source Code Enhancements - Part 5 of the Series on the New Enhancement Framework
    Cheers,
    Mahesh

  • How to listen to user actions in child class from parent class?

    Hi,
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:
    textField.addKeyListener( new KeyAdapter()
                @Override
                public void keyPressed( final KeyEvent e )
                    //user typed something
                    userTyped = true;
             });Now I have another parent class that uses ChildCustomForm, and parent class has to know once user types, then set
    its own userTyped flag.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).
    I am wondering if there is a way to do this?
    regards,

    jack_wns wrote:
    I have a basic custom class ChildCustomForm that include a JTextField. In order to know what user types, I add a listener to
    this textbox:You want to listen for input into the textbox, correct? This may take the form of keyboard input, or could be a paste-text event in which case your keylistener will miss it. I recommend that you look into a DocumentListener here so you will catch any changes, be they keyboard or cut or paste.
    My problem is: since I added listener in child class, I cannot get textfield and add listener again in parent class, so parent class will not be able to know as soon as user types (polling is not a good solution here).The observer pattern may work here.

  • How to test if MDD power supply is bad or it's Something Else

    Ok,
    I've had a MDD for 4 years. Dec 2007 the PSU died. I had it replaced under my renter's policy (yeah..) the new rev. part was $870!. I Didn't care... insurance paid for the repair.
    Now, after 1.5 years, I was having disk corruption issues which led to numerous forced shutdowns (no reset button on the MD) finally, after about 5 of these in one day, the power on light lit when pressed, and I heard a crackle & smelled a a bit of smoke. I pulled the power cord immediately.
    btw pressing the power button now did nothing at all, no "fan attempts" no crackle.. nothing.
    Same deal, I called the ins co, took MDD to the authorized techs, who checked & said the PSU was dead... again.
    The Ins Co. is "totaling" the MDD and I'm looking for a used G5.
    BUT! I'd love to get the MDD working again. Just to have it as a second machine.
    I've read a bunch of threads here on this issue & testing the PSU.
    I'm not a super geek, but I can follow instructions... which I did. There's a great online instruction set with pics and all, about how a guy found a bad solder by disassembling the PSU.
    I followed it step by step. Saw nothing remarkable.
    Then I came here looking for steps to test the PSU (I'm starting to wonder if it's more than that).
    I found a diagram of the pins and voltages.
    Connected the PSU the the juice and started testing the connector, where it plugs into the motherboard.
    Here's what I found (connected to power but obviously still not starting the computer):
    Pin 1 (says +5volts sb, which I assume means stand by?) with the black lead from the tester inserted into pin 2 (gnd). It read 5 Volts.
    No other pins showed ANY voltage EXCEPT pin 14 (which says +25Vsb). That read +24.8V when tested.
    What I DON'T know is...
    If disconnected from the MDD, should all the pins read voltage as the pinout diagram says? I'm brand new to this level of diagnosis.
    I'm wondering if maybe the CPU fried etc.
    Also, while trying to determine if the power button might be faulty I broke the switch off (duhh). Shorting across the two stubs that were left there didn't produce any powerup either (it's just a 2 pin contact switch right?)
    So I need to know if I have accurately found the PSU to be bad. I can get one on ebay for $150-ish.
    But I'm worried, since this was a +*new super better PSU*+ and it (possibly) has died, maybe something on the motherboard etc. isn't right.
    The machine hasn't been connected to power for 3 weeks & yes, the battery is now dead. I swapped it out, and reconnected the PSU... nothing.
    +*So first, did I correctly test the psu?*+
    there was a dead link to a MDD repair manual on another thread. First I have to figure out IF the psu is dead, and then decide if something else KILLED it.
    Help? I'm using wife's G4 and she's getting real PO'd after 3 weeks!
    Thanks to anyone in advance.
    Tom

    Hi,
    Thanks. By power button board, Do you mean the unit that has the power button on it? On the case front?
    If so, I mentioned the switch broke while I was testing. I guess to continue I have to get a new switch.
    I will pull the mini-board for the power button though to look for signs of damage.
    Can I get a new switch to solder on to the board, if the board looks good. The orig. switch physically broke off the board. It's a standard contact switch correct? i.e. press and there should be continuity between the two pins? I'll pull the board as well.
    I've already checked the PSU interior. No burnt wires visible anywhere. There's a lot of grey goo glue used so it's hard to see, but since the PSU passed the two passive power tests you mentioned, are we for now assuming it is a good PSU?
    Other discussions I've read, describe continuing to test different pins and look for appropriate voltages. That doesn't make sense to me with the computer not starting up.
    Aren't the rest of the voltages supposed to show ONLY after the command to supply startup power is given (by the power switch)?
    Processor "looks" good too, no signs of burnt anything after pulling the heat sink, but I haven't removed the logic board or the mother board yet to look underneath.

  • Fastest way to create child class from parent?

    As the subject states, what do you folks find is fastest when creating child classes directly from the parent? (esp. when the parent is in a lvlib) I thought I'd post up and ask because the fastest way I've found to get working takes a few steps.
    Any suggestions ae appreciatized!
    -pat

    Thanks for the quick response Ben!
    Yea, I apologize, in your response I realize my OP was more than vague haha (it hapens when you get used to your own way of doing things I guess huh)- I'm trying to create a child from a parent so that it has all of the methods that the parent has.
    In order to do so I currently have to open and close LV a few times during my current process so that vi's in memory dont get mixed up- Currently I save a copy of the parent class in a sub dir of where it is saved, close out of LV, open the new 'copy of parent.lvclass', save as>>rename 'child class.lvclass', close LV, and open up the project to 'add file', then right click>>properties>>inheritance.
    Is this the only way to do this?
    Thanks again!
    -pat
    p.s. I'm tempted to steal your cell phone sig, hope you dont mind haha good stuff!

  • Casting parent class to a child class

    Hi,
    I have a static method which returns a class called parent. Now I want to cast it it's child class. There are no compilation errors, but at runtime it's throwing me ClassCastException. This is what I'm doing.
    public Parent getObject() {
    Parent p = new Parent();
    return p;
    Child c = (Child) getObject();What is wrong with this code? I couldn't figure it out.
    Any help will be appreciated.
    Thanks,

    Parent p1 = new Parent(); // 1
    Parent p2 = new Child(); // 2
    Child c1 = new Parent(); // 3
    Child c2 = new Child(); // 4
    Parent p1 = (Parent)c1; // 5
    Parnet p2 = (Parent)c2; // 6
    Child c3 = (Child)p1; // 7
    Child c4 = (Child)p2; // 81: Ok.
    2: Ok. Every Child IS-A parent.
    3: Compile time error. A Parent object is not a Child.
    4: Ok.
    5: Ok, because every Child IS-A parent, and the cast is unnecessary. (Though since 3 is illegal a compile time we wouldn't actually have this situation.)
    6: Ok, and the cast is unnecessary, because every Child IS-A Parent.
    7: ClassCastException at runtime. The object is not a Child.
    8: Ok.

  • Executing a child class from parent.

    Hi, well, I have this parent class which I need to execute a method from a child class to get a significant part of the thing get started. Is there anyway for me to accomplish this or a workabout? Thanks..

    Sure.. I have this method in the class logic:
         public void createLocation() {
              try {
              classCoord coordSet = appinterface.decodeFile();
              int areaNum = coordSet.areaNum, cellNum = coordSet.cellNum, signalStrength = coordSet.signalStrength, receiverId = coordSet.receiverId;
              String dateTime = coordSet.dateTime, userName = coordSet.userName, location = calLocation(areaNum, cellNum);
              boolean validity=calValidity(signalStrength);
              classLocation locationObj = new classLocation(this.type, userName, receiverId, validity, location, dateTime);
              appinterface storeLocationObj = new appinterface();
              storeLocationObj.storeLocation(locationObj);
              catch (IOException ioException) {
                   appinterface.displayMessage("Logic Error: " + ioException);
              catch (ClassNotFoundException classNotFoundException) {
                   appinterface.displayMessage("Logic Error: " + classNotFoundException);
         }I need to execute this method halfway in the class appinterface, the logic class inherits from appinterface cuz I need to make use several methods from it. Is there any way to solve this somehow?

  • Parent class not waiting for child class to finish

    hi,
    i have class a and method x in class a which calls class b. its fine till there. but before my class b's action is completed, in which i have to choose a file and display those files in jtable, the remaining lines in method x getting executed. what do you think the problem is.
    i.e. my parent's class method is completely getting executed before the child class (frame) returns the result and is closed. where do u think the problem.
    please help.

    i dont know if i made myself clear. i am giving my code below.
    class A{
    btnClick{
    pnlProductsImport _pnlProductsImport=new  pnlProductsImport(dataSource,config,parent,importFile);
    _pnlProductsImport.setVisible(true);
    _pnlProductsImport.show();
    getProducts()
    here its showing my pnlProductsImport class screen and before I close that screen, getProducts method is getting executed. as I know, the control passes from class A to pnlProductsImport at show() and when its closed, it will execute remaning lines i.e getProducts, but in this case, it shows the subclass, and immedietly, executing remaining lines. but its also fact that my subclass (pnlProductsImport) implements Runnable, but thread starts only after some time when I click on one of the buttons on the screen.... and i want that getProducts() method to execute only when subclass closes completely.
    thanks

  • Cleaning up child class on parent wire

    I have a child class running on a parent wire. The parent class has a reference, and the child class has some additional references. I want to clean these up during shutdown. But, because it is a parent wire, I cannot call my child class's "destroy" method directly. Is the best way to handle this to have destroy.vi be dynamic dispatch, so it will call the child's destroy method via DD, and set "call parent method" to required? This way if the class is a child, it will dynamic dispatch the child's method, but force the programmer to also call the parent method? How have others handled this?
    CLA, LabVIEW Versions 2010-2013

    for(imstuck) wrote:
    Is the best way to handle this to have destroy.vi be dynamic dispatch...?
    Yes. That's the whole point of DD.
    Note that for cleaning up resources, the order of the cleanup might be important, so either write in such a way that it doesn't matter or document it so that the developer of the child class knows exactly when the parent destroy should be called.
    Try to take over the world!

  • Inheritance problem with parent class calling child class

    I have a problem with inheritance with a parent class calling a child class method. Below is the example pseudocode code and my problem:
    public abstract class A {
        protected void function1 ( ) { }
        protected void function2 () {
             //calls function1();
             function1();
    public abstract class B extends A {
        protected void function1 ()  {
             // do stuff
    public class C extends B {
        protected void function1 ()  {
            // do stuff
            super.function1 ();
    }I have an object instance of class C created and its function2() is invoked.
    My problem is, while in function2(), which belongs to abstract class A and the method call to function 1() is called, the call invokes the function1() of class B. Shouldn't the call invoke function 1() of class C instead? And then function1() of class B will be called after due to the super.function1(). It's not behaving like I thought it would.
    Edited by: crono77 on Jan 10, 2008 8:13 PM

    Nevermind, i found my error :)

  • Can I make methods which are public in a parent class into private in a child class ?

    I suspect the answer to my question is probably no, but...
    I have a parent class that provides several general purpose methods, I also have a child class which is intended to provide a more specific set of methods for manipulating the data in the class. As a result, calling some of the parent's methods on the child class can provide results that I'd rather not let the users of the child class have to worry about. It seemed (from my rather naive OOP experience) that the nicest way to do this would be to make access to some of the parent's public methods be private in the child class. This doesn't seem to be trivially possible.... ?
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/

    Hi Gavin,
    Unfortuneately I don't think this can be done. You can use an overide VI to change the functionality of a method in a child class but it has to have the same scope and the method it overides.
    Regards
    Jon B
    Applications Engineer
    NI UK & Ireland

  • Parent class private data accessable in Child class?

    Hi!
    I thought that this would be obvious, but my search foo fails me.  Hopefully someone would be kind enough to answer my newbie LVOOP question.
    I have a a parrent class.  This parrent class contains a cluster of class private data.  I setup all the accessor methods to this data.  I create a child class that has functions that need to access data stored in its parrent class.  Its inheritence is set, but when I try to unbundle the class data all I can seem to get to is what is setup in the child class' data cluster.
    I've watched a video and it looked like the data cluster magically appeared and was accessable through the children methods.  What am I missing?
    Thanks for input!
    -nic
    Solved!
    Go to Solution.

    Nickerbocker wrote:
    Well, that makes sense.
    One other quick question.  Is the procedure, New->"VI for Override..." from the context menu of my child class the only way to create a method that overrides the parents method?  Where is the property that defines this newly created VI as overriding my parent's VI?  Can I simply create a VI that is named the same and it have the same effect?
    That is the only method I use but I believe if you get all of your icon patterns and terminal marking as dynamic and all of the other rules, you should be able to do the same thing by hand (I base this guess on the fact I messed with those things and broke my ever-rides).
    The only thing I think has to be done from the project (scripting aside) is to set-up the inheritance.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

Maybe you are looking for