Private protected - ?

I guess I haven't looked at my Java language spec in awhile (or never did very closely), but I was surprised today to find out that the "protected" specifier allows subclasses as well as any classes in the same package. I feel this is a little too much access for my tastes.
I guess the idea here is that one developer/group will be desigining a package as a whole and will not do anything advertant or malicious with another class' protected members.
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
I noticed that in Java 1.0 also had a fifth specifier as "private protected" that is no longer supported. Was this the sought-after protection that I am looking for? What was the reason for not providing something like this?
Btw, my C++ is also a little rusty around the details, but does the "protected" specifier do the same thing with namespaces or something?

The point of such silly code (below) is simply to demonstrate that that no one should be allowed to change the key's code except the Key. If I want to subclass a Key, I shouldn't be forced to make "Key.Code" private and re-implement Code again in my subclass. From an object-oriented perspective, I still feel that "protected" should only be valid from within sub-classes and have a 5th specifier that specifies both package and subclass.
A colleague of mine pointed out that the "package" specifier is horizontal (across the package), but there is no specifier that is just vertical (only subclasses).
Is there anything stopping someone to add a package to a class and compile it? For that matter, they now have access to all the protected members of the package classes.
All classes in the same package :
package KeyLock;
class Lock
  public String lockCode = "MySecretKey";
  public Lock(String code)
    lockCode = code;
  protected void tryLock(Key k)
    if(k.getCode().equals(lockCode)
      System.out.println("Success");
    else
      System.out.println("Failure");
class Key
  protected String Code = "MySecretKey";
  public String getCode()
    return Code;
  public Key()
public class BetterKey extends Key
  public BetterKey()
    Code = "EvenBetterKey";
class LockPicker
  public LockPicker()
    Key key1 = new Key();
    Key key2 = new BetterKey();
    Lock lock = new Lock("UselessLock");
    key1.Code = "UselessLock";
    key2.Code = "UselessLock";
    lock.tryKey(key1);
    lock.tryKey(key2);
}Maybe I'm just spun...

