ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Numeric fields

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

  • Numeric fields

    Hi,

    How to declare numeric fields in physical file with right justified and no leading zeros and negative numeric fields by prefix "-" (as the first character of the number ,with no space between the sign and the number)


    Thanks..

  • #2
    Originally posted by John192 View Post
    Hi,

    How to declare numeric fields in physical file with right justified and no leading zeros and negative numeric fields by prefix "-" (as the first character of the number ,with no space between the sign and the number)


    Thanks..
    also if we are defining any field with DFT keyword and parallely can we provide it's description like text ?



    Thanks...

    Comment


    • #3
      Originally posted by John192 View Post

      also if we are defining any field with DFT keyword and parallely can we provide it's description like text ?



      Thanks...
      I tried defining a numeric field with default value as DFT(';;') but getting error CPD5244 'Indicated value not allowed for numeric field' how can we make it possible at DDS level of file or it is not possible at DDS level of file and could just be possible at program level ?


      Thanks..

      Comment


      • #4
        You can add edit codes or edit words to numeric fields in DDS for a display file or a printer file. Look up the EDTCDE and EDTWRD keywords.

        Or in your RPG program you can use %EDITC or %EDITW to get a character version of a numeric value with the kind of editing you describe.

        You can probably find examples in the manuals.

        Comment


        • #5
          You seem to be asking the same sort of thing in multiple threads and not understanding that how something is stored in a file is different to how it is visually displayed. When something is written to a file, a computer will write it as a series of 0's and 1's (binary). Binary does not contain a space or a -, it's just 0's and 1's. What you are referring to is how it is visually displayed/represented and this is very different to how it is stored. So again, I'd ask what you are trying to achieve? Are you wanting this data written to a display file in the format you have referred? Are you trying to convert it in a program to this format or something else? Barbara has given info on using it for a display file or program.

          Comment


          • #6
            it seems it's not possible at DDS level of physical file ( I am not sure how can I do it at DDS level currently) so looks like will have to try to acheive it at program level.

            So i tried it for negative number but program is giving compilation errors

            please refer below program in which i tried it to format negative sign(-) if the field value is negative and then tried to write this record in physical file whose CSAMOT field is defined as 22P 0at DDS level of y7 physical file and which is giving following compilation errors:-

            *RNF7030 30 16 000700 The name or indicator EDITW is not defined.
            *RNF7503 30 16 000700 Expression contains an operand that is not defined.
            *RNF5197 30 18 000900 File in Factor 2 does not have allowed file type fo
            operation.
            *RNF7086 00 2 000200 RPG handles blocking for file Y7. INFDS is updated -




            Code:
            **free
            dcl-f y7 disk usage(*input)
            dcl-c editw const(-);
            read rec;
            eval csamot =5-10;
            if csamot <0;
            eval csamot= %editw(csamot: editw);
            endif;
            write rec;
            *inlr =*on;

            Thanks...

            Comment


            • #7
              Originally posted by John192 View Post
              it seems it's not possible at DDS level of physical file ( I am not sure how can I do it at DDS level currently) so looks like will have to try to acheive it at program level.

              So i tried it for negative number but program is giving compilation errors

              please refer below program in which i tried it to format negative sign(-) if the field value is negative and then tried to write this record in physical file whose CSAMOT field is defined as 22P 0at DDS level of y7 physical file and which is giving following compilation errors:-

              *RNF7030 30 16 000700 The name or indicator EDITW is not defined.
              *RNF7503 30 16 000700 Expression contains an operand that is not defined.
              *RNF5197 30 18 000900 File in Factor 2 does not have allowed file type fo
              operation.
              *RNF7086 00 2 000200 RPG handles blocking for file Y7. INFDS is updated -




              Code:
              **free
              dcl-f y7 disk usage(*input)
              dcl-c editw const(-);
              read rec;
              eval csamot =5-10;
              if csamot <0;
              eval csamot= %editw(csamot: editw);
              endif;
              write rec;
              *inlr =*on;

              Thanks...
              ..also for any blank value of a field irrespective of it's data type and length if it is blank and then we can store ';;' is that field to achieve this i tried

              if fldname= *blanks; (error :- *RNF7421 Operands are no compatible with the type of operator.)


              eval fldname = ';;' ; (ERROR :-RNF7416 the types of the right and left hand side do not match in the eval operation.)

              but got this error *


              thanks....

              Comment


              • #8
                i was able to put - sign by using below program:-

                Code:
                **free
                
                dcl-f     y7   disk(*update: *output);
                
                dcl-s  fld2  char(3);
                
                eval   y7fld =10;
                
                eval  fld2 = %trim(%editc(y7fld:'N':'-'));
                
                eval y7fld = fld2;
                
                *INLR=*ON;
                but the problem in this code is like that some of the y7 file's fields are numeric and alphanumeric for numeric field though this %edic is working in above example code and in fld2 it does display value as '-10' but when i move it to file y7's y7fld which is defined as 2p 0 (packed with 2 length and decimal position zero) then i get compilation error *RNF7416- The types of the right and left hand side do not match in the eval operation now how can i move these '-' sign in y7fld of file y7 if during any calculation it's value(y7fld's value) is less than zero?


                Thanks...

                Comment


                • #9
                  If you want to assign a numeric value in an alphanumeric field to a numeric field, you have to convert the alphanumeric field to a numeric value using %DEC or %DECH.

                  For the case where you have the numeric value in an alphanumeric field, do you really have that alphanumeric field in your database? Or are you just experimenting with assigning the edited alphanumeric value back to the numeric field?

                  Comment


                  • #10
                    ok, thanks but when I do below :-


                    Code:
                    dcl-f y7 disk(*update: *output);
                    
                    dcl-s fld2 char(3);
                    
                    eval y7fld =10;
                    
                    eval fld2 = %trim(%editc(y7fld:'N':'-'));
                    
                    eval y7fld = %dec(fld:3:0);
                    
                    write  rec;
                    
                    *INLR=*ON;
                    I get '10-' value written in my 'y7fld' field of physical file y7 not the value '-10' which i want to be written as per my above program.
                    and y7fld is defined as 3p 0,had to increase it's length actual length was 2p 0 only just increased 1 length in the view of that minus sign '-' in this field bur despite increasing it's length ,using %editc ,%dec unable to write '-10' in this field.

                    however in debug mode value of 'fld2' is shown correctly as i wish like '-10' but value of physical file's field 'y7fld' is displayed as '-010' and it's actually written as '10-'.

                    so what should i do to correct it,without increasing the actual length of physical file's fields can't we put these signs like minus'-' etc. in numeric fields of physical files?



                    thanks...




                    Comment


                    • #11
                      Where are you seeing "10-" for a numeric field in a file?

                      A 2p field can hold the value -10; you don't need 3p for that. The 2p field occupies 2 bytes, where each digit occupies 4 bits and the sign is in the last 4 bits, either x'D' for negative or x'F' for positive. So the value -10 is stored in a 2p field as x'010D'. The value +10 would be x'010F'.

                      So you don't need to add an extra digit to a packed field if it might be negative.

                      I don't understand what you mean about getting "10-" where you want "-10".

                      Also, I don't understand what you're doing with the %editc. Maybe you just want %char(y7fld). That would return "10" for the value 10, or "-10" for the value -10.

                      Comment


                      • #12
                        And again, the system is storing the number in the PF as a binary value. It is not stored as -10 or 10- or anything else like that, it is stored as a series of 0's and 1's. What you are referring to here is how it is displayed. The value will be displayed differently depending on what utility you use to display it. Some utilities will display it with leading zeros, some won't, some will put the sign at the beginning, others at the end. I don't understand why you are so hung up about this and why you can't understand the difference between how it's stored and how it's displayed.
                        You mention your field is a packed field, 2 digits long. The system will allocate 2 bytes to store this in. The system will store the value -10 as 0000000100001101 or 010D in hex. The D tells the system it's a negative number. If I display this using query, it shows it as 10-. If I display it using the SQL GUI in ACS, it shows it as -10. If I display it using STRSQL from the command line, it displays it as 10-. I haven't created a program to debug it so I can't see how that will show it but I suspect it might be 010- or -010. The point is, how the value is displayed is how the utilities display them and has nothing to do with how it is stored.

                        Comment


                        • #13
                          thanks, but what changes should I make in my program so that when i do runqry or STRSQL on y7 file then should be able to see value of y7fld field as '-10' ?


                          i used %edic to get that minus sign displayed for y7fld ,also how can we use that %char here to get desired value of y7fld displayed as '-10' ?


                          To identify and display negative values stored in this y7fld ,I want to put minus sign '-' before all such values.



                          Thanks ....

                          Comment


                          • #14
                            thanks, but what changes should I make in my program so that when i do runqry or STRSQL on y7 file then should be able to see value of y7fld field as '-10' ?


                            i used %editc to get that minus sign displayed for y7fld ,also how can we use that %char here to get desired value of y7fld displayed as '-10' ?


                            To identify and display negative values stored in this y7fld ,I want to put minus sign '-' before all such values.



                            Thanks ....

                            Comment


                            • #15
                              I simply want to display all negative values stored in y7fld fields by putting minus sign('-') in front of y7fld values so that when I do 'runqry' or 'strsql' on y7 file then I should be able to display it on screen.

                              So what changes in my program should I do to achieve this?


                              Thanks...

                              Comment

                              Working...
                              X