Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Moving one dimensional array to two dimensional array

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Sep 27, 2011 6:40 pm    Post subject: Moving one dimensional array to two dimensional array
Reply with quote

ARRAY 1

Code:
05 CONV-LINE-DATA       OCCURS 99.
   10 CONV-LINE-NUMBER            PIC 9(02).


ARRAY2

Code:
05 HOLD-LINE-DATA-H  OCCURS 6 TIMES.           
   07 HOLD-LINE-DATA-HOSP       OCCURS 18.     
      10 HOLD-LINE-NUMBER-H          PIC 9(02).


my requirement is to move those 99 oocurences into the second array. can u please suggest me how to do it.[/code]
Back to top
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Sep 27, 2011 6:44 pm    Post subject:
Reply with quote

Refer this thread
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Sep 27, 2011 6:51 pm    Post subject: Reply to: Moving one dimensional array to two dimensional ar
Reply with quote

There are a different number of entries in the two-dimensional table than in the other.

We can't have anything more than a guess about how the data maps from one table to the other.

Here's my guess.

Code:
05 CONV-LINE-DATA.
  07  FILLER OCCURS 99.
   10 CONV-LINE-NUMBER            PIC 9(02). 
  07  FILLER PIX X(18) VALUE ZERO. (so you end up with zeros in the final 9 entries).


05 HOLD-LINE-DATA-H.
 06  FILLER OCCURS 6 TIMES.           
   07 HOLD-LINE-DATA-HOSP       OCCURS 18.     
      10 HOLD-LINE-NUMBER-H          PIC 9(02).

MOVE CONV-LINE-DATA TO HOLD-LINE-DATA-H


I'm one of those who always puts OCCURS on FILLERs. I like solutions with data definitions.

May not be any use to you at all, as the mapping is totally crucial to success.

Why are they PIC 9(02)? Just because it has "NUMBER" in the name, or do you use it as a numeric item?
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Sep 27, 2011 7:38 pm    Post subject:
Reply with quote

Thanks Sambhaji. I finally managed to find a solution to this one. i believe it wil work. need to test it immediately.


Code:
PARA:
  PERFORM VARYING WS-SUB1 FROM WS-SUB1 BY 1 UNTIL WS-SUB1 > 99
                                             OR (CONV-LINE-NUMBER (WS-SUB1) = (ZERO OR SPACES OR LOW VALUES))
      MOVE CONV-LINE-NUMBER (WS-SUB1)       
        TO HOLD-LINE-NUMBER (WS-SUB2 WS-SUB3)
      ADD +1 TO WS-SUB3     
      IF WS-SUB3 > 18
         MOVE +1 TO WS-SUB3
    ADD +1 TO WS-SUB2
         GO TO PARA
      END-IF
  END-PERFORM         
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Sep 27, 2011 7:50 pm    Post subject: Reply to: Moving one dimensional array to two dimensional ar
Reply with quote

If CONV-LINE-NUMBER is defined as Display-Numeric, then you're probably going to get a compilation-error, because you're checking this field directly for LOW-VALUES and SPACES.

Instead, check for NOT NUMERIC.

Mr. Bill
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Sep 27, 2011 7:51 pm    Post subject:
Reply with quote

PrabakarV, Why you have not gone for simple move shown by Bill?
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Sep 27, 2011 8:14 pm    Post subject:
Reply with quote

Sambhaji, because i am not authorized change that variable declaration... i just need to process it... icon_smile.gif
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Sep 27, 2011 8:23 pm    Post subject:
Reply with quote

My guess.... Is it interview question???
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Sep 27, 2011 8:27 pm    Post subject:
Reply with quote

better luck next time mate... they have given me copybook that i cant chagne it but should use.... what i can i do other than to find a solution.... icon_smile.gif
Back to top
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Tue Sep 27, 2011 9:17 pm    Post subject:
Reply with quote

??? And there is NO group level over the ARRAY-1 and ARRAY-2???

Seems strange.

If there were a group level over the arrays

01 ARRAY-1-GROUP-LEVEL. --and-- 01 ARRAY-2-GROUP-LEVEL.

*** then the SIMPLE MOVE statement would do the trick
MOVE ARRAY-1-GROUP-LEVEL TO ARRAY-2-GROUP-LEVEL.
MOVE SPACES TO ARRAY-2-GROUP-LEVEL (99:18).

