Top
NetCOBOL V11.0 Syntax Samples
FUJITSU Software

1.51 STORED-CHAR-LENGTH Function

The STORED-CHAR-LENGTH function returns the length of valid data excluding any trailing spaces included in an argument. Because the STORED-CHAR-LENGTH function returns the number of character positions, this function is useful for checking for numeric truncation or for determining significant data in an alphanumeric field for use with reference modification.

The STORED-CHAR-LENGTH function is unique to Win32, Winx64, Solaris, Linux, LinuxIPF, Linux64 and .NET.

000010 @OPTIONS MAIN
000020*----------------------------------------------------------------------
000030* The STORED-CHAR-LENGTH function returns the valid data length in a 
000035* data item.
000040*----------------------------------------------------------------------
000050 IDENTIFICATION   DIVISION.
000060 PROGRAM-ID.      SAMPLE.
000070 DATA             DIVISION.
000080 WORKING-STORAGE  SECTION.
000090 01 IN-DATA       PIC X(80).
000100 01 DATA-LEN      PIC 9(4) BINARY.
000110 01 BUFFER        PIC X(40) VALUE ALL "*".
000120**
000130 PROCEDURE        DIVISION.
000140     DISPLAY "Please input a character string. >> " WITH NO ADVANCING.
000150     ACCEPT IN-DATA FROM CONSOLE.
000160*----------------------------------------------------------------------
000170* If the argument is a national data item, the returned value of the 
000180* STORED-CHAR-LENGTH function is number of characters.  If the argument 
000190* is an alphanumeric data item, the value returned is the number of 
000200* bytes. Because the STORED-CHAR-LENGTH function is a numeric function, 
000202* it can be coded only in an arithmetic expression.
000203* That is why the COMPUTE statement and not the MOVE statement is used 
000204* below.
000210*----------------------------------------------------------------------
000220     COMPUTE DATA-LEN = FUNCTION STORED-CHAR-LENGTH (IN-DATA).
000230*----------------------------------------------------------------------
000240     IF DATA-LEN > FUNCTION LENGTH(BUFFER) THEN
000250       DISPLAY "The input data length has exceeded the buffer length."
000260     ELSE
000270       MOVE IN-DATA(1:DATA-LEN) TO  BUFFER(1:DATA-LEN)
000280       DISPLAY "BUFFER = " BUFFER
000290     END-IF.
000300 END PROGRAM SAMPLE.