At first glance, the solution is to use the STRING link along with two lines, including a space. The problem is that you need to know how many trailing spaces are in the FIRST-NAME, otherwise you will create something like "JOHNbbbbbbbbbbbbbbDOE", where b is the space.
There is no built-in COBOL function to determine the number of trailing spaces in a string, but there is one to determine the number of leading spaces in a string. So the fastest way, as far as I can tell, is to undo the first name, find the number of leading spaces and use the link modification for the string along with the first and last name.
You will need to add these fields to the working repository:
WORK-FIELD PIC X(15) VALUE SPACES. TRAILING-SPACES PIC 9(3) VALUE ZERO. FIELD-LENGTH PIC 9(3) VALUE ZERO.
- Cancel FIRST-NAME
- MOVEMENT FUNCTION TRANSFER (FIRST NAME) TO WORK-FIELD.
- WORK-FIELD now contains leading spaces instead of trailing spaces.
- Find the number of trailing spaces in FIRST-NAME
- INSPECT TRAINING SPACES FOR VERTEBRAL VEHICLES FOR LEADING SPACES.
- TRAILING-SPACE now contains the number of trailing spaces in FIRST-NAME.
- Find the length of the FIRST-NAME field
- COMPUTE FIELD-LENGTH = FUNCTION LENGTH (FIRST-NAME).
- Combine the two lines together.
- STRING FIRST-NAME (1: FIELD-LENGTH - TRAILING-SPACES) "" LAST-NAME DELIMITED BY SIZE, INTO FULL-NAME.
source share