ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Edit word for 0, 1, 2 and 3 decimal places

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Edit word for 0, 1, 2 and 3 decimal places

    Hi guys I'm confused how to use the edit code. For example I have an amount in a field, let's say 12000000

    what is the edit code for zero decimal place? for 1 decimal? 2 decimal? 3 decimal?

    I only know 2 decimal: ' ,.'

    any ideas?

    Here's the reference:
    Edit Words
    Edit words are patterns or masks that are specified in RPG output specifications. They are used to create ad hoc edits for numeric values, such as phone numbers, social security numbers, sales figures, and the time of day. Table 2.23 lists various edit-word masks.


    Edit Word
    Code:
        
    Description 
     *...v....1....v... 
     Unedited Value 
     Edited Output 
     
    Large value
     ' ,.' 
     00654321 
     6,543.21 
     
    Stop zero suppression
     ' , 0 . ' 
     00000027 
     0.27 
     
    Time of day
     '0 : :' 
     071223 
     07:12:23 
     
    Social Security number
     '0 - - ' 
     023456789 
     023-45-6789 
     
    Phone number
     '0( )& - ' 
     8005551212 
     (800) 555-1212 
     
    Floating currency symbol
     ' , , $0. ' 
     000009402 
     $94.02
    The number of blanks plus the zero suppression control code (i.e., the leading zero or asterisk) within an edit word must be greater than or equal to the number of digits for the field or named constant being edited.

    Because editing a numeric value often changes the overall size of the value, RPG uses ending positions for the output location of fields in the output specification. This allows the right sides of numeric values to be aligned properly after editing.


    Edit words consist of four optional elements:

    Body. The body is the area of the edit word where the numeric value is positioned.

    Status. The status is the area of the edit word consisting of the letters CR or a - (minus) sign. The status is used to indicate whether the value is negative or positive.

    Expansion. The expansion area follows the body and status (usually literal values).

    Literal values. Literal values can appear anywhere in the edit word. Literal values are included in the output only when significant digits appear to the left of the literal value. Note: While a named constant can be used as an edit word, named constants cannot be used within (i.e., as part of) the edit word itself.

    Edit Word Control Codes
    There are several control codes that can be inserted into an edit word to control zero suppression, leading asterisks, floating currency symbol, blanks, and decimal notation. The first occurrence of a control code is used as the control code. Except for the ampersand (&), which is always used as a control code, subsequent occurrences are treated as literal values. Table 2.24 contains a description of the edit word control codes that can be used in an edit word.

    Code:
    Table 2.24: Edit Word Control Codes  Control Code 
     Description 
     
    $
     Currency Symbol If the currency symbol is followed immediately by a zero,
     the currency symbol precedes the first significant digit. This is referred to 
    as a floating currency sign. If the currency symbol is not followed by a zero, 
    the currency symbol's position is fixed. When using the floating currency 
    symbol, an available blank position is displaced. Typically, the displaced 
    blank is shifted to the left of the currency symbol. The character used 
    as the currency symbol is specified by the CURSYM keyword on the 
    header specification.
     
    *
     Asterisk. Leading zeros are replaced with asterisks to the position 
    of the asterisk. Zero suppression ends at the position of the asterisk.
     
    &
     Ampersand. Always replaced with a blank when output.
     
    0
     Zero. Ends zero suppression at the position of the zero. 
    The zero is used as one of the output positions for digits to appear.
     
    (period)
    
    , (comma)
     Decimal Notation. These characters are not actual control codes; 
    they are treated as literal values. They are traditionally used for 
    decimal notation and thousands notation.
     
    b 
     Blanks. Identifies available positions for the numeric value.
     
    CR
     Status. The literal value CR is output if the value is negative.
     
    -
     Status. The - (minus) sign is output if the value is negative.
    Tip Be careful when using literal values in an edit word. Literal
    values can be any characters, including the letters CR. The first
    occurrence of the letters CR, however, is interpreted as the
    status code and will not appear when the number is greater
    than or equal to zero.


    Edit Words and Named Constants
    To use an edit word, place the desired edit word—left justified—
    into output constant/edit word positions of the output specification
    for the field being edited. The RPG output specification accepts
    edit word literal values of up to 48 positions. For edit words that
    exceed 48 positions, the entry can be continued onto a second
    output line or a named constant can be used. Edit words can be
    up to 115 positions in length and can be specified—left justified—
    into output constant/edit word positions of the output specification.
    Figure 2.20 contains examples of edit-word usage.

  • #2
    Re: Edit worf for 0, 1, 2 and 3 decimal places

    why not just use %EDITC???
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: Edit worf for 0, 1, 2 and 3 decimal places

      i can only use rpg 400 mate

      Comment


      • #4
        Re: Edit worf for 0, 1, 2 and 3 decimal places

        there's still a place in the output specs for edit code
        I'm not anti-social, I just don't like people -Tommy Holden

        Comment


        • #5
          Re: Edit worf for 0, 1, 2 and 3 decimal places

          i'll check it out. by the way it should be written in O specs for internally described printer file.

          Comment


          • #6
            Re: Edit worf for 0, 1, 2 and 3 decimal places

            yep....if you prompt the O spec you'll see this:
            Code:
            Prompt type . . .    P      Sequence number . . .  0038.00       
                                                                             
                        Field     Edit              End                      
            N01N02N03   Name      Code      B/A   Position      P/B/L/R      
                        ACCT       Z                  14                     
            Constant / Edit Word
            I'm not anti-social, I just don't like people -Tommy Holden

            Comment


            • #7
              Re: Edit worf for 0, 1, 2 and 3 decimal places

              The problem is that I must format it either in 0 decimal places 1 decimal place 2 or 3 depending on the condition or logic of my program.

              Comment


              • #8
                Re: Edit worf for 0, 1, 2 and 3 decimal places

                just dump the value in a data structure with all the sizes defined then setup a select statement and load from the correct datastructure subfield.

                jamie
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #9
                  Re: Edit worf for 0, 1, 2 and 3 decimal places

                  Or do it the long way and call a different variable defined a different way based on your logic. But that is how a freshman would code it I like Jamie's solution
                  Your future President
                  Bryce

                  ---------------------------------------------
                  http://www.bravobryce.com

                  Comment


                  • #10
                    Re: Edit worf for 0, 1, 2 and 3 decimal places

                    Thanks for all the help mate. I'll use jamief solution

                    Comment

                    Working...
                    X