Skip to Content
Custom Search

COBOL INSPECT TALLYING FOR LEADING SPACES

 

INSPECT TALLYING FOR LEADING SPACES
 
The following COBOL program depicts the use of 
INSPECT TALLYING FOR LEADING SPACES
 
 
       IDENTIFICATION DIVISION.
       PROGRAM-ID. PGM030.
       AUTHOR. MAINFRAMEWIZARD.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TEST-STRING   PIC X(40) VALUE SPACES.
       01 WS-COUNTER    PIC 9(9)  VALUE ZEROES.
       01 SEARCH-STRING PIC X(2)  VALUE SPACES.
       PROCEDURE DIVISION.
       10000-MAIN-PARA.
             MOVE '     THIS IS TEST STRING TO TEST LEADING SPACES'
              TO  TEST-STRING
             INSPECT TEST-STRING TALLYING WS-COUNTER FOR
             LEADING SPACES
             DISPLAY 'COUNT OF LEADING SPACES IS = '
               WS-COUNTER
             STOP RUN.
 
 
 
The output of the program is 
 
COUNT OF LEADING SPACES IS = 000000005                                                                                   

Comments

removing leading spaces

removing leading spaces :

if testfield not = spaces.

   move 1 to ws-counter.

   inspect testfield tallying ws-counter for leading spaces.

   move testfield(ws-counter:) to receiving-field.

end.

 

.* i use a cobol dialect, so i use more punctuation, but above is easy to do in normal cobol as well

Post new comment

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

Click the +1 button  below to share it with your friends and colleagues

 

Share this if you liked it!

 

Disclaimer



Who's online

There are currently 0 users and 21 guests online.
Dr. Radut | page