INSEPCT

Give example of Inspect TALLYING / BEFORE INTIAL / AFTER INITIAL. In which situation will use this in COBOL?

Questions by avinash556

Showing Answers 1 - 21 of 21 Answers

ananta2010

  • Jun 9th, 2010
 

In INSPECT claues Taylling is used to count the number of char's in the string. Before and after intial is used in termes of intialized the particular char. Before start counting or after done the counting it will intinalzs that char.

For example; variable - vara pic x(20) value mainframe question INSPECT vara tallying tally-count 'a' before intial 'e' after intial 'i'

  Was this answer useful?  Yes

rathi4job

  • Jul 14th, 2010
 

Tallying in INSPECT is mainly used to count the trailing spaces and number of characters in a string. Say for example: Var1 is defined with size of 20bytes. And it contain the value as "Mainframe". So in order to find the how many bytes are used in the actual 20bytes, we can first reverse the string, and then find for Leading space by using Tallying. Then we can subtract this space count from the length of Var1(Which is nothing but 20). Then the final result will be the number of bytes occupied(Which is nothing but 20-11=9.

  Was this answer useful?  Yes

* Inspect statement is used to examine the contents of a variable for the occurence of a Character/String.
* Inspect statement with tallying is used to count the no. of occurences of such character.
* Inspect statement with replacing is used to replace the string/character by another string/character.

  Was this answer useful?  Yes

INSEPCT verb is used to count or replace characters in a dataitem (string). 
Tallying is used for count the characters and replacing is used for replacing
the character by other characet.


  Was this answer useful?  Yes

-> Inspect is used to count the number of characters in a string.
-> Inspect is used for replacing the string of characters.
-> It is also used for converting the string of characters.


Let us see examples for above 3 cases.
Eg1:
01 ws-count pic 9(2).
01 ws-cobol pic x(16) value 'this is srinivas'.
procedure division.
Inspect ws-cobol tallying ws-count for all 'i'.
display ws-count.
stop run.
// here we will get output 4.

Eg2:
Inspect ws-cobol Replacing all 'i' by 's'.
display ws-cobol.
stop run.
// here we will get out put 'thss ss srsnsvas'.

Eg3:
Inspect converting 'this is srinivas' to 'THIS IS SRINIVAS' .
// here we will get output as THIS IS SRINIVAS.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions