How do I Unstring a file in Cobol?

How do I Unstring a file in Cobol?

Unstring. Unstring verb is used to split one string into multiple sub-strings. Delimited By clause is compulsory. UNSTRING ws-string DELIMITED BY SPACE INTO ws-str1, ws-str2 WITH POINTER ws-count ON OVERFLOW DISPLAY message NOT ON OVERFLOW DISPLAY message END-UNSTRING.

How does Unstring work in Cobol?

COBOL UNSTRING. UNSTRING The UNSTRING verb is used to divide a string into sub-strings The UNSTRING copies characters from the source string, to the destination strings, until a delimiter encountered that terminates data transfer.

What is string and UNSTRING in CObol?

String is used to combine two or more strings/variables in to a single string. UNSTRING verb is used to unstring/divide the source string into different sub-strings.

How do you count spaces in a string in Cobol?

we can use following logic. INSPECT FUNCTION REVERSE (Source-string) TALLYING space-count FOR LEADING SPACES. COMPUTE length-of-string = 6 – space-count. Move Source-string(space-count+1 : length-of-string ) TO ws-target-string.

How do I remove special characters in Cobol?

PROCEDURE DIVISION. PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > FUNCTION LENGTH(WS-STR) IF WS-STR(WS-I:1) = ‘*’ THEN CONTINUE ELSE MOVE WS-STR(WS-I:1) TO WS-LETTER(WS-J) ADD 1 TO WS-J ADD 1 TO WS-CNT END-IF END-PERFORM DISPLAY WS-CHAR STOP RUN.

How do I remove spaces from a string in Cobol?

DISPLAY ‘ — METHOD ONE — ‘ INSPECT FUNCTION REVERSE(ONE-A) TALLYING ONE-A-TLY FOR LEADING SPACES. SUBTRACT ONE-A-TLY FROM LENGTH OF ONE-A GIVING ONE-A-LEN. INSPECT FUNCTION REVERSE(ONE-B) TALLYING ONE-B-TLY FOR LEADING SPACES. SUBTRACT ONE-B-TLY FROM LENGTH OF ONE-A GIVING ONE-B-LEN.

What is the difference between stop run and go back in Cobol?

GOBACK is a statement which refers to the logical end of a given program in COBOL. STOP RUN, on the other hand, will terminate the program on its own or if called by a COBOL program.

Why index is faster than subscript in Cobol?

Using indexes to address a table is more efficient than using subscripts since the index already contains the displacement from the start of the table and does not have to be calculated at run time. This will allow full word arithmetic to be used during the calculations. …

How do you remove leading spaces in Cobol string?

You don’t have redefine and check each and every byte to remove the leading spaces. You can simply use the Function UNSTRING and remove the spaces. Code: 01 WS-STR PIC X(20) VALUE ‘ BBXXXYYYY’.

How do you trim a space in Cobol?

Couple of ways to trim the trailing spaces. MOVE FUNCTION REVERSE(INPUT) TO INPUT-R. INSPECT INPUT-R TALLYING CNTR FOR LEADING SPACES. COMPUTE INP-LEN = LENGTH OF INPUT-R – CNTR.

Can We reverse the string in COBOL?

We can use COBOL function REVERSE for the same. REVERSE function returns the character string of same length of the argument. this way we read last character first and by repeating the same process, reverse value of the field can be achieved.

What is the use of inspect verb in COBOL?

INSPECT in COBOL is a defined verb and is used to 1.To REPLACE some portion of data item with any value or any other data item 2.To count number of times a specific character occurs in any variable or data item. INSPECT in COBOL is used in scenarios like as below:

What are looping statements used for in COBOL?

The loop statements used in COBOL are − Perform Thru is used to execute a series of paragraph by giving the first and last paragraph names in the sequence. After executing the last paragraph, the control is returned back. Statements inside the PERFORM will be executed till END-PERFORM is reached.

What is COBOL subroutine?

COBOL – Subroutines. Cobol subroutine is a program that can be compiled independently but cannot be executed independently. There are two types of subroutines: internal subroutines like Perform statements and external subroutines like CALL verb.

author

Back to Top