Add spaces in arithmetic expressions

Hi experts,
i have to insert spaces in arithmetical expressions written by users.
For example:
INPUT (by USERS): A+B-SQRT(C)/(D**2)
OUTPUT (by Program): A + B - SQRT( C ) / ( D ** 2 )
Possible arithmetic operators are:
+; - ; *; /; **; SQRT()
Any hints will be rewarded.
Thanks in advance.
Fabio.

Thanks to all guys!
the right code is a mixt of yours hints:
  l_len = STRLEN( tb_mzcatc-/bic/zformatc ).
  DO.
    l_char = input+n(1).
    CASE l_char.
      WHEN 'Q' OR
           'R'.
        CONCATENATE formula l_char INTO formula.
      WHEN 'T'.
        l_char = input+n(2).
        CONCATENATE formula l_char INTO formula.
        n = n + 1.
      WHEN '*'.
        IF input+n(2) = '**'.
          l_char = input+n(2).
          CONCATENATE formula l_char INTO formula SEPARATED BY ' '.
          n = n + 1.
        ELSE.
          CONCATENATE formula l_char INTO formula SEPARATED BY ' '.
        ENDIF.
      WHEN OTHERS.
        CONCATENATE formula l_char INTO formula SEPARATED BY ' '.
    ENDCASE.
    n = n + 1.
    IF n GT l_len.
      EXIT.
    ENDIF.
  ENDDO.
Message was edited by:
        Fabio Cappabianca

Similar Messages

  • Need help regarding Arithmetic Expressions

    Hi Experts,
    I have a requirement where in I need to pass Arithmetic Expressions (+,-,/) as constants to a subroutine.For ex:
    constants:c_p   type char1 value '+',
                     c_m   type char1 value '-',
    data:v_a type char1 value '2',
             v_b type char1 value '6',
            v_r    type string.
    v_r = v_ a   + v_b.
    In the above instead of + I want use c_p.Please help me out is there any other way in defining Arithmetic expresiions where I could use constants or variables instead of directly using these expressions(+,-).Thanks in advance.
    With Regards,
    Srini..

    Hello Srini,
    I think you must have a look at the FMs belonging to FuGr. CALC.
    For e.g.,  EVAL_FORMULA which evaluates Literal or Variable formulas
    CONSTANTS:
    C_P TYPE CHAR1 VALUE '+',
    C_M TYPE CHAR1 VALUE '-'.
    DATA:
    V_A TYPE CHAR1 VALUE '2',
    V_B TYPE CHAR1 VALUE '6',
    V_FORMULA TYPE STRING,
    V_RES_F   TYPE F,
    V_RES_P   TYPE P.
    CONCATENATE V_A C_P V_B INTO V_FORMULA SEPARATED BY SPACE.
    CALL FUNCTION 'EVAL_FORMULA'
      EXPORTING
        FORMULA                 = V_FORMULA
      IMPORTING
        VALUE                   = V_RES_F
      EXCEPTIONS
        DIVISION_BY_ZERO        = 1
        EXP_ERROR               = 2
        FORMULA_TABLE_NOT_VALID = 3
        INVALID_EXPRESSION      = 4
        INVALID_VALUE           = 5
        LOG_ERROR               = 6
        PARAMETER_ERROR         = 7
        SQRT_ERROR              = 8
        UNITS_NOT_VALID         = 9
        MISSING_PARAMETER       = 10
        OTHERS                  = 11.
    IF SY-SUBRC = 0.
      MOVE V_RES_F TO V_RES_P.
      WRITE: V_RES_P .
    ENDIF.
    BR,
    Suhas

  • Regular expressions to parse arithmetic expression

    Hello,
    I would like to parse arithmetic expressions like the following
    "5.2 + cos($PI/2) * -5"where valid expression entities are numbers, operations, variables and paranthesis. Until now I have figured out some regular expressions to match every type of entities that I need, and combine them into one big regex supplied to a pattern and matcher. I will paste some code now to see what I wrote:
    public class RegexTest {
        /** A regular expression matching numeric expressions (floating point numbers) */
        private static final String REGEX_NUMERIC = "(-?[0-9]+([0-9]*|[\\.]?[0-9]+))";
        /** A regular expression matching a valid variable name */
        private static final String REGEX_VARIABLE = "(\\$[a-zA-Z][a-zA-Z0-9]*)";
        /** A regular expression matching a valid operation string */
        public static final String REGEX_OPERATION = "(([a-zA-Z][a-zA-Z0-9]+)|([\\*\\/\\+\\-\\|\\?\\:\\@\\&\\^<>'`=%#]{1,2}))";
        /** A regular expression matching a valid paranthesis */
        private static final String REGEX_PARANTHESIS = "([\\(\\)])";
        public static void main(String[] args) {
            String s = "5.2 + cos($PI/2) * -5".replaceAll(" ", "");
            Pattern p = Pattern.compile(REGEX_OPERATION + "|" + REGEX_NUMERIC + "|" + REGEX_VARIABLE + "|" + REGEX_PARANTHESIS);
            Matcher m = p.matcher(s);
            while (m.find()) {
                System.out.println(m.group());
    }The output is
    5
    2
    +
    cos
    $PI
    2
    5There are a few problems:
    1. It splits "5.2" into "5" and "2" instead of keeping it together (so there might pe a problem with REGEX_NUMERIC although "5.2".matches(REGEX_NUMERIC) returns true)
    2. It interprets "... * -5" as the operation " *- " and the number "5" instead of " * " and "-5".
    Any solution to solve these 2 problems are greately appreciated. Thank you in advance.
    Radu Cosmin.

    cosminr wrote:
    So, I've written some concludent examples and the output after parsing (separated by " , " ):
    String e1 = "abs(-5) + -3";
    // output now: abs , ( , - , 5 , ) , + , - , 3 ,
    // should be:  abs , ( , -5 , ) , + , - , 3 , (Notice the -5)
    I presume that should also be "-3" instead of ["-", "3"].
    String e2 = "sqrt(abs($x=1 + -10))";
    // output now: sqrt , ( , abs , ( , $x , = , 1 , + , - , 10 , ) , ) ,
    // should be:  sqrt , ( , abs , ( , $x , = , 1 , + , -10 , ) , ) ,   (Notice the -10)
    String e3 = "$e * -1 + (2 - sqrt(4))";
    // output now: $e , * , - , 1 , + , ( , 2 , - , sqrt , ( , 4 , ) , ) ,
    // should be:  $e , * , -1 , + , ( , 2 , - , sqrt , ( , 4 , ) , ) ,
    String e4 = "sin($PI/4) - 3";
    // output now: sin , ( , $PI , / , 4 , ) , - , 3 , (This one is correct)
    String e5 = "sin($PI/4) - -3 - (-4)";
    // output now: sin , ( , $PI , / , 4 , ) , - , - , 3 , - , ( , - , 4 , ) ,
    // should be:  sin , ( , $PI , / , 4 , ) , - , -3 , - , ( , -4 , ) ,  (Notice -3 and -4)I hope they are relevant, If not I will supply some more.I made a small change to REGEX_NUMERIC and also put REGEX_NUMERIC at the start of the "complete pattern" when the Matcher is created:
    import java.util.regex.*;
    class Test {
        private static final String REGEX_NUMERIC = "(((?<=[-+*/(])|(?<=^))-)?\\d+(\\.\\d+)?";
        private static final String REGEX_VARIABLE = "\\$[a-zA-Z][a-zA-Z0-9]*";
        public static final String REGEX_OPERATION = "[a-zA-Z][a-zA-Z0-9]+|[-*/+|?:@&^<>'`=%#]";
        private static final String REGEX_PARANTHESIS = "[()]";
        public static void main(String[] args) {
            String[] tests = {
                "abs(-5) + -3",
                "sqrt(abs($x=1 + -10))",
                "$e * -1 + (2 - sqrt(4))",
                "sin($PI/4) - 3",
                "sin($PI/4) - -3 - (-4)",
                "-2-4" // minus sign at the start of the expression
            Pattern p = Pattern.compile(REGEX_NUMERIC + "|" + REGEX_OPERATION + "|" + REGEX_VARIABLE + "|" + REGEX_PARANTHESIS);
            for(String s: tests) {
                s = s.replaceAll("\\s", "");
                Matcher m = p.matcher(s);
                System.out.printf("%-21s-->", s);
                while (m.find()) {
                    System.out.printf("%6s", m.group());
                System.out.println();
    }Note that since Java's regex engine does not support "variable length look behinds", you will need to remove the white spaces from your expression, otherwise REGEX_NUMERIC will go wrong if a String looks like this:
    "1 - - 1"Good luck!

  • Add space between set of Symbols - Grep Question

    hi everyone,
    I have another Grep question someone hopefully can help with. I need to find the following symbols in my long document < > + =      
    All these symbols need space either side of the character. I would like to setup a grep expression and have it find the symbols and add spaces either side. So far I can find each symbol but can't figure out how to add spaces before and after with the replace feature?
    find:
    =|<|>|+
    replace:
    can anyone help..
    lister

    Use this line in Find option: \+|\=|<|>
    Use this line in Replace option: <space>$0<space>
    Siva

  • How do I add a second Airport Express for Airtunes only?

    I already have one Airport Express hooked up to my G5 for wireless internet. Works just fine. How, in simple english, do I add a second Airport Express to my downstairs stereo fot playing my iTunes music through.
    I have looked through the help sections, but it all comes across too complicated sounding. It can't be that hard.
    What do I do to set it up & NOT screw up my already working internet conection?
    I have the audio cable hooked up to my stereo/Airport Express downstairs & the Airport Express plugged in... "Yellow Light" lit on Express, what next?
    Thanks fellow Mac Fans!

    For the AX connected to the speakers:
    To set up AirTunes on the AirPort Express Base Station (AX), using the AirPort Admin Utility, connect your computer directly (using an Ethernet cable) to the Ethernet port of the AX, and then, try these settings:
    AirPort tab
    - Base Station Name: <whatever you wish or use the default>
    - Wireless Mode: Join an Existing Wireless Network (Wireless Client)
    - Wireless Network: <select the existing wireless network>
    Music tab
    - Enable AirTunes on this base station (checked)
    - Enable AirTunes over the Ethernet port (optional)
    - iTunes Speaker Name: <whatever you wish>
    - iTunes Speaker Password (optional)
    In iTunes:
    iTunes > Preferences... > Advanced > General
    - Look for remote speakers connected with AirTunes (checked)

  • How to add spaces at the end of record

    Hi Friends,
    i am creating a file which contains more than 100 records.
    In ABAP i have internal table with on field(135) type c.
    some time record have length 120, somtime 130 its vary on each record.
    but i would like to add space at the end of each record till 135 length.
    Can you please help me how to add speace at the end of record.
    regards
    Malik

    So why did you said that in your first posting? My glass sphere is out for cleaning...
    Instead of type c use strings and add spaces until they have the appropriate length.
    loop at outtab assigning <pout>.
      while strlen( <pout>-val ) < 135.
        concatenate <pout>-val `` into <pout>-val.
      endwhile.
    endloop.

  • My HD is almost full. I need to add space. Can I use an external HD to continue using my startup disc as it is?

    My HD is almost full. I need to add space. Can I use an external HD to continue using my startup disc as it is?
    I create music and have run out of space. the message says 'your startup disc is almost full', and i just thought maybe buying an external hard drive and using it as the startup disc or whatever would do the trick. Does anyone know? Thanks!

    External hard drives are relatively inexpensive...see some of those on OWC, www.macsales.com
    You can use a large external drive to provide additional space by simply saving material to that volume instead of the startup disk.  You can also partition the external drive to use part for Time Machine backups, and another partition for extended space.  Or a third partition for a clone of the boot system made by Carbon Copy Cloner or SuperDuper, both free downloads, so should the internal drive have problems you could always boot from the external partition.
    All of that can be done from Disk Utility.
    Keep in mind that Mac OS X gets very unhappy when there is less than 15% of the startup disk space free.

  • Can I add a second Airport Express?

    I have an Extreme Base Station connected to my Time Warner Cable Modem. It comes into my house in my office, which is over my garage, a separate structure in my backyard. The iMacs there are connected via Ethernet to the Apple Base Station. In my house, maybe 30 feet away, where I use two Macbook Pro's, iPhone 6, iPad 3 etc, all via Wireless, I have an Airport Express as an extender to amplify the signal because my house with it's lathe walls is a great shield. This works OK up to a point. The further away I get from the Airport Express, the fainter the signal gets.
    Naturally, the farthest room away is my family room with a Smart TV, Apple TV, A/V receiver, DirecTV Cinema box, Playstation3 etc. I just added an Amazon FireStick TV via HDMI. It found my wireless network perfectly and joined. Problem is, it's buffering like crazy when I try to watch a movie and reporting "bandwidth too low". So I have a problem. I need to boost the signal one more time.
    Can I add a second Airport Express to my existing network as an extender, which now consists of a Extreme BaseStation and one Airport Express.
    If not, does anyone have any ideas?
    Thank you.

    Can I add a second Airport Express to my existing network as an extender, which now consists of a Extreme BaseStation and one Airport Express.
    Sorry, but no. Even if it was possible, the speed loss would be amazing, and would really hurt, not help the current network performance.
    Probably not the answer that you want to hear, but the only way to get the same signal strength and speed from your office to a location in the home is to run an Ethernet cable between the two locations.
    There is no loss of signal or speed through an Ethernet cable up to 330 feet, or 100 meters. Good old Ethernet cable. Nothing comes close to a wire in terms of performance.
    I faced a similar problem, and while the initial outlay to the electrician was significant, it has been the best investment that I ever made in terms of improving network performance....far better than the "improvement" with any new product, or any new router or any new technology that might have been available.
    If you absolutely cannot run the Ethernet cable, then a pair of Ethernet Over Powerline (EOP) adapters might be able to send the Ethernet signal over the existing power lines in your office and home.
    The theory with EOP products is that you already have the wiring in place.....you just need the adapters. Unfortunately, things do not always work as well in practice as the theory might suggest.......having the signal hop several different circuits would be one major challenge.....whether the office and home are on the same master circuit would be a question as well.
    Given your situation, I would not even consider trying EOP adapters unless the store agreed to take them back within 7-14 days if they don't work well for you.

  • I have an airport extreme attached to cable, then one airport express to extend the range. when i try to add an additional airport express to extend range in another area of house, can't get it to work. unility says it has found a new base station

    i have an airport extreme attached to cable, then one airport express to extend the range. when i try to add an additional airport express to extend range in another area of house, can't get it to work. utility says it has found a new base station and asks if i want to use it. if i click yes, then the old setup is disabled.

    Ok, thanks for clarifying which models you have. Please see the following Apple Support article on how to configure these older base stations for a Wireless Distribution System (WDS).

  • "ABAP Basics" Book - arithmetic expression error in the sample code

    Hi all,
    I have just started learning ABAP on mini SAP system (NW7.01) by following "ABAP Basics" book.
    This question might be a FAQ, but I have spent a few days searching a right answer without success.
    I appreciate if you could help me on this.
    On the page 162, there is a function module sample, which contains the line as following:
    e_amount = i_km * '0.3'.
    Here l_km (import) is type of i, and e_amount (export) is type of f.
    Though I do not think of any problem with this line, it throws an arithmetic expression error when executed directly for testing as well as when called from a program.
    When I tried a similar thing in a program, it was fine.
    However within a function module it throws this error.
    Thanks in advance.
    Terry

    Like I said before, I do not think any problem about the code itself.
    I suspect some environmental things?
    I should have mentioned SAP mini system NW7.01 is running on Vista Business?
    To be specifc, I receive this message:
    Arithmetic operations are only expected for operands that can be converted to numbers.
    (numeric operands). - (numeric operands). - - - -
    with the following function module:
    [code]
    FUNCTION ZPTB00_CALCULATE_TRAVEL_EXPENS.
    ""Local Interface:
    *"  IMPORTING
    *"     VALUE(I_KM) TYPE REF TO  I
    *"  EXPORTING
    *"     VALUE(E_AMOUNT) TYPE REF TO  F
    *"  EXCEPTIONS
    *"      FAILED
    e_amount = i_km * '0.3'.
    IF sy-subrc <> 0.
      RAISE failed.
    ENDIF.
    ENDFUNCTION.
    [/code]

  • Add spaces in XML tag in XI mapping

    Hello guys,
    In an IDoc to XML file scenario within XI, we want to add spaces at the end of an IDoc field that contains text description. When the IDoc gets generated on SAP ECC, the IDoc field is repeated so many times until all the contents are displayed, separated with spaces. However, once the IDoc is sent to XI, the spaces get lost. Is it possible to add a space at the end of each field presence within XI message mapping or they will get lost again ?
    Thank you.
    Best Regards,
    Evaggelos Gkatzios
    Edited by: Evaggelos Gkatzios on Nov 12, 2010 4:49 PM

    > In an IDoc to XML file scenario within XI, we want to add spaces at the end of an IDoc field that contains text description.
    The way IDoc processing works, that does not make any sense at all.
    An IDoc is a fixed length container and the fields are filled with spaces automaticically.
    The IDoc XML generation removes trailing spaces to reduce message size.
    If you need trailing spaces in an XML field, you can add them easily with a UDF. But I think that there are only rare scenarios where you really would need this.

  • How to add space between two tabs in accodion widget?

    Hi! I am using the accordion widgets and trying to add space between each of the tabs, would someone help me on this. Thanks

    Directly editing the output of Muse is virtually always a bad idea. At a minimum it will create a very cumbersome workflow since Muse will overwrite your changes every time you re-export (export, upload, publish, preview).
    It depends on exactly what visual effect you want to achieve, but you probably just need to select the accordion widget and use the Spacing panel to adjust the vertical gutter value.

  • Add space

    Hi!
    I have a string lets say str... i know what the maximum length of this string can be .Lets assume it to be 30. the data value thats coming into this string is of length 5 chars. what i want to do is to add spaces after the data value upto its maximum length..liek in this case i should add 25 spaces to make it of length 30. Is there any function in java using which i could do it.There is an option for finding the present length and using a loop to add spaces.. but that would be a bit lengthy.. Pls help .. Thanx..

    > PS... i did not get what you meant by 1 of
    loop....and in that length() function
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
    In the link above there is given an example of a for loop (statement). The variable int i starts at 1 and gets incremented to a certain value. You need to adjust the initial size and the "end" size of i.
    In the loop you append, or prepend, a white space to your String.

  • Add space between Pop Menu Magic items?

    Is there a way to add space between the menu items in
    generated by Pop Menu Magic? By this I mean, can you have the
    various menu items (the "tabs" or "buttons") exist with some space
    between them
    (something
    like this but with maybe more space), as opposed to the default
    way the "tabs" are generated (butted up to one another
    like
    this)?
    I have tried editing the p7pm CSS to acheive this in a page
    design I'm roughing out. I get close sometimes but no cigar.....I
    have tried messing with the list items in the HTML code itself, but
    no luck there either.
    Hope I am making enough sense here....
    Thanks,
    Tommy

    Have you asked the question on the PVII newsgroup? You'd
    probably get a
    much faster response over there
    Nadia
    Adobe� Community Expert : Dreamweaver
    http://www.csstemplates.com.au
    - CSS Templates | Free Templates
    http://www.perrelink.com.au
    - Web Dev
    http://www.DreamweaverResources.com
    - Dropdown Menu Templates|Tutorials
    http://www.adobe.com/devnet/dreamweaver/css.html
    "steelkat" <[email protected]> wrote in
    message
    news:e5fapn$kmo$[email protected]..
    > Is there a way to add space between the menu items in
    generated by Pop
    > Menu
    > Magic? By this I mean, can you have the various menu
    items (the "tabs" or
    > "buttons") exist with some space between them <a
    target=_blank
    > class=ftalternatingbarlinklarge
    > href="
    http://css.maxdesign.com.au/listamatic/vertical11.htm">(something
    > like
    > this but with maybe more space)</a>, as opposed to
    the default way the
    > "tabs"
    > are generated (butted up to one another <a
    target=_blank
    > class=ftalternatingbarlinklarge
    > href="
    http://www.projectseven.com/viewer/index.asp?demo=pmm">like
    > this)</a>?
    >
    > I have tried editing the p7pm CSS to acheive this. I get
    close sometimes
    > but
    > no cigar.....I have tried messing with the list items in
    the HTML code
    > itself,
    > but no luck there either.
    >
    > Hope I am making enough sense here....
    >
    > Thanks,
    >
    > Tommy
    >

  • How do I add spaces in mission control in mountain lion?

    I use an external monitor on the right side of my mbp, the external monitor (when in use) is my main screen. I want my (auto retracting) dock on the right side of my right screen (the external one). The top right corner is my hot corner for mission control.
    With this setup, when I move my mouse to the right top corner I'll enter mission control, but somehow the "add a new space pop-up button" will not show up. I haven't tried this setup in Lion so I do not know if this is a bug for ML. I really like my dock on the right side of the screen, left is no option and I'm sick of having it at the bottom, but I do want to be able to add spaces, any thoughts how to do this?

    multiple ways,
    go to mission control and:
    hold option, a half of a desktop with a plus will appear, click it.
    drag an application's window next to the spaces there are already.
    put an app in fullsreen mode.
    move mouse over the top left side of the screen, and the desktop with the plus sign will appear to add a new space.

Maybe you are looking for

  • How to get the groups info for user

    Hi guys i am new to ALUI.. i am trying to do some enhancement. i want to know how to get the information of the users group and the group details using the IDK API? Can sombody share some code?

  • List box in search help

    is it possible to attach a listdown box for a search help field.. when F4 is given for a field the search help is displayed, can a drop down be attached to the search field in this.

  • How to Sync webgallery to iPhoto???????

    So as I upgraded to leopard i reinstalled iPhoto. Now how can I get .mac web gallery to sync to my clean installation of iPhoto? Is there a way to get the pics uploaded back to my computer? thanks

  • Buffalo Link Station Live

    Hi, I've got Infinity with a Home Hub 3 and the Huawei box in front of it.  Have a Buffalo Link Station on the gigabit port of the hub and all works fine - can view files from the LS on any device connecting to the hub either wired or wireless and th

  • Iphoto stops responding when trying to export photos

    I'm trying to prepare my photos from my summer holiday for the internet by using the Share>Export feature and letting the program resize them while I'm at it. The first batch worked perfectly, I resized some 250 photos, however I'm not able to finish