Cobol tables - moving items from one table into another one



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Cobol tables - moving items from one table into another one

Postby dbhasty » Fri May 06, 2011 11:40 pm

Hi

I'm having some trouble trouble with cobol tables and was wondering if anyone could help show me where i'm going wrong?

Here is the layout of the tables im using.

01 WS-TBS1-TABLE.
05 WS-TBS1 OCCURS 50 TIMES.
10 WS1-NAME PIC X(20).
10 WS1-ADDRESS PIC X(30).
10 WS1-DEPT PIC X(04).
10 WS1-SALARY PIC X(05).
10 WS1-PEN-DESC PIC X(08).
10 WS1-PEN-TYPE PIC X(02) VALUE 'P1'.

So i basically have 5 tables like this (WS-TBS1-TABLE to WS-TBS5-TABLE). Then i have another exactly the same called WS-TBSA-TABLE.

What i need to do is move the first occurrence of tables WS-TBS1-TABLE to WS-TBS5-TABLE to the first occurrence of WS-TBSA-TABLE, then the second occurrence etc… until WS-TBSA-TABLE has 50 occurrences.

Here is the code i have been using.

MOVE 0 TO I.
MOVE 0 TO X.

PARA-1.
IF X < 50 AND WS-TBS1(I) NOT = SPACES
MOVE WS-TBS1(I) TO WS-TBSA(X)
ADD 1 TO X.
IF X < 50 AND WS-TBS2(I) NOT = SPACES
MOVE WS-TBS2(I) TO WS-TBSA(X)
ADD 1 TO X.
IF X < 50 AND WS-TBS3-TABLE(I) NOT = SPACES
MOVE WS-TBS3(I) TO WS-TBSA(X)
ADD 1 TO X.
IF X < 50 AND WS-TBS4(I) NOT = SPACES
MOVE WS-TBS4(I) TO WS-TBSA(X)
ADD 1 TO X.
IF X < 50 AND WS-TBS5(I) NOT = SPACES
MOVE WS-TBS5(I) TO WS-TBSA(X)
ADD 1 TO X.
ADD 1 TO I
GO TO PARA-1.

I've been getting the following errors when trying to compile this:

"WS1-NAME OF WS-TBS1" was a table element but was not subscripted or indexed. The first occurrence of the table element was assumed.
I basically get this error for every table.

I've never really used cobol only had basic training. So any help would be grateful. If you's need to know any more info let me know.

Many thanks.
dbhasty
 
Posts: 6
Joined: Fri May 06, 2011 11:05 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Cobol tables - moving items from one table into another

Postby Robert Sample » Fri May 06, 2011 11:49 pm

Normally, the COBOL compiler indicates which line number the error occurred on. Since you did not provide this vital piece of data, and nonoe of the code you DID provide references WS1-NAME, my best guess (and it can only be a guess) is that some code you didn't post had the error because you are referencing WS1-NAME without using parentheses after it.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Cobol tables - moving items from one table into another

Postby BillyBoyo » Sat May 07, 2011 5:16 am

I have put your code inside the "code tags" to better look at it.

01 WS-TBS1-TABLE.
    05 WS-TBS1   OCCURS 50 TIMES.
         10 WS1-NAME               PIC X(20).
         10 WS1-ADDRESS          PIC X(30).
         10 WS1-DEPT                 PIC X(04).
         10 WS1-SALARY            PIC X(05).
         10 WS1-PEN-DESC         PIC X(08).
         10 WS1-PEN-TYPE         PIC X(02) VALUE 'P1'.


Do you set your tables to spaces before you load them up? If so, the VALUE clause for WS1-PEN-TYPE is redundant. If not, your test for WS-TBS1 (sub) equal to space will never work how you intend, because none of the occurences can ever be spaces.

MOVE 0 TO I.
MOVE 0 TO X.

PARA-1.
        IF X < 50 AND WS-TBS1(I) NOT = SPACES
           MOVE WS-TBS1(I) TO WS-TBSA(X)
           ADD 1 TO X.
        IF X < 50 AND WS-TBS2(I) NOT = SPACES
           MOVE WS-TBS2(I) TO WS-TBSA(X)
           ADD 1 TO X.
        IF X < 50 AND WS-TBS3-TABLE(I) NOT = SPACES
           MOVE WS-TBS3(I) TO WS-TBSA(X)
           ADD 1 TO X.
        IF X < 50 AND WS-TBS4(I) NOT = SPACES
           MOVE WS-TBS4(I) TO WS-TBSA(X)
           ADD 1 TO X.
        IF X < 50 AND WS-TBS5(I) NOT = SPACES
           MOVE WS-TBS5(I) TO WS-TBSA(X)
           ADD 1 TO X.
           ADD 1 TO I
           GO TO PARA-1.


You set your subscripts to an initial value of zero. For a subscript, the smallest logical value is +1, which means the first entry in the table.

You'll never use the 50th occurrence, because you only test further if X < 50, even though you allow X to reach 50.

You have no way out of your loop. You'll just keep adding to I until you run out of TIME on your step, or the OPS cancel the job.

You have a reference to WS-TBS3-TABLE with a subscript. This should give a compile error, unless you have defined your third table differently from the example.

Looking at your indenting, ADD 1 TO I and GO TO PARA-1 are in the wrong place.

What are you supposed to do with any data for which there is no room in TBSA?

Using END-IF will make your code neater, more easy to follow:
        IF X < 50 AND WS-TBS1(I) NOT = SPACES
           MOVE WS-TBS1(I) TO WS-TBSA(X)
           ADD 1 TO X
        END-IF


As to your compile error, I agree with Robert. Best guess.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post