Similar Messages

  • Inheritance and access control - "private protected"

    I'm reopening an old topic, seems to have been last discussed here 2-3 years ago.
    It concerns the concept of restricting access to class members to itself, and its subclasses. This is what "protected" does in C++ and "private protected" did in early versions of the Java language. This feature was removed from Java with a motivation along the lines of not being "simple", and "linear" (in line with the other access modes, each being a true subset of the next). Unfortunately, the article which explained Sun's position on this keyword combination seems to have been removed from the site, so I haven't been able to read its original text.
    But regardless of simplicity of implementation or explaining Java's access modifiers to newbies, I believe it is a fundamental part of OO programming for such an access mode to exist. The arguments for having the standard "private" mode in fact also apply for having a C++-style "protected" mode. (Arguing that classes within a package are related and it therefore doesn't hurt to also give them access to Java's "protected" members, is equally arguing that "private" is unneccessary, which noone of course believes.)
    The whole concept of inheritance and polymorphism and encapsulation builds on the access modes private, protected, and public (in the C++ senses). In Java the "package" concept was added - a nice feature! But I see no justification for it to negate the proper encapsulation of a class and its specializations.

    What effect upon inheritance other than hiding members
    from subclasses is there?
    None. And I cant think of another declaration that prevents members from being inherited but private.
    Of course the onus comes on the programmer with Java's
    definition of "protected" - but
    1) there is rarely a single programmer working within
    a package
    The point was the package is a unit which does not hide from itself. Just like all methods within a class can see each other, all classes within a package can, and all packages within a program can.
    2) it muddies the encapsulation in the design - when
    you see a "protected" method someone else, or yourself
    some time ago - wrote, how do you know if the design
    intention is to have it accessed solely by the class
    and its subclasses, or if it is indeed intended to be
    shared with the whole package? The only way to do
    this today is to always explicitly specify this in the
    comments, which may be lacking, inconsistent, and
    abused (since it isn't enforced).Encapsulation would be implementation hiding. Not method hiding. The only thing you should probably allow out of your package is an interface and a factory anyway.
    I understand where you are coming from, but I really have not had occasion to take issue with it. I can't think of a real codeing situation where this is required. OTOH, I can't think of a coding situation where I need to access a protected method from another class either.

  • Reopened topic "private protected" modifier

    I respond to reply in thread <http://forums.sun.com/thread.jspa?threadID=503004>. There I posted following:
    I would like to express that something like "private protected" is really missing. I develop packages for modelling of engineering structures. I have real and clear example why I need this. I was very surprised that I cannot open fields for subclasses only! Therefore I have to use "private" because I dont want to see these fields from another classes. It does not make sense in this way.
    There is my example:
    Imagine that there is a model for analysis of a engineering structure. This model can be 2D or 3D. Im developing three packages. First, the most abstract, contains classes useful in both 2D and 3D branches. For example class AbstractMassPoint, which has field mass. Second package is 2D brach and third package is 3D branch. In 2D and 3D branch are subclasses of AbstractMassPoint named MassPoint. I both versions of MassPoint class are relationships using mass field and one natural solution is access it directly without using getMass() method. But I like encapsulation and I dont want to see this field outside class AbstractMassPoint except subclases MassPoint which are natural subclasses. Modifier protected is too weak. I dont want to see this field in classes from package. Therefore current state is private modifier and something like getMass() methods. You can see source codes on my page (keywords: kitnarf's library, fydik).
    I like Java, but this is wrong. Why it is not possible?

    kitnarf wrote:
    There is my example:
    Imagine that there is a model for analysis of a engineering structure. This model can be 2D or 3D. Im developing three packages. First, the most abstract, contains classes useful in both 2D and 3D branches. For example class AbstractMassPoint, which has field mass. Second package is 2D brach and third package is 3D branch. In 2D and 3D branch are subclasses of AbstractMassPoint named MassPoint. I both versions of MassPoint class are relationships using mass field and one natural solution is access it directly without using getMass() method. But I like encapsulation and I dont want to see this field outside class AbstractMassPoint except subclases MassPoint which are natural subclasses. Modifier protected is too weak. I dont want to see this field in classes from package. Therefore current state is private modifier and something like getMass() methods. You can see source codes on my page (keywords: kitnarf's library, fydik).
    I like Java, but this is wrong. Why it is not possible?Although you might have a case for this very specific application how does it apply to the other million possible applications that one might create? If 900,000 of them could use it in such a way that it makes the code better then it is a good idea. But if only 1 could use it then it isn't.
    Given that I can get to private members if I want but it just isn't convenient to do so. So all you are doing is providing encouragement to someone to do the right thing. The best way to do that is correctly design the classes in the first place and provide correct and complete documentation. That works much better that trying to find ways to restrict it.

  • Forcing invocation of private/protected methods

    Has anyone, any idea how can be forced the invocation of a private/protected method on a object. The client that invokes the method has a reference to the object and is declared in a different object than the targeted object.
    See code below:
    package src.client;
    import java.lang.reflect.Method;
    import src.provider.CPBook;
    public class Tester {
         public static void main(String [] args) {
              CPBook targetObj = new CPBook();
              Method [] mths = targetObj.getClass().getDeclaredMethods();
              Method targetMth = null;
              for (int i = 0; i < mths.length; i++) {               
                   if ("getMgr".equals(mths.getName())) {
                        targetMth = mths[i];
              if (targetMth != null) {
                   try {
                        Object [] obj = new Object[1];
                        obj[0] = new Boolean(true);
                        targetMth.invoke(b, obj);
                   } catch (Exception e) {                    
                        e.printStackTrace();
    package src.provider;
    public class CPBook {
         public void startDownload() {                    
         public void stopDownload() {     
         protected void getMgr(boolean bool) {
              System.out.println("------- OK ------- : " + bool);
    }Thank you.
    Best regards.

    The class java.lang.reflect.Method has a setAccessible(boolean) method on it. I think that's what you're asking for. Code that makes use of it might run into trouble if a security manager is involved, though. Generally, methods are private for a reason, too, so if your code depends on a private method, it's dependent on an implementation detail it probably shouldn't be concerned about, or even aware of

  • Applying Private & Protected methods inside JSP

    I am trying to apply (or copy) codings from Servlet into JSP.
    One of the issue that I encountered was bringing Private and Protected methods that were listed inside the Servlet class (this case: public abstract class CatalogPage).
    If I only copy everything inside "Public void doGet", JSP would not work.
    1) My question is, is it better approach to apply Private and Protected method beside wrapping around with ( <%! %> (with !)) (like below)?
    I think I heard about using " ! " for private methods somewhere in the internet..
    Here is what I have at JSP.
    <%!
    Private CatalogItem[] items;
    Private String[] itemIDs;
    private String title;
    protected void setItems(String[] itemIDs) {
    protected void setTitle(String title) {
    %>
    <%
    if (items == null) {
    response.sendError(response.SC_NOT_FOUND,
    "Missing Items.");
    return;
    %>
    2) Is there any other ways I could make the functionality of Private and Protected methods
    work inside the JSP's <% %>?
    Thank you.
    Here is the original Servlet code.
    public abstract class CatalogPage extends HttpServlet {
      private CatalogItem[] items;
      private String[] itemIDs;
      private String title;
      protected void setItems(String[] itemIDs) {
        this.itemIDs = itemIDs;
        items = new CatalogItem[itemIDs.length];
        for(int i=0; i<items.length; i++) {
          items[i] = Catalog.getItem(itemIDs);
    protected void setTitle(String title) {
    this.title = title;
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    if (items == null) {
    response.sendError(response.SC_NOT_FOUND,
    "Missing Items.");
    return;
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1 ALIGN=\"CENTER\">" + title + "</H1>");
    CatalogItem item;
    for(int i=0; i<items.length; i++) {
    out.println("<HR>");
    item = items[i];
    // Show error message if subclass lists item ID
    // that's not in the catalog.
    if (item == null) {
    out.println("<FONT COLOR=\"RED\">" +
    "Unknown item ID " + itemIDs[i] +
    "</FONT>");
    } else {
    out.println();
    String formURL =
    "/servlet/coreservlets.OrderPage";
    // Pass URLs that reference own site through encodeURL.
    formURL = response.encodeURL(formURL);
    out.println
    ("<FORM ACTION=\"" + formURL + "\">\n" +
    "<INPUT TYPE=\"HIDDEN\" NAME=\"itemID\" " +
    " VALUE=\"" + item.getItemID() + "\">\n" +
    "<H2>" + item.getShortDescription() +
    " ($" + item.getCost() + ")</H2>\n" +
    item.getLongDescription() + "\n" +
    "<P>\n<CENTER>\n" +
    "<INPUT TYPE=\"SUBMIT\" " +
    "VALUE=\"Add to Shopping Cart\">\n" +
    "</CENTER>\n<P>\n</FORM>");
    out.println("<HR>\n</BODY></HTML>");
    null

    I am trying to apply (or copy) codings from Servlet into JSP.What benefit is there to copying code from a servlet to a JSP? Is the servlet "working"?
    One of the issue that I encountered was bringing
    Private and Protected methods that were listed inside
    the Servlet class.
    If I just copy everything inside "Public void doGet",
    JSP would not work.Sounds like you need a redesign.
    1) My question is, is it better approach to apply
    Private and Protected method beside wrapping around
    with ( <%! %> (with !)) (like below)?
    I think I heard about using " ! " for private
    methods somewhere in the internet..Never heard of such a thing. Please cite the link if you have it.
    Here is what I have at JSP.Please, I can't look. This is wrong on so many levels. You've got scriptlet code, CSS style stuff, embedded HTML in one unmaintainable mess.
    Learn JSTL and CSS. Do not, under any circumstances, put scriptlet code in your JSP.
    The right way is to use the JSP purely as display and keep those protected and private methods on the server side where they belong. Have the JSP make a request to another object to do some work, get the result, and displa it.
    %

  • Private, protected Access Modifiers with a class

    Why cant we use private and protected access modifiers with a class?
    Thanks.

    Matiz wrote:
    >
    Public access allows you to extend a parent class in some other package. If you only want users to extend your class rather than instantiate it directly, make the class abstract and design for extension.Agreed. However, would the same argument be not true for the default access at the class level? No. Default access would only allow you to extend a parent class in the same package (as opposed to some other package).
    Now my confusion is why is a class allowed default access at the top level and not protected?Because protected for a top-level class makes no sense. The protected keyword provides member access to any other class in the same package and extending classes outside the package. A top-level class isn't a member of a class, by definition, so there's nothing that protected would do provide differently than public.
    So, the two access modifiers for a top-level class are public and default. Public allows access to the class outside the package, whereas default restricts access to the class within the package.
    ~

  • Inheritance: public, private, protected & default?

    I have a good idea where, and when, to use public, private and protected, but what is the default used for? By default I mean just not specifing the inheritance.
    Ex:
    String aString;
    Thanks in advance,
    Brian

    It means basically that only classes written to the same package as that one, would be able to access the member, regardless of whether they inherit from the class or not. If a class inherits from it, but is not written in the same package, it cannot access the member - it's just as if it were written as "private" in that case.

  • Private, protected advantages, disadvantages

    Hi,
    Is there a significant difference between private and protected instead of the sight in the package?
    The question is cause of the often usage of protected in "official" code instead of private.
    regards
    Olek

    Navy_Coder wrote:
    Olek wrote:
    Hi,
    Is there a significant difference between private and protected instead of the sight in the package?
    The question is cause of the often usage of protected in "official" code instead of private.
    regards
    Olek??? What do you mean by "official" code? I write "official" code (or so I thought any way) and I use significantly more private variables than protected.Me too. I tend to follow the doctrine that a variable should be private unless there is a good reason for it not to be. I always restrict access as far as seems reasonable, and rarely ever use protected variables. I find there are very few examples of times I think I need access to a super class's data members. On occasion, I will use protected methods or protected constructors, but there again, if I don't need them to be protected, I'm definitely going to make them private, instead.
    - Adam

  • Static, public, private, protected?

    Sorry for these questions, but I still don't know why properly why you use static, prublic, protected?
    And also is it possible to have a multi array first bit being and short and second being a byte e.g.
    int item_id[] byte[]so item_id[0][0] = 5
    first 0 means you got nothing on
    second 0 is the hp stat
    = 5 adds 5 hp onto the total is this possible

    Morpher wrote:
    Sorry for these questions, but I still don't know why properly why you use static, prublic, protected?No problem, that's how you learn.
    Look at this and this .
    And also is it possible to have a multi array first bit being and short and second being a byte e.g.Why would you want to do that? If you feel like using wrapper classes, you can make an array of Objects.

  • Can java have Protected or Private Constructor

    Hi,
    can java have Priavte or protected constructor,
    as we know java have default and public constructor ,
    and in using singleton design patters we can use private & protected constructor,
    so, what is the main logic,
    Regards,
    Prabhat

    Hi,
    Yes, We can declare constructor as private/public/protected also.
    Having only private constructors means that you can't instantiate the class from outside the class (although instances could still be created from within the class - more about this later). However, when you instantiate a class, you must first initialize all superclasses of that class by invoking their constructors. If one of the superclasses has only private constructors declared, we have a problem. We can't invoke the superclass' constructor which means that we can't instantiate our object. Because of this, we've essentially made a class that can't be extended.
    example:
    class TheWorld
    private static TheWorld _instance = null;
    private TheWorld() {}
    public static TheWorld instance()
    if ( _instance == null )
    _instance = new TheWorld();
    return _instance;
    public void spin() {...}
    public class WorldUser
    public static void main(String[] args)
    TheWorld.instance().spin();
    }

  • What happens to private data?

    Hello everybody,
    This question is purely out of curiosity, but it just came to me:
    Lets say you have a class that has some data and, say, methods "foo" and "bar" are the only ones to manipulate that data. I say this in a sense where that data would be useless, totally inaccessible, if those two methods were to be overridden. Now lets say they are. For some reason, some sub-class would need to implement the same functionality in some other way, overrides those methods and uses an entirely new set of data. Does the previous, private/protected data, get "shipped" with the child class anyway? Is there some kind of optimization to detect this situation and disregard the data as usable? Or is that not possible, for some reason? If you were facing a problem like that in your designs (ie, the class you are extending as not been written by you, so you either have to "play along" or you just don't know about it), how would you solve it?
    I know that the GC could do it. So the main question is: does it?
    Kind regards ;)
    Fratelli

    That's not very good design either. Make all your base classes with weak references so people can extend them, ignoring their fields, and allow those fields to be garbage collected? What if the superclass needs that one reference to keep the value? When you design a class, you should know whether you plan for it to be extended or not, and if the answer is yes, then you should know how it's meant to be extended. If there's a field that could reasonably be ignored by a subclass, then it shouldn't be there at all -- rather, you should provide a specific subclass using that field, so other subclasses can branch off the superclass that doesn't have it. If the field in question is integral to the functioning of the superclass... then unless a weak reference is part of the semantics of the superclass, it shouldn't use a weak reference, and if a subclass wants to use the superclass but ignore that field, then the subclass is being poorly designed. You can't compensate for unknown future bad design in advance, aside from just making it more difficult.

  • A keyword for marking default protection

    Today java is missing a keywork for marking default (package) protection. This is marked just by not using private, protected or public.
    To me code with a explicit defined protection is easier to read than code where protection is defined by not using any keyword.
    I think java should have a keyword for explicitly declaring the protection level.
    I have searched bugs.sun.com for an issue about this, but didn't find any.
    Does anybody here has any thoughts about this topic?
    -Kaj :)
    Edited by: kajh on Apr 19, 2008 12:50 PM

    DrClap wrote:
    An optional package-private keyword would be just another source of confusionThen don't tell anyone about it :). Those who wanted it will find out, one way or another.
    I agree that I wish package-private had its own keyword, as I think it would make code more readable (a compiler preprocessor instruction forcing yourself to specify access level might be nice too). Personally, because there was no keyword for package-private, I spent the majority of my Java life thinking that the default (no keyword) was the same as "protected", because I assumed it had to be one of the three (public, protected or private). So from my experience anyway, not having a keyword is introducing a lot more confusion than adding one late in the game.
    The biggest problem I'd see with the addition would be that they haven't reserved a suitable keyword, and introducing a new keyword will either 1. run the risk of breaking existing code (identifiers using keywords added late) or 2. increase parser complexity.
    Could always use the default keyword in a separate context though:
    public class Clazz  {
       default int myData;
    }Or change the grammar rules for declarations:
    public class Clazz {
       package private int myData;
    }

  • Private methods of CL_GUI_ALV_GRID

    Hi All,
      How can we use the private & protected methods of CL_GUI_ALV_GRID class in a custom program, a sample code will be helpful.

    Hai Vijay
    try with the following Code( Just copy the code & try with in SE38 Tcode & Execute it that all)
    REPORT ZALV_SALES_HEADER_DETAIL MESSAGE-ID Z50650(MSG) .
    TABLES
    TABLES: VBAK . "SALES DOCUMENT HEADER
    DATA OBJECTS DECLARATION
    DATA: IT_VBAK TYPE STANDARD TABLE OF ZVBAK_STRUC,
    IT_VBAP TYPE STANDARD TABLE OF ZVBAP_STRUC,
    GS_LAYOUT TYPE LVC_S_LAYO,
    GS1_LAYOUT TYPE LVC_S_LAYO,
    GRID TYPE REF TO CL_GUI_ALV_GRID,
    CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
    VBAK_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
    VBAP_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
    WA_VBAK LIKE LINE OF IT_VBAK,
    WA_VBAP LIKE LINE OF IT_VBAP,
    SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
    TOP_OF_PAGE_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
    GRID_VBAP TYPE REF TO CL_GUI_ALV_GRID,
    TOP_PAGE TYPE REF TO CL_DD_DOCUMENT,
    FLAG(1).
    *"EVENT RECIEVER CLASS DEFINITION
    CLASS LCL_EVENT_RECIEVER DEFINITION DEFERRED.
    DATA: OBJ_EVENT TYPE REF TO LCL_EVENT_RECIEVER.
    SELECTION-SCREEN
    SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.
    PARAMETERS: P_VBTYP LIKE VBAK-VBTYP DEFAULT 'C'.
    SELECTION-SCREEN: END OF BLOCK B1.
    CLASS DEFINITION AND DECLARATIONS
    CLASS LCL_EVENT_RECIEVER DEFINITION.
    PUBLIC SECTION.
    EVENTS:DOUBLE_CLICK,
    TOP_OF_PAGE.
    METHODS:HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
    IMPORTING E_ROW .
    METHODS: HANDLE_TOP_OF_PAGE FOR EVENT TOP_OF_PAGE OF CL_GUI_ALV_GRID.
    ENDCLASS. "LCL_EVENT_RECIEVER DEFINITION
    CLASS LCL_EVENT_RECIEVER IMPLEMENTATION
    CLASS LCL_EVENT_RECIEVER IMPLEMENTATION.
    METHOD: HANDLE_DOUBLE_CLICK.
    READ TABLE IT_VBAK INDEX E_ROW-INDEX INTO WA_VBAK.
    PERFORM FETCH_ITEM_DETAILS USING WA_VBAK.
    PERFORM ALV_GRID.
    ENDMETHOD. "HANDLE_DOUBLE_CLICK
    METHOD: HANDLE_TOP_OF_PAGE.
    CALL METHOD TOP_PAGE->ADD_TEXT
    EXPORTING
    TEXT = 'SALES HEADER & ITEM DETAILS'.
    CALL METHOD TOP_PAGE->DISPLAY_DOCUMENT
    EXPORTING
    PARENT = TOP_OF_PAGE_CONTAINER.
    ENDMETHOD. "HANDLER_TOP_OF_PAGE
    ENDCLASS. "LCL_EVENT_RECIEVER IMPLEMENTATION
    AT SELECTION-SCREEN
    AT SELECTION-SCREEN.
    IF S_VBELN IS NOT INITIAL.
    SELECT COUNT(*)
    FROM VBAK
    WHERE VBELN IN S_VBELN.
    IF SY-DBCNT = 0.
    MESSAGE E000 WITH 'NO TABLE ENTRIES FOUND FOR LOW KEY SPECIFIED'.
    ENDIF.
    ENDIF.
    START-OF-SELECTION.
    START-OF-SELECTION.
    PERFORM FETCH_SALES_HEADER_RECORD.
    PERFORM CREATE_CALL. "CREATION OF OBJECTS & CALLING METHODS
    END-OF-SELECTION.
    END-OF-SELECTION.
    *& Module STATUS_0100 OUTPUT
    text
    MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'ZSTATUS'.
    SET TITLEBAR 'xxx'.
    ENDMODULE. " STATUS_0100 OUTPUT
    *& Form FETCH_SALES_HEADER_RECORD
    text
    --> p1 text
    <-- p2 text
    FORM FETCH_SALES_HEADER_RECORD .
    SELECT
    VBELN
    AUDAT
    VBTYP
    AUART
    AUGRU
    NETWR
    WAERK
    FROM VBAK
    INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
    WHERE VBELN IN S_VBELN
    AND VBTYP = P_VBTYP.
    ENDFORM. " FETCH_SALES_HEADER_RECORD
    *& Form CREATE_CALL
    text
    --> p1 text
    <-- p2 text
    FORM CREATE_CALL .
    IF CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT CUSTOM_CONTAINER
    EXPORTING
    PARENT =
    CONTAINER_NAME = 'CUSTOM_CONTAINER'
    STYLE =
    LIFETIME = lifetime_default
    REPID =
    DYNNR =
    NO_AUTODEF_PROGID_DYNNR =
    EXCEPTIONS
    CNTL_ERROR = 1
    CNTL_SYSTEM_ERROR = 2
    CREATE_ERROR = 3
    LIFETIME_ERROR = 4
    LIFETIME_DYNPRO_DYNPRO_LINK = 5
    OTHERS = 6
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CREATE OBJECT SPLITTER
    EXPORTING
    TOP = 5
    PARENT = CUSTOM_CONTAINER
    ROWS = 3
    COLUMNS = 1
    EXCEPTIONS
    CNTL_ERROR = 1
    CNTL_SYSTEM_ERROR = 2
    OTHERS = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL METHOD SPLITTER->GET_CONTAINER
    EXPORTING
    ROW = 1
    COLUMN = 1
    RECEIVING
    CONTAINER = TOP_OF_PAGE_CONTAINER.
    CALL METHOD SPLITTER->GET_CONTAINER
    EXPORTING
    ROW = 2
    COLUMN = 1
    RECEIVING
    CONTAINER = VBAK_CONTAINER.
    CALL METHOD SPLITTER->GET_CONTAINER
    EXPORTING
    ROW = 3
    COLUMN = 1
    RECEIVING
    CONTAINER = VBAP_CONTAINER.
    CREATE OBJECT GRID
    EXPORTING
    I_SHELLSTYLE = 0
    I_LIFETIME =
    I_PARENT = VBAK_CONTAINER
    I_APPL_EVENTS = space
    I_PARENTDBG =
    I_APPLOGPARENT =
    I_GRAPHICSPARENT =
    I_NAME =
    EXCEPTIONS
    ERROR_CNTL_CREATE = 1
    ERROR_CNTL_INIT = 2
    ERROR_CNTL_LINK = 3
    ERROR_DP_CREATE = 4
    OTHERS = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    GS_LAYOUT-GRID_TITLE = 'SALES HEADER DETAILS.'(100).
    CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
    I_BUFFER_ACTIVE =
    I_BYPASSING_BUFFER =
    I_CONSISTENCY_CHECK =
    I_STRUCTURE_NAME = 'ZVBAK_STRUC'
    IS_VARIANT =
    I_SAVE =
    I_DEFAULT = 'X'
    IS_LAYOUT = GS_LAYOUT
    IS_PRINT =
    IT_SPECIAL_GROUPS =
    IT_TOOLBAR_EXCLUDING =
    IT_HYPERLINK =
    IT_ALV_GRAPHICS =
    IT_EXCEPT_QINFO =
    CHANGING
    IT_OUTTAB = IT_VBAK
    IT_FIELDCATALOG =
    IT_SORT =
    IT_FILTER =
    EXCEPTIONS
    INVALID_PARAMETER_COMBINATION = 1
    PROGRAM_ERROR = 2
    TOO_MANY_LINES = 3
    OTHERS = 4
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDIF.
    CREATE OBJECT OBJ_EVENT .
    SET HANDLER OBJ_EVENT->HANDLE_DOUBLE_CLICK FOR GRID.
    SET HANDLER OBJ_EVENT->HANDLE_TOP_OF_PAGE FOR GRID.
    CREATE OBJECT TOP_PAGE
    EXPORTING
    STYLE = 'ALV_GRID'
    CALL METHOD TOP_PAGE->INITIALIZE_DOCUMENT.
    CALL METHOD GRID->LIST_PROCESSING_EVENTS
    EXPORTING
    I_EVENT_NAME = 'TOP_OF_PAGE'
    I_DYNDOC_ID = TOP_PAGE.
    CALL SCREEN 100.
    ENDFORM. " CREATE_CALL
    *& Module USER_COMMAND_0100 INPUT
    text
    MODULE USER_COMMAND_0100 INPUT.
    CASE SY-UCOMM.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE. " USER_COMMAND_0100 INPUT
    *& Form FETCH_ITEM_DETAILS
    text
    --> p1 text
    <-- p2 text
    FORM FETCH_ITEM_DETAILS USING WA_VBAK TYPE ZVBAK_STRUC .
    SELECT
    VBELN
    POSNR
    MATNR
    MATWA
    PMATN
    CHARG
    FROM VBAP
    INTO TABLE IT_VBAP
    WHERE VBELN = WA_VBAK-VBELN.
    IF SY-SUBRC <> 0.
    MESSAGE E000 WITH 'NO RECORDS FOUND FOR SPECIFIED KEY'.
    ENDIF.
    ENDFORM. " FETCH_ITEM_DETAILS
    *& Module STATUS_0200 OUTPUT
    text
    MODULE STATUS_0200 OUTPUT.
    SET PF-STATUS 'ZSTATUS'.
    SET TITLEBAR 'xxx'.
    ENDMODULE. " STATUS_0200 OUTPUT
    *& Module USER_COMMAND_0200 INPUT
    text
    MODULE USER_COMMAND_0200 INPUT.
    CASE SY-UCOMM.
    WHEN 'EXIT'.
    LEAVE PROGRAM.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.
    ENDCASE.
    ENDMODULE. " USER_COMMAND_0200 INPUT
    *& Form alv_grid
    text
    --> p1 text
    <-- p2 text
    FORM ALV_GRID .
    IF FLAG = ''.
    FLAG = 'X'.
    CREATE OBJECT GRID_VBAP
    EXPORTING
    I_SHELLSTYLE = 0
    I_LIFETIME =
    I_PARENT = VBAP_CONTAINER
    I_APPL_EVENTS = space
    I_PARENTDBG =
    I_APPLOGPARENT =
    I_GRAPHICSPARENT =
    I_NAME =
    EXCEPTIONS
    ERROR_CNTL_CREATE = 1
    ERROR_CNTL_INIT = 2
    ERROR_CNTL_LINK = 3
    ERROR_DP_CREATE = 4
    others = 5
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDIF.
    GS1_LAYOUT-GRID_TITLE = 'SALES ITEM DETAILS.'(100).
    CALL METHOD GRID_VBAP->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
    I_BUFFER_ACTIVE =
    I_BYPASSING_BUFFER =
    I_CONSISTENCY_CHECK =
    I_STRUCTURE_NAME = 'ZVBAP_STRUC'
    IS_VARIANT =
    I_SAVE =
    I_DEFAULT = 'X'
    IS_LAYOUT = GS1_LAYOUT
    IS_PRINT =
    IT_SPECIAL_GROUPS =
    IT_TOOLBAR_EXCLUDING =
    IT_HYPERLINK =
    IT_ALV_GRAPHICS =
    IT_EXCEPT_QINFO =
    CHANGING
    IT_OUTTAB = IT_VBAP
    IT_FIELDCATALOG =
    IT_SORT =
    IT_FILTER =
    EXCEPTIONS
    INVALID_PARAMETER_COMBINATION = 1
    PROGRAM_ERROR = 2
    TOO_MANY_LINES = 3
    OTHERS = 4
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM. " alv_grid
    Thanks & regards
    Sreenivasulu P

  • What is the diff b/w Abstract class and an interface ?

    Hey
    I am always confused as with this issue : diff b/w Abstract class and an interface ?
    Which is more powerful in what situation.
    Regards
    Vinay

    Hi, Don't worry I am teach you
    Abstract class and Interface
    An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
    Edited by SASIKUMARA
    SIT INNOVATIONS- Chennai
    Message was edited by:
    sasikumara
    Message was edited by:
    sasikumara

  • Problem with constructor of inner class.

    Hi everybody!
    I have an applet which loads images from a database.
    i want to draw the images in a textarea, so i wrote an inner class, which extends textarea and overrides the paint method.
    but everytime i try to disply the applet in the browser this happens:
    java.lang.NoClassDefFoundError: WohnungSuchenApplet$Malfl�che
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
    at java.lang.Class.getConstructor0(Class.java:1762)
    at java.lang.Class.newInstance0(Class.java:276)
    at java.lang.Class.newInstance(Class.java:259)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)
    at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1778)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)
    at sun.applet.AppletPanel.run(AppletPanel.java:293)
    at java.lang.Thread.run(Thread.java:536)
    so my class has no own constructor, it just has the paint method overwritten.
    my class looks like this:
    public class Malfl�che extends javax.swing.JTextArea{
    public void paint(Graphics g){
    Color grey=new Color(220,220,220);
    g.drawImage(img,10,10,null);
    how should a constructor for this class look like?
    sorry i am quite new to this, so i really dont have a clue!
    my class does not have any attributes or requires any so it doesnt need a constructor, doesnt it?
    thanks a lot
    tim

    First off, unlike regular classes, inner classes can be declared public, private, protected, and default.
    Secondly, why are you using the JTextArea to display an image, why not use a JLabel, which takes an Image object as its constructor.
    Thirdly, when you drew your image you did not give it a width and height
    g.drawImage(img, 0,0, img.getWidth(null), img.getHeight(null), null);
    otherwise it will make your image 1 X 1 pixels. not big enough to see.

Maybe you are looking for

  • ACS 5.3 Stripping Radius User Prefix

    Hi, I have configure my ACS 5.3 to strip the prefix of the radius username (Domain\weekwang) it received and I also configured my ACS as the External Radius Server. However, this does not seem to work. The authentication protocol that I am using is P

  • I can't get my SSD to boot

    Hello everyone. I've been searching for an answer to this for over a day now, and although I find people talking about having the same problem, doesn't seem like anyone actually posts a SOLUTION on what to do! I recently purchased this http://www.ama

  • Bold text in af:table column header

    Guys, I want to bold the text in af:column header. I want "label1" text to be bold.. Any suggestions welcome. <af:column sortProperty="test1" headerText="label1" inlineStyle="font-weight:bold;"> <af:outputText value="#{row.attribute1}" id="ot129"> </

  • Can I play what is on my iPad 2 through my apple tv?

    Can I play what is on my iPad 2 through my apple tv?

  • IPhone won't turn on or connect to iTunes after trying to restore/ios8

    Hello i bought this iPhones 4s broken to fix as he stated it was faulty and thought it was a screen problem as he could hear siri but i couldnt hear anything when came but: Once i bought it i tried the usual resets with the home and power button etc.