Integer to curr/quantity mapping

Hi all
From R/3, im getting integer values, in BW its mapped to either a curr field or a Quan field.
is there any chance of getting wrong values in BW.
I tried loading into PSA and i get wrong values too..which is surprising.
For e.g for integer values 3,3,7 in PSA im getting 7,7,7.
There are no transformation or ABAP code in between and the mapping is perfect.Moreover as i said im getting wrong values in PSA itself.
All this is happening in the Quality box where as its working fine in  Development.
Any clues/suggestions?
Thanks
JPJP

Hi JPJP,
In rsa3 you get the correct values. in PSA you say you are getting them wrong? Try to run the extraction again and check the values from the exact same fields. The PSA its the same you get in RSA3.
Hope this helps.
Regards,
Diego

Similar Messages

  • Quantity Mapping in Message mapping

    I have the below mapping conditions...
    Create for every quantity related to billcode and Sponsorcode.  If there is no quantity, create segment with quantity 0.
    How to map this?  Please help how to map this clearly...
    Thanks in advance..

    Hello,
    This can be solved by using the node function mapWithDefault. Since your quantity is 0..1, you can use a logic that looks like this
    quantity --> mapWithDefault: 0 --> target
    Please take note that for the mapWithDefault to work, there should be no context manipulations in your quantity field.
    Hope this helps,
    Mark

  • Urgent!!!! Quantity Mapping

    Hello Experts,
    I am passing quantity as 'ABCD' from my Legacy system to a WebService.
    When I execute this Web Service the documnet gets posted with 1236.000 quantity.
    I have given quantity as Decimal type.
    In R/3 document gets posted with 1236.000 as quantity inspite of giving ABCD as the quantity.
    Please help!!

    Hey Aamir,
    I checked in Payloads, it is giving me ASDF......
    In message mapping also, I tested, even that gives me ASDF.
    But, in R/3 my document gets posted with 1346.000 :(((((((
    Also, in R/3, quantity field itself can not accept any values like ASDF...as it does not allow.
    Also, I am not using any conversion routines for Quantity field..
    Please suggest some solution....as it is very urgent!!!

  • How to find length of integer elements using message mapping

    Hi all,
             How can I find the number of digits in an element using message mapping
    XIer

    Satish,
               Cause I have to write the code for 100 elements, I have decided to have a AUDF with two inputs;
    1) for the element
    2) for the length of the data type (I am passing length using Constant message mapping func).
    Now when I change my UDF and try running it I get the following error:
    <b><i>Start of test
    Source code has syntax error:  /usr/sap/B06/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0999e66045cf11dcc83b4ebcfc11da82/source/com/sap/xi/tf/_MM_Recordcount1_.java:160: operator >= cannot be applied to int,java.lang.String if(Element_Name.length()>=Element_Length) ^ /usr/sap/B06/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map0999e66045cf11dcc83b4ebcfc11da82/source/com/sap/xi/tf/_MM_Recordcount1_.java:166: operator <= cannot be applied to int,java.lang.String for(int i=Element_Name.length();i<=Element_Length;i++) ^ 2 errors</i></b>
    The code I have used is:
    public String Include_Space(String Element_Name,String Element_Length,Container container)
    {StringBuffer sb= new StringBuffer();
    if(Element_Name.length()>=Element_Length)
    return""Element_Name"";
    else
    for(int i=Element_Name.length();i<=Element_Length;i++)
    if(i==Element_Name.length())
    sb.append(Element_Name);
    else
    sb.append(" ");
    return ""sb.toString()"";
    Pls advice, where I am going wrong...
    XIer
    Message was edited by:
            XIer

  • Comparision of Integer field with Quantity

    Hi folks,
    I Need Help from you.My problem is i have two fields like F1 and F2.
    F1INT4 Datatype    F2Quantity Fiels.
    i need to compare those two fields..I have done all the conversion types nut iam unable to get proper outcome out of it due to the Quantity field.
    Please Tell me your suggestions ASAP.

    Hi Vijay ,
    I have got the solution like converting Quantity into STRING field and Splitting at '.' into two fields two get number before decimal.
    Thanks vijay for responding.

  • JPA One-To-Many Parent-Child Mapping Problem

    I am trying to map an existing legacy Oracle schema that involves a base class table and two subclass tables that are related by a one-to-many relationship which is of a parent-child nature.
    The following exception is generated. Can anybody provide a suggestion to fix the problem?
    Exception [EclipseLink-45] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DescriptorException
    Exception Description: Missing mapping for field [BASE_OBJECT.SAMPLE_ID].
    Descriptor: RelationalDescriptor(domain.example.entity.Sample --> [DatabaseTable(BASE_OBJECT), DatabaseTable(SAMPLE)])
    The schema is as follows:
    CREATE TABLE BASE_OBJECT(
    "BASE_OBJECT_ID" INTEGER PRIMARY KEY NOT NULL,
    "NAME" VARCHAR2(128) NOT NULL,
    "DESCRIPTION" CLOB NOT NULL,
    "BASE_OBJECT_KIND" NUMBER(5,0) NOT NULL );
    CREATE TABLE SAMPLE(
    "SAMPLE_ID" INTEGER PRIMARY KEY NOT NULL,
    "SAMPLE_TEXT" VARCHAR2(128) NOT NULL )
    CREATE TABLE SAMPLE_ITEM(
    "SAMPLE_ITEM_ID" INTEGER PRIMARY KEY NOT NULL,
    "SAMPLE_ID" INTEGER NOT NULL,
    "QUANTITY" INTEGER NOT NULL )
    The entities are related as follows:
    SAMPLE.SAMPLE_ID -> BASE_OBJECT.BASE_OBJECT_ID - The PKs that are used to join the sample to the base class
    SAMPLE_ITEM.SAMPLE_ITEM_ID -> BASE_OBJECT.BASE_OBJECT_ID - The PKs that are used to join the sample item to the base class
    SAMPLE_ITEM.SAMPLE_ID -> SAMPLE.SAMPLE_ID - The FK that is used to join the sample item to the sample class as a child of the parent.
    SAMPLE is one to many SAMPLE_ITEM
    The entity classes are as follows:
    @Entity
    @Table( name = "BASE_OBJECT" )
    @Inheritance( strategy = InheritanceType.JOINED )
    @DiscriminatorColumn( name = "BASE_KIND", discriminatorType = DiscriminatorType.INTEGER )
    @DiscriminatorValue( "1" )
    public class BaseObject
    extends SoaEntity
    @Id
    @GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "BaseObjectIdSeqGen" )
    @SequenceGenerator( name = "BaseObjectIdSeqGen", sequenceName = "BASE_OBJECT_PK_SEQ", allocationSize = 1 )
    @Column( name = "BASE_ID" )
    private long baseObjectId = 0;
    @Entity
    @Table( name = "SAMPLE" )
    @PrimaryKeyJoinColumn( name = "SAMPLE_ID" )
    @AttributeOverride(name="baseObjectId", column=@Column(name="SAMPLE_ID"))
    @DiscriminatorValue( "2" )
    public class Sample
    extends BaseObject
    @OneToMany( cascade = CascadeType.ALL )
    @JoinColumn(name="SAMPLE_ID",referencedColumnName="SAMPLE_ID")
    private List<SampleItem> sampleItem = new LinkedList<SampleItem>();
    @Entity
    @Table( name = "SAMPLE_ITEM" )
    @PrimaryKeyJoinColumn( name = "SAMPLE_ITEM_ID" )
    @AttributeOverride(name="baseObjectId", column=@Column(name="SAMPLE_ITEM_ID"))
    @DiscriminatorValue( "3" )
    public class SampleItem
    extends BaseObject
    @Basic( optional = false )
    @Column( name = "SAMPLE_ID" )
    private long sampleId = 0;
    Edited by: Chris-R on Mar 2, 2010 4:45 PM

    Thanks for the thoroughness. There was a mistake in moving the code over for the forum. The field names are correct throughout the original source code.
    BASE_OBJECT_ID is used throughout.
    I suspect the problem lies in the one-to-many sampleItem(s) relationship that is based upon the subclassed item class. (The relationship is actually "sampleItems" in the real code and somehow got changed in the move over.)
    The problem may lie in the mapping of the attribute override in the child class to the referencing of the item class from the parent side of the relationship in the Sample class.
    I further suspect this may be specific to Eclipselink based upon other postings I've seen on the web that have similar problems...
    Any thoughts?
    Edited by: Chris-R on Mar 3, 2010 9:56 AM

  • 1-1 mapping Primary Key association problem

    Hi, I have two tables Indiv (Id, col1, col2 ) and IndivExt(Id, col3)....where "Id" is the PKey in both the tables.
    In TopLink, I have mapped
    Indiv table --> IndivClass
    IndivExt table --> IndivExtClass
    class IndivClass{
    Integer Id;
    Integer col1;
    Integer col2;
    class IndivExtClass{
    IndivClass oIndiv; // relation - one-to-one
    Integer col3;
    While running the app, there is an Integrity TopLink exception that says that IndivClass descriptor doesnt have IndivExt table in it.
    So, I used advanced feature of multi-table info and created the Primary Key association between these two descriptors.
    If I am right, This association assumes that there is a row in IndivExt for every row in Indiv...correct me if im wrong. I assume this coz of the kinda sql query it creates when im trying to read a IndivClass object. The sql query uses a join on both the tables.
    But...For every row in Indiv table there MIGHT or MIGHT NOT be a row in IndivExt table.
    So the sql that is formed will not return the required Indiv rows (in case there are no corresponding IndivExt rows).
    How do I resolve this.
    Thanks,
    Krishna

    Hi James,
    Thanx for that update.
    So just for clarification...
    Im going to remove the multi-table info.
    And use normal foreign key reference,
    and apply the patch...then the Integrity error
    should not occur.
    Right ?
    One more question... If I also want to refer IndivExt from the Indiv object...then I would change my classes
    to be like...
    class IndivClass{
    Integer Id;
    Integer col1;
    Integer col2;
    IndivExt oIndivExt; //relation - one-to-one (rel2)
    class IndivExtClass{
    IndivClass oIndiv; // relation - one-to-one (rel1)
    Integer col3;
    and the mapping (for rel2) in IndivClass descriptor will use the same reference that was used by rel1...ie., a normal foreign key ref. Is that right ?
    And also...Is there a bug number related to this issue and how do I get the patch ? Where can I download it from?
    Thanks,
    Krishna

  • Change the Business Graphic Y-axis from decimal scale value to integer

    Hi,
    I am trying to get rid of the decimal points of the Y axis scale to integer.
    The scale value is currently showing like below:
    13.86
    10.395
    6.93
    3.465
    (This actual data set is currently fall between 3.xxxx to 12.xxxx)
    I want the scale label to display in integer, like this:
    15
    12
    9
    6
    3
    or
    13
    10
    6
    3
    This is determined dynamically as I have made the below settings.I am mapping the seriesSource of the Percentage BusinessGraphic to a node of attributes type of decimal.
    In the Chart Designer, I am setting the Y Value Axis configuration as below:
    Minimum  value: 0
    Minumum calculation: Automatic
    Maximum value: 100
    Maximum Calculation: Automatic
    Can you advise me how I can control the graph Y axis scale label to display in integer while I am mapping to a node of decimal data (for percentage values)?
    Thanks,
    KC

    Hi, Poojith.
    After making the below change:
    1. The "Scaling Type" in the "Value Axis" of the Chart Designer is Linear.
    2. I converted the type of the attribute bound to the SimpleSeries to new Decimal(double)
    I am still not able to achieve what I want. I am checking the value of the Value Axis --> Line --> Format.
    Based on the field description ("Specifies the format of the label output"), it seems like it is the value I should change. It is currently BLANK.
    Let me try it out. Please advise if you have any information on the Format string pattern I should use.
    Thanks,
    Kent

  • Removing decimal in mapping

    Hi,
    How do I remove decimal from float (source) to unsigned integer (target) in graphical mapping?
    For eg:
    Source = 1500.23
    Target = 150023
    Reg,
    Shobhit

    If you want a quick way of just letting numbers to pass, use:
    return a.replaceAll([^0-9], "");
    in a UDF.
    Regards,
    Henrique.

  • Integer static valueOf(int) question

    Hi there.
    Im wondering is it at all possible for an Integer reference variable to be returned
    a null by invoking this method from the API:
    Integer myInt = Integer.valueOf(//some int);The reason I am asking this question is that my SCJP book asks a question
    about using a method that is similar to the following:
    class BankAccount {
    private Map<String, Integer> accountFunds = new HashMap<String, Integer>();
    public int customerBalance(String custAccount) {
       return accountFunds.get(custAccount);
    public void setCustomerBalance(String custAccount, int balance) {
       accountFunds.put(custAccount, Integer.valueOf(balance));
    }Looking at the single return statement in the customerBalance method, my book states that this is inappropriate
    because a null cant unbox to 0 I disagree because if you look at the setCustomerBalance method you are putting an Integer
    instance that is initialized with an int primitive into the Map. So how could it be possible to have
    a null Integer instance in the map if you pass an int primitive to the valueOf method? I can understand
    if you were using a String to instantiate the Integer, and you passed null, that you would get a NumberFormatException or something like that, but about you are using a primitive, not an Object.
    Any clarification greatly received,
    Thanks & best regards.

    I disagree because if you look at the setCustomerBalance method you are putting an Integer
    instance that is initialized with an int primitive into the Map.And what happens if you call customerBalance() (which should really be named getCustomerBalance()) with a customer ID that doesn't exist?

  • EL Map won't work with numerical index - works with string

    If I populate a map with a numeric index, the values won't appear when I refer to it as ${myMap[0]} in JSP. In my servlet I populate myMap by doing a put(0,value).
    However, when I do a myMap["index0"] or myMap.index0, it works! I simply change the line that populates the Map to put("index0",value).
    Why won't it work with a numerical index? Does it have something to do with JDK 1.5's autoboxing? I cast the 0 to an int in the put( ) method, but that makes no difference.
    What could be happening here? Does it work for you?
    Thanks.

    Whats causing this?
    Basically autoboxing puts an Integer object into the Map.
    ie: map.put(new Integer(0), "myValue")
    EL evaluates 0 as a Long and thus goes looking for a Long as the key in the map.
    ie it evaluates: map.get(new Long(0))
    As a Long is never equal to an Integer object, it does not find the entry in the map.
    Thats it in a nutshell.
    JSP page demonstrating this:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ page import="java.util.*" %>
    <h2> Server Info</h2>
    Server info = <%= application.getServerInfo() %> <br>
    Servlet engine version = <%=  application.getMajorVersion() %>.<%= application.getMinorVersion() %><br>
    Java version = <%= System.getProperty("java.vm.version") %><br>
    <%
      Map map = new LinkedHashMap();
      map.put("2", "String(2)");
      map.put(new Integer(2), "Integer(2)");
      map.put(new Long(2), "Long(2)");
      map.put(42, "AutoBoxedNumber");
      pageContext.setAttribute("myMap", map); 
      Integer lifeInteger = new Integer(42);
      Long lifeLong = new Long(42); 
    %>
      <h3>Looking up map in JSTL - integer vs long </h3>
      This page demonstrates how JSTL maps interact with different types used for keys in a map.
      Specifically the issue relates to autoboxing by java using map.put(1, "MyValue") and attempting to display it as ${myMap[1]}
      The map "myMap" consists of four entries with different keys: A String, an Integer, a Long and an entry put there by AutoBoxing Java 5 feature.      
      <table border="1">
         <tr><th>Key</th><th>value</th><th>Key Class</th></tr>
         <c:forEach var="entry" items="${myMap}" varStatus="status">
         <tr>      
           <td>${entry.key}</td>
           <td>${entry.value}</td>
           <td>${entry.key.class}</td>
         </tr>
         </c:forEach>
    </table>
        <h4> Accessing the map</h4>   
        Evaluating: ${"${myMap['2']}"} = <c:out value="${myMap['2']}"/><br>
        Evaluating: ${"${myMap[2]}"}   = <c:out value="${myMap[2]}"/><br>   
        Evaluating: ${"${myMap[42]}"}   = <c:out value="${myMap[42]}"/><br>   
        <p>
        As you can see, the EL Expression for the literal number retrieves the value against the java.lang.Long entry in the map.
        Attempting to access the entry created by autoboxing fails because a Long is never equal to an Integer
        <p>
        lifeInteger = <%= lifeInteger %><br/>
        lifeLong = <%= lifeLong %><br/>
        lifeInteger.equals(lifeLong) : <%= lifeInteger.equals(lifeLong) %> <br>
        That at least explains what is going on.
    Not sure exactly what I would do to "fix" it. Would have to look at what the requirements are. But basically I think it would end up as having to use Longs rather than Integers as keys in the map, meaning autoboxing could not be used.
    Cheers,
    evnafets

  • Problem instantiating maps

    I want to create a deck of cards in a Map. The Key is an integer, Ace = 1, Two = 2...... Ten = 10, Jack = 11 and so on. The Value is a string of its suit, Hearts, Diamonds, Clubs, or Spades.
    package card;
    import java.util.Map;
    public class Card {
         Map<Integer, String> cardMap = new Map <Integer, String>();This is what I have so far, and its giving me an error on the second "Map" in the constructing line, saying that it cant instantiate it.
    How can I fix this, or is there a more efficient way I can go about doing this?

    secretempire1 wrote:
    public class Deck {
         private Map<Integer, String> cardMap;
         public void CreateCards()
              for (int i = 1; i <= 13; i++)
                   cardMap.put(i, "Heart");
    Even when / if you get your map working, it still looks like the entirely wrong data structure here. Does it make any sense to get "Heart" from your map when you put in 2? Your not really needing to map anything here. Your deck should be a collection, say an ArrayList of Card objects, each Card holding a value and a suit. The value can be an int, the suit should be a constant value of some sort, again enums are often used here, and in fact it is a classic example of what enums are best for.
    Good luck.

  • Variable might not have been initialized, but I can't get around it...

    I'm getting a variable might not have been initialized error, and I know why, but I can't get around it. Basically, this snippet of my code is reading in a map file for a game. The first two lines of the map file are configuration information, and the rest is coordinates for the tiling graphics.
    while ((str = in.readLine()) != null) {
                    if(!read_info){
                        //process first line: tileset image, size, playerpos
                        temp = str.split(",");
                        loadTileset(temp[0],32);
                        size_x = Integer.parseInt(temp[1]);
                        size_y = Integer.parseInt(temp[2]);
                        map = new Tile[size_x][size_y];
                        player.resetLoc(Integer.parseInt(temp[3]),Integer.parseInt(temp[4]));
                        //process second line: impassible
                        str = in.readLine();
                        temp = str.split("!");
                        impassable = new Point[temp.length];
                        for(int m=0;m<temp.length;m++){
                            tmp_coords = temp[m].split(",");
                            impassable[m] = new Point(Integer.parseInt(tmp_coords[0]),Integer.parseInt(tmp_coords[1]));
                        read_info = true;
                    } else{
                        temp = str.split("!");
                        for(int i=0;i<size_x;i++){
                            tmp_coords = temp.split(",");
    boolean ti = true;
    for(int p=0;p<impassable.length;p++){
    map[i][j] = new Tile(Integer.parseInt(tmp_coords[0]),Integer.parseInt(tmp_coords[1]),true);
    j++;
    I'm not including everything.. this should make sense. Impassable is a Point[].
    I can't say how big the Impassable list will be until it reads the second line of the map file. However, that happens in the first run-through of the file-reading processes.
    Is there a try/catch statement I can use to get past this?

    If you set that variable to null you will fix this
    error.
    Object obj;to
    Object obj = null;Beware this may cuase NullPointerExceptions, so you
    should check this variable for being null before you
    try to access it.That's usually the wrong way to approach this. Getting this compiler error is often a sign of a logic error. Only initialize the variable if it makes sense for the variable to have that value. Don't do it just to satisfy the compiler.

  • I'm new to java and need help please

    I have an assignment involves modifying a previous assignment. the code for the previous assigment is shown below.(it was required to be done as an applet this assigment can be an application or an applet) I'm trying to modify this code to read a text file (items.txt) that looks like this:
    item # description price(this line does not appear in the text file)
    001 shaving cream 400.00
    999 razors 30.00
    I need to load the item# and price from the text file into arrays(I have no clue how to use multi-dimensional arrays in java and would prefer not to)
    I need to search the arrays based on the values entered by the user (item # and quantity) calculate the total for that item then create a new text file which has each line item for that order in the form:
    item# quant price per item total(price per item*quant entered)
    also also I need to be able to display the four items listed above after each loop as well as all the previous item number and quantities they selected until they indicate they don't want to select anymore.
    I've been working on this for days and it seems like nothing I try works. My major problems are:
    1. I have no idea how to read the text file and load those 2 items into their respective arrays
    2. I can't seem to create a textfile that looks like text for the output file.
    code]
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.*;
    import java.util.Locale;
    public class arraySelection
    extends JApplet {
    //Initialize the applet
    private Container getContentPane=null;
    public void init() {
    String string_item, string_quantity;
    String output = "";
    String description= "";
    int counter= 0;
    int itemNumber= 0;
    double quantity = 0 ;
    double tax_rate=.07;
    double total= 0, price= 0;
    double tax, subtotal;
    double Pretotal= 0;
    double priceArray[] = {1, .5, 3.65, 0.02, 0.09};
    String descriptionArray[] = {"salt", "pepper", "paprika", "garlic", "thyme"};
    // create number format for currency in US dollar format
    NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );
    //format to have the total with two digits precision
    DecimalFormat twoDigits = new DecimalFormat("0.00");
    //Jtextarea to display results
    JTextArea outputArea = new JTextArea ();
    // get applet's content pane
    Container container = getContentPane ();
    //attach output area to container
    container.add(outputArea);
    //set the first row of text for the output area
    output += "Invoice\nItem#\tDescription\tQuant@Price\t Line Total" + "\n";
    do //begin loop structure obtain input from user
    // obtain item number from user
    string_item = JOptionPane.showInputDialog(
    "Please enter an item number 1, 2, 3, 4, or 5:");
    //obtain quantity of each item that user enter
    string_quantity = JOptionPane.showInputDialog("Enter the quantity:");
    // convert numbers from type String to Integer or Double
    itemNumber = Integer.parseInt(string_item);
    quantity = Double.parseDouble(string_quantity);
    switch (itemNumber) {//Determine input from user to assign price and description
    case 10: // user input item =10
    price = priceArray[0];
    description = descriptionArray[0];
    break;
    case 20: // user input item =20
    price = priceArray [1];
    description = descriptionArray[1];
    break;
    case 30: //user input item =30
    price=priceArray[2];
    description = descriptionArray[2];
    break;
    case 40: //user input item =40
    price=priceArray[3];
    description = descriptionArray[3];
    break;
    case 50: //user input item =50
    price=priceArray[4];
    description = descriptionArray[4];
    break;
    default: // user input item is not on the list
    output += "Invalid value entered"+ "\n";
    price=0;
    description= "";
    //Calculates the total for each item number and stores it in subtotal
    subtotal = price * quantity;
    //display input from user
    output += itemNumber + "\t" + description + "\t\t"+ quantity + "@" +
    moneyFormat.format( price) + "\t" + moneyFormat.format( subtotal) + "\n";
    //accumulates the overall subtotal for all items
    Pretotal = Pretotal + subtotal;
    //verifies that the user wants to stop entering data
    string_item = JOptionPane.showInputDialog(" Enter a positive integer to continue or 0 to stop. ");
    itemNumber = Integer.parseInt(string_item);
    // loop termination condition if user's input is 0 .It will end the loop
    } while ( itemNumber!= 0);
    tax = Pretotal * tax_rate; // calculate tax amount
    total = Pretotal + tax; //calculate total = subtotal + tax
    //appends data regarding the subtotal, tax, and total to the output area
    output += "\n" + "Order Subtotal" + "\t" + moneyFormat.format( Pretotal) +
    "\n" + "Tax" + "\t\t" + twoDigits.format( tax ) + "\n" + "Order Total" +
    "\t\t" + moneyFormat.format( total );
    //attaches the data in the output variable to the output area
    outputArea.setText( output );
    } //end init
    }// end applet Invoice
    Any help or sugestions would be greatly appreaciated. I've been working on this for over a week and everything I try goes nowhere.

    item # description price(this
    line does not appear in the text file)
    001 shaving cream 400.00
    999 razors 30.00
    I need to load the item# and price from the text file
    into arrays(I have no clue how to use
    multi-dimensional arrays in java and would prefer not
    to)That's good, because you shouldn't use multidimensional arrays here. You should have a one-dimensional array (or java.util.List) of objects that encapsulate each line.
    I've been working on this for days and it seems like
    nothing I try works. My major problems are:
    1. I have no idea how to read the text file and load
    those 2 items into their respective arrays
    2. I can't seem to create a textfile that looks like
    text for the output file.The java.io package has file reading/writing classes.
    Here's a tutorial:
    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • I'm new to java and need help please(repost)

    I have an assignment involves modifying a previous assignment. the code for the previous assigment is shown below.(it was required to be done as an applet this assigment can be an application or an applet) I'm trying to modify this code to read a text file (items.txt) that looks like this:
    item # description price(this line does not appear in the text file)
    001 shaving cream 400.00
    999 razors 30.00
    I need to load the item# and price from the text file into arrays(I have no clue how to use multi-dimensional arrays in java and would prefer not to)
    I need to search the arrays based on the values entered by the user (item # and quantity) calculate the total for that item then create a new text file which has each line item for that order in the form:
    item# quant price per item total(price per item*quant entered)
    also also I need to be able to display the four items listed above after each loop as well as all the previous item number and quantities they selected until they indicate they don't want to select anymore.
    I've been working on this for days and it seems like nothing I try works. My major problems are:
    1. I have no idea how to read the text file and load those 2 items into their respective arrays
    2. I can't seem to create a textfile that looks like text for the output file.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.*;
    import java.util.Locale;
    public class arraySelection
        extends JApplet {
      //Initialize the applet
      private Container getContentPane=null;
      public void init() {
           String string_item, string_quantity;
           String output = "";
           String description= "";
           int counter= 0;
           int itemNumber= 0;
           double quantity = 0 ;
           double tax_rate=.07;
           double total= 0, price= 0;
           double tax, subtotal;
           double Pretotal= 0;
           double priceArray[] = {1, .5, 3.65, 0.02, 0.09};
           String descriptionArray[] = {"salt", "pepper", "paprika", "garlic", "thyme"};
         // create number format for currency in US dollar format
         NumberFormat moneyFormat = NumberFormat.getCurrencyInstance( Locale.US );
         //format to have the total with two digits precision
         DecimalFormat twoDigits = new DecimalFormat("0.00");
         //Jtextarea to display results
         JTextArea outputArea = new JTextArea ();
         // get applet's content pane
          Container container = getContentPane ();
          //attach output area to container
          container.add(outputArea);
         //set the first row of text for the output area
        output +=  "Invoice\nItem#\tDescription\tQuant@Price\t Line Total" + "\n";
        do //begin loop structure obtain input from user
               // obtain item number from user
               string_item = JOptionPane.showInputDialog(
                   "Please enter an item number 1, 2, 3, 4, or 5:");
               //obtain quantity of each item that user enter
               string_quantity = JOptionPane.showInputDialog("Enter the quantity:");
               // convert numbers from type String to Integer or Double
               itemNumber = Integer.parseInt(string_item);
               quantity = Double.parseDouble(string_quantity);
                 switch (itemNumber) {//Determine input from user to assign price and description
                    case 10: // user input item =10
                      price = priceArray[0];
                      description = descriptionArray[0];
                      break;
                    case 20: // user input item =20
                      price = priceArray [1];
                      description = descriptionArray[1];
                      break;
                    case 30: //user input item =30
                      price=priceArray[2];
                      description = descriptionArray[2];
                      break;
                    case 40: //user input item =40
                      price=priceArray[3];
                      description = descriptionArray[3];
                      break;
                    case 50: //user input item =50
                      price=priceArray[4];
                      description = descriptionArray[4];
                      break;
                    default: // user input item is not on the list
                    output += "Invalid value entered"+ "\n";
                    price=0;
                    description= "";
             //Calculates the total for each item number and stores it in subtotal
             subtotal = price * quantity;
             //display input from user
             output += itemNumber + "\t" + description + "\t\t"+ quantity + "@" +
                       moneyFormat.format( price) + "\t" + moneyFormat.format( subtotal) + "\n";
             //accumulates the overall subtotal for all items
             Pretotal = Pretotal + subtotal;
            //verifies that the user wants to stop entering data
            string_item = JOptionPane.showInputDialog(" Enter a positive integer to continue or 0 to stop. ");
            itemNumber = Integer.parseInt(string_item);
          // loop termination condition if user's input is 0 .It will end the loop
       } while ( itemNumber!= 0);
        tax = Pretotal * tax_rate; // calculate tax amount
        total = Pretotal + tax; //calculate total = subtotal + tax
        //appends data regarding the subtotal, tax, and total to the output area
        output += "\n" + "Order Subtotal" + "\t" + moneyFormat.format( Pretotal) +
                  "\n" + "Tax" + "\t\t" + twoDigits.format( tax ) + "\n" + "Order Total" +
                  "\t\t" + moneyFormat.format( total );
         //attaches the data in the output variable to the output area
         outputArea.setText( output );
      } //end init
    }// end applet InvoiceAny help or sugestions would be greatly appreaciated. I've been working on this for over a week and everything I try goes nowhere.

    First answer: You shouldn't ask multiple questions in the same thread. Ask a specific question, with an appropriate subject line (optionally, assign the number of Dukes you are willing to give for the help). When question #1 is answered and question #2 arises, it's time for a new thread (don't forget to give out Dukes before moving on).
    Second answer: I think you need a Transfer Object (http://java.sun.com/blueprints/patterns/TransferObject.html). It's whole purpose is to hold/transfer instance data where it is needed. Create a class something like this:
    public class ItemTO
        private String _number;
        private String _description;
        private double _price;
        public ItemTO( String number, String description, double price )
            _number = number;
            _description = description;
            _price = price
        // Getter/Setter methods go here
    }then, in the code where you read in the file do something like this:
    BufferedReader input = null;
    try
        input  = new BufferedReader( new FileReader( "c:\\a.txt" ) );
        List items = new ArrayList();
        String line;
        String itemNumber;
        String itemDescription;
        double itemPrice;
        while ( (line  = input.readLine() ) != null )
         System.out.println( line );
            itemNumber = // Parse it from line
            itemDescription // Parse it from line
            itemPrice = // Parse it from line
            items.add( new ItemTO( itemNumber, itemDescription, itemPrice ) );
    catch ( FileNotFoundException fnfe )
        fnfe.printStackTrace();
    catch ( IOException ioe )
        ioe.printStackTrace();
    finally
        try
            if ( input != null )
                input.close();
        catch ( Exception e )
            e.printStackTrace();
    }As for how to parse the line of the file, I'll leave that to you for now. Are the three values delimited with any special characters?
    jbisotti

Maybe you are looking for