Search

Saturday, March 16, 2013

Creating Different Dimension Tables in COBOL

As we saw single dimension table in my blog linked here . There are many other ways to use COBOL table.
Another Way of Single Dimension TABLE:

COBOL Declaration:


01  A1-TABLE.
      05 A2-TABLE OCCURS 100 TIMES
            15 P1-NO             PIC X(05).
            15 P1-NAME        PIC X(10).
             15 P1-TEL NO.
                   25   LAND-LINE  PIC 9(10).
                   25   MOBILE        PIC 9(11).

This declarlation will work in COBOL as table described below:

Interview Questions for COBOL


How do you do in-line PERFORM? 
        
PERFORM ... <UNTIL> ...
<sentences>
END-PERFORM

When would you use in-line perform?

     When the body of the perform will not be used in other paragraphs. If the body of the perform is a generic type of code (used from various other places in the program), it would be better to put the code in a separate Para and use
      PERFORM Para name rather than in-line perform.

 What is the difference between CONTINUE & NEXT SENTENCE ?
 They appear to be similar, that is, the control goes to the next sentence in the paragraph. 
 But, Next Sentence would take the control to the sentence after it finds a full stop (.). 
 Check out by writing the following code example, one if sentence followed by 3 display statements 
 If 1 > 0 then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. Note- there is a dot (.) only at the end of the last 2 statements, see the effect by replacing Next Sentence with Continue.     

Sunday, March 3, 2013

Efficient use of decalartion in COBOL


Efficiently use of alphanumeric and numeric declaration in COBOL


In Working Section:

03  WS-ALPHX.                          
    05  WS-NUM          PIC 9(4).     

We can use this way as alphanumeric as well as to check numeric.

For Eg:

MOVE CAPIN(1:4)      TO WS-ALPHAX

IF WS-ALPHAX (1:1) IS NOT NUMERIC       
   MOVE 0 TO WS-ALPHAX (1:1)
END-IF      
                                  
IF WS-NUM IS NUMERIC                  
   MOVE WS-NUM TO CAPIN2
ELSE                                          
   MOVE 0              TO CAPIN2
END-IF                        

Search Option of COBOL


Here is how to use search option in COBOL

COBOL Declaration:


01  A1-TABLE.                                               
    03   FILLER                     PIC 9(02) VALUE  01.    
    03   FILLER                     PIC 9(02) VALUE  02.    
    03   FILLER                     PIC 9(02) VALUE  03.    
    03   FILLER                     PIC 9(02) VALUE  40.    
    03   FILLER                     PIC 9(02) VALUE  50.    
                                                               
01 AE-TABLE REDEFINES A1-TABLE.                            
    03  IE-CODE        PIC 9(02)  OCCURS 5 TIMES           
                           INDEXED BY P1.                     

Code in procedure division : 

      SET P1 TO 1.                                
      SEARCH IE-CODE                            
          AT END SET NOT-IE-CODE TO TRUE        
      WHEN AE-CODE IS EQUAL TO IE-CODE (P1)   
          SET IE-CODE1 TO TRUE