Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
PrabakarV

New User

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

Posted: Tue Sep 27, 2011 6:40 pm    Post subject: Moving one dimensional array to two dimensional array

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]

Escapa

Senior Member

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

 Posted: Tue Sep 27, 2011 6:44 pm    Post subject: Refer this thread
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

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

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?
PrabakarV

New User

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

Posted: Tue Sep 27, 2011 7:38 pm    Post subject:

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
Bill O'Boyle

CICS Moderator

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

 Posted: Tue Sep 27, 2011 7:50 pm    Post subject: Reply to: Moving one dimensional array to two dimensional ar 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
Escapa

Senior Member

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

 Posted: Tue Sep 27, 2011 7:51 pm    Post subject: PrabakarV, Why you have not gone for simple move shown by Bill?
PrabakarV

New User

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

 Posted: Tue Sep 27, 2011 8:14 pm    Post subject: Sambhaji, because i am not authorized change that variable declaration... i just need to process it...
Escapa

Senior Member

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

 Posted: Tue Sep 27, 2011 8:23 pm    Post subject: My guess.... Is it interview question???
PrabakarV

New User

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

 Posted: Tue Sep 27, 2011 8:27 pm    Post subject: 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....
ridgewalker58

New User

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

 Posted: Tue Sep 27, 2011 9:17 pm    Post subject: ??? 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).
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

Posted: Tue Sep 27, 2011 9:46 pm    Post subject:

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).
PrabakarV

New User

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

Posted: Tue Sep 27, 2011 10:10 pm    Post subject:

 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?

 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

 Quote: We assume SUB2 and SUB3 are given a value of one somewhere before the perform.
Yes Bill. Moved 1 to them.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm Moving a PS file as body of a mail! Vignesh Sid JCL & VSAM 4 Tue Nov 21, 2017 9:23 pm Moving UDB database to Db2 on z/OS Keith Hooley DB2 4 Wed Sep 27, 2017 12:38 am Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm Dynamic array request/response contai... Suja.Sai CICS 2 Tue Jan 24, 2017 11:37 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us