Use of private methods

Can someone tell me when a java program would use private methods? I understand that use of private instance variables is the norm and when extending a class, the use of the public methods is required to access the data. But when would it be necessary to use a private method? Thanks.

Okay, so you create a class. And some other class uses that class.
public class Useful {
  public void doSomethingUseful() {
public class User {
  // Use a Useful to do something useful
  Useful u = new Useful();
  u.doSomethingUseful();
}Now, you could put a whole bunch of krap into the single doSomethingUseful method, or you could be smart and break its work down into smaller methods, which each method having it's own responsibility. Those methods would be private, because there's no reason to expose the implementation details of the public method.

Similar Messages

  • UnusedPrivateMethod - bug when using static private method?

    Hi,
    I get the following violation:UnusedPrivateMethod. This private method (createDefaultSolidColors) does not seem to be used.
    For the foloowing code snippet:
    private  static const defaultSolidColors:Array = createDefaultSolidColors(); 
    private static function createDefaultSolidColors():Array { 
         var _a:Array = new Array(); 
         for each (var color:uint in defaultColors) {          _a.push(
    new SolidColor(color, 0.8));     }
         return _a;}
    Why is it a violation? the function is used by the defaultSolidColors property.
    Is it a bug or am I missing something?
    Thanks,
    -ilan

    This is a known issue, which has been fixed on trunk.
    The fix will be in the next release:
    https://bugs.adobe.com/jira/browse/FLEXPMD-173

  • Extending the BC4J objects which has private methods

    Hi,
    I faced a situation which requires to extended the AM and CO of a page which has some private methods.
    As we cant inherit the which private methods of a class I thought of using the same code in the extended class.
    As it is not feasible solution n not upgrade safe we have not taken up the development..
    Any one faced the same issue and any workaround on the same will be appreciated..
    Thanks,
    Nagu

    Copy the private method code into your extended objects. Then it'll use the private methods in your extended code....

  • How to access the private method

    All,
    I have class ABC with private method getfilename().
    I want to use this private method ...
    Is it possible to use this method without inheritence ?
    Is it possible to access this private method using annoymous inner class ?
    or any other alternatives ??
    namanc

    I have class ABC with private method getfilename().
    I want to use this private method ... You can't; it's private to the instantiations of that class.
    Is it possible to use this method without inheritence ? No, no even with inheritance.
    Is it possible to access this private method using
    annoymous inner class ? Nope, unless you can write that anonymous inner class yourself.
    or any other alternatives ?? Nope; privvy parts are privvy parts and only the owner of those privvy
    parts can touch them. (ahem)
    kind regards,
    Jos
    ps. unless you want to do reflection surgery of course.

  • How to access private method of an inner class using reflection.

    Can somebody tell me that how can i access private method of an inner class using reflection.
    There is a scenario like
    class A
    class B
    private fun() {
    now i want to use method fun() of an inner class inside third class i.e "class c".
    Can i use reflection in someway to access this private method fun() in class c.

    I suppose for unit tests, there could be cases when you need to access private methods that you don't want your real code to access.
    Reflection with inner classes can be tricky. I tried getting the constructor, but it kept failing until I saw that even though the default constructor is a no-arg, for inner classes that aren't static, apparently the constructor for the inner class itself takes an instance of the outer class as a param.
    So here's what it looks like:
            //list of inner classes, if any
            Class[] classlist = A.class.getDeclaredClasses();
            A outer = new A();
            try {
                for (int i =0; i < classlist.length; i++){
                    if (! classlist.getSimpleName().equals("B")){
    //skip other classes
    continue;
    //this is what I mention above.
    Constructor constr = classlist[i].getDeclaredConstructor(A.class);
    constr.setAccessible(true);
    Object inner = constr.newInstance(outer);
    Method meth = classlist[i].getDeclaredMethod("testMethod");
    meth.setAccessible(true);
    //the actual method call
    meth.invoke(inner);
    } catch (Exception e) {
    throw new RuntimeException(e);
    Good luck, and if you find yourself relying on this too much, it might mean a code redesign.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Error while usind Private Method of a global class

    HI All..
    I created a global class (ZLINE_GLOBAL) which has TOT_DATA private method. I have to call this private method in my report, I know that using Friend class we can do this.
    But it is not working and showing the same error  "  METHOD "TOT_DATA" is unknown or Private or Public..
    code i tried is
    CLASS c2 DEFINITION DEFERRED.
    CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
      PUBLIC SECTION.
        METHODS : m1.
      PRIVATE SECTION.
        METHODS: m2.
    ENDCLASS.
    CLASS ZLINE_GLOBAL IMPLEMENTATION .
      METHOD m1.
        WRITE : 'Public Method C1'.
      ENDMETHOD.                    "M1
      METHOD m2.
        WRITE : 'Private Method C1'.
      ENDMETHOD.
    ENDCLASS.
    CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL.  "my friends are here, allow them access to my (C2's) private components
      PUBLIC SECTION.
        METHODS :m3.
    ENDCLASS.
    CLASS c2 IMPLEMENTATION.
      METHOD m3.
        DATA : obj TYPE REF TO ZLINE_GLOBAL.
        CREATE OBJECT obj.
        CALL METHOD obj->TOT_DATA.    "here Iam calling Private method of global class
      ENDMETHOD.                    "M3
    ENDCLASS.
    START-OF-SELECTION.
      DATA obj_c2 TYPE REF TO c2.
      CREATE OBJECT obj_c2.
      obj_c2->m3( ).
    can anybody help me on this..
    Murthy

    Hi Murthy,
    Replace TOT_DATA with M2, you do not have any method by name "TOT_DATA" in your code.
    CLASS c2 DEFINITION DEFERRED.
    CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
      PUBLIC SECTION.
        METHODS : m1.
      PRIVATE SECTION.
        METHODS: m2.
    ENDCLASS.
    CLASS ZLINE_GLOBAL IMPLEMENTATION .
      METHOD m1.
        WRITE : 'Public Method C1'.
      ENDMETHOD.                    "M1
      METHOD m2.
        WRITE : 'Private Method C1'.
      ENDMETHOD.
    ENDCLASS.
    CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL.  "my friends are here, allow them access to my (C2's) private components
      PUBLIC SECTION.
        METHODS :m3.
    ENDCLASS.
    CLASS c2 IMPLEMENTATION.
      METHOD m3.
        DATA : obj TYPE REF TO ZLINE_GLOBAL.
        CREATE OBJECT obj.
        CALL METHOD obj->M2.    "here Iam calling Private method of global class
      ENDMETHOD.                    "M3
    ENDCLASS.
    START-OF-SELECTION.
      DATA obj_c2 TYPE REF TO c2.
      CREATE OBJECT obj_c2.
      obj_c2->m3( ).
    Regards,
    Chen

  • Creation of a static class with private methods

    I'm new to java programming and am working on a project where I need to have a static class that does a postage calculation that must contain 2 private methods, one for first class and one for priority mail. I can't seem to figure out how to get the weight into the class to do the calculations or how to call the two private methods so that when one of my other classes calls on this class, it retrieves the correct postage. I've got all my other classes working correct and retrieving the information required. I need to use the weight from another class and return a "double". Help!!!
    Here's my code:
    * <p>Title: Order Control </p>
    * <p>Description: Order Control Calculator using methods and classes</p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: Info 250, sec 001, T/TH 0930</p>
    * @author Peggy Blake
    * @version 1.0, 10/29/02
    import javax.swing.*;
    public class ShippingCalculator
    static double firstClass, priorityMail;
    //how do I get my weight from another class into this method to use??? not sure I understand how it works.
    public static double ShippingCalculator(double weight)
    String responseFirstClass;
    double quantity, shippingCost;
    double totalFirstClass, firstClass, priorityMail, totalShipping;
    double priorityMail1 = 3.50d;//prioritymail fee up to 1 pound
    double priorityMail2 = 3.95d;//prioritymail fee up to 2 pounds
    double priorityMail3 = 5.20d;//prioritymail fee up to 3 pounds
    double priorityMail4 = 6.45d;//prioritymail fee up to 4 pounds
    double priorityMail5 = 7.70d;//prioritymail fee up to 5 pounds
    quantity = 0d;//ititialization of quantity
    // weight = 0d;//initialization of weight
    // shippingCost = 0d;
    //calculation of the number of items ordered..each item weights .75 ounces
    quantity = (weight/.75);
    if (quantity <= 30d)
    //add 1 ounce to quantities that weigh less than 30 ounces
    weight = (weight + 1);
    else
    //add 2 ounces to quantities that weigh more than 30 ounces
    weight = (weight + 2);
    if (weight > 80d)
    //message to orderclerk ..order over 5 lbs, cannot process
    JOptionPane.showMessageDialog(null, "Order exceeded 5 lbs, cannot process");
    //exit system, do not process anything else
    System.exit (0);
    else
    if (weight < 14d)
    //send message to customer: ship firstclass or priority, y or n
    responseFirstClass = JOptionPane.showInputDialog(null, "Ship first class? y or n?");
    if (responseFirstClass.equals("y"))
    //compute FirstClass shipping cost
    totalFirstClass = ((weight - 1) * .23d) + .34d;
    firstClass = totalFirstClass;
    else
    //compute PriorityMail cost for orders less than 14 ounces
    priorityMail = (priorityMail1);
    else
    if (weight <=16d)
    //compute totalshipping for orders up to 16 ounces
    priorityMail = (priorityMail1);
    else
    if (weight <=32d)
    //compute totalshipping for orders up to 32 ounces
    priorityMail = (priorityMail2);
    else
    if (weight <=48d)
    //compute totalshipping for orders up to 48 ounces
    priorityMail = (priorityMail3);
    else
    if (weight <= 64d)
    //compute totalshipping for orders up to 64 ounces
    priorityMail = (priorityMail4);
    else
    //compute totalshipping for orders up to 80 ounces
    priorityMail = (priorityMail5);
    priorityMail = 0d;
    firstClass = 0d;
    firstClassMail ();
    priorityMailCost ();
    //I think this is where I should be pulling the two methods below into my code, but can't figure out how to do it.
    shippingCost = priorityMail + firstClass;
    return (shippingCost);
    }//end method calculate shipping
    private static double firstClassMail()//method to get first class ship cost
    return (firstClass);
    }//end method firstclass shipping
    private static double priorityMailCost()//method to get priority mail cost
    return (priorityMail);
    }//end method priorityMail
    }//end class shipping calculator

    public class A {
    public String getXXX () {
    public class B {
    A a = new A();
    public void init () {
    a.getXXX();
    }

  • Trying to use the Instance Method

    I'm trying to get the second class to use the instance method in the first class to make some Turtles move around in Triangle shape.
    Class one code:
    public class TryInstanceMethod
    private Turtle t;
    public TryInstanceMethod(Turtle turtle)
    t = turtle;
    public void drawTriangle(int length)
    t.forward(length);
    t.turn(-120);
    t.forward(length);
    t.turn(-120);
    t.forward(length);
    Class two code:
    import java.awt.*;
    public class UseInstanceMethod
    public void main(String[] args)
    World w1 = new World();
    Turtle t1 = new Turtle(w1);
    TryInstanceMethod TM1 = new TryInstanceMethod(t1);
    TM1.drawTriangle(100);
    World w2 = new World();
    Turtle t2 = new Turtle(w2);
    TryInstanceMethod TM2 = new TryInstanceMethod(t2);
    TM2.drawTriangle(200);
    it compiles fine but it will not use the instance method drawTriangle to draw two triangles in two different worlds

    When posting code highlight it and click the CODE button to retain formatting
    fox_1 wrote:
    it compiles fine but it will not use the instance method drawTriangle to draw two triangles in two different worldsSo what does it do instead? We do not read minds and cannot see you computer screen. So you need to provide as much information as possible. Such as the Turtle and World classes.

  • Use of a method in class CL_GUI_ALV_GRID

    Dear all,
    I have a requirement in which i have to use the method - SHOW_GRAPHICS of the class - CL_GUI_ALV_GRID, but the problem is there is a red traffic light in front of the method. Now my dilemma is how to turn that light green so that i can use this method.
    Kindly help.
    Thanks,
    Saurabh Chauhan.

    The red light says that it is a private method .. So it means that this method can not be used out side the class !
    There is a way out ... Create your own class that ZCL_GUI_ALV_GRID that inherits the CL_GUI_ALV_GRID.
    Here you create a public method my_method and in this method call the private method.
    Warning : If the architect had created that method as a Private one ... he must have done it for a reason .. may be this method has access to some attributes that must not be made available to the outside world ... which might cause serious damage !!
    Rule 1: Trust the architect .. If he has made it private.. it is for a reason... and Ideally there can not be any case why some one else would use this method out side the class..
    Hint: May be it is possible to achieve the same without using this method (in a different way) ..
    Regards,
    Varun.

  • How to use my findTheHighest method to find the highest value in my two dim

    I am going to create a 13row by 10 colume two dimensional array.
    how to use my findTheHighest method to find the highest value in my two dimensional array.
    .When i compile this program , i got those as following;
    "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsExce
    at TaxEvolution.findTheHighest(TaxEvolution.java:31)
    at TaxEvolutionClient.main(TaxEvolutionClient.java:25)"
    public class TaxEvolution{
    public double[][] salesTaxRates;
    public TaxEvolution()
      salesTaxRates = new double[13][10];
      fillProvinTaxRates();
    private void fillProvinTaxRates()
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          salesTaxRates[row][column]= (int)(Math.random()*5000) + 1;
    public double findTheHighest()
        double highest = salesTaxRates[0][0];
        for ( int row = 0; row <= salesTaxRates.length; row++ )
          for ( int column = 0; column <= salesTaxRates[row].length; column++ )
             if ( salesTaxRates[row][column] >= highest )
                   highest = salesTaxRates[row][column];
        return highest;   
    public double[][] arrayTaxEvolution()
      double[][] returnTaxRates = new double[13][10];
      for ( int row = 0; row < salesTaxRates.length; row++ )
        for ( int column = 0; column < salesTaxRates[row].length; column++ )
          returnTaxRates = salesTaxRates;
      return returnTaxRates;
    public class TaxEvolutionClient{
    public static void main( String[] args ){
      TaxEvolution protaxRateList = new TaxEvolution();
      double[][] taxRateList = protaxRateList.arrayTaxEvolution();
        for ( int i = 0; i < taxRateList.length; i++ )
          for ( int j = 0; j < taxRateList[0].length; j++ )
            System.out.print( taxRateList[i][j] + "\t" );               
            System.out.print( protaxRateList.findTheHighest + "\t" );
    }

    Multiposted
    http://forum.java.sun.com/thread.jspa?threadID=699057&tstart=0

  • Call Enterprise Bean (or Database) from private Method in Session-Bean

    Hi Everybody,
    I've a question regarding the possibility to call an dependency injected EJB in an private method of a session bean.
    Imagine the following.
    @Stateless
    public class SomeBean implements SomeLocal{
       @EJB
       private AnotherLocal anotherBean;
       /** Will be called from a web-app via delegate layer */
       @TransactionAttribute(TransactionAttribute.RequiresNew)
       public void someBusisnessMethod(){
           String something = this.getSomeThing();
           //Do more
       private String getSomeThing(){
          return anotherBean.aMethodWhichCallsTheEntityManager();
    }I've to refactor code with uses such Call-Hierachy and I want to know whether this is a correct way? Somebody told me that such stuff should not be made, and I quess he told me an explanation, why not to do such stuff, but unfortunally I've forgotten that. Do someone have a suggestion why not to do this? Could it blow the application to hell? Is there any difference to the following code (The way I would have done it)?
    @Stateless
    public class SomeBean implements SomeLocal{
       @EJB
       private AnotherLocal anotherBean;
        @Resource
        private SessionContext sessionContext;
       /** Will be called from a web-app via delegate layer */
       @TransactionAttribute(TransactionAttribute.RequiresNew)
       public void someBusisnessMethod(){
           SomeLocal self = this.sessionContext.getBusinessObject(SomeLocal.class);
           String something = self.getSomeThingBusinessMethod();
           //Do more
       @TransactionAttribute(TransactionAttribute.Required)
       public String getSomeThingBusinessMethod(){
          return anotherBean.aMethodWhichCallsTheEntityManager();
    }

    Found the answer by myself....
    Here it is if someone might have the same question:
    http://stackoverflow.com/questions/3381002 or if the link may down sometime the content of the answer...
    >
    The motivation here is that most EJB implementations work on proxies. You wouldn't be too far off in thinking of it as old-school AOP. The business interface is implemented by the EJB container, quite often via a simple java.lang.reflect.Proxy, and this object is handed to everyone in the system who asks for the ejb via @EJB or JNDI lookup.
    The proxy is hooked up to the container and all calls on it go directly to the container who will preform security checks, start/stop/suspend transactions, invoke interceptors, etc. etc. and then finally delegate the call to the bean instance -- and of course do any clean up required due to any exceptions thrown -- then finally hand the return value over through the proxy to the caller.
    Calling this.foo() directly, or passing 'this' to a caller so they can make direct calls as well, will skip all of that and the container will be effectively cut out of the picture. The 'getBusinessObject(Class)' method allows the bean instance to essentially get a proxy to itself so it can invoke its own methods and make use of the container management services associated with it -- interceptors, transaction management, security enforcement, etc.
    written by David Blevins

  • Problem exporting crystal PDF using printoutputController.export method

    Has anyone used PrintOutputController().export() method in ReportClientdocument to export Crystal PDF report to a JavaIOStream. I am getting an error when I try to export it using this method. The error I get is unable to connect RAS.rptappsrver followed by classcast unable to export to IXMLSerializable. Here is the code I am using.
    Is there some setting I need to enable on the server to use the export function or any other idea will be appreciated?
    IReportAppFactory reportAppFactory = (IReportAppFactory) enterpriseSession.getService("","RASReportFactory");
    ReportClientDocument reportClientDoc = reportAppFactory.openDocument(reportID, 0, Locale.ENGLISH);
    return reportClientDoc.getPrintOutputController().export(exportOptions);
    Here is the exact Exception:
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException: Unable to connect to the server: FICLDEV303VWIN.RAS.rptappserver. --- com/crystaldecisions/sdk/occa/report/exportoptions/ReportExportFormat incompatible with com/crystaldecisions/xml/serialization/IXMLSerializable---- Error code:-2147217387 Error code name:connectServer
    Caused by:
    java.lang.ClassCastException: com/crystaldecisions/sdk/occa/report/exportoptions/ReportExportFormat incompatible with com/crystaldecisions/xml/serialization/IXMLSerializable
         at com.crystaldecisions.proxy.remoteagent.FetchReportViewingRequest.saveContents(Unknown Source)
         at com.crystaldecisions.proxy.remoteagent.FetchReportViewingRequest.save(Unknown Source)
         at com.crystaldecisions.xml.serialization.XMLObjectSerializer.save(Unknown Source)
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.CECORBACommunicationAdapter.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.CECORBACommunicationAdapter.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.managedreports.ras.internal.CECORBACommunicationAdapter.request(Unknown Source)
         at com.crystaldecisions.proxy.remoteagent.z.a(Unknown Source)
         at com.crystaldecisions.proxy.remoteagent.s.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.cf.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(Unknown Source)
         at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(Unknown Source)
         at com.fmr.fic.fund2fund.web.servlet.CrystalReportServlet.getReportByteStream(CrystalReportServlet.java)
         at com.fmr.fic.fund2fund.web.servlet.CrystalReportServlet.processUsingReportExportControl(CrystalReportServlet.java)
         at com.fmr.fic.fund2fund.web.servlet.CrystalReportServlet.doGet(CrystalReportServlet.java:128)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
         at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
         at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
         at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
         at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
         at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
         at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
         at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
         at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:94)
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
         at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
         at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)
    I
    Is there some setting I need to enable on the server to use the export function or any other idea will be appreciated?
    Edited by: Dilshad Ahmed on Nov 5, 2008 5:55 PM
    Edited by: Dilshad Ahmed on Nov 5, 2008 6:09 PM

    Here is the answer. After getting ReportClientDoc from factory we need to set the DatabaseController userid and password (if report on Crystal server is accessing oracle database as datasource). In addition we need to set parameters on the ReportClientDoc for reports and subreports before doing the the export.
    Here is snippet of code: The code below is used to get ReportClientDocument and export it as PDF using bytestream.
    /* Code for getting report client document */
    private static synchronized ReportClientDocument getReportClientDocument() throws Exception
             int count = 3;
             ReportClientDocument rpt = null;
             while (count > 0 && rpt == null)
                  try
                       if (_enterpriseSession == null)
                            ISessionMgr _sessionMgr = CrystalEnterprise.getSessionMgr();
                            _enterpriseSession = _sessionMgr.logon(CRYSTAL_USERID, CRYSTAL_PASSWORD, CRYSTAL_SERVER, CRYSTAL_AUTH);
                             LOG.info("Successful Logging into Crystal Server: " + CRYSTAL_SERVER);
                             _reportAppFactory = (IReportAppFactory)_enterpriseSession.getService("", "RASReportFactory");
                             _infoStore = (IInfoStore)_enterpriseSession.getService("InfoStore");
                             IInfoObjects result = _infoStore.query("Select SI_ID, SI_NAME From CI_INFOOBJECTS Where SI_NAME = '" + CRYSTAL_REPORT_NAME + "' And SI_INSTANCE = 0");
                             IInfoObject infoObject = (IInfoObject)result.get(0);
                             _reportId = infoObject.getID();
                             LOG.info("Located Report Id on Crystal Server: "+_reportId);
                        LOG.info("Created or found CR session");
                        rpt = _reportAppFactory.openDocument(_reportId, 0, Locale.ENGLISH);
                        break;
                  catch (Exception e)
                       rpt = null;
                       _enterpriseSession = null;
                       if (--count == 0)
                            throw e;
              return rpt;
    /* report for setting parameter */
    private synchronized void setReportParameters(ParameterFieldController fieldController, String reportName,
                  String[] reportParameterValues,     DataDefController subDataController) throws SalesforceException
             try
                  Fields params = subDataController.getDataDefinition().getParameterFields();
                   for (Iterator it = params.iterator(); it.hasNext();)
                        ParameterField paramField = (ParameterField)it.next();
                        int paramIndex = getElementIndex(_reportParameters, paramField.getName());
                        if (paramIndex < 0)
                             throw new SalesforceException("Parameter not defined in the configuration");
                        ParameterFieldDiscreteValue dVal = new ParameterFieldDiscreteValue();
                        dVal.setValue(reportParameterValues[paramIndex]);
                        fieldController.setCurrentValue(reportName, paramField.getName(), dVal);
                   LOG.info("Completed setting parameters for report " + reportName);
             catch (ReportSDKException e)
                   LOG.error("Set Report Parameters error: ", e);
                   throw new SalesforceException("Set Report Parameters error", e);
         catch (Exception e)
                   LOG.error("Error from getElementIndex: ", e);
                   throw new SalesforceException("Set Report Parameters error", e);
    /* main method used to getReport based on passing information */
        private synchronized byte[] getReport(String contactId) throws SalesforceException
             try
                  String[] reportParameterValues =
                       new String[] {_sessionId, _viewId, _requestId, contactId, _language};
                   DataDefController reportDefController = reportClientDoc.getDataDefController();
                   reportParameterValues[0] = (_cache.equalsIgnoreCase("true") ? "CACHE:Main" : "Main");
                   setReportParameters(reportDefController.getParameterFieldController(), null,
                             reportParameterValues, reportDefController);//.getDataDefinition().getParameterFields());
                   IStrings subRepNames = reportClientDoc.getSubreportController().getSubreportNames();
                   for (Iterator iname = subRepNames.iterator(); iname.hasNext();)
                        String subName = (String)iname.next();
                        reportParameterValues[0] = (_cache.equalsIgnoreCase("true") ? "CACHE:" : "") + subName;
                        setReportParameters(reportDefController.getParameterFieldController(), subName, reportParameterValues,
                                  reportClientDoc.getSubreportController().getSubreport(subName).getDataDefController());//.getDataDefinition().getParameterFields());
                   InputStream is = reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);
                 byte[] reportBinaries = new byte[is.available()];
                 is.read(reportBinaries);
                 is.close();
                 LOG.info("Completed exporting Crystal Report as InputStream using export() method: "+contactId);
                 return reportBinaries;
             catch (ReportSDKException e)
                   LOG.error("Report generating error: ", e);
                   throw new SalesforceException("Report generating error", e);
             catch (IOException e)
                   LOG.error("Report exporting error: ", e);
                   throw new SalesforceException("Report exporting error", e);

  • Does abap unit testclass can get acces to private methods of classes to tes

    Hi,
    I want to do a abap unit test inside a user program. the program calls my class and i want some of the methods there to be tested (i.e. db layer, some business logic etc).
    My problem is, that I can define unit test very goog on program level or even for public methods of the class.
    But what should I do if I want the maybe 3 private methods called by the public method to be tested standalone?
    Does anyone have a idea for that?
    THX
    regards,
    Jens

    Hello Jens,
    you may test private methods with the help of the FRIEND statement. For sample you place a local testclass in the class pool. In order to get friendship you may than use the following sequence of statements.
      class ltc_Repository definition deferred.
      class cl_Global definition local friends ltc_Repository.
      class ltc_Repository                     "#AU Risk Level Harmless
        definition for testing.
        private section.
          methods:
            retrieve_Fails_For_Bad_Key   for testing,
            update_Fails_For_Dup_Key     for testing.
    endclass.
    or
      interface lif_Unit_Test.
      endinterface.
      class cl_Global definition local friends lif_Unit_Test.
      class ltc_Repository                     "#AU Risk Level Harmless
        definition for testing.
        public section.
          interfaces: lif_Unit_Test.
        private section.
          methods:
            retrieve_Fails_For_Bad_Key   for testing,
            update_Fails_For_Dup_Key     for testing.
    endclass.
    By this technique you can grant access to private members of the global class to any local class. Without exposing something to the outside world! This code can be placed in the local implementation include of the class pool, or in test class include from release 7.02 onwards.
    Using transaction /nABAPHELP provides all details on the FRIEND statement.
    Testing private methods can be useful but also tends to result in [fragile tests|http://xunitpatterns.com/Fragile%20Test.html]. That means changes to the implementation may make your test turn red without any violation of the outside contract.
    Ciao
      Klaus

  • Help w/ private methods program..

    hi guys...
    i was just wondering if somebody can help me w/ the code i am writing for a project..
    the project is about prime numbers and its factors.
    -we have to create a private method called checkInput() which is sent the users String inputted number as a parameter and returns a boolean indicating wether the input is valid or not. (I am using inputNum as the variable that holds the number)
    -also i have to call that checkInput private method from some other private method, which giving me errors when compiling...
    thanks a lot...
    private void getInput()throws IOException
    BufferedReader stdin = new BufferedReader
    (new InputStreamReader(System.in));
    System.out.print("Enter an INTEGER number greater than "+MIN+". ");
    while (inputNum <= 1)
    System.out.print("Enter an INTEGER number greater than "+MIN+". ");
    inputNum= Integer.parseInt(stdin.readLine());
    }//end of while loop
    checkInput();
    }//end of method getInput.
    // This method is to send the users String inputted
    // number as a formal parameter and returns
    // a boolean indicating whether the input is valid
    // or not.
    private boolean checkInput(String inputNum)
    while(inputNum != null)
    return true;
    }///end of checkInput method.
    // This method is to pass a formal parameter number
    // which is a valid integer number that the user
    // entered. The method will return a Boolean
    // value indicating whether the number is a prime.
    private boolean IsPrime (int number)
    if (number == 1 || number == 2)
    return true;
    for (int i=2; i<(int)(number/2); i++)
    if ( (number/i)==(int)(number/i) )
    return false;
    return true;
    }//end of method IsPrime.
    // This method calls the IsPrime method passing
    // it the actual parameter inputNum which is
    // valid user inputted number.
    private void checkForPrime ()
    IsPrime(inputNum);
    if(true){
    System.out.println(inputNum+ " is a prime");
    }else
    System.out.println(inputNum+ " is not a prime");
    printAllFactors(inputNum);
    }// end of checkForPrime method.
    // This method prints out "Its factors are:",
    // skips a line and then prints out all the factors
    // of the formal parameter number.
    private void printAllFactors (int number)
    System.out.println("Its factors are: ");
    System.out.println();
    for (int i = 2; i <= number; i++){
    if(inputNum % number == 0)
    System.out.println(number + " is a factor.");
    break;
    System.out.println(number + " is not a factor.");
    }// end of printAllFactors method.
    }// end of main class.this is the code i have so far...

    Please don't crosspost. It cuts down on the effectiveness of responses, leads to people wasting their time answering what others have already answered, makes for difficult discussion, and is generally just annoying and bad form.

  • ALV using clases and  methods

    Hi all
    how can i use alv 's for reading data from table mara and dispyaing 10 records on out put screen as a grid  using classes or methods
    thanks in advance

    Hi,
    look into the sample code:
                           TYPE-POOLS                                    *
    TYPE-POOLS: slis.
                         TRANSPARENT TABLES                              *
    TABLES: rbkp,rbco,sscrfields,t009b.
          CLASS cl_event_receiver DEFINITION
    CLASS cl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS: handle_double_click
                 FOR EVENT double_click OF cl_gui_alv_grid
                 IMPORTING e_row e_column,
                 handle_top_of_page
                 FOR EVENT print_top_of_page OF cl_gui_alv_grid.
      PRIVATE SECTION.
    ENDCLASS.
          CLASS CL_EVENT_RECEIVER IMPLEMENTATION
    CLASS cl_event_receiver IMPLEMENTATION.
    *--Method double click
      METHOD :handle_double_click.
        PERFORM drill_down USING e_column-fieldname
                                 e_row-index .
      ENDMETHOD.
    *--Method top of page
      METHOD handle_top_of_page.
        PERFORM event_top_of_page.
      ENDMETHOD.                 "top_of_page
    ENDCLASS.
    DATA: event_receiver TYPE REF TO cl_event_receiver.
                          Global Variables                               *
    DATA:
      v_xblnr     LIKE rbkp-xblnr,         " Refernce Doc No
      v_lifnr     LIKE lfa1-lifnr,         " Vendor
      v_bukrs     LIKE t001-bukrs,         " Company Code
      v_zzmprd    LIKE mara-matnr,         " MPM
      v_monat     LIKE t009b-poper.        " Fiscal Period
                         GLOBAL TYPES                                    *
    *-Structure for Invoice details
    TYPES:BEGIN OF y_invoice,
            belnr LIKE rbkp-belnr,                    " Invoice Doc No
            gjahr LIKE rbkp-gjahr,                    " Fiscal Year
            blart LIKE rbkp-blart,                    " Document type
            bldat LIKE rbkp-bldat,                    " Document date
            budat LIKE rbkp-budat,                    " Posting date
            xblnr LIKE rbkp-xblnr,                    " Refernce Doc no
            bukrs LIKE rbkp-bukrs,                    " Company Code
            lifnr LIKE rbkp-lifnr,                    " Vendor
            waers LIKE rbkp-waers,                    " Local Currency
            bktxt LIKE rbkp-bktxt,                    " Doc header text
            zlspr LIKE rbkp-zlspr,                    " payment block
            buzei LIKE rseg-buzei,                    " Invoice Item No
            ebeln LIKE rseg-ebeln,                    " PO
            ebelp LIKE rseg-ebelp,                    " PO line item
            matnr LIKE rseg-matnr,                    " SAP Material
            bwtar LIKE rseg-bwtar,                    " Valuation type
            wrbtr LIKE rseg-wrbtr,                    " Inv Value
            menge LIKE rseg-menge,                    " Inv Qty
          END OF y_invoice,
    *-Structure for Material details
          BEGIN OF y_material,
            matnr LIKE mara-matnr,                   " Material No
            normt LIKE mara-normt,                   " Article Number
            ismconttype LIKE mara-ismconttype,       " Window
            ismdesign LIKE mara-ismdesign,           " No of disc in MPM
            werks LIKE marc-werks,                   " Plant
            mfrgr LIKE marc-mfrgr,                   " Product Line
          END OF y_material,
    Structure for Costtype data
         BEGIN OF y_costtype,
           bukrs    LIKE zsn0325_costtype-bukrs,      " Company Code
           land1    LIKE zsn0325_costtype-land1,      " Country key
           window   LIKE zsn0325_costtype-window,     " Window
           ewlnr    LIKE zsn0325_costtype-ewlnr,      " Cost type
           distmeth LIKE zsn0325_costtype-distmeth,   " Distribution type
           zvalfrom LIKE zsn0325_costtype-zvalfrom,   " Posting date from
           zvalto   LIKE zsn0325_costtype-zvalto,     " Posting Date TO
           disc1pr  LIKE zsn0325_costtype-disc1pr,    " Disc price
           disc2pr  LIKE zsn0325_costtype-disc2pr,    " Disc price
         END OF y_costtype,
    Structure for Distmeth data
        BEGIN OF y_distmeth,
           distmeth  LIKE zsn0325_distmeth-distmeth,  " Distribution Methods
           distext  LIKE zsn0325_distmeth-distext,    " Description
        END OF y_distmeth,
    *-structure for rbco
          BEGIN OF y_rbco,
            belnr LIKE rbco-belnr,                    " Account Doc#
            gjahr LIKE rbco-gjahr,                    " Fiscal year
            buzei LIKE rbco-buzei,                    " Doc item in inv doc
            cobl_nr LIKE rbco-cobl_nr,                " 4 Character
                                                       " Seq No for Coding
            wrbtr LIKE rbco-wrbtr,                    " Amt in doc currency
            saknr LIKE rbco-saknr,                    " G/L Account Number
            sgtxt LIKE rbco-sgtxt,                    " Item text
            zzcou LIKE rbco-zzcou,                    " Country
            zzmprd LIKE rbco-zzmprd,                  " MPM Product
            menge LIKE rbco-menge,                    " Quantity
            bukrs LIKE rbco-bukrs,                    " Company Code
            xnegp LIKE rbco-xnegp,                    " Variance Flag
            matnr LIKE mara-matnr,                    " MPM Product
            land1 LIKE zsop_fame-sop_cnt,           " SOP country code
          END OF y_rbco,
    *-structure for rbco_tmp
          BEGIN OF y_rbco_tmp,
           bukrs LIKE rbco-bukrs,                     " Company Code
           sgtxt LIKE rbco-sgtxt,                     " Item text
           ewlnr    LIKE zsn0325_costtype-ewlnr,      " Cost type
           distmeth LIKE zsn0325_costtype-distmeth,   " Distribution type
           land1    LIKE zsop_fame-sop_cnt,           " SOP country code
          END OF y_rbco_tmp,
    *-Structure for setleaf
         BEGIN OF y_setleaf,
         setname      LIKE  setleaf-setname,
           valsign    LIKE  setleaf-valsign,
           valoption  LIKE  setleaf-valoption,
           valfrom    LIKE  setleaf-valfrom,
           valto      LIKE  setleaf-valto,
         END OF y_setleaf,
    *-Structure for Output data
         BEGIN OF y_output,
           bukrs      LIKE rbkp-bukrs,                " Company Code
           gjahr      LIKE rbkp-gjahr,                " Fiscal year
           lifnr      LIKE rbkp-lifnr,                " Vendor
           zlspr      LIKE rbkp-zlspr,                " Payment block
           xblnr      LIKE rbkp-xblnr,                " Refernece Doc no
           bldat      LIKE rbkp-bldat,                " Document date
           budat      LIKE rbkp-budat,                " Posting date
           belnr      LIKE rbkp-belnr,                " Invoice Doc No
           bktxt      LIKE rbkp-bktxt,                " Invoice Type
           normt      LIKE mara-normt,                " Article Number
           ismconttype LIKE mara-ismconttype,         " Window
           zzcou      LIKE rbco-zzcou,                " Country
           zzmprd     LIKE rbco-zzmprd,               " MPM Product
           xnegp      LIKE rbco-xnegp,                " Cost type variance
           cobl_nr    LIKE rbco-cobl_nr,              " 4 Character
                                                       " Seq No for Coding
           invfqty    LIKE rbco-menge,                " Inventory Fee Qty
           discqty    LIKE rbco-menge,                " Dist Cost Qty
           disrqty    LIKE rbco-menge,                " Dist Return Qty
           sseqty     LIKE rbco-menge,                " Special Services Qty
           sgtxt      LIKE rbco-sgtxt,                " Item Text
           ismdesign  LIKE mara-ismdesign,            " No of disc on MPM
           mfrgr      LIKE marc-mfrgr,                " Product Line
           ddeal(3),                                  " Distribution DEAL
           distmeth   LIKE zsn0325_costtype-distmeth, " Distribution type
           distext    LIKE zsn0325_distmeth-distext,  " Description
           ndisc(2)   TYPE c,                         " NO of disc on INV
           rifval     LIKE rbco-wrbtr,                " Inv fee value
           stdrif     LIKE zsn0325_costtype-disc1pr,  " STD Inv fee
           rfvar      LIKE zsn0325_costtype-disc1pr,  " Inv Fee Variance
           dicval     LIKE rbco-wrbtr,                " Dist cost Value
           stddico    LIKE zsn0325_costtype-disc1pr,  " STD Dis cost
           dicvar     LIKE zsn0325_costtype-disc1pr,  " Dist Cost Variance
           disrev     LIKE rbco-wrbtr,                " Dist Return Value
           stdirco    LIKE zsn0325_costtype-disc1pr,  " STD Dis Return cost
           drevar     LIKE zsn0325_costtype-disc1pr,  " Dist Ret Variance
           adj_qty_ct LIKE rbco-menge,                " Adjustments Qty
           adj_pr_ct  LIKE rbco-wrbtr,                " Adjustments Value
           ssval      LIKE rbco-wrbtr,                " Special Value
           color_cell TYPE lvc_t_scol,                " Cell Color
           END OF y_output,
    *-Structure for Temporary Output data
         BEGIN OF y_output_tmp,
           bukrs      LIKE rbkp-bukrs,                " Company Code
           gjahr      LIKE rbkp-gjahr,                " Fiscal year
           lifnr      LIKE rbkp-lifnr,                " Vendor
           zlspr      LIKE rbkp-zlspr,                " Payment block
           xblnr      LIKE rbkp-xblnr,                " Refernece Doc no
           bldat(10)    TYPE  c,                      " Document Date
           budat(10)    TYPE  c,                      " Posting date
           belnr      LIKE rbkp-belnr,                " Invoice Doc No
           bktxt      LIKE rbkp-bktxt,                " Invoice Type
           normt(18)    TYPE  c,                      " Article Number
           ismconttype LIKE mara-ismconttype,         " Window
           zzcou      LIKE rbco-zzcou,                " Country
           zzmprd     LIKE rbco-zzmprd,               " MPM Product
           xnegp      LIKE rbco-xnegp,                " Cost type variance
           cobl_nr    LIKE rbco-cobl_nr,              " 4 Character
                                                       " Seq No for Coding
           invfqty    LIKE rbco-menge,                " Inventory Fee Qty
           discqty    LIKE rbco-menge,                " Dist Cost Qty
           disrqty    LIKE rbco-menge,                " Dist Return Qty
           sseqty     LIKE rbco-menge,                " Special Services Qty
           sgtxt      LIKE rbco-sgtxt,                " Item Text
           ismdesign(2) TYPE c,                       " No of disc on MPM
           mfrgr      LIKE marc-mfrgr,                " Product Line
           ddeal(3),                                  " Distribution DEAL
           distmeth   LIKE zsn0325_costtype-distmeth, " Distribution type
           distext    LIKE zsn0325_distmeth-distext,  " Description
           ndisc(2)   TYPE c,                         " NO of disc on INV
           rifval     LIKE rbco-wrbtr,                " Inv fee value
           stdrif     LIKE zsn0325_costtype-disc1pr,  " STD Inv fee
           rfvar      LIKE zsn0325_costtype-disc1pr,  " Inv Fee Variance
           dicval     LIKE rbco-wrbtr,                " Dist cost Value
           stddico    LIKE zsn0325_costtype-disc1pr,  " STD Dis cost
           dicvar     LIKE zsn0325_costtype-disc1pr,  " Dist Cost Variance
           disrev     LIKE rbco-wrbtr,                " Dist Return Value
           stdirco    LIKE zsn0325_costtype-disc1pr,  " STD Dis Return cost
           drevar     LIKE zsn0325_costtype-disc1pr,  " Dist Ret Variance
           adj_qty_ct LIKE rbco-menge,                " Adjustments Qty
           adj_pr_ct  LIKE rbco-wrbtr,                " Adjustments Value
           ssval      LIKE rbco-wrbtr,                " Special Value
           color_cell TYPE lvc_t_scol,                " Cell Color
          END OF y_output_tmp.
                   GLOBAL DATA -INTERNAL TABLES                          *
    DATA: i_invoice      TYPE STANDARD TABLE OF y_invoice,
          i_output       TYPE STANDARD TABLE OF y_output,
          i_output_tmp   TYPE STANDARD TABLE OF y_output_tmp,
          i_rbco         TYPE STANDARD TABLE OF y_rbco,
          i_rbco_tmp     TYPE STANDARD TABLE OF y_rbco_tmp,
          i_setleaf      TYPE STANDARD TABLE OF y_setleaf,
          i_material     TYPE STANDARD TABLE OF y_material,
          i_costtype     TYPE STANDARD TABLE OF y_costtype,
          i_distmeth     TYPE STANDARD TABLE OF y_distmeth,
          i_toolbar_excluding TYPE ui_functions,
          i_fieldcatalog TYPE lvc_t_fcat.
                            WORK AREAS                                   *
    DATA: w_invoice       TYPE  y_invoice,
          w_material      TYPE  y_material,
          w_output        TYPE  y_output,
          w_output_tmp    TYPE  y_output_tmp,
          w_costtype      TYPE  y_costtype,
          w_distmeth      TYPE  y_distmeth,
          w_rbco          TYPE  y_rbco,
          w_rbco_tmp      TYPE  y_rbco_tmp,
          w_setleaf       TYPE  y_setleaf,
          w_toolbar_excluding TYPE ui_func,
          w_fieldcatalog  TYPE  lvc_s_fcat.
    *--Ranges
    RANGES: r_setinv FOR setleaf-valfrom,
            r_matnr FOR mara-matnr.
             DATA DECLARATION FOR ALV                                    *
    *--Data declaration for ALV Grid
    DATA :w_alvgrid    TYPE REF TO cl_gui_alv_grid,
          w_ccontainer TYPE REF TO cl_gui_custom_container,
          w_okcode     LIKE sy-ucomm.
    *--Color cell
    DATA: i_color    TYPE lvc_t_scol,
          w_color    TYPE lvc_s_scol.
    *--- Layout structure
    DATA w_layout TYPE lvc_s_layo .
                     SELECTION SCREEN                                    *
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-055.
    SELECT-OPTIONS:
      s_bukrs FOR rbkp-bukrs,                           " Company Code
      s_lifnr FOR rbkp-lifnr,                           " Vendor
      s_xblnr FOR rbkp-xblnr,                           " Reference Doc No
      s_gjahr FOR rbkp-gjahr OBLIGATORY,                " Fiscal Year
      s_monat FOR t009b-poper,                          " Period
      s_budat FOR rbkp-budat,                           " Posting date
      s_bldat FOR rbkp-bldat,                           " Document date
      s_zzmprd FOR rbco-zzmprd.                         " MPM
    SELECTION-SCREEN END OF BLOCK blk1.
                    AT SELECTION SCREEN                                  *
    Validating Company Code
    AT SELECTION-SCREEN ON s_bukrs.
      IF NOT s_bukrs[] IS INITIAL.
        SELECT bukrs                        " Company Code
               UP TO 1 ROWS
               INTO v_bukrs
               FROM t001
               WHERE bukrs IN s_bukrs.
        ENDSELECT.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH 'Invalid Company Code'(e06).
        ENDIF.
      ENDIF.
    Validating ODS Invoice Document No.
    AT SELECTION-SCREEN ON s_xblnr.
      IF NOT s_xblnr[] IS INITIAL.
        SELECT xblnr                        " Reference Document number
               UP TO 1 ROWS
               INTO v_xblnr
               FROM rbkp
               WHERE xblnr IN s_xblnr.
        ENDSELECT.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH 'Invalid ODS Invoice No.'(e05).
        ENDIF.
      ENDIF.
    Validating Vendor Number
    AT SELECTION-SCREEN ON s_lifnr.
      IF NOT s_lifnr[] IS INITIAL.
        SELECT lifnr                        " Vendor Number
               UP TO 1 ROWS
               INTO v_lifnr
               FROM lfa1
               WHERE lifnr IN s_lifnr.
        ENDSELECT.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH 'Invalid Vendor Number'(e04).
        ENDIF.
      ENDIF.
    Validating MPM
    AT SELECTION-SCREEN ON s_zzmprd.
      REFRESH r_matnr.
      LOOP AT s_zzmprd.
        MOVE-CORRESPONDING s_zzmprd TO r_matnr.
        IF NOT s_zzmprd IS INITIAL.
          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
               EXPORTING
                    input        = s_zzmprd-low
               IMPORTING
                    output       = r_matnr-low
               EXCEPTIONS
                    length_error = 1
                    OTHERS       = 2.
          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
               EXPORTING
                    input        = s_zzmprd-high
               IMPORTING
                    output       = r_matnr-high
               EXCEPTIONS
                    length_error = 1
                    OTHERS       = 2.
          APPEND r_matnr.
        ENDIF.
      ENDLOOP.
      SELECT matnr                          " MPM
             UP TO 1 ROWS
             INTO v_zzmprd
             FROM mara
             WHERE matnr IN r_matnr.
      ENDSELECT.
      IF sy-subrc NE 0.
        MESSAGE e000 WITH 'Invalid MPM'(e09).
      ENDIF.
    Validating Fiscal Period
      IF NOT s_monat[] IS INITIAL.
        SELECT poper                        " Fiscal Period
               UP TO 1 ROWS
               INTO v_monat
               FROM t009b
               WHERE periv = 'K4'
                 AND poper IN s_monat
                 AND bdatj IN s_gjahr.
        ENDSELECT.
        IF sy-subrc NE 0.
          MESSAGE e000 WITH 'Invalid Fiscal Period'(e02).
        ENDIF.
      ENDIF.
    *For Company Code & Vendor
    AT SELECTION-SCREEN.
      MOVE sy-ucomm TO sscrfields-ucomm.
      IF sy-ucomm EQ 'ONLI'
      AND s_bukrs[] IS INITIAL
      AND s_lifnr[] IS INITIAL.
        MESSAGE i000 WITH
           'Either Company code or Vendor must be selected'(e03).
        STOP.
      ENDIF.
      IF ( NOT s_budat[] IS INITIAL OR NOT s_bldat IS INITIAL )
          AND NOT s_monat[] IS INITIAL.
        MESSAGE i000 WITH
    'Select either Period or Posting date,Document date'(e01).
        STOP.
      ENDIF.
                     START OF SELECTION                                  *
    START-OF-SELECTION.
    *-Retrieve Invoice Details from RBKP & RSEG
      PERFORM get_invoice.
      IF NOT i_invoice[] IS INITIAL.
    *-Retrieve Invoice Details from RBCO
        PERFORM get_rbco.
      ENDIF.
      IF NOT i_rbco[] IS INITIAL.
    *-Retrieve Material Document details from MARA & MARC
        PERFORM get_material.
      ENDIF.
      IF NOT i_invoice[] IS INITIAL.
    *-Retrieve costtype details from zsn0325_costtype & zsn0325_distmeth
        PERFORM get_costtype.
        PERFORM get_distmeth.
      ENDIF.
    *-Populate internal table  for output
      PERFORM populate_output.
                     END OF SELECTION                                    *
    END-OF-SELECTION.
    *-TO Display Output
      IF NOT i_invoice[] IS INITIAL
        AND  NOT i_output[]  IS INITIAL.
        PERFORM display_report.
        CALL SCREEN 100.
      ENDIF.
    *&      Form  get_Invoice
    Retrieve Invoice Details from RBKP & RSEG
    FORM get_invoice.
      DATA : lv_monat LIKE bkpf-monat.
    *-Get  Value form set zsn_doc_types_inv
      SELECT setname
             valsign
             valoption
             valfrom
             valto
             FROM setleaf
             INTO TABLE i_setleaf
             WHERE setclass = '0000'
             AND setname =  'ZSN_DOC_TYPES_INV'.
      IF sy-subrc = 0.
        LOOP AT i_setleaf INTO w_setleaf.
          r_setinv-sign = w_setleaf-valsign.
          r_setinv-option = w_setleaf-valoption.
          r_setinv-low = w_setleaf-valfrom.
          r_setinv-high = w_setleaf-valto.
          APPEND r_setinv.
        ENDLOOP.
      ENDIF.
    Get Invoice Doc details
      SELECT a~belnr                       " Document number of an invoice
             a~gjahr                       " Fiscal Year
             a~blart                       " Document type
             a~bldat                       " Document Date in Document
             a~budat                       " Posting Date in the Document
             a~xblnr                       " Reference Document Number
             a~bukrs                       " Company Code
             a~lifnr                       " Different invoicing party
             a~waers                       " Currency Key
             a~bktxt                       " Document header text
             a~zlspr                       " Payment Block Key
             b~buzei                       " Document item in invoice
             b~ebeln                       " Purchasing Document Number
             b~ebelp                       " Item Number of PO Document
             b~matnr                       " Material Number
             b~bwtar                       " Valuation type
             b~wrbtr                       " Amount in document currency
             b~menge                       " Quantity
             INTO TABLE i_invoice
             FROM rbkp AS a
             LEFT OUTER JOIN rseg AS b
             ON abelnr EQ bbelnr
             WHERE a~bukrs IN s_bukrs
             AND a~gjahr IN s_gjahr
             AND a~bldat IN s_bldat
             AND a~blart IN r_setinv
             AND a~budat IN s_budat
             AND a~xblnr IN s_xblnr
             AND a~lifnr IN s_lifnr.
      IF sy-subrc NE 0.
        MESSAGE i000 WITH 'No Invoice exists for this selection'(e07)
                       'criteria'(e08).
        STOP.
      ELSE.
        SORT i_invoice BY belnr gjahr.
        LOOP AT i_invoice INTO w_invoice.
          CALL FUNCTION 'FI_PERIOD_DETERMINE'
            EXPORTING
              i_budat             = w_invoice-budat
             i_bukrs              = w_invoice-bukrs
             i_periv              = 'K4'
             i_gjahr              = w_invoice-gjahr
          I_MONAT              = 00
          X_XMO16              = ' '
           IMPORTING
          E_GJAHR              =
             e_monat              = lv_monat
          E_POPER              =
           EXCEPTIONS
             fiscal_year          = 1
             period               = 2
             period_version       = 3
             posting_period       = 4
             special_period       = 5
             version              = 6
             posting_date         = 7
             OTHERS               = 8.
          IF sy-subrc <> 0.
            DELETE i_invoice.
          ELSE.
            IF lv_monat IN s_monat.
            ELSE.
              DELETE i_invoice.
            ENDIF.
          ENDIF.
        ENDLOOP.
        IF i_invoice[] IS INITIAL.
          MESSAGE i000 WITH 'No Invoice exists for this selection'(e07)
                         'criteria'(e08).
          STOP.
        ENDIF.
      ENDIF.
    ENDFORM.                    " get_Invoice
    *&      Form  get_rbco
    Retrieve Invoice Details from RBCO
    FORM get_rbco.
      SELECT belnr
             gjahr
             buzei
             cobl_nr
             wrbtr
             saknr
             sgtxt
             zzcou
             zzmprd
             menge
             bukrs
             xnegp
             FROM rbco
             INTO TABLE i_rbco
             FOR ALL ENTRIES IN i_invoice
             WHERE belnr = i_invoice-belnr
               AND gjahr = i_invoice-gjahr
               AND wrbtr <> 0
               AND zzmprd IN s_zzmprd.
      IF sy-subrc NE 0.
        MESSAGE i000 WITH 'No Distribution Data Exists'(e10).
        STOP.
      ELSE.
        SORT i_rbco BY belnr gjahr.
      ENDIF.
    ENDFORM.                    " get_rbco
    *&      Form  get_material
    Retrieve Material Document details from MARA & MARC
    FORM get_material.
      LOOP AT i_rbco INTO w_rbco.
        SELECT SINGLE sop_cnt
                      INTO w_rbco_tmp-land1
                      FROM zsop_fame
                      WHERE fame_cnt = w_rbco-zzcou.
        IF sy-subrc = 0.
          w_rbco_tmp-bukrs = w_rbco-bukrs.
          w_rbco_tmp-ewlnr = w_rbco-sgtxt+7(2).
          w_rbco_tmp-distmeth = w_rbco-sgtxt+0(3).
        ENDIF.
        w_rbco-land1 = w_rbco_tmp-land1.
        APPEND w_rbco_tmp TO i_rbco_tmp.
        CLEAR w_rbco_tmp.
        CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
             EXPORTING
                  input        = w_rbco-zzmprd
             IMPORTING
                  output       = w_rbco-matnr
             EXCEPTIONS
                  length_error = 1
                  OTHERS       = 2.
        MODIFY i_rbco FROM w_rbco.
        CLEAR w_rbco.
      ENDLOOP.
      SELECT     a~matnr                             " Material Number
                 a~normt                             " Article Number
                 a~ismconttype                       " Window
                 a~ismdesign                         " No of discs in MPM
                 b~werks                             " Plant
                 b~mfrgr                             " Product Line
                 INTO TABLE i_material
                 FROM mara AS a
                 INNER JOIN
                 marc AS b
                 ON amatnr = bmatnr
                 FOR ALL ENTRIES IN i_rbco
                 WHERE a~matnr = i_rbco-matnr.
      IF sy-subrc = 0.
        SORT i_material BY matnr.
      ENDIF.
    ENDFORM.                    " get_material
    *&      Form  get_costtype
    Retrieve costtype details from zsn0325_costtype
    FORM get_costtype.
      SELECT bukrs                                " Company code
             land1                                " Country key
             window                               " Window
             ewlnr                                " Cost type
             distmeth                             " Distribution type
             zvalfrom                             " Invoice date
             zvalto                               " Invoice date
             disc1pr                              " Disc Price
             disc2pr                              " Additional DiscPrice
              FROM zsn0325_costtype
             INTO TABLE i_costtype
             FOR ALL ENTRIES IN i_rbco_tmp
             WHERE bukrs = i_rbco_tmp-bukrs
               AND ewlnr = i_rbco_tmp-ewlnr
               AND distmeth = i_rbco_tmp-distmeth
               AND land1 = i_rbco_tmp-land1.
      IF sy-subrc = 0.
        SORT i_costtype BY bukrs land1 window ewlnr distmeth.
      ENDIF.
    ENDFORM.                    " get_costtype
    *&      Form  get_distmeth
    Retrieve costtype details from zsn0325_distmeth
    FORM get_distmeth.
      SELECT distmeth
             distext
             FROM zsn0325_distmeth
             INTO TABLE i_distmeth
             FOR ALL ENTRIES IN i_costtype
             WHERE distmeth = i_costtype-distmeth.
      IF sy-subrc = 0.
        SORT i_distmeth BY distmeth.
      ENDIF.
    ENDFORM.                    " get_distmeth
    *&      Form  display_report
    TO Display Output
    FORM display_report.
      IF NOT i_output[] IS INITIAL.
        SORT i_output BY xblnr.
        PERFORM build_fieldcat.
      ENDIF.
    ENDFORM.                    " display_report
    *&      Form  build_fieldcat
    Build Field Catalog
    FORM build_fieldcat.
      PERFORM fill_fieldcat USING 'BUKRS'         'I_OUTPUT'
                                                  'Company Code'(001) 12.
      PERFORM fill_fieldcat USING 'LIFNR'         'I_OUTPUT'
                                                  'Vendor'(002) 6.
      PERFORM fill_fieldcat USING 'ZLSPR'         'I_OUTPUT'
                                                  'Payment Block'(003) 13.
      PERFORM fill_fieldcat USING 'XBLNR'         'I_OUTPUT'
                                               'Vendor Invoice No'(004) 17.
      PERFORM fill_fieldcat USING 'BLDAT'         'I_OUTPUT'
                                                  'Invoice Date'(005) 12.
      PERFORM fill_fieldcat USING 'BUDAT'         'I_OUTPUT'
                                                  'Posting Date'(006) 12.
      PERFORM fill_fieldcat USING 'BKTXT'         'I_OUTPUT'
                                                  'Invoice Type'(007) 12.
      PERFORM fill_fieldcat USING 'BELNR'         'I_OUTPUT'
                                                  'R/3 Invoice No'(008) 14.
      PERFORM fill_fieldcat USING 'COBL_NR'       'I_OUTPUT'
                                                  'Line Item'(009) 9.
      PERFORM fill_fieldcat USING 'NORMT'         'I_OUTPUT'
                                                  'Article No'(010) 10.
      PERFORM fill_fieldcat USING 'ZZMPRD'        'I_OUTPUT'
                                                  'MPM Product'(034) 11.
      PERFORM fill_fieldcat USING 'ISMCONTTYPE'   'I_OUTPUT'
                                                  'Window'(011) 6.
      PERFORM fill_fieldcat USING 'NDISC'         'I_OUTPUT'
                                           'No of Discs on invoice'(012) 22.
      PERFORM fill_fieldcat USING 'ISMDESIGN'     'I_OUTPUT'
                                               'No of discs on MPM'(013) 10.
      PERFORM fill_fieldcat USING 'DISTMETH'      'I_OUTPUT'
                                               'Distribution type'(014) 17.
      PERFORM fill_fieldcat USING 'DISTEXT'       'I_OUTPUT'
                                                  'Description'(015) 11.
      PERFORM fill_fieldcat USING 'DDEAL'         'I_OUTPUT'
                                               'Distribution Deal'(016) 17.
      PERFORM fill_fieldcat USING 'MFRGR'         'I_OUTPUT'
                                               'MPM Product Line'(017) 16.
      PERFORM fill_fieldcat USING 'ZZCOU'         'I_OUTPUT'
                                                  'Country'(018) 7.
      PERFORM fill_fieldcat USING 'XNEGP'         'I_OUTPUT'
                                                  'Qty Var flag'(019) 12.
      PERFORM fill_fieldcat USING 'INVFQTY'       'I_OUTPUT'
                                                  'Inv fee Qty'(020) 11.
      PERFORM fill_fieldcat USING 'RIFVAL'        'I_OUTPUT'
                                                  'Inv fee Value'(021) 13.
      PERFORM fill_fieldcat USING 'STDRIF'        'I_OUTPUT'
                                                  'Std Inv fee'(022) 11.
      PERFORM fill_fieldcat USING 'RFVAR'         'I_OUTPUT'
                                                  'Inv fee Var'(023) 11.
      PERFORM fill_fieldcat USING 'DISCQTY'       'I_OUTPUT'
                                                  'Dis cost Qty'(024) 11.
      PERFORM fill_fieldcat USING 'DICVAL'        'I_OUTPUT'
                                                  'Dist Cost Value'(025) 15.
      PERFORM fill_fieldcat USING 'STDDICO'       'I_OUTPUT'
                                                  'Std Dist Cost'(026) 11.
      PERFORM fill_fieldcat USING 'DICVAR'        'I_OUTPUT'
                                                  'Dist Cost Var'(027) 13.
      PERFORM fill_fieldcat USING 'DISRQTY'       'I_OUTPUT'
                                                  'Dis Ret Qty'(028) 11.
      PERFORM fill_fieldcat USING 'DISREV'        'I_OUTPUT'
                                                  'Dis Ret Value'(029) 11.
      PERFORM fill_fieldcat USING 'STDIRCO'       'I_OUTPUT'
                                               'Std Dis Ret cost'(030) 11.
      PERFORM fill_fieldcat USING 'DREVAR'        'I_OUTPUT'
                                                  'Dis Ret Var'(031) 11.
      PERFORM fill_fieldcat USING 'ADJ_QTY_CT'    'I_OUTPUT'
                                               'Adjustments Qty'(035) 15.
      PERFORM fill_fieldcat USING 'ADJ_PR_CT'     'I_OUTPUT'
                                               'Adjustments Value'(036) 17.
      PERFORM fill_fieldcat USING 'SSEQTY'        'I_OUTPUT'
                                               'Special Ser Qty'(032) 15.
      PERFORM fill_fieldcat USING 'SSVAL'         'I_OUTPUT'
                                               'Special Ser Value'(033) 17.
    ENDFORM.                    " build_fieldcat
    *&      Form  fill_fieldcat
         Fill fieldcatalog for ALV                                       *
    FORM fill_fieldcat USING    value(p_fieldname)
                                value(p_tabname)
                                value(p_seltext_m)
                                value(p_outputlen).
      w_fieldcatalog-fieldname = p_fieldname.
      w_fieldcatalog-ref_table = p_tabname.
      w_fieldcatalog-coltext = p_seltext_m.
      w_fieldcatalog-outputlen = p_outputlen.
      APPEND w_fieldcatalog TO i_fieldcatalog.
      CLEAR w_fieldcatalog.
    ENDFORM.                    " fill_fieldcat
    *&      Module  STATUS_0100  OUTPUT
    Process Before output
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN1'.
      SET TITLEBAR 'TITLE'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  alV_display  OUTPUT
    ALv Display in PBO                                             *
    MODULE alv_display OUTPUT.
      IF w_ccontainer IS INITIAL.
        PERFORM create_objects.
    Excluding unnecessary function codes from the grid
        PERFORM exclude_fcodes.
        PERFORM display_alv_grid.
      ENDIF.
    ENDMODULE.                 " alV_display  OUTPUT
    *&      Form  create_objects
    Create ALV Objects
    FORM create_objects.
      IF w_alvgrid IS INITIAL .
    *----Creating custom container instance
        CREATE OBJECT w_ccontainer
          EXPORTING
            container_name = 'CONTAINER'
          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.
    *--Exception handling
        ENDIF.
    *----Creating ALV Grid instance
        CREATE OBJECT w_alvgrid
           EXPORTING
               i_parent = w_ccontainer
           EXCEPTIONS
              error_cntl_create = 1
              error_cntl_init = 2
              error_cntl_link = 3
              error_dp_create = 4
              others = 5 .
        IF sy-subrc <> 0.
    *--Exception handling
        ENDIF.
    *--Create Event Receiver
        CREATE OBJECT event_receiver.
        SET HANDLER event_receiver->handle_top_of_page FOR w_alvgrid.
      ENDIF.
    ENDFORM.                    " create_objects
    *&      Form  display_alv_grid
    Display ALV Grid
    FORM display_alv_grid.
      w_layout-grid_title  = 'Distribution Report'(042).
      IF NOT w_alvgrid IS INITIAL .
        MOVE 'COLOR_CELL' TO w_layout-ctab_fname.
        CALL METHOD w_alvgrid->set_table_for_first_display
               EXPORTING
                 is_layout = w_layout
                 it_toolbar_excluding  = i_toolbar_excluding[]
                I_DEFAULT = 'X'
               CHANGING
                 it_outtab = i_output_tmp[]
                 it_fieldcatalog = i_fieldcatalog[]
               EXCEPTIONS
                  invalid_parameter_combination = 1
                  program_error = 2
                  too_many_lines = 3
                  OTHERS = 4 .
        IF sy-subrc <> 0.
    *--Exception handling
        ENDIF.
      ELSE .
        CALL METHOD w_alvgrid->refresh_table_display
        EXCEPTIONS
        finished = 1
        OTHERS = 2 .
        IF sy-subrc <> 0.
        ENDIF.
      ENDIF .
    *--handler for ALV grid
      SET HANDLER event_receiver->handle_double_click FOR w_alvgrid.
    ENDFORM.                    " display_alv_grid
    *&      Module  USER_COMMAND_0100  INPUT
    At User Command
    MODULE user_command_0100 INPUT.
      MOVE sy-ucomm TO w_okcode.
      CASE w_okcode.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
        WHEN 'EXIT'.
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  populate_output
    Populate internal table  for output
    FORM populate_output.
      DATA: lv_invval  TYPE rbco-wrbtr.
      LOOP AT i_rbco INTO w_rbco.
    *-Check whether ndisc is numeric value.
        IF w_rbco-sgtxt+4(2) CO '0123456789'.
          MOVE: w_rbco-sgtxt+4(2) TO w_output-ndisc.
        ENDIF.
        MOVE:w_rbco-cobl_nr TO w_output-cobl_nr,
             w_rbco-zzcou TO w_output-zzcou,
             w_rbco-zzmprd TO w_output-zzmprd,
             w_rbco-xnegp TO w_output-xnegp.
    For Invoice
        READ TABLE i_invoice INTO w_invoice WITH KEY belnr = w_rbco-belnr
                                                     gjahr = w_rbco-gjahr
                                                     BINARY SEARCH.
        IF sy-subrc = 0.
          MOVE: w_invoice-bukrs       TO   w_output-bukrs,
                w_invoice-lifnr       TO   w_output-lifnr,
                w_invoice-zlspr       TO   w_output-zlspr,

Maybe you are looking for

  • Mac mini dvi

    I got a Mac mini with a Intel core duo 1.66 GHz I need a DVI to VGA connector as my monitor uses vga I'm wondering if I can us a dvi-i connector 24+5 dual link to a vga 15 converter

  • Report Manager in Arabic

    Is it possible to have the Report Manager in Arabic? There's been no problem creating the report names, report folders and report content in Arabic.  But so far, we've been unable to get the Report Manager itself (Home, Site Settings, New Folder, etc

  • How can I restore my system to 2 days ago without Time Machine?

    I don't want to wipe the disc, just restore the settings to 2 days ago. Time Machine hadn't been set up yet.

  • Lost Video IN\Out put

    I have lost my video in/out via firewire. I have check and the firewire reads my DSR-11. I have control (play, ff, rw) but i am not recieving any video or audio. Audio/Video settings-----DV NTSC 48khm Device Control-----------Firewire NTSC View Video

  • Portal Application

    Hi All, I want to know how a portal application is created and how i can integrate all the views into a portal application. thanks & regards Manoj.