![]() |
Introduction | |
![]() |
The
STRING verb This section examines the syntax, functioning and rules of the STRING verb | |
![]() |
STRING examples |
|
|
STRING examples | |
Introduction |
This section starts with some examples to reinforce the material you have just read and it ends with a few test/examples to let you see if you have understood everything so far. |
Example 1 |
The animation in this example shows how the STRING works by stepping though each clause in the STRING statement.
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.
|
Example 2
|
The WITH POINTER phrase is often very useful because it means that we don't have to STRING all the source strings together in one go. Using the WITH POINTER we can build the destination string by executing a number of separate STRING statements or by executing a STRING statement a number of times. In this example we show how a destination string may be built a piece at a time by executing several separate STRING statements. At the end of this unit in the combined example you will see how a STRING statement may be used within a loop to build a destination string.
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.
|
Self assessment questions/examples |
The examples below consist of data delarations and a number of STRING statements. For each STRING example, write out the text that would be displayed by the DISPLAY statement. Assume that the data starts off fresh for each STRING statement. Treat the examples as an opportunity to test your understanding of the STRING verb. Before you click on the answers in the frame below write down your own answer.
Data Declarations. 01 StringFields. 02 Field1 PIC X(18) VALUE "Where does this go". 02 Field2 PIC X(30) VALUE "This is the destination string". 02 Field3 PIC X(15) VALUE "Here is another". 02 Field4 PIC X(15) VALUE SPACES. 01 StrPointers. 02 StrPtr PIC 99. 02 NewPtr PIC 9. STRING examples. 1. STRING Field1 DELIMITED BY SPACES INTO Field2. DISPLAY Field2. 2. STRING Field1 DELIMITED BY SIZE INTO Field2. DISPLAY Field2. 3. MOVE 6 TO StrPtr. STRING Field1, Field3 DELIMITED BY SPACE INTO Field2 WITH POINTER StrPtr ON OVERFLOW DISPLAY "String Error" NOT ON OVERFLOW DISPLAY "No Error" END-STRING. DISPLAY Field2. 4. STRING Field1, Field2, Field3 DELIMITED BY SPACES INTO Field4 END-STRING. DISPLAY Field4 5. MOVE 4 TO NewPtr. STRING Field1 DELIMITED BY "this" Field3 DELIMITED BY SPACE "END" DELIMITED BY SIZE INTO Field2 END-STRING. DISPLAY Field2. 6. MOVE 4 TO NewPtr. STRING Field1 DELIMITED BY "this" Field3 DELIMITED BY SPACE "Tom" DELIMITED BY SIZE INTO Field2 WITH POINTER NewPtr ON OVERFLOW DISPLAY "String Error" NOT ON OVERFLOW DISPLAY "No Error" END-STRING. DISPLAY Field2. |
Answers to SAQs |
Left click or PageDown to go to the next answer and right click or press PageUp to go to the previous answer. |
|
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 |