2

I tried to get 10 digit format value from integer(actual format is 4 digit). But its trimming prefix zero and return the same value.

Let me share what I tried.

DEFINE VARIABLE idata AS INTEGER NO-UNDO.
DEFINE VARIABLE iValue AS INTEGER NO-UNDO.

idata = 111.

iValue = INTEGER(STRING(idata, "99999999999")).

DISPLAY iValue.

May I know what is wrong here? and way to get an answer for my question?

Thiru
  • 231
  • 6
  • 20

3 Answers3

4

Do you want

0000000111 to be displayed?

Then use 9 to describe the format. It will insert 0. > Will inser

DEFINE VARIABLE idata AS INTEGER NO-UNDO.

idata = 111.

DISPLAY iData FORMAT "9999999999".

Or simply

DEFINE VARIABLE idata AS INTEGER NO-UNDO FORMAT "9999999999".

idata = 111.

DISPLAY iData.

To convert it to a 10 character string with zeros prefixed:

DEFINE VARIABLE idata AS INTEGER   NO-UNDO.
DEFINE VARIABLE cdata AS CHARACTER NO-UNDO.

idata = 111.

cData = STRING(iData, "9999999999").

DISPLAY cData.
Jensd
  • 7,886
  • 2
  • 28
  • 37
3
DISPLAY iValue FORMAT "99999999999" .
Mike Fechner
  • 6,627
  • 15
  • 17
  • One more doubt that as you know iValue is now 10 char(actual is 3) when we displaywe can see 10 char format but how can i assign that into another int variable?? if we do that then its happening the same(trimmed prefix 0) – Thiru Jul 12 '19 at 07:17
  • The integer will be stored as 3 characters. You have to define the display format each time you display the variable. – jdpjamesp Jul 12 '19 at 07:31
  • What? each time i need to display with the format? Is there no way to store the format in integer filed in progress 4GL? – Thiru Jul 12 '19 at 07:43
  • 2
    I suggest you have a look at the syntax of the DEFINE VARIABLE statement. That allows to specify the FORMAT as well and that's used whenever you use the DISPLAY statement (but not MESSAGE, etc.). – Mike Fechner Jul 12 '19 at 08:27
3

Your problem is that storage is independent of display format.

Unlike SQL, Progress does not link the two together. This is a feature and a strength of the 4gl.

Storage of data depends on the datatype. For an integer the range is from: -(2^31) to ((2^31) - 1)

(To make it even more exciting -- under the hood storage of every data type, including integers, is variable length. No more space is used than is necessary. Your programs have no way to know that and it really doesn't matter except to a DBA who is planning for disk space requirements.)

Every field or variable also has a default DISPLAY format. For integers the default format is "->,>>>,>>9". You can always override this when you define or display a field or variable. It has no impact on the storage of the data and does not affect assignments in any way.

Every data type also has EXPORT format which allows the full precision of the underlying data without any additional formatting characters such as commas, leading zeros, currency symbols etc.

Tom Bascom
  • 13,405
  • 2
  • 27
  • 33