COBOL

COBOL

COBOL

COBOL is responsible for the efficient, reliable, secure, and unseen day-to-day operations of the world's economy.

 View Only
  • 1.  Cobol array

    Posted Fri July 01, 2016 11:15 AM

    Hello I'm new to Cobol and I'm having trouble with REDEFINE a TABLE.

    So I'm reading an input file of about 4000 lines, and the length of each record is 59 bytes long but not all 59 are used. For example:  "A G T J S K H E T Y "

     01  WS-CLASS-IN.                         
        03 WS-CLASS-FILL1      PIC X(7).     
        03 WS-CLASS-CODE       PIC X(52).    
                                             

     01  WS-CLASS-TABLE.                                    
         03  WS-CLASS-ITEM OCCURS 4000 TIMES.               
              05  WS-CLASS-CODE-T     PIC X(52) VALUE SPACES.  

         03   CLASS-INDEX         PIC 9(4)  VALUE ZEROS.  

     

    Here is my method

    010-PROCESS-LOAD-CLASS-TBL.                               
        PERFORM 600-READ-DFI-CLASS-IN THRU 600-EXIT           
        IF WCLASS-EOF = 'Y'                                   
           GO TO 010-EXIT                                     
        END-IF                                                
        ADD 1 TO CLASS-INDEX                                  
        MOVE WS-CLASS-CODE TO WS-CLASS-CODE-T(CLASS-INDEX)    
        DISPLAY WS-CLASS-CODE.                                                           
    010-EXIT.                                                 
        EXIT.    

    My above code works and I'm able to display the string of characters. My next step is to remove the spaces which I'm having an epic headache, I've tried it in many ways but I was unsuccessful. I read that I have to use REDEFINE  

     

    01  WS-CLASS-TABLE.                                     
        03  WS-CLASS-ITEM OCCURS 4000 TIMES.                
             05  WS-CLASS-CODE-T PIC X(52) VALUE SPACES.    
             05  WS-CLASS-CODE-R REDEFINES WS-CLASS-CODE-T  
                                OCCURS 26 TIMES.            
                 10  WS-CLASS-R  PIC X(1)  VALUE SPACES.    
                 10  FILLER      PIC X(1)  VALUE SPACES.    

        03   CLASS-INDEX       PIC 9(4)  VALUE ZEROS.        
        03   I                                 PIC 9(4)  COMP VALUE ZEROS.   
       03   J                                 PIC 9(4)  COMP VALUE ZEROS.   
       03   K                                PIC 9(4)  COMP VALUE ZEROS.   
       03   WCLASS-TEMP         PIC X(52) VALUE SPACES.  

     

    I'm trying to make a new table where I can put the String of Characters and just pull from there WS-CLASS-R.      

    WCLASS is my output

    ICLASS is my input file

     

    MOVE SPACES TO WCLASS                           
    MOVE WS-CLASS-CODE-T(ICLASS)   TO  WCLASS-TEMP  
    PERFORM VARYING I FROM 1 BY 1 UNTIL I  > 26     
       ADD 1 TO J                                   
       MOVE WS-CLASS-R(I) TO WCLASS(J)              
    END-PERFORM.    

     

    What am I doing wrong? Please help                                                                 

    _Karin_


  • 2.  Re: Cobol array

    Posted Fri July 01, 2016 12:45 PM

    Try this:

     

    PERFORM VARYING I FROM 1 BY 1 UNTIL I  > 26     

       if ws-class-r(i) > space 

           ADD 1 TO J        

           MOVE WS-CLASS-R(I) TO WCLASS(J)        

       end-if    
    END-PERFORM.    

    TerryWin


  • 3.  Re: Cobol array

    Posted Fri July 01, 2016 02:35 PM

    Thank you for your reply.

    I have tried it that way before and now. I keep getting this error messages, I believe my REDEFINE clause is wrong.

    01  WS-CLASS-TABLE.                                     
        03  WS-CLASS-ITEM OCCURS 4000 TIMES.

              05  WS-CLASS-CODE-R REDEFINES WS-CLASS-CODE-T                    
                                                            OCCURS 26 TIMES.                              
                  10  WS-CLASS-R  PIC X(1)  VALUE SPACES.                      
                                                                               
                                                                               
     A "VALUE" CLAUSE WAS SPECIFIED FOR AN ITEM THAT CONTAINED, OR WAS         
     SUBORDINATE TO AN ITEM THAT CONTAINED, A "REDEFINES" CLAUSE.  THE "VALUE" 
     CLAUSE WAS DISCARDED.  
                                                      
                                                                               
                  10  FILLER      PIC X(1)  VALUE SPACES.                      
                                                                               
                                                                               
     A "VALUE" CLAUSE WAS SPECIFIED FOR AN ITEM THAT CONTAINED, OR WAS         
     SUBORDINATE TO AN ITEM THAT CONTAINED, A "REDEFINES" CLAUSE.  THE "VALUE" 
     CLAUSE WAS DISCARDED.

     

     

     

     

           
          MOVE SPACES TO WCLASS                                                
          MOVE WS-CLASS-CODE-T(ICLASS)   TO  WCLASS-TEMP                       
          MOVE WCLASS-TEMP TO  WS-CLASS-CODE-R                                 
                                                                               
     "WS-CLASS-CODE-R" WAS A TABLE ELEMENT BUT WAS NOT SUBSCRIPTED OR INDEXED.
      THE FIRST OCCURRENCE OF THE TABLE ELEMENT WAS ASSUMED.          
            
                                                                               
          PERFORM VARYING I FROM 1 BY 1 UNTIL I  > 26                          
            IF WS-CLASS-R(I) > SPACE                                           
                                                                               
     NOT ENOUGH SUBSCRIPTS OR INDICES WERE SPECIFIED FOR "WS-CLASS-R".  A     
      SUBSCRIPT OR INDEX VALUE OF 1 WAS ASSUMED FOR EACH MISSING SUBSCRIPT OR  
      INDEX.    
       

     

     

    Thank you for your time                                                                                                              

    _Karin_


  • 4.  Re: Cobol array

    Posted Mon July 04, 2016 08:43 AM

    1. The VALUE clause and REDEFINES can't be matched together. Delete the "VALUE SPACES" in all subitems of the REDEFINES.

    2. "REDEFINES" + "OCCURS": the effect is, that all subitems are table arrays and must be subscripted. And because the variable above the REDEFINES is also subscripted ... you have two dimensions. ;-)

     

    Does this help?

    Ralf

    RalfSeidler