java.lang.Exception;

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arijeet
    New Member
    • Mar 2008
    • 2

    java.lang.Exception;

    Hi,
    I am facing the following error while compiling my code:
    unreported exception java.lang.Excep tion; must be caught.....(err or is at line 100
    function = this.createFunc tion("ZTEST", mRepository);)


    The code is :

    [code=java]
    // imports to include the required libraries.
    //Start of imports.

    import com.sap.mw.jco. *;
    import com.sap.spe.pri cing.*;
    import java.math.BigDe cimal;
    import com.sap.spe.bas e.logging.Usere xitLogger;
    import com.sap.spe.con version.ICurren cyValue;
    import com.sap.spe.pri cing.transactio ndata.userexit. IGroupCondition UserExit;
    import com.sap.spe.pri cing.transactio ndata.userexit. IPricingConditi onUserExit;
    import com.sap.spe.pri cing.transactio ndata.userexit. IPricingDocumen tUserExit;
    import com.sap.spe.pri cing.transactio ndata.userexit. IPricingItemUse rExit;
    import com.sap.spe.pri cing.transactio ndata.userexit. ValueFormulaAda pter;

    //End of imports.

    public class zconprc1 extends ValueFormulaAda pter
    {
    public BigDecimal overwriteCondit ionValue(IPrici ngItemUserExit item,
    IPricingConditi onUserExit condition) {

    BigDecimal item_guid;
    String guid;
    JCO.Structure finalStructure;

    guid = item.getProduct ().getId(); //Returns GUID


    item_guid = new BigDecimal(guid );
    finalStructure = passPar(item_gu id); //Call to the remote function.

    return item_guid;
    }



    public JCO.Function createFunction( String name,JCO.Reposi tory mRepository) throws Exception
    {

    try
    {
    IFunctionTempla te ft = mRepository.get FunctionTemplat e(name.toUpperC ase());

    if (ft == null)
    return null;
    return ft.getFunction( );
    }
    catch (Exception ex){
    throw new Exception("Prob lem retrieving JCO.Function object.");
    }
    }





    public JCO.Structure passPar(BigDeci mal item_guid)
    {
    JCO.Client mConnection;


    // Create a client connection to a dedicated R/3 system
    mConnection = JCO.createClien t("100", // SAP client
    "crm_jco", // remote userid
    "SAREGAMA", // password
    "EN", // language
    "192.168.39.209 ", // host name
    "01", // system number
    "192.168.39.209 ", //Gateway Host
    "sapgw01" ); //Gateway Service Name

    //Establishing the connection
    try
    {
    System.out.prin tln("Starting Session....");
    System.out.prin tln("\n");
    System.out.prin tln("\n");

    mConnection.con nect();
    //System.out.prin tln(mConnection .getAttributes( ));
    // Not required


    }
    catch (Exception e){
    e.printStackTra ce();
    System.exit(1);
    }




    JCO.Repository mRepository;
    JCO.Function function;

    //Creating a JCO repository
    mRepository = new JCO.Repository( "TEST", mConnection);

    //Executing a Function
    function = this.createFunc tion("ZTEST", mRepository);

    //Import Scalar Import Parameter (item_guid)
    //codes = function.getTab leParameterList ().getTable("") ;

    function.getImp ortParameterLis t().setValue("Z TEST","item_gui d");

    mConnection.exe cute(function);

    JCO.Structure returnStructure = function.getExp ortParameterLis t().getStructur e("RETURN");

    return returnStructure ;



    }


    }[/code]

    Why is this happening??Appr eciate some help

    Regards,
    Arijeet
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    You defined your createFunction to throw an Exception. When you call it
    you don't try .. catch that possible Exception; that's what your compiler is
    complaining about: you either have to define your calling function to throw an
    Exception as well or you have to catch the Exception thrown by the createFunction.

    kind regards,

    Jos

    ps. I added code tags around your code for readability reasons.

    Comment

    • arijeet
      New Member
      • Mar 2008
      • 2

      #3
      Originally posted by JosAH
      You defined your createFunction to throw an Exception. When you call it
      you don't try .. catch that possible Exception; that's what your compiler is
      complaining about: you either have to define your calling function to throw an
      Exception as well or you have to catch the Exception thrown by the createFunction.

      kind regards,

      Jos

      ps. I added code tags around your code for readability reasons.
      Hi Jos,

      I have made the following changes in the code:
      Code:
      // imports to include the required libraries.
      //Start of imports.
      
      import com.sap.mw.jco.*;
      import com.sap.spe.pricing.*;
      import java.math.BigDecimal;
      import com.sap.spe.base.logging.UserexitLogger;
      import com.sap.spe.conversion.ICurrencyValue;
      import com.sap.spe.pricing.transactiondata.userexit.IGroupConditionUserExit;
      import com.sap.spe.pricing.transactiondata.userexit.IPricingConditionUserExit;
      import com.sap.spe.pricing.transactiondata.userexit.IPricingDocumentUserExit;
      import com.sap.spe.pricing.transactiondata.userexit.IPricingItemUserExit;
      import com.sap.spe.pricing.transactiondata.userexit.ValueFormulaAdapter;
      
      //End of imports.
      
      public class zconprc1 extends ValueFormulaAdapter
      {
      	public BigDecimal overwriteConditionValue(IPricingItemUserExit item,
      				IPricingConditionUserExit condition) {
      		
      		BigDecimal item_guid;
      		String guid;
      		JCO.Structure finalStructure;
      
      		guid = item.getProduct().getId(); //Returns GUID
      		
      		
      		item_guid = new BigDecimal(guid);
      		finalStructure = passPar(item_guid); //Call to the remote function.
      
      		return item_guid;
      	}
      
      
      
      	public JCO.Function createFunction(String name,JCO.Repository mRepository) extends Exception
      	{
      
      			try
      			{
      				IFunctionTemplate ft = mRepository.getFunctionTemplate(name.toUpperCase());					
      										
      			}
      			catch (Exception ex){
      				throw new Exception("Problem retrieving JCO.Function object.");
      			}
      			
      			if (ft == null)
      				return null;
      			return ft.getFunction();
      	}
      
      
      	
      
      
      	public JCO.Structure passPar(BigDecimal item_guid) 
      	{
      			JCO.Client mConnection;
      			
      		
      			// Create a client connection to a dedicated R/3 system
      			 mConnection =   JCO.createClient("100",      // SAP client
                      		      	       	       "crm_jco",         // remote userid
                              		       	       "SAREGAMA",         // password
                                     			       "EN",       // language
                                     	       		       "192.168.39.209", // host name
                                     	       	       	       "01",     // system number 
      	                         	 	       "192.168.39.209", //Gateway Host
      					               "sapgw01" );      //Gateway Service Name
      
      			//Establishing the connection
      			try
      			{
      				System.out.println("Starting Session....");
      				System.out.println("\n");
      				System.out.println("\n");
      
      				mConnection.connect();
      				//System.out.println(mConnection.getAttributes());
      				// Not required
      
      			JCO.Repository mRepository;
      			JCO.Function function;
      			
      			//Creating a JCO repository
      			mRepository = new JCO.Repository("TEST", mConnection);
      
      			//Executing a Function
      			function = this.createFunction("ZTEST", mRepository);
      			
      			//Import Scalar Import Parameter (item_guid)
      			function.getImportParameterList().setValue("int","item_guid");
      			
      			mConnection.execute(function);
      
      			JCO.Structure returnStructure = function.getExportParameterList().getStructure("RETURN");
      		
      			//return returnStructure;
      						
      										
      			}
      			
      			catch (Exception e){
      				e.printStackTrace();
      				System.exit(1);
      			}
      
      			return returnStructure;		
      
      
      	}
      
      
      }
      It now gives the error :
      zconprc1.java:3 7: ';' expected
      public JCO.Function createFunction( .....) extends Exception

      I have included the function call within the try block. Why this error??

      Regards,
      Arijeet

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        A method can't "extend" anything; only classes can extend other classes.

        kind regards,

        Jos

        Comment

        • satch
          New Member
          • Feb 2008
          • 23

          #5
          Originally posted by JosAH
          A method can't "extend" anything; only classes can extend other classes.

          kind regards,

          Jos
          @arijeet : you didn't read Jos's reply carefully. he never said that you have to modify the 'createFunction' function. This is what Jos suggested :
          1. define your calling function to throw an Exception as well -> which means that 'passPar'(this is the calling function) should also throw an exception. See the implementation of 'createFunction' function in your code(the one before you modified it) to see how a method is declared to throw an exception.
          2.catch the Exception thrown by the 'createFunction' -> this means that the call to 'createFunction' (which is in line 100 of the unmodified code of yours) should be surrounded by a try/catch block. There is already a try/catch block in 'passPar'. Look at it to see how it is used.

          @Jos : After the mistake that arijeet made after your reply, i felt he would need a little more explanation.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by satch
            @Jos : After the mistake that arijeet made after your reply, i felt he would need a little more explanation.
            Sure, I hope s/he gets it now; randomly juggling with keywords and hoping it
            means what one hopes it means is an endless mess. IMHO the OP should read
            a tutorial first.

            kind regards,

            Jos

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              Originally posted by JosAH
              Sure, I hope s/he gets it now; randomly juggling with keywords and hoping it
              means what one hopes it means is an endless mess. IMHO the OP should read
              a tutorial first.

              kind regards,

              Jos
              Like this: http://java.sun.com/docs/books/tutor...ons/index.html

              Comment

              Working...