-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path8.texi
More file actions
3656 lines (2962 loc) · 199 KB
/
8.texi
File metadata and controls
3656 lines (2962 loc) · 199 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@comment *********************************************************************
@comment ** 8. Functions **
@comment *********************************************************************
@newchapter{8,Functions}
@menu
* 8.1: Intrinsic Functions.
* 8.2: Built-In System Subroutines.
@end menu
@newsection{8.1,Intrinsic Functions}
GnuCOBOL supports a wide variety of ``intrinsic functions'' that may be used anywhere in the PROCEDURE DIVISION where a literal is allowed. For example:
@example
MOVE FUNCTION LENGTH(Employee-Last-Name) TO Employee-LN-Len
@end example
Note how the word @code{FUNCTION} is part of the syntax when you use an intrinsic function. You can use intrinsic functions without having to include the reserved word @code{FUNCTION} via settings in the @syntaxref{REPOSITORY} paragraph. You may accomplish the same thing by specifying the
@switchidx{-fintrinsics} to the GnuCOBOL compiler when you compile your programs.
User-written functions (@pxref{Subprogram Types}) never require the @code{FUNCTION} keyword when they are executed, because each user-written function a program uses @i{must} be included in that program's @code{REPOSITORY} paragraph, which therefore makes the @code{FUNCTION} keyword optional.
The following intrinsic functions, known to other ``dialects'' of COBOL, are defined to GnuCOBOL as reserved words but are not otherwise implemented currently. Any attempts to use these functions will result in a compile-time error message. However they are described at the end of this chapter.
@example
BOOLEAN-OF-INTEGER
CHAR-NATIONAL
DISPLAY-OF
EXCEPTION-FILE-N
EXCEPTION-LOCATION-N
INTEGER-OF-BOOLEAN
NATIONAL-OF
STANDARD-COMPARE
@end example
@verbatim
Date and Time Formats
~~~~~~~~~~~~~~~~~~~~~
@end verbatim
For functions @code{FORMATTED-CURRENT-DATE}, @code{FORMATTED-DATE}, @code{FORMATTED-TIME}, and @code{FORMATTED-DATETIME}, the format literal argument indicates the format of the date or time value that is the result of the function. The result of the function will have the same type as its format literal, which can be alphanumeric, national or UTF-8.
For functions @code{INTEGER-OF-FORMATTED-DATE}, @code{SECONDS-FROM-FORMATTED-TIME}, and @code{TEST-FORMATTED-DATETIME}, the format literal indicates the format of the date or time value specified as the second argument of the function.
The permissible format strings are listed as follows. For a full description of each subfield in the format literals, including a range of permissible values in data associated with the formats, see the Value meanings and limits section.
@verbatim
Integer date form:
~~~~~~~~~~~~~~~~~
@end verbatim
A value in integer date form is a positive integer that represents the number of days since 31 December, 1600 in the Gregorian calendar.
It must be greater than zero and less than or equal to the value of FUNCTION INTEGER-OF-DATE (99991231), which is 3,067,671.
@verbatim
Standard date form:
~~~~~~~~~~~~~~~~~~
@end verbatim
A value in standard date form is an integer of the form YYYYMMDD, calculated using (YYYY * 10,000) + (MM * 100) + DD, where:
YYYY represents the year in the Gregorian calendar. It must be an integer in the range [1601, 9999].
MM represents a month and must be an integer in the range [01, 12].
DD represents a day and must be an integer in the range [01, 31], valid for the specified month and year combination.
@verbatim
Julian date form:
~~~~~~~~~~~~~~~~
@end verbatim
A value in Julian date form is an integer of the form YYYYDDD, calculated using (YYYY * 1000) + DDD, where:
YYYY represents the year in the Gregorian calendar. It must be an integer in the range [1601, 9999].
DDD represents the day of the year. It must be a positive integer in the range [1, 366], valid for the year specified.
@verbatim
UTC offset value:
~~~~~~~~~~~~~~~~
@end verbatim
A UTC offset value is an integer representation of offset from UTC (Coordinated Universal Time) expressed in minutes. The value must be greater than or equal to -1439 and less than or equal to 1439.
Note: The offset value 1439 represents 23 hours 59 minutes, which is one minute less than a day.
Standard numeric time form
A value in standard numeric time form is a numeric value representing seconds past midnight. The value must be greater than or equal to zero and less than 86,400
@verbatim
Date and time formats:
~~~~~~~~~~~~~~~~~~~~~
@end verbatim
For functions @code{FORMATTED-CURRENT-DATE}, @code{FORMATTED-DATE}, @code{FORMATTED-TIME}, and @code{FORMATTED-DATETIME}, the format literal argument indicates the format of the date or time value that is the result of the function. The result of the function will have the same type as its format literal, which can be alphanumeric, national or UTF-8.
For functions @code{INTEGER-OF-FORMATTED-DATE}, @code{SECONDS-FROM-FORMATTED-TIME}, and @code{TEST-FORMATTED-DATETIME}, the format literal indicates the format of the date or time value specified as the second argument of the function.
The permissible format strings are listed as follows. For a full description of each subfield in the format literals, including a range of permissible values in data associated with the formats, see Value meanings and limits.
@verbatim
Date formats Format literals
~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
Basic calendar date YYYYMMDD
Extended calendar date YYYY-MM-DD
Basic ordinal date YYYYDDD
Extended ordinal date YYYY-DDD
Basic week date YYYYWwwD
Extended week date YYYY-Www-D
Integer-seconds time formats:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Integer-seconds time formats Format literals
Basic local time hhmmss
Extended local time hh:mm:ss
Basic Coordinated Universal Time (UTC) hhmmssZ
Extended UTC time hh:mm:ssZ
Basic offset time hhmmss+hhmm
Extended offset time hh:mm:ss+hh:mm
Fractional-seconds time formats:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fractional-seconds time formats Format literals
Basic local time hhmmss.ssss
Extended local time hh:mm:ss.ssss
Basic Coordinated Universal Time (UTC) hhmmss.ssssZ
Extended UTC time hh:mm:ss.ssssZ
Basic offset time hhmmss.ssss+hhmm
Extended offset time hh:mm:ss.ssss+hh:mm
@end verbatim
Note: The period is used as the decimal separator, and four "s" characters after the period are used for illustrative purposes. The number of "s" characters that might be specified after the decimal separator in these formats might range from 1 to 9.
@verbatim
Value meanings and limits:
~~~~~~~~~~~~~~~~~~~~~~~~~
The permissible date and time formats have the following meanings and limits:
Format Meaning and limits
YYYY Year, 1601-9999
MM Month, 01-12
DD Day of month, 01-{28|29|30|31} dependent on month sub-field
DDD Day of year for ordinal date formats, 001-365|366
ww Week of year, 01-53
D Day of week, 1-7
W
-
hh Hours, 00-23
mm Minutes, 00-59
ss Seconds, 00-59
.s Fractional seconds, always prefixed with '.' then 1-9 's'
+|-hh:mm UTC offset hours (extended times only), the offset can be adjusted
upward (by a '+' prefix) or downward (by a - prefix). A prefix of 0
(zero) indicates that an offset of UTC is not available on the system.
Z UTC time indicator
@end verbatim
@verbatim
Value meanings and limits:
~~~~~~~~~~~~~~~~~~~~~~~~~
The permissible date and time formats have the following meanings and limits:
Format Meaning and limits:
~~~~~~~~~~~~~~~~~~~~~~~~~~
YYYY Year, 1601-9999
MM Month, 01-12
DD Day of month, 01-{28|29|30|31} dependent on month sub-field
DDD Day of year for ordinal date formats, 001-365|366
ww Week of year, 01-53
D Day of week, 1-7
W
-
hh Hours, 00-23
mm Minutes, 00-59
ss Seconds, 00-59
.s Fractional seconds, always prefixed with '.' then 1-9 's'
+|-hh:mm UTC offset hours (extended times only), the offset can be adjusted
upward (by a '+' prefix) or downward (by a - prefix).
A prefix of 0 (zero) indicates that an offset of UTC is not available
on the system.
Z UTC time indicator
@end verbatim
The supported intrinsic functions are listed in the following sections, along with their syntax and usage notes.
@menu
* 8.1.1: ABS
* 8.1.2: ACOS
* 8.1.3: ANNUITY
* 8.1.4: ASIN
* 8.1.5: ATAN
* 8.1.6: BIT-OF
* 8.1.7: BIT-TO-CHAR
* 8.1.8: BYTE-LENGTH
* 8.1.9: CHAR
* 8.1.10: COMBINED-DATETIME
* 8.1.11: CONCAT
* 8.1.11: CONCATENATE
* 8.1.12: CONTENT-LENGTH
* 8.1.13: CONTENT-OF
* 8.1.14: COS
* 8.1.15: CURRENCY-SYMBOL
* 8.1.16: CURRENT-DATE
* 8.1.17: DATE-OF-INTEGER
* 8.1.18: DATE-TO-YYYYMMDD
* 8.1.19: DAY-OF-INTEGER
* 8.1.20: DAY-TO-YYYYDDD
* 8.1.21: E
* 8.1.22: EXCEPTION-FILE
* 8.1.23: EXCEPTION-LOCATION
* 8.1.24: EXCEPTION-STATEMENT
* 8.1.25: EXCEPTION-STATUS
* 8.1.26: EXP
* 8.1.27: EXP10
* 8.1.28: FACTORIAL
* 8.1.29: FORMATTED-CURRENT-DATE
* 8.1.30: FORMATTED-DATE
* 8.1.31: FORMATTED-DATETIME
* 8.1.32: FORMATTED-TIME
* 8.1.33: FRACTION-PART
* 8.1.34: HEX-OF
* 8.1.35: HEX-TO-CHAR
* 8.1.36: HIGHEST-ALGEBRAIC
* 8.1.37: INTEGER
* 8.1.38: INTEGER-OF-DATE
* 8.1.39: INTEGER-OF-DAY
* 8.1.40: INTEGER-OF-FORMATTED-DATE
* 8.1.41: INTEGER-PART
* 8.1.42: LENGTH
* 8.1.43: LENGTH-AN
* 8.1.44: LOCALE-COMPARE
* 8.1.45: LOCALE-DATE
* 8.1.46: LOCALE-TIME
* 8.1.47: LOCALE-TIME-FROM-SECONDS
* 8.1.48: LOG
* 8.1.49: LOG10
* 8.1.50: LOWER-CASE
* 8.1.51: LOWEST-ALGEBRAIC
* 8.1.52: MAX
* 8.1.53: MEAN
* 8.1.54: MEDIAN
* 8.1.55: MIDRANGE
* 8.1.56: MIN
* 8.1.57: MOD
* 8.1.58: MODULE-CALLER-ID
* 8.1.59: MODULE-DATE
* 8.1.60: MODULE-FORMATTED-DATE
* 8.1.61: MODULE-ID
* 8.1.62: MODULE-PATH
* 8.1.63: MODULE-SOURCE
* 8.1.64: MODULE-TIME
* 8.1.65: MONETARY-DECIMAL-POINT
* 8.1.66: MONETARY-THOUSANDS-SEPARATOR
* 8.1.67: NUMERIC-DECIMAL-POINT
* 8.1.68: NUMERIC-THOUSANDS-SEPARATOR
* 8.1.69: NUMVAL
* 8.1.70: NUMVAL-C
* 8.1.70B: NUMVAL-C-2
* 8.1.71: NUMVAL-F
* 8.1.72: ORD
* 8.1.73: ORD-MAX
* 8.1.74: ORD-MIN
* 8.1.75: PI
* 8.1.76: PRESENT-VALUE
* 8.1.77: RANDOM
* 8.1.78: RANGE
* 8.1.79: REM
* 8.1.80: REVERSE
* 8.1.81: SECONDS-FROM-FORMATTED-TIME
* 8.1.82: SECONDS-PAST-MIDNIGHT
* 8.1.83: SIGN
* 8.1.84: SIN
* 8.1.85: SQRT
* 8.1.86: STANDARD-DEVIATION
* 8.1.87: STORED-CHAR-LENGTH
* 8.1.88: SUBSTITUTE
* 8.1.89: SUBSTITUTE-CASE
* 8.1.90: SUM
* 8.1.91: TAN
* 8.1.92: TEST-DATE-YYYYMMDD
* 8.1.93: TEST-DAY-YYYYDDD
* 8.1.94: TEST-FORMATTED-DATETIME
* 8.1.95: TEST-NUMVAL
* 8.1.96: TEST-NUMVAL-C
* 8.1.97: TEST-NUMVAL-F
* 8.1.98: TRIM
* 8.1.99: UPPER-CASE
* 8.1.100: VARIANCE
* 8.1.101: WHEN-COMPILED
* 8.1.102: YEAR-TO-YYYY
* 8.1.103: BOOLEAN-OF-INTEGER
* 8.1.104: CHAR-NATIONAL
* 8.1.105: DISPLAY-OF
* 8.1.106: EXCEPTION-FILE-N
* 8.1.107: EXCEPTION-LOCATION-N
* 8.1.108: INTEGER-OF-BOOLEAN
* 8.1.109: NATIONAL-OF
* 8.1.110: STANDARD-COMPARE
@end menu
@comment *********************************************************************
@comment ** 8.1.1 ABS **
@comment *********************************************************************
@page
@newsubsection{8.1.1,ABS}
@diagram{ABS Function,FN-ABS,FN-ABS,None}
This function determines and returns the absolute value of @var{number} (a numeric literal or data item) supplied as an argument.
Note that @code{ABSOLUTE-VALUE} has an alias for this function.
@comment *********************************************************************
@comment ** 8.1.2 ACOS **
@comment *********************************************************************
@page
@newsubsection{8.1.2,ACOS}
@diagram{ACOS Function,FN-ACOS,FN-ACOS,None}
The @code{ACOS} function determines and returns the trigonometric arc-cosine, or inverse cosine, of @var{cosine} value (a numeric literal or data item) supplied as an argument.
The result will be an angle, expressed in radians. You may convert this to an angle measured in degrees, as follows:
@example
COMPUTE @var{degrees} = ( @var{radians} * 180 ) / FUNCTION PI
@end example
@comment *********************************************************************
@comment ** 8.1.3 ANNUITY **
@comment *********************************************************************
@page
@newsubsection{8.1.3,ANNUITY}
@diagram{ANNUITY Function,FN-ANNUITY,FN-ANNUITY,None}
This function returns a numeric value approximating the ratio of an annuity paid at @var{interest-rate} (numeric data item or literal) for each of @var{number-of-periods} (numeric data items or literals).
@var{interest-rate} is the rate of interest paid at each payment. If you only have an annual interest rate and you wish to compute monthly annuity payments, divide the annual interest rate by 12 and use that value for @var{interest-rate}.
Multiply the result of this function times the desired principal amount to determine the amount of each period's payment.
A note for the financially challenged: an annuity is basically a reverse loan; an accountant would take the result of this function multiplied by -1 times the principal amount to compute a loan payment you are making.
@comment *********************************************************************
@comment ** 8.1.4 ASIN **
@comment *********************************************************************
@page
@newsubsection{8.1.4,ASIN}
@diagram{ASIN Function,FN-ASIN,FN-ASIN,None}
The @code{ASIN} function determines and returns the trigonometric arc-sine, or inverse sine, of @var{sine} value (a numeric literal or data item) supplied as an argument.
The result will be an angle, expressed in radians. You may convert this to an angle measured in degrees, as follows:
@example
COMPUTE @var{degrees} = ( @var{radians} * 180 ) / FUNCTION PI
@end example
@comment *********************************************************************
@comment ** 8.1.5 ATAN **
@comment *********************************************************************
@page
@newsubsection{8.1.5,ATAN}
@diagram{ATAN Function,FN-ATAN,FN-ATAN,None}
Use this function to determine and return the trigonometric arc-tangent, or inverse tangent, of @var{tangent} value (a numeric literal or data item) supplied as an argument.
The result will be an angle, expressed in radians. You may convert this to an angle measured in degrees, as follows:
@example
COMPUTE @var{degrees} = ( @var{radians} * 180 ) / FUNCTION PI
@end example
@comment *********************************************************************
@comment ** 8.1.6 BIT-OF **
@comment *********************************************************************
@page
@newsubsection{8.1.6,BIT-OF}
@diagram{BIT-OF Function,FN-BIT-OF,FN-BIT-OF,None}
@code{BIT-OF} function returns an alphanumeric character string of '1' and '0' characters, which represents the binary value of each byte in the argument used on input.
@enumerate
@item
The function type is alphanumeric.
@item
@var{argument-1} must be a data item, literal, or an intrinsic function result of any data class.
@end enumerate
@noindent
Returned values:
@enumerate
@item
An alphanumeric character string consisting of the binary representation of each byte in @var{argument-1}.
@item
The length of the character string returned, in bytes, is eight times the length of @var{argument-1}, in bytes.
@end enumerate
@example
>>SOURCE FREE
*> Example of use of function BIT-OF
identification division.
program-id. pgmbitof.
environment division.
configuration section.
repository. function all intrinsic.
data division.
working-storage section.
01 AAA PIC XXX VALUE "1 2".
01 BBB PIC XXX VALUE "A B".
procedure division.
display BIT-OF(1) at 0110
display BIT-OF(2) at 0210
display BIT-OF(3) at 0310
display BIT-OF(0123) at 0410
display BIT-OF(AAA) at 0510
display BIT-OF(BBB) at 0610
accept omitted
stop run.
Produces :
00110001
00110010
00110011
00110000001100010011001000110011
001100010010000000110010
010000010010000001000010
@end example
@comment *********************************************************************
@comment ** 8.1.7 BIT-TO-CHAR **
@comment *********************************************************************
@page
@newsubsection{8.1.7,BIT-TO-CHAR}
@diagram{BIT-TO-CHAR Function,FN-BIT-TO-CHAR,FN-BIT-TO-CHAR,None}
@code{BIT-TO-CHAR} function returns a character string that represents a bit pattern supplied on input.
@enumerate
@item
The function type is alphanumeric.
@item
@var{argument-1} must be an alphanumeric literal, alphanumeric data item, or alphanumeric group item.
@item
@var{argument-1} must consist only of the characters "0" and "1".
@item
The length of @var{argument-1} must be a multiple of 8 bytes.
@end enumerate
@noindent
Returned values:
@enumerate
@item
A character string consisting of bytes representing the sequence of "0" and "1" characters in @var{argument-1}.
@item
The length of the result string is equal to the length of the input string divided by 8.
@end enumerate
@example
>>SOURCE FREE
*> Example of use of function BIT-TO-CHAR
identification division.
program-id. pgmbittochar.
environment division.
configuration section.
repository. function all intrinsic.
data division.
working-storage section.
01 AAA PIC X(8) VALUE "0110000".
procedure division.
display BIT-TO-CHAR("00110000") at 0610
display BIT-TO-CHAR("00110001") at 0710
display BIT-TO-CHAR("00110010") at 0810
display BIT-TO-CHAR("00110011") at 0910
display BIT-TO-CHAR(AAA) at 1010
accept omitted
stop run.
Produces:
0
1
2
3
a
@end example
@comment *********************************************************************
@comment ** 8.1.8 BYTE-LENGTH **
@comment *********************************************************************
@page
@newsubsection{8.1.8,BYTE-LENGTH}
@diagram{BYTE-LENGTH Function,FN-BYTE-LENGTH,FN-BYTE-LENGTH,None}
@code{BYTE-LENGTH} returns the length --- in bytes --- of @var{string} (a group item, @code{USAGE DISPLAY} elementary item or alphanumeric literal). This intrinsic function is identical to the @syntaxref{LENGTH-AN} function. Note that the value returned by this function is not necessarily the number of @i{characters} comprising @var{string}, but rather the number of actual @i{bytes} required to store it.
For example, if @var{string} is encoded using a double-byte character set such as Unicode UTF-16 (where each character is represented by 16 bits of storage, not the 8-bits inherent to character sets like @sc{ASCII} or @sc{EBCDIC}), then calling this function with a @var{string} argument whose @syntaxref{PICTURE} is @code{N(4)} would return a value of 8 rather than the value 4.
Contrast this with the @syntaxref{LENGTH} function.
@comment *********************************************************************
@comment ** 8.1.9 CHAR **
@comment *********************************************************************
@page
@newsubsection{8.1.9,CHAR}
@diagram{CHAR Function,FN-CHAR,FN-CHAR,None}
This function returns the character in the ordinal position specified by @var{integer} (a numeric integer literal or data item with a value of 1 or greater) from the @syntaxrefalt{COLLATING SEQUENCE,OBJECT-COMPUTER} being used by the program.
For example, if the program is using the (default) @sc{ASCII} character set, CHAR(34) returns the 34th character in the @sc{ASCII} character set --- an exclamation-point (@samp{!}). If you are using this function to convert a numeric value to its corresponding @sc{ASCII} character, you must use an argument value one greater than the numeric value.
If an argument whose value is less than 1 or greater than 256 is specified, the character in the program collating sequence corresponding to a value of all zero bits is returned.
The following code is an alternative approach when you just wish to convert a number to its @sc{ASCII} equivalent:
@example
01 Char-Value.
05 Numeric-Value USAGE BINARY-CHAR.
@dots{}
MOVE numeric-character-value TO Numeric-Value
@end example
The @code{Char-Value} item now has the corresponding @sc{ASCII} character value.
@comment *********************************************************************
@comment ** 8.1.10 COMBINED-DATETIME **
@comment *********************************************************************
@page
@newsubsection{8.1.10,COMBINED-DATETIME}
@diagram{COMBINED-DATETIME Function,FN-COMBINED-DATETIME,FN-COMBINED-DATETIME,None}
This function returns a 12-digit numeric result, the first seven digits of which are the integer value of @var{days} argument (a numeric data item or literal) and the last five of which are the integer value of @var{seconds} argument (also a numeric data item or literal).
If @var{days} is less than 1 or greater than 3,067,671, or if @var{seconds} is less than 1 or greater than 86,400, a value of 0 is returned and a runtime error will result.
@var{days}
Must be in integer date form. For details, see Integer date form.
A value in integer date form is a positive integer that represents a number of days succeeding 31 December 1600, in the Gregorian calendar. It is based on a starting date of Monday, 1 January 1601 and integer date 1 represents Monday, 1 January 1601.
@var{seconds}
Must be in standard numeric time form. For details, see Standard numeric time form. A value in standard numeric time form is a numeric value
representing seconds past midnight.
The returned value is determined by arithmetic expression
Days-1 + (Seconds-2/100000).
The date occupies the integer part of the returned value and the time is
represented in the fractional part of the returned value.
Example
Given the integer date form value "143951", which represents the date 15 February 1995, and the standard numeric time form value "18867.812479168304", which represents the time "05:14:27.812479168304", the returned value would be exactly "143951.1886781247".
@comment *********************************************************************
@comment ** 8.1.11 CONCAT **
@comment *********************************************************************
@page
@newsubsection{8.1.11,CONCAT}
@diagram{CONCAT Function,FN-CONCATENATE,FN-CONCATENATE,None}
This function concatenates the @var{argument-1}, @var{argument-2}, @dots{} (group items, @code{USAGE DISPLAY} elementary items and/or alphanumeric literals) together into a single string result.
If a numeric literal or @code{PIC 9} identifier is specified as an argument, decimal points, if any, will be removed and negative signs in @code{PIC S9} fields or numeric literals will be inserted as defined by the @syntaxref{SIGN IS} clause (or absence thereof) of the field. Numeric literals are processed as if @code{SIGN IS TRAILING SEPARATE} were in effect.
@comment *********************************************************************
@comment ** 8.1.11 CONCATENATE **
@comment *********************************************************************
@page
@newsubsection{8.1.11,CONCATENATE}
@diagram{CONCATENATE Function,FN-CONCATENATE,FN-CONCATENATE,None}
This function concatenates the @var{string-1}, @var{string-2}, @dots{} (group items, @code{USAGE DISPLAY} elementary items and/or alphanumeric literals) together into a single string result.
If a numeric literal or @code{PIC 9} identifier is specified as an argument, decimal points, if any, will be removed and negative signs in @code{PIC S9} fields or numeric literals will be inserted as defined by the @syntaxref{SIGN IS} clause (or absence thereof) of the field. Numeric literals are processed as if @code{SIGN IS TRAILING SEPARATE} were in effect.
CONCATENATE is a GnuCOBOL extention BUT also see the ISO standard CONCAT function.
@comment *********************************************************************
@comment ** 8.1.12 CONTENT-LENGTH **
@comment *********************************************************************
@page
@newsubsection{8.1.12,CONTENT-LENGTH}
@diagram{CONTENT-LENGTH Function,FN-CONTENT-LENGTH,FN-CONTENT-LENGTH,None}
Scans for a NUL byte delimiter of the data starting at address in given pointer, and returns the length. The NUL byte is not included in the count. An EC-DATA-PTR-NUL exception is set to exist if the pointer is NUL, and a zero length is returned.
Function CONTENT-LENGTH is a GnuCOBOL extention.
@verbatim
Example:
01 ptr USAGE POINTER.
01 str PIC X(4) VALUE z"abc".
SET ptr TO ADDESS OF str.
DISPLAY FUNCTION CONTENT-LENGTH (str).
Will display 3.
@end verbatim
@comment *********************************************************************
@comment ** 8.1.13 CONTENT-OF **
@comment *********************************************************************
@page
@newsubsection{8.1.13,CONTENT-OF}
@diagram{CONTENT-OF Function,FN-CONTENT-OF,FN-CONTENT-OF,None}
Takes a pointer and optional length. Returns a character field of the data addressed by the pointer, either up to a NUL byte or to the given length.
The NUL byte is not included in the data when no optional length is given.
With an optional count, the character field can hold any content including NUL bytes,
An EC-DATA-PTR-NUL exception is set to exist if the pointer is NUL, and a zero length space is returned.
An EC-SIZE-TRANCATION is set if the resulting field would exceed character field limits and the data is truncated.
Reference modification is allowed on resulting field.
Function CONTENT-OF is a GnuCOBOL extention.
@comment *********************************************************************
@comment ** 8.1.14 COS **
@comment *********************************************************************
@page
@newsubsection{8.1.14,COS}
@diagram{COS Function,FN-COS,FN-COS,None}
The @code{COS} function determines and returns the trigonometric cosine of @var{angle} (a numeric literal or data item) supplied as an argument.
@var{angle} is assumed to be a value expressed in radians. If you need to determine the cosine of an angle measured in degrees, you first need to convert that angle to radians as follows:
@example
COMPUTE @var{radians} = ( @var{degrees} * FUNCTION PI) / 180
@end example
@comment *********************************************************************
@comment ** 8.1.15 CURRENCY-SYMBOL **
@comment *********************************************************************
@page
@newsubsection{8.1.15,CURRENCY-SYMBOL}
@diagram{CURRENCY-SYMBOL Function,FN-CURRENCY-SYMBOL,FN-CURRENCY-SYMBOL,None}
The @code{CURRENCY-SYMBOL} function returns the currency symbol character currently in effect for the locale under which your program is running. On UNIX systems, your locale is established via the
@envvarruntimeref{LANG} environment variable. On Windows, the Control Panel's "Regional and Language Options" define the locale.
Changing the currency symbol via the @syntaxref{SPECIAL-NAMES} paragraph's @code{CURRENCY SYMBOL} setting will @i{not} affect the value returned by this function.
@comment *********************************************************************
@comment ** 8.1.16 CURRENT-DATE **
@comment *********************************************************************
@page
@newsubsection{8.1.16,CURRENT-DATE}
@diagram{CURRENT-DATE Function,FN-CURRENT-DATE,FN-CURRENT-DATE,None}
Returns the current date and time as the following 21-character structure:
@example
01 CURRENT-DATE-AND-TIME.
05 CDT-Year PIC 9(4).
05 CDT-Month PIC 9(2). *> 01-12
05 CDT-Day PIC 9(2). *> 01-31
05 CDT-Hour PIC 9(2). *> 00-23
05 CDT-Minutes PIC 9(2). *> 00-59
05 CDT-Seconds PIC 9(2). *> 00-59
05 CDT-Hundredths-Of-Secs PIC 9(2). *> 00-99
05 CDT-GMT-Diff-Hours PIC S9(2)
SIGN LEADING SEPARATE.
05 CDT-GMT-Diff-Minutes PIC 9(2). *> 00 or 30
@end example
Since this function has no arguments, no parenthesis should be specified.
@comment *********************************************************************
@comment ** 8.1.17 DATE-OF-INTEGER **
@comment *********************************************************************
@page
@newsubsection{8.1.17,DATE-OF-INTEGER}
@diagram{DATE-OF-INTEGER Function,FN-DATE-OF-INTEGER,FN-DATE-OF-INTEGER,None}
This function returns a numeric calendar date in @i{yyyymmdd} (i.e. Gregorian) format. The date is determined by adding the number of days specified as @var{integer} (a numeric integer data item or literal) to the date December 31, 1600. For example, @code{DATE-OF-INTEGER(1)} returns 16010101 while @code{DATE-OF-INTEGER(150000)} returns 20110908.
A value less than 1 or greater than 3067671 (9999/12/31) will return a result of 0.
@comment *********************************************************************
@comment ** 8.1.18 DATE-TO-YYYYMMDD **
@comment *********************************************************************
@page
@newsubsection{8.1.18,DATE-TO-YYYYMMDD}
@diagram{DATE-TO-YYYYMMDD Function,FN-DATE-TO-YYYYMMDD,FN-DATE-TO-YYYYMMDD,None}
You can use this function to convert the six-digit Gregorian date specified as @var{yymmdd} (a numeric integer data item or literal) to an eight-digit format (@i{yyyymmdd}).
The optional @var{yy-cutoff} (a numeric integer data item or literal) argument is the year cutoff used to delineate centuries; if the year component of the date meets or exceeds this cutoff value, the result will be 19yymmdd; if the year component of the date is less than the cutoff value, the result will be 20yymmdd. The default cutoff value if no second argument is given will be 50.
The optional @var{yy-execution-time} argument (a numeric integer data item or literal) The default execution time value if no third argument is given will be now equivalent to specifying @code{(FUNCTION NUMVAL (FUNCTION CURRENT-DATE (1:4)))}.
@comment *********************************************************************
@comment ** 8.1.19 DAY-OF-INTEGER **
@comment *********************************************************************
@page
@newsubsection{8.1.19,DAY-OF-INTEGER}
@diagram{DAY-OF-INTEGER Function,FN-DAY-OF-INTEGER,FN-DAY-OF-INTEGER,None}
This function returns a calendar date in yyyyddd (i.e. Julian) format. The date is determined by adding the number of days specified as integer (a numeric integer data item or literal) to December 31, 1600. For example, @code{DAY-OF-INTEGER(1)} returns 1601001 while @code{DAY-OF-INTEGER(250000)} returns 2011251.
A value less than 1 or greater than 3067671 (9999/12/31) will return a result of 0.
@comment *********************************************************************
@comment ** 8.1.20 DAY-TO-YYYYDDD **
@comment *********************************************************************
@page
@newsubsection{8.1.20,DAY-TO-YYYYDDD}
@diagram{DAY-TO-YYYYDDD Function,FN-DAY-TO-YYYYDDD,FN-DAY-TO-YYYYDDD,None}
You can use this function to convert the five-digit Julian date specified as @var{yyddd} (a numeric integer data item or literal) to a seven-digit numeric Julian format (yyyyddd).
The optional @var{yy-cutoff} argument (a numeric integer data item or literal) is the year cutoff used to delineate centuries; if the year component of the date meets or exceeds this cutoff value, the result will be 19yyddd; if the year component of the date is less than the cutoff, the result will be 20yyddd. The default cutoff value if no second argument is given will be 50.
The optional @var{yy-execution-time} argument (a numeric integer data item or literal) The default execution time value if no third argument is given will be now equivalent to specifying (FUNCTION NUMVAL (FUNCTION CURRENT-DATE (1:4))).
@comment *********************************************************************
@comment ** 8.1.21 E **
@comment *********************************************************************
@page
@newsubsection{8.1.21,E}
@diagram{E Function,FN-E,FN-E,None}
This function returns the mathematical constant @i{E} (the base of natural logarithms). The maximum precision with which this value may be returned is 2.7182818284590452353602874713526625.
Since this function has no arguments, no parenthesis should be specified.
@comment *********************************************************************
@comment ** 8.1.22 EXCEPTION-FILE **
@comment *********************************************************************
@page
@newsubsection{8.1.22,EXCEPTION-FILE}
@diagram{EXCEPTION-FILE Function,FN-EXCEPTION-FILE,FN-EXCEPTION-FILE,None}
This function returns I/O exception information from the most-recently executed input or output statement. The information is returned as a 34-character string, where the first two characters are the two-digit file status value (@pxref{File Status Codes}) and the remaining 32 are the @var{file-name-1} specification from the file's @syntaxref{SELECT} statement.
The name returned after the file status information will be returned only if the returned file status value is not 00.
Since this function has no arguments, no parenthesis should be specified.
The documentation of the @subpgmref{CBL_ERROR_PROC} built-in subroutine illustrates the use of this function.
@comment *********************************************************************
@comment ** 8.1.23 EXCEPTION-LOCATION **
@comment *********************************************************************
@page
@newsubsection{8.1.23,EXCEPTION-LOCATION}
@diagram{EXCEPTION-LOCATION Function,FN-EXCEPTION-LOCATION,FN-EXCEPTION-LOCATION,None}
This function returns exception information from the most-recently failing statement. The information is returned to a 1023 character string in one of the following formats, depending on the nature of the failure:
@itemize @bullet
@item
primary-entry-point-name; paragraph OF section; statement-number
@item
primary-entry-point-name; section; statement-number
@item
primary-entry-point-name; paragraph; statement-number
@item
primary-entry-point-name; statement-number
@end itemize
Since this function has no arguments, no parenthesis should be specified.
The program must be compiled with the
@switchidx{-debug},
@switchidx{-ftraceall} or
@switchidx{-g} for this function to return any meaningful information.
The documentation of the @subpgmref{CBL_ERROR_PROC} built-in subroutine illustrates the use of this function.
@comment *********************************************************************
@comment ** 8.1.24 EXCEPTION-STATEMENT **
@comment *********************************************************************
@page
@newsubsection{8.1.24,EXCEPTION-STATEMENT}
@diagram{EXCEPTION-STATEMENT Function,FN-EXCEPTION-STMT,FN-EXCEPTION-STMT,None}
This function returns the most-recent COBOL statement that generated an exception condition.
Since this function has no arguments, no parenthesis should be specified.
The program must be compiled with the
@switchidx{-debug},
@switchidx{-ftraceall} or
@switchidx{-g} for this function to return any meaningful information.
The documentation of the @subpgmref{CBL_ERROR_PROC} built-in subroutine illustrates the use of this function.
@comment *********************************************************************
@comment ** 8.1.25 EXCEPTION-STATUS **
@comment *********************************************************************
@page
@newsubsection{8.1.25,EXCEPTION-STATUS}
@diagram{EXCEPTION-STATUS Function,FN-EXCEPTION-STATUS,FN-EXCEPTION-STATUS,None}
This function returns the error type (a text string --- see column 2 of the upcoming table for the possible values) from the most-recent COBOL statement that generated an exception condition.
Since this function has no arguments, no parenthesis should be specified.
The documentation of the @subpgmref{CBL_ERROR_PROC} built-in subroutine illustrates the use of this function.
The following are the error type strings, and their corresponding exception codes and descriptions.
@anchoridx{Error Exception Codes}@anchoridx{Error Type Strings}
@multitable @columnfractions .075 .35 .575
@headitem Code @tab Error Type @tab Description
@item @code{0101}
@tab @code{EC-ARGUMENT-FUNCTION} @tab Function argument error
@item @code{0202}
@tab @code{EC-BOUND-ODO} @tab @code{OCCURS @dots{} DEPENDING} ON data item out of bounds
@item @code{0204}
@tab @code{EC-BOUND-PTR} @tab Data-pointer contains an address that is out of bounds
@item @code{0205}
@tab @code{EC-BOUND-REF-MOD} @tab Reference modifier out of bounds
@item @code{0207}
@tab @code{EC-BOUND-SUBSCRIPT} @tab Subscript out of bounds
@item @code{0303}
@tab @code{EC-DATA-INCOMPATIBLE} @tab Incompatible data exception
@item @code{0500}
@tab @code{EC-I-O} @tab input-output exception
@item @code{0501}
@tab @code{EC-I-O-AT-END} @tab I-O status @code{1x}
@item @code{0502}
@tab @code{EC-I-O-EOP} @tab An end of page condition occurred
@item @code{0504}
@tab @code{EC-I-O-FILE-SHARING} @tab I-O status @code{6x}
@item @code{0505}
@tab @code{EC-I-O-IMP} @tab I-O status @code{9x}
@item @code{0506}
@tab @code{EC-I-O-INVALID-KEY} @tab I-O status @code{2x}
@item @code{0508}
@tab @code{EC-I-O-LOGIC-ERROR} @tab I-O status @code{4x}
@item @code{0509}
@tab @code{EC-I-O-PERMANENT-ERROR} @tab I-O status @code{3x}
@item @code{050A}
@tab @code{EC-I-O-RECORD-OPERATION} @tab I-O status @code{5x}
@item @code{0601}
@tab @code{EC-IMP-ACCEPT} @tab Implementation-defined accept condition
@item @code{0602}
@tab @code{EC-IMP-DISPLAY} @tab Implementation-defined display condition
@item @code{0A00}
@tab @code{EC-OVERFLOW} @tab Overflow condition
@item @code{0A02}
@tab @code{EC-OVERFLOW-STRING} @tab @code{STRING} overflow condition
@item @code{0A03}
@tab @code{EC-OVERFLOW-UNSTRING} @tab @code{UNSTRING} overflow condition
@item @code{0B05}
@tab @code{EC-PROGRAM-NOT-FOUND} @tab Called program not found
@item @code{0D03}
@tab @code{EC-RANGE-INSPECT-SIZE} @tab Size of replace item in inspect differs
@item @code{1000}
@tab @code{EC-SIZE} @tab Size error exception
@item @code{1004}
@tab @code{EC-SIZE-OVERFLOW} @tab Arithmetic overflow in calculation
@item @code{1005}
@tab @code{EC-SIZE-TRUNCATION} @tab Significant digits truncated in store
@item @code{1007}
@tab @code{EC-SIZE-ZERO-DIVIDE} @tab Division by zero
@item @code{1202}
@tab @code{EC-STORAGE-NOT-ALLOC} @tab The data-pointer specified in a @code{FREE} statement does not identify currently allocated storage
@item @code{1203}
@tab @code{EC-STORAGE-NOT-AVAIL} @tab The amount of storage requested by an @*@code{ALLOCATE} statement is not available
@end multitable
@comment *********************************************************************
@comment ** 8.1.26 EXP **
@comment *********************************************************************
@page
@newsubsection{8.1.26,EXP}
@diagram{EXP Function,FN-EXP,FN-EXP,None}
Computes and returns the value of the mathematical constant @i{e} raised to the power specified by @var{number} (a numeric literal or data item).
@comment *********************************************************************
@comment ** 8.1.27 EXP10 **
@comment *********************************************************************
@page
@newsubsection{8.1.27,EXP10}
@diagram{EXP10 Function,FN-EXP10,FN-EXP10,None}
Computes and returns the value of 10 raised to the power specified by @var{number} (a numeric literal or data item).
@comment *********************************************************************
@comment ** 8.1.28 FACTORIAL **
@comment *********************************************************************
@page
@newsubsection{8.1.28,FACTORIAL}
@diagram{FACTORIAL Function,FN-FACTORIAL,FN-FACTORIAL,None}
This function computes and returns the factorial value of @var{number} (a numeric literal or data item).
@comment *********************************************************************
@comment ** 8.1.29 FORMATTED-CURRENT-DATE **
@comment *********************************************************************
@page
@newsubsection{8.1.29,FORMATTED-CURRENT-DATE}
@diagram{FORMATTED-CURRENT-DATE Function,FN-FORMATTED-CURRENT-DATE,FN-FORMATTED-CURRENT-DATE,None}
@code{FORMATTED-CURRENT-DATE} returns the current date and time provided by the system at run-time, formatted according to date-and-time-format according to the argument type.
FUNCTION FORMATTED-CURRENT-DATE gives you exactly what you asked it to, including up to nanoseconds (8 decimal positions in the seconds) [but the system may only provide miliseconds, especially on older win32].
The function argument must be a national or alphanumeric literal and the content, a combined date and time format.
The returned value is formatted to the same form as @var{argument-1}.
@comment *********************************************************************
@comment ** 8.1.30 FORMATTED-DATE **
@comment *********************************************************************
@page
@newsubsection{8.1.30,FORMATTED-DATE}
@diagram{FORMATTED-DATE Function,FN-FORMATTED-DATE,FN-FORMATTED-DATE,None}
@code{FORMATTED-DATE} uses a format to convert a date in integer date form to a date in the requested format. The returned value will be in date format.
@var{argument-1} shall be a national or alphanumeric literal.
@var{argument-2} shall be a value in integer date form.
Example
Given the date format "YYYYMMDD" and the value "143951", which represents the date 15 February 1995, the returned value would be "19950215".
@comment *********************************************************************
@comment ** 8.1.31 FORMATTED-DATETIME **
@comment *********************************************************************
@page
@newsubsection{8.1.31,FORMATTED-DATETIME}
@diagram{FORMATTED-DATETIME Function,FN-FORMATTED-DATETIME,FN-FORMATTED-DATETIME,None}
@code{FORMATTED-DATETIME} uses a combined time and date form to convert and combine a date in integer form and a numeric time expressed as seconds past midnight in UTC. See Date and Time Formats for details.
@var{argument-1} shall be a national or alphanumeric literal.
@var{argument-2} shall be a value in integer date form.
@var{argument-3} shall be a value in standard numeric time form.
@var{argument-4} is an integer specifying the offset from UTC expressed in minutes. If specified but have a value equal or less than 1439.
Note: The offset value 1439 represents 23 hours 59 minutes which is one minutes less than a day.
@var{argument-4} must not be specified if the time portion in @var{argument-1} is neither a UTC nor an offset format.
The returned value is a representation of the date contained in @var{argument-2} combined with the time contained in @var{argument-3} according to the format in @var{argument-1}.
If the format in @var{argument-1} indicates that the returned value is to be expressed in UTC, the time portion of the returned value reflects the adjustment of the value in @var{argument-3} by the offset in @var{argument-4}.
If the format in @var{argument-1} indicates that the time is to be returned as an offset from UTC, the value in @var{argument-3} is reflected directly in the time portion of the returned value and the offset in @var{argument-4} is reflected directly in the offset portion of the returned value.
Example
If the first argument has the format "YYMMDDThhmmss.ss+hhmm", the second argument the value
"143951", the third argument the value "18867.812479168304", and the fourth argument the value
"+300", the returned value would be "19950215T05142781+0500".
@comment *********************************************************************
@comment ** 8.1.32 FORMATTED-TIME **
@comment *********************************************************************
@page
@newsubsection{8.1.32,FORMATTED-TIME}
@diagram{FORMATTED-TIME Function,FN-FORMATTED-TIME,FN-FORMATTED-TIME,None}
@code{FORMATTED-TIME} converts a value representing seconds past midnight formatted time of day with optional offset.
@var{argument-1} shall be a national or alphanumeric literal.
@var{argument-2} shall be a value in integer time form.
@var{argument-3} is an integer specifying the offset from UTC expressed in minutes. If specified but have a value equal or less than 1439.
Note: The offset value 1439 represents 23 hours 59 minutes which is one minutes less than a day.
@var{argument-3} must not be specified if the time portion in @var{argument-1} is neither a UTC nor an offset format.
Returned value :
Is a representation of the standard numeric time contained in @var{argument-2} according to the format in @var{argument-1}.
If the format in @var{argument-1} indicates that the returned value is to be expressed in UTC, the time portion of the returned value reflects the adjustment of the value in @var{argument-2} by the offset in @var{argument-3}.
If the format in @var{argument-1} indicates that the time is to be returned as an offset from UTC, the value in @var{argument-2} is reflected directly in the time portion of the returned value and the offset in @var{argument-3} is reflected directly in the offset portion of the returned value.
Example
If the first argument has the format "hhmmss.ss+hhmm", the second argument the value "18867.812479168304" which represents the local time, and the third argument the value "-300", which represents the five hours that Eastern Standard Time (EST) differs from UTC, the returned value would be "05142781-0500".
@comment *********************************************************************
@comment ** 8.1.33 FRACTION-PART **
@comment *********************************************************************
@page