0

I'd like to join a few instructions in a single line in my NATURAL program. Just like this :

**before
    Statement1
    Statement2
    Statement3
 **after
    Statemen1 statement2 statement3

I know that is quite easy doing in most languages, but I'm not sure it's possible in Natural.

Tomás
  • 77
  • 1
  • 11

2 Answers2

3

There aren't any restrictions in the language that prevent putting statements on one line. For example, here's a whole program on one line.

DEFINE DATA LOCAL 1 #A (A10) END-DEFINE MOVE 'XX' TO #A WRITE #A END

However, that really is not fun to read and applies to all languages. Keep that in mind for the next person having to maintain the code.

Larz
  • 323
  • 4
  • 4
1

Douglas Bader, the British Flying Ace & others are quoted as saying
"Rules are for the guidance of wise men and the obedience of fools"

I always say:
"The only rule that's always valid is that no rules are always valid"

In programming we have a number of useful rules, one of which is:
"Every Statement on a new line"
...and it is wise to follow that adage, but there are exceptions.
Sometimes, you can actually improve the readablity of code by breaking the rule.

Here's an example (written in Natural):

define data
    local 1     DATE-FROM (D)  /* (D=Natural Date-Format)
          1     DATE-TO   (D)
end-define

    DATE-FROM := *DatX  /* System Variable = "Today"
    DATE-TO   := DATE-FROM + 1
    perform   P800-WRITE-DATE

    DATE-FROM := DATE-TO
    DATE-TO   := DATE-FROM + 2
    perform   P800-WRITE-DATE

    DATE-FROM := DATE-TO
    DATE-TO   := DATE-FROM + 3
    perform   P800-WRITE-DATE

    DATE-FROM := DATE-TO
    DATE-TO   := DATE-FROM + 4
    perform   P800-WRITE-DATE

define subroutine P800-WRITE-DATE
    write  DATE-FROM(em=DD.MM.YYYY)
           DATE-TO  (em=DD.MM.YYYY)
end-subroutine
END

Now, I would write the doing-bit of that as follows:

DATE-FROM := *DatX      DATE-TO := DATE-FROM + 1    perform P800-WRITE-DATE
DATE-FROM := DATE-TO    DATE-TO := DATE-FROM + 2    perform P800-WRITE-DATE
DATE-FROM := DATE-TO    DATE-TO := DATE-FROM + 3    perform P800-WRITE-DATE
DATE-FROM := DATE-TO    DATE-TO := DATE-FROM + 4    perform P800-WRITE-DATE

It's much easier to understand, spot typos & deliver quality.

The Output today was:

28.02.2021  01.03.2021
01.03.2021  03.03.2021
03.03.2021  06.03.2021
06.03.2021  10.03.2021

Getting back to the original question:
in Natural, you may end a Statement with a ";" but it is not necessary. The following is perfectly valid:

DATE-FROM := *DatX    ;  DATE-TO := DATE-FROM + 1  ;  perform P800-WRITE-DATE;
DATE-FROM := DATE-TO  ;  DATE-TO := DATE-FROM + 2  ;  perform P800-WRITE-DATE;
DATE-FROM := DATE-TO  ;  DATE-TO := DATE-FROM + 3  ;  perform P800-WRITE-DATE;
DATE-FROM := DATE-TO  ;  DATE-TO := DATE-FROM + 4  ;  perform P800-WRITE-DATE;

While we're at it, another little typing-aid is the continuation character "-", originally conceived for continuing literals on the next line, but can also be used to increase readability:

define data
    local 1     DATE-A8 (a8)
end-define

    DATE-A8 := '20211231'

    DATE-A8 := '2021' - '12' - '31'

    DATE-A8 := '2021'
            -  '12'
            -  '31'
END

I hope you found that useful.

Dave The Dane
  • 650
  • 1
  • 7
  • 18
  • That's my point - improve readability for little groups of statements that make sense being in a single "sentence". And saving screen space sometimes help seeing a whole "procedure" in a single screen (when using 3270 editor). – Tomás Mar 03 '21 at 11:34
  • This continuation character is a very useful resource. I didn't know that. Thanks! – Tomás Mar 03 '21 at 11:37
  • 1
    Since you mention 3270: most people work with 24*80 resolution, some with 43*80 & others with 27*132 (useful for job output), but it is possible to work with 43*132 in Terminal-Emulation & Natural does support that. If you want to know more, I suggest you start a new Thread. – Dave The Dane Mar 03 '21 at 12:02
  • That's a great topic that I'd like to know, despite that my company is migrating the editing to an Eclipse-based Natural IDE where I can even use my favourite local editor. – Tomás Mar 15 '21 at 12:01
  • Which IDE? NaturalONE (aka. Natural Designer) or the other one? With NaturalONE there is still an issue with linesize & pagesize, because you have to set it on the Server, not on the Client (there is a Thread for that in Software AG's Tech Community). At my current customer we run 2 Servers: 1 for "normal" 24*80 & one on another Port for a larger Pagesize. – Dave The Dane Mar 15 '21 at 13:42
  • We´re using NaturalONE. About this linesize issue I didn't notice that, for now. Actually I'm using Sublime Text for some editing, and NaturalOne for everything else. – Tomás Mar 18 '21 at 15:38