Aligning output

Hi, does anyone know any quick methods on how to align output in java programs. I wrote this program that inputs an item number, name and price and than prints those things in columns, but if someone enters a name too long than all the formatting gets mixed up. Here is the program:
import javax.swing.JOptionPane;
import java.text.NumberFormat;
class Input extends Printout {
     public void Ask(){
          System.out.println("--------------------------------------------------------------------------------");
          System.out.println("                               Comedy Video House");
           System.out.println("                               1225 Programmers Road");
           System.out.println("                               Customer Invoice");
           System.out.println("--------------------------------------------------------------------------------");
           System.out.println("ITEM #\t\t\t\t ITEM NAME\t\t\t\t PRICE");
           System.out.println("--------------------------------------------------------------------------------");
          for (int i = 0; (nIN > 0); i++){
          ItemNumber = JOptionPane.showInputDialog("Input Item Number:");
          nIN = Integer.parseInt(ItemNumber);
          if (nIN <= 0){
               break;//If item numbere is 0 or less than exit loop
          ItemName = JOptionPane.showInputDialog("Input Item Name:");
          ItemPrice = JOptionPane.showInputDialog("Input Item Price:");
          nIP = Double.parseDouble(ItemPrice);
          System.out.println(nIN + "\t\t\t\t" + ItemName + "\t\t\t\t" + nIP);
          Subtotal = Subtotal + nIP;
          PST = (Subtotal * 0.08);
          GST = (Subtotal * 0.07);
          Total = Subtotal + PST + GST;
          System.out.println(" ");
          System.out.println("\t\t\t\t" + "Subtotal: " + "\t\t\t\t" + formatter.format(Subtotal));
          System.out.println(" ");
          System.out.println("\t\t\t\t" + "PST: " + "\t\t\t\t" + formatter.format(PST));
          System.out.println("\t\t\t\t" + "GST: " + "\t\t\t\t" + formatter.format(GST));
          System.out.println(" ");
          System.out.println("\t\t\t\t" + "TOTAL: " + "\t\t\t\t" + formatter.format(Total));
public class Printout {
     String ItemNumber;
     String ItemName;
     String ItemPrice;
     int nIN = 1;
     double nIP;
     double Subtotal;
     double PST, GST;
     double Total;
     //set currency format for costs
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    public static void main(String[] args) {
     Input aInput = new Input();
     aInput.Ask();
   }Thanks

you could just only show a maximum of whatever number of characters you want to have. for example:
String name = "Goolahee Butkiss";
if(name.length()>12){
    name = name.substring(0,12);
}Kind of a workaround but take it or leave it

Similar Messages

  • How to align output formatted and output text in the same line?

    Hi All,
    I want an output formatted label and a text on the same line,. I've surrounded these components wth a panel form layout and they automatically align one below the other. how do I kepe them in the same line?
    Thanks.

    Try as per the code snippet below:
    <af:document title="TestPage.jspx" id="d1">
    <af:messages id="m1" inline="true"/>
    <af:form id="f1">
    *<af:panelGroupLayout id="pgl1" layout="horizontal">*
    *<af:outputFormatted value="outputFormatted1" id="of1"/>*
    *<h:outputText value="outputText1" id="ot1"/>*
    *</af:panelGroupLayout>*
    </af:form>
    </af:document>
    Thanks,
    Navaneeth

  • How to align output

    How do u align Text in the JOptionPane.showMessageDialog?????
    like for example:
    mr. Benjamin singapore
    mr. christopher malaysia
    how do we align everything?

    Hi Christopher92,
    You may find some inspiration from the following coding :
    public static void main(String[] args) {
            JPanel pane = new JPanel();
            pane.setLayout(new GridLayout(2,1));
            JLabel[] labels = new JLabel[2];
            for (int i = 0; i < 2; i++) {
                labels[i] = new JLabel();
                labels.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    labels[i].setPreferredSize(new Dimension(100, 30));
    labels[i].setHorizontalAlignment(JLabel.TRAILING);
    pane.add(labels[i]);
    labels[0].setText("mr. Benjamin");
    labels[1].setText("mr. Christopher");
    JOptionPane.showMessageDialog(null, pane);

  • Console output

    Is it possible to align output text to the console?
    I'm printing a UI to the console which gives users the ability to select an option
    System.out.printf("*********************%n");
    System.out.printf("Welcome to the system%n");
    System.out.printf("Please select an select an option%n");
    System.out.printf("1 - Login with username and password%n");
    System.out.printf("2 - Create an account%n");
    System.out.printf("3 - Options%n");
    System.out.printf("4 - Exit%n");
    System.out.printf("*********************%n");
    I was wondering if I can format this text to be aligned to a certain side. Or columns if not, but I prefer alignment. Also is there a more efficient way to write a large paragraph to be output(like above)?
    Thank you!

    double post console output

  • Problem in SAP-script alignment

    Hi Experts,
    Need your help in aligning script.
    in the script output , one field "BAPIESLL-QUANTITY" in not getting display properly.
    Problem is if it fetches 6 digit value e.g.100000, it displays proprly aligned but if it fetches 2 digit values its not coming in proper alignment.
    I have maintained its left margin as 0.40 CM and TAB as 1CH left alignment.
    output is like
    1st Output                                                                                2nd Output
    ACCOM ALLOW HYDRAULIC SERV                                        ACCOM ALLOW HYDRAULIC SERV
         60                                                                                100000
    I am not getting why its showing 2 different alignment format for same filed.
    Could you please help me in this issue.
    Thanks in advance.
    Regards,
    Rachna

    Rachna,
    Welcome to SDN.
    All quantity and currency fields should be provided with Right-justified.
    also in ur code in sapscript hope u used tab notations.
    &FIELD1& ,, &FIELD2&
    here '  ,,  ' will be tab of 0.40 CM
    other wise ur field 2 will be starting after the field1.
    Regards
    Syed A

  • Formatting console output text

    Is it possible to align output text to the console?
    I'm printing a UI to the console which gives users the ability to select an option
    System.out.printf("*********************%n");
    System.out.printf("Welcome to the system%n");
    System.out.printf("Please select an select an option%n");
    System.out.printf("1 - Login with username and password%n");
    System.out.printf("2 - Create an account%n");
    System.out.printf("3 - Options%n");
    System.out.printf("4 - Exit%n");
    System.out.printf("*********************%n");
    I was wondering if I can format this text to be aligned to a certain side. Or columns if not, but I prefer alignment. Also is there a more efficient way to write a large paragraph to be output(like above)?
    Thank you!

    To the plain-jane console? If that's what you're asking, then you should really be creating a GUI app, not a console-based one.

  • Query regarding alignment of data in Application server

    My requirement is to download data to the application server. To get an aligned output, i need to give offset position manually for each input.
    For example :
          lw_outtab+0(15) = in_itab-matnr.
          lw_outtab+25(10) = in_itab-vkorg.
              append lw_outtab to i_outtab.
            Instead of manualy giving the offset position  
    Is there is any function module to get an aligned output in the Application server directly.
    And also i would like to know if color formating is possible for the downloaded data.
    ...Waiting for ur suggestions.
    Regards,
    Dhana...

    Hi Dhanachezhiyan,
    In order to get alligned data in an outputfile to application server you could do something like this:
    Define your own types (of course you can add as much fields you need)
    TYPES: BEGIN OF ty_in_itab,
             matnr(15) TYPE c,
             buf01(10) TYPE c,
             vkorg(10) TYPE c,
             buf01(10) TYPE c,
           END   OF ty_in_itab,
    Make sure that the length here is equal to length of ty_in_itab
           ty_outtab(100) TYPE c.
    Define your own tables/workarea's
    DATA:  in_itab   TYPE ty_in_itab OCCURS 0 WITH HEADER LINE,
           in_outtab TYPE ty_outtab  OCCURS,
           lw_outtab TYPE ty_outtab.
    Logic to fill in_itab.
        MOVE CORRESPONDING VBAK TO in_itab.
        APPEND in_itab.
    After this filling logic do your trick
      LOOP AT in_itab.
        lw_outtab = in_itab.
        APPEND lw_outtab TO in_outtab.
      ENDLOOP.
    And afterwards download it
    Hope this sample will help you along.
    Regards,
    Rob.

  • Fixed field for numbers?

    Hello
    My program is to read numbers from file, and present these according to my specifications. I have succsessfully forced the output using DecimalFormatSymbols and pattern, with one exception: they do not have a fixed outputfield. I want this to be able to align the numbers at their decimal point, despite how large the numbers are.
    I know I can make a method that inserts blanks in front of the number to fill out the space. In the case the number is too large, I can adopt a FORTRAN style: ******** instead of the number. However, I would like to be consistent, and find a solution using i18n methods. And frankly, I find it hard to believe that the DecimalFormat do not support decimal-aligned formats. So, what am I missing? Can you help me?
    Regards
    JT

    The NumberFormat api mentions two ways to align output.
    import java.awt.*;
    import java.awt.font.*;
    import java.text.*;
    import javax.swing.*;
    public class Alignment
        public static void main(String[] args)
            double[] numbers = {
                100.95, 1.1234567, 21.19, 888295.16, 99.1525, 8, 16.75, 12.2
            AlignmentPanel alignmentPanel = new AlignmentPanel(numbers);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(alignmentPanel);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class AlignmentPanel extends JPanel
        Font font;
        NumberFormat nf;
        String[] text;
        final int
            top           =  50,
            decimalOffset = 100;    // from decimal to right edge of page
        public AlignmentPanel(double[] numbers)
            setBackground(Color.white);
            font = new Font("lucida typewriter regular", Font.PLAIN, 24);
            nf = new DecimalFormat("#.####");
            formatInput(numbers);
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setFont(font);
            int w = getWidth();
            int h = getHeight();
            FontRenderContext frc = g2.getFontRenderContext();
            float yPos = top;
            for(int j = 0; j < text.length; j++)
               String toDot = text[j];
               // get substring up to decimal point - integer portion
               if(text[j].indexOf(".") != -1)
                   toDot = text[j].substring(0, text[j].indexOf("."));
               // get width and height of integer portion
               float width = (float)font.getStringBounds(toDot, frc).getWidth();
               LineMetrics lm = font.getLineMetrics(toDot, frc);
               float height = lm.getHeight();
               float x = (w - width - decimalOffset);
               float y = yPos + height;
               g2.drawString(text[j], x, y);
               yPos += height;
        private void formatInput(double[] n)
            text = new String[n.length];
            int maxFractionLength = 0;
            for(int j = 0; j < n.length; j++)
                text[j] = nf.format(n[j]);
    }

  • Text Symbols printing

    is there any thing called as left justification while printing text symbols..... or pls some one help me on how to give spaces in widow editor????
    and also
    is it true that the output varies when we adjust the output by giving the spaces..???
    pls help...
    thanks,
    CAPC

    HI,
    &SYMBOL& No formatting
    &SYMBOL+4& Offset - Output begins here. Offset refers to formatted value
    &SYMBOL(5)& Length - Output data in the specified length
    &SYMBOL(I)& Suppress initial value - If the field has been initialized, nothing is output
    &SYMBOL(Z)& Suppress leading zeros
    &SYMBOL(C)& Compress blank spaces - Consecutice spaces are compressed into a single space. Leading spacesare suppressed.
    &SYMBOL(R)& Right align output
    &SYMBOL(S)& Operators are suppressed
    &SYMBOL(*)& Dictionary length - The data length is defined by the ABAP dictionary
    &SYMBOL(8.2)& Decimal format. Length 8 decimals 2
    &'text1'SYMBOL'text2'& Text can be inserted before and after the symbol
    By default symbols are printed with left justification

  • Formating technique problem in list ouput

    hi friends .
    iam doin a report  i want blank output if there is no value in date ,and quantity field and also iam calculating when the result is in
    negative it should display -2 but its displaying 2- can any body pls help me.
    reagrds
    farukh

    hi
    if ur using scripts u can use like this
    <b>&ITCDP-TDULPOS& 100.00-
    &ITCDP-TDULPOS(<)& -100.00</b>
    in abap reports chk these formatting options
    WRITE - Formatting options
    Options:
    ... NO-ZERO
    ... NO-SIGN
    ... NO GROUPING
    ... DD/MM/YY
    ... MM/DD/YY
    ... DD/MM/YYYY
    ... MM/DD/YYYY
    ... DDMMYY
    ... MMDDYY
    ... YYMMDD
    ... CURRENCY w
    ... DECIMALS d
    ... ROUND r
    ... UNIT u
    ... TIME ZONE tz
    ... EXPONENT e
    ... USING EDIT MASK mask
    ... USING NO EDIT MASK
    ... UNDER g (only with WRITE)
    ... NO-GAP (only with WRITE)
    ... LEFT-JUSTIFIED
    ... CENTERED
    ... RIGHT-JUSTIFIED
    Note
    The formatting options UNDER g and NO-GAP are intended only output to lists and therefore cannot be used with WRITE ... TO.
    Option
    ... NO-ZERO
    Effect
    If the contents of f are equal to zero, only blanks are output; if f is of type C or N, leading zeros are replaced by blanks.
    Option
    ... NO-SIGN
    Effect
    The leading sign is not output if f is of type I, P or F.
    Option
    ... NO GROUPING
    Effect
    If f has the type I or P, the thousand separators are omitted.
    Option
    ... DD/MM/YY
    Option
    ... MM/DD/YY
    Effect
    If f is a date field (type D), the date is output with a 2-character year as specified in the user's master record. Both of these formatting options have the same value.
    Option
    ... DD/MM/YYYY
    Option
    ... MM/DD/YYYY
    Effect
    If f is a date field (type D), the date is output with a 4-character year as specified in the user's master record. Both of these formatting options have the same value.
    Option
    ... DDMMYY
    Option
    ... MMDDYY
    Effect
    Date formatting like the additions ... DD/MM/YY and ... MM/DD/YY, but without separators.
    Option
    ... YYMMDD
    Effect
    If f is a date field (type D), the date is output in the format YYMMDD (YY = year, MM = month, DD = Day).
    Option
    ... CURRENCY w
    Effect
    Correct format for currency specified in the field w.
    Treats the contents of f as a currency amount. The currency specified in w determines how many decimal places this amount should have.
    The contents of w are used as a currency key for the table TCURX; if there is no entry for w, the system assumes that the currency amount has 2 decimal places.
    Option
    ... DECIMALS d
    Effect
    d specifies the number of decimal places for a number field (type I, P or F) in d. If this value is smaller than the number of decimal places in the number, the number is rounded. If the value is greater, the number is padded with zeros.
    Since accuracy with floating point arithmetic is up to about 15 decimal places (see ABAP number types), up to 17 digits are output with floating point numbers (type F). (In some circumstances, 17 digits are needed to differentiate between two neighboring floating point numbers.) If the output length is not sufficient, as many decimal places as possible are output. Negative DECIMALS specifications are treated as DECIMALS 0.
    Example
    Effect of different DECIMALS specifications:
    DATA: X TYPE P DECIMALS 3 VALUE '1.267',
          Y TYPE F            VALUE '125.456E2'.
    WRITE: /X DECIMALS 0,  "output: 1
           /X DECIMALS 2,  "output: 1.27
           /X DECIMALS 5,  "output: 1.26700
           /Y DECIMALS 1,  "output: 1.3E+04
           /Y DECIMALS 5,  "output: 1.25456E+04
           /Y DECIMALS 20. "output: 1.25456000000000E+04
    Option
    ... ROUND r
    Effect
    Scaled output of a field of type P.
    The decimal point is first moved r places to the left (r > 0) or to the right (r < 0); this is the same as dividing with the appropriate exponent 10**r. The value determined in this way is output with the valid number of digits before and after the decimal point. If the decimal point is moved to the left, the number is rounded.
    For further information about the interaction between the formatting options CURRENCY and DECIMALS, see the notes below.
    Example
    Effect of different ROUND specifications:
    DATA: X TYPE P DECIMALS 2 VALUE '12493.97'.
    WRITE: /X ROUND -2,   "output: 1,249,397.00
           /X ROUND  0,   "output:    12,493.97
           /X ROUND  2,   "output:       124.94
           /X ROUND  5,   "output:         0.12
    Option
    ... UNIT u
    Effect
    Formats a value according to the unit specified in the field u.
    The contents of f are treated as a quantity. The unit specified in u determines how many decimal places should be output.
    If f has more places after the decimal point than determined in u, the output value will only have the number of decimal places determined by u, unless the operation truncates digits other than zero.
    If f has fewer places after the decimal point than determined by u, the option has no effect.
    The contents of u are used as a unit in the table T006, but if there is no entry, the formatting option has no effect.
    The field f which is to be output must have the type P. This option is used for table fields which have the Dictionary type QUAN, or for fields defined with reference to such fields ( DATA ... LIKE ...).
    This formatting option excludes the options DECIMALS and ROUND.
    Example
    Suppose the unit 'STD' has 3 decimals
    DATA HOUR TYPE P DECIMALS 3 VALUE '1.200'.
    WRITE (6) HOUR UNIT 'STD'. "output:   1,2
    HOUR = '1.230'.
    WRITE (6) HOUR UNIT 'STD'. "output: 1,230
    Option
    ... TIME ZONE tz
    Effect
    Outputs f as a time stamp with reference to time zone tz.
    f must have type P(8) (short form) or type P(11) with 7 decimal places (long form). tz must have type C(6). You can specify the type exactly by using DATA ... LIKE ... with reference to the appropriate elements of the structure TZONREF in the ABAP Dictionary.
    It is assumed that the time stamp f is in UTC time (see GET TIME STAMP FIELD f). The system then uses the time zone tz to determine the difference from UTC time and converts the time stamp. If tz has the initial value ' ', the time stamp is output in UTC time
    Outputting a time stamp in long form requires 27 characters, the short form requires 19. The date (corresponding to a date output with length 10) is formatted according to the setting in the user master record. There is a space between date and time. In the time part (corresponding to a time output with length 8), the system inserts ':' as a separator. If you output a time stamp in its long form, the system separates seconds and fractions of seconds using a comma. If you use an output length shorter than the default, all separators in both the time and date parts are omitted. If the time stamp is still too long, the system omits the spaces between the date and the time. After this, the output is truncated from the right-hand end. If you specify a date formatting option that uses separators, these are not suppressed, even when you shorten the output.
    If the time stamp f is inconsistent, or the system cannot find the time zone tz, it places a '*' as the first character of the output. The time stamp f is then output without taking the time zone into account (in other words, as UTC time). The output is shifted one character to the right, and the last character is omitted.
    If time zone tz does not exist, you may need to create (or recreate) it in table TTZZ.
    You may not use the TIME ZONE option with CURRENCY, DECIMALS, EXPONENT, NO-SIGN, NO-GROUPING, NO-ZERO, ROUND or UNIT.
    Example
    Effect of the TIME ZONE option:
    DATA: S_TST  TYPE timestamp,
          L_TST  TYPE timestampl.
    SET COUNTRY 'US'.
    GET TIME STAMP FIELD S_TST.   " S_TST = 19971224111245
    GET TIME STAMP FIELD L_TST.   " L_TST = 19971224111245,1234567
    WRITE: S_TST TIME ZONE 'UTC+12', " 12/24/1997 23:12:45
        /, L_TST TIME ZONE 'UTC+12', " 12/24/1997 23:12:45,1234567
        /, (18) S_TST TIME ZONE 'UTC+12', " 24121997 231245
        /, (26) L_TST TIME ZONE 'UTC+12', " 24121997 231245,1234567
        /, S_TST TIME ZONE 'UTC+12' DD/MM/YY, " 12/24/97 23:12:45
        /, S_TST TIME ZONE 'no tz ' DD/MM/YY. " *12/24/97 11:12:4
    Option
    ... EXPONENT e
    Effect
    The field e defines a fixed exponent for a floating point number (type F). The mantissa is adjusted to the exponent by moving the decimal point and padding with zeros. With EXPONENT 0, the exponent specification is suppressed.
    However, if the output length is too short to accommodate all digits before the decimal point, the standard output format is used.
    Example
    Effect of different EXPONENT specifications:
    DATA: X TYPE P VALUE '123456789E2'.
    WRITE: /X     EXPONENT 0,    "output:     12345678900,000000
           /X(10) EXPONENT 0,    "output:  1,235E+10
           /X     EXPONENT 3,    "output:  12345678,90000000E+03
           /Y     EXPONENT -3,   "output:  12345678900000,00E-03
           /Y     EXPONENT 9,    "output:  12,34567890000000E+09
           /Y     EXPONENT 2
           /Y     DECIMALS 4.    "output:     123456789,0000E+02
    Option
    ... USING EDIT MASK mask
    Effect
    Outputs f according to the formatting template mask.
    Without this addition, f is output in the standard format for that particular type or with a format defined in the ABAP Dictionary. The addition allows you to define a different format.
    You can specify the formatting template as follows:
    '_'represents one character of the field f
    or one digit with type P or I
    'V'only with fields of type P or I:
    output of leading sign
    'LL'at beginning of template:
    left justify (standard)
    'RR'at beginning of template:
    right justify
    '==conv'perform output conversion conv
    ':', ...separator
    (all other characters)
    When formatting, the characters '_' in the template are replaced from the left ( 'LL') or from the right ('RR') by the characters or digits (type P or I) of the field f.
    Notes
    When using a template, you must specify the an explicit output length because otherwise the implicit output length of the field f is used. Usually, the template is longer than the implicit output length.
    If the leading sign is to be output with a field of type P or I, you must specify the wildcard character V at the desired place. If this character does not appear in the template, no leading sign will be output if the value of f is negative.
    When formatting a field of type P with decimal places, the value is not aligned with a character in the template representing the decimal point (either a period or a comma). If you want to have this character in the output, you must insert it in the correct position in the template and define the formatting from the right. If there is no character for the decimal point in the template, no such character is output.
    Fields of type F are first converted to the standard format and the resulting sequence is then copied to the template in the case of a field of type C.
    You implement the user-specific conversion conv with a function module called CONVERSION_EXIT_conv_OUTPUT, e.g. CONVERSION_EXIT_ALPHA_OUTPUT for the conversion of numeric values with leading zeros to a format without leading zeros for type C fields. If a Dictionary field is output and the domain of that field defines a conversion routine, this is executed automatically. For a description of the conversion, refer to the documentation of the appropriate function module.
    Example
    Formatted output of the time:
    DATA TIME TYPE T VALUE '154633'.
    WRITE (8) TIME USING EDIT MASK '__:__:__'.  "Output: 15:46:33
    If the output length "(8)" was not specified here, the output would be "15:46:" because the implicit output length for the type T is 6.
    Option
    ... USING NO EDIT MASK
    Effect
    Switches off a conversion routine specified in the ABAP Dictionary.
    Option
    ... UNDER g
    Effect
    Output of the field f begins at the column from which the field g was output. If this happens in the same output line, the output of the field g is overwritten.
    Note
    After UNDER, the field g must be written exactly as the reference field in the previous WRITE statement, i.e. with an offset and length if necessary. The exception to this rule is if g is a text symbol. In this case, the reference field is determined by the number of the text symbol (not by the text stored there).
    Example
    Align output to the reference fields:
    FIELD-SYMBOLS <FNAME>.
    ASSIGN 'First Name' TO <FNAME>.
    WRITE: /3 'Name'(001), 15 <FNAME>, 30 'RoomNo', 40 'Age'(002).
    WRITE: /   'Peterson' UNDER 'Name'(001),
               'Ron'      UNDER <FNAME>,
               '5.1'      UNDER 'RoomNo',
           (5) 24         UNDER TEXT-002.
    This produces the following output (numbers appear right-justified in their output fields!):
       Name          First Name     RoomNo    Age
       Peterson      Ron            5.1         24
    Option
    ... NO-GAP
    Effect
    Suppresses the blank after the field f. Fields output one after the other are then displayed without gaps.
    Example
    Output several literals without gaps:
    WRITE: 'A' NO-GAP, 'B' NO-GAP, 'C'.  "Output: ABC
    If NO-GAP was not specified here, the output would have been "A B C" because one blank is always implicitly generated between consecutive output fields.
    Option
    ... LEFT-JUSTIFIED
    ... CENTERED
    ... RIGHT-JUSTIFIED
    Effect
    Left-justified, centered or right-justified output.
    For number fields (types I, P and F), RIGHT-JUSTIFIED is the standard output format, but LEFT-JUSTIFIED is used for all other types, as well as for templates.
    Examples
    Output to a list (WRITE):
    DATA: FIELD(10) VALUE 'abcde'.
      WRITE: / '|' NO-GAP, FIELD LEFT-JUSTIFIED  NO-GAP, '|',
             / '|' NO-GAP, FIELD CENTERED        NO-GAP, '|',
             / '|' NO-GAP, FIELD RIGHT-JUSTIFIED NO-GAP, '|'.
    Output: |abcde     |
            |  abcde   |
            |     abcde|
    Formatting in a program field (WRITE...TO...)
    DATA: TARGET_FIELD1(10),
          TARGET_FIELD2 LIKE TARGET-FIELD1,
          TARGET_FIELD3 LIKE TARGET-FIELD1.
    WRITE: '123' LEFT-JUSTIFIED  TO TARGET-FIELD1,
           '456' CENTERED        TO TARGET-FIELD2,
           '789' RIGHT-JUSTIFIED TO TARGET-FIELD3.
      WRITE: / '|' NO-GAP, TARGET_FIELD1 NO-GAP, '|',
    / '|' NO-GAP, TARGET-FIELD2 NO-GAP, '|',
    / '|' NO-GAP, TARGET_FIELD3 NO-GAP, '|'.
    Output: |123 |
    | 456 |
    | 789|
    Note
    Setting date format und decimal character
    Every user can specify in his/her master record (User defaults) how the date is to be formatted on output and whether the decimal character should be a comma or a period. You can also set these output parameters for a particular program by using the statement SET COUNTRY.
    Notes
    Specifying several formatting options
    You can use the additions of the first group (NO-ZERO, NO-SIGN, DD/MM/YY etc., CURRENCY, DECIMALS, ROUND, EXPONENT) simultaneously, provided it makes sense. You can combine the additions UNDER and NO-GAP with all other additions in any permutation; however, they are not taken into account until the field f has been formatted according to all the other options.
    Templates, conversion routines and alignment
    If you want to format a field using a special conversion routine , all the other additions (apart from UNDER and NO-GAP) are ignored. This also applies if the conversion routine is not explicitly specified, but comes from the ABAP Dictionary.
    If you want to format a field using a template, the system first takes into account the options of the first group, and then places the result in the template. However, if you specify one of the date-related formatting options (DD/MM/YY etc.), the template is ignored.
    Finally, the formatted field or the template is copied to the target field according to the requested alignment. For type C fields, it is the occupied length that is relevant, not the defined length; this means that trailing blanks are not taken into account.
    Combined usage of CURRENCY, DECIMALS and ROUND
    The rounding factor (from the right) in
    WRITE price CURRENCY c ROUND r DECIMALS d
    results from the formula
    rounding factor = c + r - d.
    If DECIMALS is not specified, d = c applies.
    You read this formula in the following manner:
    The field price is supposed to be of ABAP type P (or I); it contains a currency amount. The CURRENCY specification expresses how many decimal places price is to have and may differ from the definition of price (the decimal point is not stored internally, but comes from the type attributes of price). Normally, price is output with as many decimal places as the field has internally according to the type attributes or the CURRENCY specification. You can override this number of output decimal places with DECIMALS. The addition ROUND addition moves the decimal point r places to the left, if r is positive, otherwise to the right. This means that a $ amount is output with ROUND 3 in the unit 1000 $.
    According to the above formula, there can also be a "negative" rounding factor; then, the corresponding number of zeros is appended to the amount price on the right using the "rounding factor". However, the value of "rounding factor" must be at least equal to -14.
    Currency fields and DATA with DECIMALS
    If the field price is normally formatted with decimal places (e.g. fields for currency amounts), these are treated like a CURRENCY specification when rounding, if CURRENCY was not expressly specified.
    If present, the DECIMALS specification defines how many decimal places are to be output after rounding.
    If the DECIMALS and the (explicit or implicit) CURRENCY specifications are different, rounding takes place according to the above formula, even if no ROUND specification was made (i.e. r = 0).
    If a field in the DATA statement was declared with DECIMALS n, WRITE treats it like a currency field with n decimal places.
    Examples
    Sales in pfennigs or lira: 246260
    Unit TDM or TLira with 1 decimal place.
    DATA SALES TYPE P VALUE 246260.
    WRITE SALES CURRENCY 'DEM' ROUND 3 DECIMALS 1. "    2,5  TDM
    WRITE SALES CURRENCY 'ITL' ROUND 3 DECIMALS 1. "  246,3  TLira
    Sales in pfennigs or lira: 99990
    Unit TDM or TLira with 1 decimal place.
    SALES = 99990.
    WRITE SALES CURRENCY 'DEM' ROUND 3 DECIMALS 1. "   1,0  TDM
    WRITE SALES CURRENCY 'ITL' ROUND 3 DECIMALS 1. " 100,0  TLira
    Sales in pfennigs or lira: 93860
    Unit 100 DM or 100 lira with 2 decimal places:
    SALES = 93860.
    WRITE SALES CURRENCY 'DEM' ROUND 2 DECIMALS 2. "   9,38 HDM
    WRITE SALES CURRENCY 'ITL' ROUND 2 DECIMALS 2. " 938,60 HLira
    Sales in pfennigs: 93840
    Unit 1 DM without decimal places.
    SALES = 93860
    WRITE SALES CURRENCY 'DEM'         DECIMALS 0. " 938    DM
    Sales in pfennigs: 93860
    Unit 1 DM without decimal places.
    SALES = 93860.
    WRITE SALES CURRENCY 'DEM'         DECIMALS 0. " 939    DM
    Exceptions
    Non-Catchable Exceptions
    Cause: CURRENCY parameter in the WRITE statement is not of type C
    Runtime Error: WRITE_CURRENCY_ILLEGAL_TYPE
    Cause: Rounding parameter is less than -14
    Runtime Error: WRITE_ROUND_TOO_SMALL
    Cause: UNIT parameter in the WRITE statement is not of type C
    Runtime Error: WRITE_UNIT_ILLEGAL_TYPE
    plz reward if useful

  • Arabic font in Adobe forms

    Hi experts,
               I am working on displaying Arabic text in Adobe forms using Include Text.I am getting the arabic text displayed in the output from right to left(RTL) in LP01 output deive type.But the arabic text is not right aligned in the output.In smartform the same include text is coming absoulutely fine with properly right aligned in the output.But in smartform we use ZARSWIN device type for printing the arabic text.So my question  is do we need to use special device type for priting arabic text in  adobe forms.Please let me know why i am not getting the right aligned output in adobe forms for Arabic include text.
    Thanks,
    Vignesh

    Hi,
    Please check the following links,
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d4fe7fca-0b01-0010-569a-9a9c1ddf4132
    https://www.sdn.sap.com/irj/sdn/docs?rid=/webcontent/uuid/7c3bc67e-0c01-0010-dbb3-908315896909 [original link is broken] [original link is broken]
    https://www.sdn.sap.com/irj/sdn/docs?rid=/webcontent/uuid/7c3bc67e-0c01-0010-dbb3-908315896909 [original link is broken] [original link is broken]
    /people/vani.krishnamoorthy/blog/2006/05/17/fillable-adobe-forms-using-abap

  • Variables in Script

    Iam new to script can any one tell me the meaning of
    &GF_CP_TOTAL_TXBAS(R)& ,,&GF_CP_TOTAL_TXBTR(R)&
    here in brackets they used R what does it mean.
    Thanks in advance,
    RRK.
    Edited by: Alvaro Tejada Galindo on Feb 6, 2008 4:55 PM

    Hi Ravi,
    these are the formatting options available in scripts :
    &SYMBOL&      --No formatting
    &SYMBOL+4&  --Offset - Output begins here. Offset refers to formatted value
    &SYMBOL(5)&  --Length - Output data in the specified length
    &SYMBOL(I)&  --Suppress initial value - If the field has been initialized, nothing is output
    &SYMBOL(Z)&  --Suppress leading zeros
    &SYMBOL(C)&  --Compress blank spaces - Consecutive spaces are compressed into a single space. Leading spaces are suppressed.
    &SYMBOL(R)&  --Right align output
    &SYMBOL(S)&  --Operators are suppressed
    &SYMBOL(*)&   --Dictionary length - The data length is defined by the ABAP dictionary
    &SYMBOL(8.2)&  --Decimal format. Length 8 decimals 2
    &'text1'SYMBOL'text2'&  --Text can be inserted before and after the symbol
    thanks,
    satheesh

  • Show Space in Print layout

    Hi all,
    if there a value in the variable then print it else how to leave that much blank space in layout .
    Regards,
    Mohsin

    hi,
    From your post it appears that the length of the variables are same.
    BETTER GO WITH UNDER OPTION WITH WRITE STATEMENT
    CHECK THE EXTRACT BELLOW FROM sap help
    ... UNDER g
    Effect
    Output of the field f begins at the column from which the field g was output. If this happens in the same output line, the output of the field g is overwritten.
    Note
    After UNDER, the field g must be written exactly as the reference field in the previous WRITE statement, i.e. with an offset and length if necessary. The exception to this rule is if g is a text symbol. In this case, the reference field is determined by the number of the text symbol (not by the text stored there).
    Example
    Align output to the reference fields:
    FIELD-SYMBOLS <FNAME>.
    ASSIGN 'First Name' TO <FNAME>.
    WRITE: /3 'Name'(001), 15 <FNAME>, 30 'RoomNo', 40 'Age'(002).
    WRITE: /   'Peterson' UNDER 'Name'(001),
               'Ron'      UNDER <FNAME>,
               '5.1'      UNDER 'RoomNo',
           (5) 24         UNDER TEXT-002.
    REGARDS,
    ANIRBAN

  • Enable to get the aligned XML Publisher Report output

    Hi All,
    In BI Publisher report there is a column called short_text which have data like
    i) Price Basis : Free Delivery to Tata Power SED
    (ii) Delivery time : Within 6 weeks from the date of PO
    (iii) Payment : After acceptance within 7 Days
    (iv) Freight : Nil
    (v) Insurance : Nil
    (vi) Packing & Forwarding :Nil
    (vii) CST/VAT : @ 5% VAT
    (viii) Excise Duty : @ 10.3%
    (ix) Service Tax : Nil
    (x) Entry Tax : Nil
    (xi) Warranty : Nil
    But the data in the output is not coming in the aligned manner like above.
    Could anyone please help on this??
    Regards,
    Swapna.

    Hello Bala,
    I wouldn't SUBMIT the same program to get the Spool number. You can achieve the same by [NEW-PAGE PRINT ON|http://help.sap.com/abapdocu_702/en/abapnew-page_print.htm#!ABAP_ADDITION_1@1@] command.
    Check the code snippet i've provided below:
    DATA: spfli_wa         TYPE spfli,
          print_parameters TYPE pri_params,
          valid_flag       TYPE c LENGTH 1.
    START-OF-SELECTION.
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          no_dialog            = 'X'
        IMPORTING
          out_parameters       = print_parameters
          valid                = valid_flag
        EXCEPTIONS
          invalid_print_params = 2
          OTHERS               = 4.
      IF valid_flag = 'X' AND sy-subrc = 0.
    *   1. Write the output to the output list(no spool is generated)
        SELECT carrid connid
               FROM spfli
               INTO CORRESPONDING FIELDS OF spfli_wa.
          WRITE: / spfli_wa-carrid, spfli_wa-connid.
        ENDSELECT.
    *   2. Write the output to SAP spool(no list is displayed)
        NEW-PAGE PRINT ON PARAMETERS print_parameters NO DIALOG.
        SELECT carrid connid
               FROM spfli
               INTO CORRESPONDING FIELDS OF spfli_wa.
          WRITE: / spfli_wa-carrid, spfli_wa-connid.
        ENDSELECT.
        NEW-PAGE PRINT OFF.
        MESSAGE i000(zibi027) WITH 'Spool' sy-spono 'is generated!!!'.
        "You can use the spool number (SY-SPONO) to email the list output
      ENDIF.
    Hope this helps.
    BR,
    Suhas

  • XML Report Excel Output Numeric & Character value left aligned

    Hi,
    I want the XML Report Excel ouput both numberic and character values to be left aligned in the report ouput. Currently my report excel ouput prints the number value right aligned and character value left aligned.
    I have tried to concat a space to the value to make that as a character value, but this gives a extra space in the report output, which shld not happen..
    Please could anyone help me with a solution.
    Thanks

    Hi Uday,
    You are making number as a string, by adding a character :) , so it will be displayed as string with space and not as number.

Maybe you are looking for