The returned value of BAPI call

Hi, experts,
I have a question about returned value of BAPI call.
when the returned value is mapped as an attribute and this return value itsself is of the type: table of a certain structure. Is there any possibility that the value of this table still can be extracted from the mapped attribute? If it is possible, how?
If not, how should this kind of situation be handled:
when the returned value of the function at the backend has more one layer structure?
Thanks and best regards,
Fan

In my experience you shouldn't use the service wizard to generate the context of such deeply nested structures. They don't generate or map correctly because it tries to put the table type as the type of the context attribute.
Instead you should propery model the relationship in the context using nested nodes. Here is an example of address <-> address text where you can have multiple address texts per address.  From the service this was a returned nested table.
****BP Address and Address Text
  data lo_nd_bp_addr type ref to if_wd_context_node.
  data lo_nd_bp_addr_text type ref to if_wd_context_node.
  data lo_el_bp_addr type ref to if_wd_context_element.
* navigate from <CONTEXT> to <BP_ADDR> via lead selection
  lo_nd_bp_addr = wd_context->get_child_node( name = wd_this->wdctx_bp_addr ).
  lo_nd_bp_addr->bind_table( wd_this->gt_bp_addr ).
****Add the Address Text Table as Child of each Address Context Record
  data element_set type wdr_context_element_set.
  field-symbols <wa_set> like line of element_set.
  field-symbols <wa_bp_addr> like line of wd_this->gt_bp_addr.
  element_set = lo_nd_bp_addr->get_elements( ).
  loop at element_set assigning <wa_set>.
    read table wd_this->gt_bp_addr index sy-tabix assigning <wa_bp_addr>.
    lo_nd_bp_addr_text = <wa_set>->get_child_node( name = if_componentcontroller=>wdctx_bp_addr_text ).
    lo_nd_bp_addr_text->bind_table( <wa_bp_addr>-t_text ).
  endloop.

