![]() |
Introduction Unit aims, objectives and prerequisites. | |
![]() |
The
UNSTRING verb This section examines the syntax, functioning and rules of the UNSTRING. | |
![]() |
UNSTRING examples This section starts with some abstract examples, goes on to a more practical example and ends with a example program | |
![]() |
A combined example |
|
|
UNSTRING examples | ||
Introduction |
This section starts with 6 short examples exploring various aspects the UNSTRING. Example 7 is a longer and more practical example Finally the section ends with an example program that uses the UNSTRING. | |
Examples 1 - 6 |
When you view these examples start by carefully examining the UNSTRING statement. See if you can figure out what it's going to do (you may need to review the material above for this). When you are happy with your prediction step through the example and see if you were correct. If your prediction is not correct try to discover what misunderstanding has led to your error.
| |
Example 7 |
The WITH POINTER phrase is often very useful because it means that we don't have to unpack the whole source string in one go.. In this example, we unpack a full name, any number of Christian names followed by a surname, and display the names one after another.
| |
Example program |
Comma delimited or comma separated values (CSV) is a file format widely used in the computing industry. It allows data to be transferred between applications with incompatible file formats (Excel, for example, can save its spreadsheets in this form). But before the records in a CSV format file can be processed they must be unpacked into individual fields. In this example, a file of customer records is held in file with a CSV-like format. Each record contains a customer name, a customer address and the customer balance. The fields are separated from one another by commas. The individual parts of the customer address are separated by the slash "/" character. An example record is - Michael Ryan,3 Winchester Drive/Castletroy/Limerick/Ireland,0022456 The program below reads the file, unpacks each the record into separate fields and writes the unpacked record to a new file.
|
|
Combined example | |
Introduction |
This example takes a string, containing a name consisting of any number of Christian names followed by a surname, and converts it by reducing the Christian names to their first letters followed by a period. For example "Michael John Tim James Ryan" becomes "M.J.T.J. Ryan". |
Data items used in the example |
01 OldName PIC X(80). 01 TempName. 02 NameInitial PIC X. 02 FILLER PIC X(15). 01 NewName PIC X(30). 01 Pointers. 02 StrPtr PIC 99 VALUE 1. 02 UnstrPtr PIC 99 VALUE 1. 88 NameProcessed VALUE 81.
|
Animation |
Click on the diagram below to step through
the animation. Left click or PageDown to go to the next step and right
click or press PageUp to go to the previous step.
|
|
Copyright NoticeThese COBOL course materials are the copyright property of Michael Coughlan. All rights reserved. No part of these course materials may be reproduced in any form or by any means - graphic, electronic, mechanical, photocopying, printing, recording, taping or stored in an information storage and retrieval system - without the written permission of the author. (c) Michael Coughlan Last updated : April 1998 |