ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Explanation: Declaration for a string and an integer

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

  • Explanation: Declaration for a string and an integer

    Hello,

    Here is an example below

    Code:
         H
    
         D Name            S             20A
         D Number       S              5S 0
          *
          /Free
    
            Name = 'Juliette';
            dsply Name;
            Number = 2;
            dsply ('Number ' + %Char(Number ) );
            *inlr = *on;
          /End-Free

    Concerning the declaration for the Name variable, I have 2 questions:


    1) The 'S' after the declaration of the variable corresponds to ?
    2) The 'A' corresponds to 'alphabetical' and if it's alphanumeric?


    Concerning the declaration for the Number variable,

    1) the values '5' corresponds to ?
    2) the 'S' after the value 5 corresponds to ?


    Thank you

  • #2
    The S means "Stand-alone", which means it is not part of a data-structure definition.
    The A means character data. You can put any characters you like in it, and they will always be treated as if they were just text - they will never be treated like a number.
    The 5 means 5 digits in total (because you have a 0, it means all 5 will be the left of the decimal point)
    The S there means 'zoned decimal' (!) It relates to the way the number is represented in memory.

    Comment


    • #3
      Welcome to the community Juliette - great to have a new developer on board.

      To add to RayGilliesJones explanation, here is a great article on the difference between defining variables in column based and all-free.
      Perhaps the biggest changes from RPG fixed format to free format are the definitions of variables, data structures, and constants

      Comment


      • #4
        Hello,

        Thank you very much RayGilliesJones for your explanations. I understood.

        Thank you Ghost + for the website.

        Comment


        • #5
          Couple of comments just to clarify Juliette.

          Strictly speaking your field Number is not an integer. It is a zoned decimal numeric with zero decimal places which is not quite the same thing. In most languages that support decimal math (RPG and COBOL among others) numerics can have decimal places. If you wanted a real integer the data type would be an I(nteger) or a U(nsigned integer). The other type of numerics that RPG supports are type F(loating point) and P(acked decimal).

          As a newcomer (and assuming you know other languages) you will almost certainly find it easier to learn the free-form syntax for RPG. Your definitions in that format would be:
          Code:
          Dcl-s Number Zoned(5); // Or Zoned(5:0) is acceptable
          Dcl-s Name Char(20);
          Dcl-s Number Int(5); /// For a true integer
          I should also point out that /Free and /End-Free are not required and have not been for some time.

          And since Ghost has already pointed you to Simon's stuff I feel no guilt in promoting my own humber offerings which you can find here: https://authory.com/jonparisandsusangantner where among other things you can find my "Geezers Guide" to free-form RPG and (if you are interested) a br ief history of the development of the RPG IV language.

          Comment


          • #6
            Thanks JonBoy - I had no idea that link existed to view all of your writings. Will add that to my package of links for future use.

            And take my word for it Juliette , the Geezers Guide is filled to the brim with exceptionally useful information.

            Comment


            • #7
              Glad to hear it Ghost. We started it after IBM Systems Magazine told us they were going to "reorganize" their web site and drop most of the older articles. Since the last two re-orgs they had done resulted in the loss of a bunch of links, we decided it was time to take control of our own material.

              If you ever find that the full article that you link from our Authory site is missing just let us know and we will make the cached version public. We can't do that as a default since technically the magazines owns the original version so we have to link to them if they have it.

              Paul Tuohy also has an Authory collection if you like his stuff https://authory.com/paultuohy

              In both cases you can sign up to receive emails whenever new stuff is published. In the future we intend to publish some things only on Authory.

              Comment


              • #8
                Brilliant! Cheers JonBoy !! We definitely don't want these good resources vanishing. Appreciate it.

                Comment


                • #9
                  Wellcome aboard, Juliette.

                  Simon Hutchinson has an excellent homepage - most of it is for the more experienced programmer
                  but some of it I think will help you.

                  Take a look at this article about "Defining variables in RPG all free".
                  Perhaps the biggest changes from RPG fixed format to free format are the definitions of variables, data structures, and constants


                  Simons homepage is here:
                  This blog is about the IBM i, formerly the AS400, and offers advice about programming, operations, communications and anything else I can think of

                  Comment


                  • #10
                    Hello,

                    Thank you Peder Udesen. ^^

                    Comment

                    Working...
                    X