Similar Messages

  • Call C# method from javascript in WebView and retrieve the return value

    The issue I am facing is the following :
    I want to call a C# method from the javascript in my WebView and get the result of this call in my javascript.
    In an WPF Desktop application, it would not be an issue because a WebBrowser
    (the equivalent of a webView) has a property ObjectForScripting to which we can assign a C# object containg the methods we want to call from the javascript.
    In an Windows Store Application, it is slightly different because the WebView
    only contains an event ScriptNotify to which we can subscribe like in the example below :
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    this.webView.ScriptNotify += webView_ScriptNotify;
    When the event ScriptNotify is raised by calling window.external.notify(parameter), the method webView_ScriptNotify is called with the parameter sent by the javascript :
    function CallCSharp() {
    var returnValue;
    window.external.notify(parameter);
    return returnValue;
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = DoSomerthing(parameter);
    The issue is that the javascript only raise the event and doesn't wait for a return value or even for the end of the execution of webView_ScriptNotify().
    A solution to this issue would be call a javascript function from the webView_ScriptNotify() to store the return value in a variable in the javascript and retrieve it after.
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = ReturnResult();
    await this.webView.InvokeScriptAsync("CSharpCallResult", new string[] { result });
    var result;
    function CallCSharp() {
    window.external.notify(parameter);
    return result;
    function CSharpCallResult(parameter){
    result = parameter;
    However this does not work correctly because the call to the CSharpResult function from the C# happens after the javascript has finished to execute the CallCSharp function. Indeed the
    window.external.notify does not wait for the C# to finish to execute.
    Do you have any solution to solve this issue ? It is quite strange that in a Window Store App it is not possible to get the return value of a call to a C# method from the javascript whereas it is not an issue in a WPF application.

    I am not very familiar with the completion pattern and I could not find many things about it on Google, what is the principle? Unfortunately your solution of splitting my JS function does not work in my case. In my example my  CallCSharp
    function is called by another function which provides the parameter and needs the return value to directly use it. This function which called
    CallCSharp will always execute before an InvokeScriptAsync call a second function. Furthermore, the content of my WebView is used in a cross platforms context so actually my
    CallCSharp function more look like the code below.
    function CallCSharp() {
    if (isAndroid()) {
    //mechanism to call C# method from js in Android
    //return the result of call to C# method
    } else if (isWindowsStoreApp()) {
    window.external.notify(parameter);
    // should return the result of call to C# method
    } else {
    In android, the mechanism in the webView allows to return the value of the call to a C# method, in a WPF application also. But I can't figure why for a Windows Store App we don't have this possibility.

  • Get the return value of an RFC function / BAPI

    Hello,
    I'm a Web Dynpro Java beginner and I try to get the return value (domain: NUMC6) of an RFC function without success.
    Here is what I do, could you please tell me what is wrong?
    First, here is my context:
    Context
    |
    |---- ZMy_Bapi
         |
         |---- MyOutputResult
         |     |
         |     |---- MyReturnValue
         |
         |---- MyInput
    My model:
    MyModel
    |
    |---- ZMy_Bapi_Input
         |
         |---- Output
         |     |
         |     |---- ZMy_Bapi_Output
         |          |
         |          |---- Return_Value
         |
         |---- Input_Value
    The mapping between them:
    - MyInput is mapped to Input_Value
    - MyReturnValue is mapped to Return_Value
    And my code:
    ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
    wdContext.nodeZMy_Bapi().bind(bapiInput);
    bapiInput.setInput_Value("A value");
    executeZMy_Bapi();
    ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
    wdContext.nodeMyOutputResult().bind(bapiOutput);
    IMyOutputResultElement outputElement = wdContext.nodeMyOutputResult().currentMyOutputResultElement();
    String result = outputElement.getMyReturnValue();
    Finally, here is the code of the executeZMy_Bapi() function:
    try {
         wdContext.currentZMy_BapiElement().modelObject().execute();
         wdContext.nodeMyOutputResult().invalidate();
    } catch (Exception ex) {
         ex.printStackTrace();
    My problem is that "result" keeps being empty
    Thanks in advance for your help!

    It still doesn't work, I'm gonna turn crazy!
    But there is one good point: I get the method you mentioned: getZMy_Bapi_OutputElementAt and getMyReturnValue without casting, just as you said first.
    Here are the updated context, model, mapping and code.
    Context:
    MyContext
    |
    |---- ZMy_Bapi
         |
         |---- MyOutputResult
         |     |
         |     |---- ZMy_Bapi_Output
         |          |
         |          |---- MyReturnValue
         |
         |---- MyInput
    Model:
    MyModel
    |
    |---- ZMy_Bapi_Input
    |     |
    |     |---- Output
    |     |     |
    |     |     |---- ZMy_Bapi_Output
    |     |          |
    |     |          |---- Return_Value
    |     |
    |     |---- Input_Value
    |
    |
    |---- ZMy_Bapi_Output
         |
         |---- Return_Value
    Mapping
    ZMy_Bapi     --> ZMy_Bapi_Input
    MyOutputResult     --> Output
    ZMy_Bapi_Output     --> ZMy_Bapi_Output
    MyReturnValue     --> Return_Value
    MyInput          --> Input_Value
    Code
    ZMy_Bapi_Input bapiInput = new ZMy_Bapi_Input();
    wdContext.nodeZMy_Bapi().bind(bapiInput);
    bapiInput.setInput_Value("A value");
    executeZMy_Bapi();
    ZMy_Bapi_Output bapiOutput = new ZMy_Bapi_Output();
    wdContext.nodeMyOutputResult().bind(bapiOutput);
    String result = "";
    for (int i = 0; i < wdContext.nodeZMy_Bapi_Output().size(); i++) {
         IZMy_Bapi_OutputElement resultElem = wdContext.nodeZMy_Bapi_Output().getZMy_Bapi_OutputElementAt(i);
         if (resultElem.getMyReturnValue() != "" && resultElem.getMyReturnValue() != null) {
              result = resultElem.getMyReturnValue();
    Edited by: Franis Pignon on Oct 17, 2008 11:16 PM

  • How to retreive and display return value from BAPI

    Hello,
    I am using SUP to create a sales order application. In my MBO I have a create operation which calls a BAPI to create a sales order. How can I retrieve the return value (saled doc number) and display it on a screen and display it as an Alert of BB application.
    Regards
    Nidhideep Bhandari

    Hi David Brandow,
    I have tried your solution where I just created a MBO for my 'operation' and I'm using sync parameters to execute the RFC.
    The problem I'm facing is, for example, if I create a record it gets saved in the MBO table and the record successfully gets created in SAP as well after a sync. But when I create another record and sync, the previously saved record in MBO table also gets executed so I'm getting duplicate entries in SAP.
    Have you or anyone faced this problem?
    Any response is appreciated. Please let me know if I'm not clear, I realized its a complicated scenario.
    Thanks,
    Sandeep

  • Remote Object - not able to get the returned value from java method

         Hi ,
    I am developing one sample flex aplication that connects to the java code and displays the returned value from the
    java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.
    lastResult is giving null .  I am able to see the sysout messages in server console.
    I am using flex 3.2 and blazeds server  and java 1.5
    Here is the code what I have written.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">
     <mx:Script><![CDATA[
    import mx.controls.Alert; 
    import mx.binding.utils.ChangeWatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.messaging.*; 
    import mx.messaging.channels.* 
    public function initApp():void { 
         var cs:ChannelSet = new ChannelSet(); 
         var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");     cs.addChannel(customChannel);
         remoteObj.channelSet = cs;
    public function writeToConsole():void {      remoteObj.writeToConsole(
    "hello from Flash client");
          var returnedVal:String = remoteObj.setName().lastResult;     Alert.show(returnedVal);
    //[Bindable] 
    // private var returnedVal:String; 
    ]]>
    </mx:Script>
    <mx:RemoteObject id="remoteObj" destination="sro" /> 
    <mx:Form width="437" height="281">
     <mx:FormItem>  
    </mx:FormItem>  
    <mx:Button label="Write To Server Console" click="writeToConsole()"/>
     </mx:Form>
     </mx:WindowedApplication>
    Java code
    public  
         public SimpleRemoteObject(){  
              super();     }
      class SimpleRemoteObject { 
         public void writeToConsole(String msg) {          System.out.println("SimpleRemoteObject.write: " + msg);     }
         public String setName(){          System.
    out.println("Name changed in Java"); 
              return "Name changed in Java";
    And I have configured destination in  remote-config.xml
    <destination id="sro">
       <properties>    
        <source>SimpleRemoteObject</source>
        <scope>application</scope>
       </properties>
      </destination>
    Please help me .

    You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"
    In this you define what you wish to do.
    More importantly in the remote object you need to define which method you wish to call using the method class like this
    <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >
         <Method name="javaMethodName" result="r2" fault="f2"/>
    <mx:RemoteObject>
    r2 is the function where you get the result back from java and can use it to send the alert.

  • How to Change the return value for the parameters

    Hi, Can anyone help me with my problem?
    I have a parameter called "P1_Projects" defined in the HTMLDB page, on the report region, there are 2 buttons, one is "Go" button to submit the report on the screen, so user can preview the report, then another button "Export to PDF" can be clicked to generate the report using Oracle Report Services. The "Export to PDF" button will use the same set of parameters submitted for the "Go" button.
    So, the parameter "P1_Projects" is being used by these 2 buttons. and I have to pass a "%" wild card for "All Projects". To make the "Export to PDF" button work, I have to safe encode the return value for "%" to "%25" in order to pass the URL formula, but now my "Go" button doesn't work with "%25", it only recognize the "%" wild card.
    Is there a way to conditionally change the value depends which button is clicked?
    Any hint or help is highly appreciated!
    Hong

    try creating a plsql process which sets the P1_Projects item as required.
    in the plsql you can do:
    if :REQUEST = 'GO' then
    xxx
    else
    xxxx
    end if;
    set the condition to plsql expression:
    :REQUEST in ('GO', 'EXPORT')
    NB. the request value is usually set to the button name when a page is submitted from a button

  • How to get the return value of a LOV item using javascript

    Hello,
    I am trying to put an onchange attribute in the HTML Form Element Attributes field of a LOV item. The javascript should access the new return value of the item. How is this done ? All the methods I have tried give only the display value, not the return value. For example $v() returns the display value.
    Tiina

    If your item is called P1_ITEM this will give you the return value of a popup (displays description,returns key value)
    alert($x('P1_ITEM_HIDDENVALUE').value)
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How to pass the return value?

    when i call another procedure in a different vi file(xxx.sql), how am i going to pass the return value that the end user key in?
    how to Promt the message and accept the value that keyed in?
    Please help...
    this is urgent!
    Thank you.

    Use OUT paramter to pass values from called procedure.
    You can pass the values as IN / IN OUT / OUT
    parameters.
    For sample coding please mail
    null

  • How to Access the Return Value of a Function

    Hi,
    How do I access the return value when calling an Oracle function from .NET using Oracle.DataAccess.Client? The function returns an integer of 0, 1 or 99.
    Dim db_command_oracle As New OracleCommand()
    db_command_oracle.Connection = db_connection_oracle
    db_command_oracle.CommandType = CommandType.StoredProcedure
    db_command_oracle.CommandText = "swsarsi.import_appointments"
    Dim ret_value As New OracleParameter()
    ret_value.OracleDbType = OracleDbType.Int32
    ret_value.Direction = ParameterDirection.ReturnValue
    ret_value.Size = 2
    ret_value.OracleDbType = OracleDbType.Int32
    db_command_oracle.Parameters.Add(ret_value)
    Dim IN_student_id As New OracleParameter()
    IN_student_id.OracleDbType = OracleDbType.Varchar2
    IN_student_id.Direction = ParameterDirection.Input
    IN_student_id.Size = 10
    IN_student_id.Value = student_id
    db_command_oracle.Parameters.Add(IN_student_id)
    db_command_oracle.ExecuteNonQuery()
    messagebox.show(ret_value) ?????

    Your ODP.NET code looks correct. What error are you seeing?
    One thing that will definitely generate an error is that .NET message boxes require that strings be displayed. ret_value is a parameter object. You need to access its value and convert it to a string. At a minimum, you need to change that.

  • Problem with the return value from a tablemodel after filtering

    I have a form (consult that return a value) with a jtextfield and a jtable. when the user types in the textfield, the textfield call a method to filter the tablemodel.
    everything works fine, but after filtering the model, the references are lost and the return value does not match with the selected row.
    I read that convertColumnIndexToView, convertRowIndexToView, vertColumnIndexToModel and convertRowIndexToModel, solve the problem, but I used all and nothing.
    **** This is the code to fill the jtable
    DefaultTableModel modelo=(DefaultTableModel)this.jTable1.getModel();
    while(rs.next()){
    Object[] fila= new Object[2];
    fila[0]=rs.getObject("id_categoria");
    fila[1]=rs.getObject("nombre");
    modelo.addRow(fila);
    this.jTable1.getColumnModel().removeColumn(this.jTable1.getColumnModel().getColumn(0));
    // I delete the first column because is a ID, I dont want that the user see it. the value is only for me**** this is the method to filter from the jtextfield
    private void FiltrarJtable1() {
    TableRowSorter sorter = new TableRowSorter(this.jTable1.getModel());
    sorter.setRowFilter(RowFilter.regexFilter("^"+this.jTextField1.getText().toUpperCase(), 1));
    this.jTable1.setRowSorter(sorter);
    this.jTable1.convertRowIndexToModel(0);
    }*** this is the method that return the ID (id_categoria) from the tablemodel
    private void SeleccionarRegistro(){
    if(this.jTable1.getSelectedRow()>-1){
    String str_id =this.jTable1.getModel().getValueAt(this.jTable1.getSelectedRow(),0).toString();
    int_idtoreturn=Integer.parseInt(str_id);
    this.dispose();
    }else{
    JOptionPane.showMessageDialog(this,"there are no records selected","Warning!",1);
    }Who I can solve this problem?

    m_ilio wrote:
    I have a form (consult that return a value) with a jtextfield and a jtable. when the user types in the textfield, the textfield call a method to filter the tablemodel.
    everything works fine, but after filtering the model, the references are lost and the return value does not match with the selected row.
    I read that convertColumnIndexToView, convertRowIndexToView, vertColumnIndexToModel and convertRowIndexToModel, solve the problem, but I used all and nothing.
    You're right in that you have to use convertRowIndexToModel(), but you are using it wrong. That method takes as input the index of a row in the view, i.e. the table, and returns the corresponding row in the underlying TableModel. No data is changed by the call, so this:
    this.jTable1.convertRowIndexToModel(0);is meaningless by itself.
    What you need to do is the following:
    int selectedRow = this.jTable1.getSelectedRow(); // This is the selected row in the view
    if (selectedRow >= 0) {
        int modelRow = this.jTable1.convertRowIndexToModel(selectedRow); // This is the corresponding row in the model
        String str_id =this.jTable1.getModel().getValueAt(modelRow, 0).toString();
    }Hope this helps.

  • Router not seeing the return value from a webservice

    Hello. I have two input fields and a button that calls a web service, is an action that is passed to a router.
    So it looks like this form-->execute web service-->router-->decision
    I'm passing back a string of success or failure as follows:
    @WebMethod
    public String doLogin(String userName, String password)
    if(userName.equals("1"))
    return "failure";
    return "success";
    It executes the method fine, but the router doesn't see the return value correctly. It always evaluates to false (which is the default)
    My text boxes and button is defined as follows:
    <af:inputText value="#{bindings.arg0.inputValue}"
    label="Username:"
    required="#{bindings.arg0.hints.mandatory}"
    columns="#{bindings.arg0.hints.displayWidth}"
    maximumLength="#{bindings.arg0.hints.precision}"
    shortDesc="#{bindings.arg0.hints.tooltip}">
    <f:validator binding="#{bindings.arg0.validator}"/>
    </af:inputText>
    <af:inputText value="#{bindings.arg1.inputValue}"
    label="Password:"
    required="#{bindings.arg1.hints.mandatory}"
    columns="#{bindings.arg1.hints.displayWidth}"
    maximumLength="#{bindings.arg1.hints.precision}"
    shortDesc="#{bindings.arg1.hints.tooltip}">
    <f:validator binding="#{bindings.arg1.validator}"/>
    </af:inputText>
    <af:commandButton actionListener="#{bindings.doLogin.execute}"
    text="doLogin"
    disabled="#{!bindings.doLogin.enabled}"
    action="doLogin"/>
    </af:panelFormLayout>
    My loginpagedef.xml is as follows:
    <?xml version="1.0" encoding="UTF-8" ?>
    <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
    version="11.1.1.51.88" id="loginPageDef"
    Package="customerportal.pageDefs">
    <parameters/>
    <executables>
    <variableIterator id="variables">
    <variable Type="java.lang.String" Name="doLogin_Return"
    IsQueriable="false" IsUpdateable="0"
    DefaultValue="${bindings.doLogin.result}"/>
    <variable Type="java.lang.String" Name="doLogin_arg0"
    IsQueriable="false"/>
    <variable Type="java.lang.String" Name="doLogin_arg1"
    IsQueriable="false"/>
    </variableIterator>
    </executables>
    <bindings>
    <methodAction id="doLogin" RequiresUpdateModel="true" Action="invokeMethod"
    MethodName="doLogin" IsViewObjectMethod="false"
    DataControl="OracleWebServices"
    InstanceName="OracleWebServices"
    ReturnName="OracleWebServices.methodResults.doLogin_OracleWebServices_doLogin_result">
    <NamedData NDName="arg0" NDValue="${bindings.doLogin_arg0}" NDType="java.lang.String"/>
    <NamedData NDName="arg1" NDType="java.lang.String"
    NDValue="${bindings.doLogin_arg1}"/>
    </methodAction>
    <attributeValues IterBinding="variables" id="arg0">
    <AttrNames>
    <Item Value="doLogin_arg0"/>
    </AttrNames>
    </attributeValues>
    <attributeValues IterBinding="variables" id="arg1">
    <AttrNames>
    <Item Value="doLogin_arg1"/>
    </AttrNames>
    </attributeValues>
    </bindings>
    </pageDefinition>
    What am I doing wrong? I can never seem to get the router to view the result coming back from the web service. Thanks in advance!

    Hi,
    Can you try this
    <method-call id="DepartmentCheck">
    <method>#{bindings.DepartmentCheck.execute}</method>
    <return-value>#{pageFlowScope.checkResult}</return-value>
    <outcome>
    <fixed-outcome>result</fixed-outcome>
    </outcome>
    </method-call>
    <router id="routerReturnCheck">
    <case>
    <expression>#{pageFlowScope.checkResult==true}</expression>
    <outcome>succes</outcome>
    </case>
    <default-outcome>return</default-outcome>
    </router>
    just put the result of a method in pageFlowScope variable then the flow case go the router where you evaluate the variable
    hope this helps

  • How to get the return values from a web page

    Hi all :
       how to get the return values from a web page ?  I mean how pass values betwen webflow and web page ?
    thank you very much
    Edited by: jingying Sony on Apr 15, 2010 6:15 AM
    Edited by: jingying Sony on Apr 15, 2010 6:18 AM

    Hi,
    What kind of web page do you have? Do you have possibility to for example make RFCs? Then you could trigger events (with parameters that could "return" the values) and the workflow could react to those events. For example your task can have terminating events.
    Regards,
    Karri

  • How can I use comma in the return values of a static list of values

    Hi all,
    I want to create a select list (static LOV) like the following:
    Display Value / Return Value
    both are "Y" / 'YY'
    one is "Y" / 'YN','NY'
    I write the List of values definition is like this:
    STATIC:both are "Y"; 'YY',one is "Y";'YN', 'NY'
    However, it is explain by htmldb like this:
    Display Value / Return Value
    both are "Y" / 'YY'
    one is "Y" / 'YN'
    / 'NY'
    I tried using "\" before the ",", or using single or double quote, but all these do not work:(
    How can I use a comma in the return values?
    Thanks very much!

    "Better still, why not process the code of both Y with 2Y and one is Y with 1Y? "
    Could you please explain in detail? thanks! I am quite new to htmldb
    In fact I have a table which has too columns "a1" and "a2", both the values of these two columns are "Y" or "N". AndI want to choose the records that both a1 and a2 are "Y", or just one of a1, a2 is "Y".
    So I write the report sql like this:
    "select * from t1 where a1 || a2 in(:MYSELECTLIST) "
    Thus, I need to use "," in the LOV, since expression list in IN(,,,) using ",".
    Any other way to implement this?

  • Job scheduling error : The return value was unknown. The process exit code was -1073741819. The step failed.

    I am working in Sqlserver 2008 R2, SSIS 64 bit version
    I am getting the below  error while scheduling the job in the development server  Database. 
    The return value was unknown.  The process exit code was -1073741819.  The step failed.
    The SSIS front end execution runs fine.
    Have anyone  faced this issue before?

    Hi Venkat,
    If you already changed to 64bit and still doesn't work then create proxy account.. 
    To create a proxy account
    In Object Explorer, expand a server.
    Expand SQL Server Agent.
    Right-click Proxies and select New Proxy.
    On the General page of the New Proxy Account dialog, specify the proxy name, credential name, and
    description for the new proxy. Note that you must create a credential first before you create a proxy if one is not already available. For more information about creating a credential, see How
    to: Create a Credential (SQL Server Management Studio) or CREATE CREDENTIAL (Transact-SQL).
    Check the appropriate subsystem for this proxy.
    On the Principals page, add or remove logins or roles to grant or remove access to the proxy account.
    Thanks

  • Getter/setter methods -- how do I use the return values

    I'm just learning Java, and I haven't been to this site since the end of July, I think. I have a question regarding getter and setter methods. I switched to the book Head First Java after a poster here recommended it. I'm only about a hundred pages into the book, so the code I'm submitting here reflects that. It's the beginnings of a program I'd eventually like to complete that will take the entered information of my CD's and alphabetize them according to whatever criteria I (or any user for that matter) choose. I realize that this is just the very beginning, and I don't expect to have the complete program completed any time soon -- it's my long term goal, but I thought I could take what I'm learning in the book and put it to practical use as I go along (or at lest try to).
    Yes I could have this already done it Excel, but where's the fun and challenge in that? :) Here's the code:
    // This program allows the user to enter CD information - Artist name, album title, and year of release -- and then organizes it according the the user's choice according to the user's criteria -- either by artist name, then title, then year of release, or by any other order according to the user's choice.
    //First, the class CDList is created, along with the necessary variables.
    class CDList{
         private String artistName;//only one string for the artist name -- including spaces.
         private String albumTitle;//only one string the title name -- including spaces.
         private int yearOfRelease;
         private String recordLabel;
         public void setArtistName(String artist){
         artistName = artist;
         public void setAlbumTitle(String album){
         albumTitle = album;
         public void setYearOfRelease(int yor){
         yearOfRelease = yor;
         public void setLabel(String label){
         recordLabel = label;
         public String getArtistName(){
         return artistName;
         public String getAlbumTitle(){
         return albumTitle;
         public int getYearOfRelease(){
         return yearOfRelease;
        public String getLabel(){
        return recordLabel;
    void printout () {
           System.out.println ("Artist Name: " + getArtistName());
           System.out.println ("Album Title: " + getAlbumTitle());
           System.out.println ("Year of Release: " + getYearOfRelease());
           System.out.println ("Record Label: " + getLabel());
           System.out.println ();
    import static java.lang.System.out;
    import java.util.Scanner;
    class CDListTestDrive {
         public static void main( String[] args ) {
              Scanner s=new Scanner(System.in);
              CDList[] Record = new CDList[4];
              int x=0;     
              while (x<4) {
              Record[x]=new CDList();
              out.println ("Artist Name: ");
              String artist = s.nextLine();
              Record[x].setArtistName(artist);
              out.println ("Album Title: ");
              String album = s.nextLine();
              Record[x].setAlbumTitle(album);
              out.println ("Year of Release: ");
              int yor= s.nextInt();
                    s.nextLine();
              Record[x].setYearOfRelease(yor);
              out.println ("Record Label: ");
              String label = s.nextLine();
              Record[x].setLabel(label);
              System.out.println();
              x=x+1;//moves to next CDList object;
              x=0;
              while (x<4) {
              Record[x].getArtistName();
              Record[x].getAlbumTitle();
              Record[x].getYearOfRelease();
              Record[x].getLabel();
              Record[x].printout();
              x=x+1;
                   out.println("Enter a Record Number: ");
                   x=s.nextInt();
                   x=x-1;
                   Record[x].getArtistName();
                Record[x].getAlbumTitle();
                Record[x].getYearOfRelease();
                Record[x].getLabel();
                Record[x].printout();
         }//end main
    }//end class          First, I'd like to ask anyone out there to see if I could have written this any more efficiently, with the understanding that I'm only one hundred pages into the book, and I've only gotten as far as getter and setter methods, instance variables, objects and methods. The scanner feature I got from another book, but I abandoned it in favor of HFJ.
    Secondly --
    I'm confused about getter and setter methods -- I'd like someone to explain to me what they are used for exactly and the difference between the two. I have a general idea, that getters get a result from the method and setters set or maybe assign a value to variable. I submitted this code on another site, and one of the responders told me I wasn't using the returned values from the getter methods (he also told me about using a constructor method, but I haven't got that far in the book yet.). The program compiles and runs fine, but I can't seem to figure out how I'm not using the returned values from the getter methods. Please help and if you can explain in 'beginners terms,' with any code examples you think are appropriate. It will be greatly appreciated.
    By the way, I'm not a professional programmer -- I'm learning Java because of the intellectual exercise and the fun of it. So please keep that in mind as well.
    Edited by: Straitsfan on Sep 29, 2009 2:03 PM

    Straitsfan wrote:
    First, I'd like to ask anyone out there to see if I could have written this any more efficiently, with the understanding that I'm only one hundred pages into the book, and I've only gotten as far as getter and setter methods, instance variables, objects and methods. The scanner feature I got from another book, but I abandoned it in favor of HFJ.Yes, there is tons you could have done more efficiently. But this is something every new programmer goes through, and I will not spoil the fun. You see, in 3 to 6 months when you have learned much more Java, assuming you stick with it, you will look back at this and be like "what the hell was I thinking" and then realize just haw far you have come. So enjoy that moment and don't spoil it now by asking for what could have been better/ more efficient. If it works it works, just be happy it works.
    Straitsfan wrote:
    Secondly --
    I'm confused about getter and setter methods -- I'd like someone to explain to me what they are used for exactly and the difference between the two. I have a general idea, that getters get a result from the method and setters set or maybe assign a value to variable. I submitted this code on another site, and one of the responders told me I wasn't using the returned values from the getter methods (he also told me about using a constructor method, but I haven't got that far in the book yet.). The program compiles and runs fine, but I can't seem to figure out how I'm not using the returned values from the getter methods. Please help and if you can explain in 'beginners terms,' with any code examples you think are appropriate. It will be greatly appreciated.
    By the way, I'm not a professional programmer -- I'm learning Java because of the intellectual exercise and the fun of it. So please keep that in mind as well.First, if you posted this somewhere else you should link to that post, it is good you at least said you did, but doubleposting is considered very rude because what inevitably happens in many cases is the responses are weighed against each other. So you are basically setting anyone up who responds to the post for a trap that could make them look bad when you double post.
    You are setting you getters and setters up right as far as I can tell. Which tells me that I think you grasp that a getter lets another class get the variables data, and a setter lets another class set the data. One thing, be sure to use the full variable name so you should have setRecordLabel() and getRecodLabel() as opposed to setLabel() and getLabel(). Think about what happens if you go back and add a label field to the CDList class, bad things the way you have it currently. Sometimes shortcuts are not your friend.
    And yes, you are using the getters all wrong since you are not saving off what they return, frankly I am suprised it compiles. It works because you don't really need to use the getters where you have them since the CDList Record (should be lowercase R by the way) object already knows the data and uses it in the printout() method. Basically what you are doing in lines like:
    Record[x].getArtistName();is asking for the ArtistName in Record[x] and then getting the name and just dropping it on the floor. You need to store it in something if you want to keep it, like:
    String artistName = Record[x].getArtistName();See how that works?
    Hope this helped, keep up the good learning and good luck.
    JSG

Maybe you are looking for

  • Pls Help: monitor died, need quick access.

    Current situation: -Have a mac pro -Screen died / have no backup monitor -Have iBook & G4 iMac Question: Is there a quick/easy/free way to get to my iMac (like something similar to remote desktop etc...)? I know I can boot it just to access the drive

  • ITunes 7 not playing downloaded videos?

    I had downloaded Quicktime 7.1.3 and iTunes 7, but my downloaded videos were not playing. I was also getting errors that iTunes was waiting to authorize computer and a gray video window screen. I removed the plug-in QuicktimeComponents from HD/Librar

  • Opening pdf files in Adobe Acrobat within Safari?

    can pdf files be opened with adobe acrobat files in Safari? if so, how? any insight would be greatly appreciated!

  • Itunes to ipod

    Why does my computer say I can't play some songs I download from itunes on my macbook or put them on my ipod.

  • Tutorial on file upload/downloads questions

    Hi Everyone. Can you tell me how to clear a field such as the :p2_file_name field? I was thinking you could use :p2_file_name := '' like we do in Oracle Forms but that did not work. I put that code into a pl/sql process. The intent was to clear the f