.ARRAY 1

Code:
05 CONV-LINE-DATA OCCURS 99.
10 CONV-LINE-NUMBER PIC 9(02).


ARRAY2

Code:
05 HOLD-LINE-DATA-H OCCURS 6 TIMES.
07 HOLD-LINE-DATA-HOSP OCCURS 18.
10 HOLD-LINE-NUMBER-H PIC 9(02).
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Tue Sep 27, 2011 9:46 pm    Post subject:
Reply with quote

PrabakarV wrote:
Thanks Sambhaji. I finally managed to find a solution to this one. i believe it wil work. need to test it immediately.


Code:
PARA:
  PERFORM VARYING WS-SUB1 FROM WS-SUB1 BY 1 UNTIL WS-SUB1 > 99
                                             OR (CONV-LINE-NUMBER (WS-SUB1) = (ZERO OR SPACES OR LOW VALUES))
      MOVE CONV-LINE-NUMBER (WS-SUB1)       
        TO HOLD-LINE-NUMBER (WS-SUB2 WS-SUB3)
      ADD +1 TO WS-SUB3     
      IF WS-SUB3 > 18
         MOVE +1 TO WS-SUB3
    ADD +1 TO WS-SUB2
         GO TO PARA
      END-IF
  END-PERFORM         


You have a GO TO from within your perform. This is not good practice, and is unnecessary. If you just remove the GO TO it'll be better, it will find the end of the if, the end of the perform structure and just normally continue the perform.

I assume "LOW VALUES" is a typo. Always, please, copy-and-paste your code here rather than re-type, else we may get led astray by a typo.

You seem to think the first table is not initialised. Have you confirmed this? Usually if a table contains uninitialised values there will be a count on the record for how many entries are occupied, and your other tests would not be necessary. If you need them, check in your Cobol manuals as the compiler option NUMPROC might get in your way (check on option ZWB if NUMPROC(NOPFD)).

Are you absolutely sure you can't validly have zero somewhere in the middle of the table?

Are you sure that is the data-mapping you want? No more logic than fill as much of the second table one at a time as you can. Do you set the second table, each time, to some starting value? If not, you are going to get a mix of data. If the first table the first time has 10 entries, you will copy 10 to the second table. If the second time the first has only one, you will copy one, but it will "look" like there are 10 if you use similar code to test for the presence of values in the second table.

We assume SUB2 and SUB3 are given a value of one somewhere before the perform.

Why the dumb names for your subscripts? Doesn't the data mean anything in business terms? Why don't you name your subscripts reflecting that, which will make the code easier to understand for anyone picking it up later (which may be you, a few months down the line).

I think the WS-SUB1 FROM WS-SUB1 will cause confusion to the reader. Someone will wonder whether the value changes each time through the loop.

Whoever "designed" the data structure in the first place did you no favours, with no group item (as ridgewalker pointed out and as my example would need).
Back to top
View user's profile Send private message
PrabakarV

New User


Joined: 21 Dec 2007
Posts: 88
Location: My Desk

PostPosted: Tue Sep 27, 2011 10:10 pm    Post subject:
Reply with quote

Quote:
I assume "LOW VALUES" is a typo. Always, please, copy-and-paste your code here rather than re-type, else we may get led astray by a typo.
- yes. Typo

Quote:
Are you absolutely sure you can't validly have zero somewhere in the middle of the table?
its already taken care.

Quote:
Are you sure that is the data-mapping you want?
No. Not really. It was given to me. I need to do process it. sometimes u got that as you are told icon_sad.gif

Quote:
We assume SUB2 and SUB3 are given a value of one somewhere before the perform.
Yes Bill. Moved 1 to them.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Moving a PD to PD spoorni DFSORT/ICETOOL 8 Fri Oct 07, 2016 9:52 pm
No new posts Moving character data to smallint in db2 rikdeb DB2 5 Thu Jul 14, 2016 12:38 am
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts MOVING COMP-3 into binary akodakka COBOL Programming 2 Tue Dec 01, 2015 5:02 pm
No new posts CICS- Moving to High availability vicky10001 CICS 8 Fri Oct 23, 2015 7:49 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us