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
 

 

How to read array backward( in reverse order)

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
pradyutonnet
Currently Banned

New User


Joined: 13 Nov 2005
Posts: 29
Location: pune,mumbai

PostPosted: Tue Feb 02, 2010 1:57 am    Post subject: How to read array backward( in reverse order)
Reply with quote

i have a array of 15 and i have did some processing to store data in it, now i want read backward from last entered data to 1st one, can some one please give me syntex for the same..

like forward read syntex would be:-

Code:
PERFORM VARYING WS-TEXT-SUB
           FROM 1
             BY 1
          UNTIL WS-TEXT-SUB > 15
             OR WS-TEXT-FOUND = 'Y'

    IF WS-TEXT-Q-LINE (WS-TEXT-SUB) > SPACES
        MOVE 'Y'              TO WS-TEXT-FOUND
    END-IF

END-PERFORM.


in above code array will read thru WS-TEXT-SUB 1 TO 15..

BUT i have diff req and i want read from 15th data to 1st one...how it is possible...can somebudddy help me to resolve the issue with correct syntex

thanks
Prady
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Feb 02, 2010 2:20 am    Post subject:
Reply with quote

Real hard to do!

Code:
PERFORM VARYING WS-TEXT-SUB
           FROM 15
             BY -1
          UNTIL WS-TEXT-SUB <  1
             OR WS-TEXT-FOUND = 'Y'
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Feb 02, 2010 3:37 am    Post subject:
Reply with quote

Hello,

I suspect the original "sample" code posted is not the same as the "real" code. . .

If data was loaded into the array, i would expect the first entry to have non-space values, so the loop would terminate on the first iteration . . .

If the actual requirement was described, someone may have an additional suggestion.
Back to top
View user's profile Send private message
pradyutonnet
Currently Banned

New User


Joined: 13 Nov 2005
Posts: 29
Location: pune,mumbai

PostPosted: Tue Feb 02, 2010 12:55 pm    Post subject: Reply to: How to read array backward( in reverse order)
Reply with quote

sample code i have given in the req is for example only, all i want to know how to read array backward...i hope "Craq Giegerich" reply will work for me..if can we use "DECREMENT" instead of "-1"

Please provide me syntex for the same.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Feb 02, 2010 2:41 pm    Post subject: Reply to: How to read array backward( in reverse order)
Reply with quote

Quote:
Please provide me syntex for the same.

why not look at the manual Yourself???
click on the link at the top of the page
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Feb 02, 2010 8:34 pm    Post subject:
Reply with quote

Hello,

Quote:
i hope "Craq Giegerich" reply will work for me
Is there any good reason you have not already tried the code?

You seemed ok with incrementing thru the array using 1 - why the concern with -1?
Back to top
View user's profile Send private message
pradyutonnet
Currently Banned

New User


Joined: 13 Nov 2005
Posts: 29
Location: pune,mumbai

PostPosted: Tue Feb 02, 2010 8:43 pm    Post subject:
Reply with quote

hey dick ,,i was at home that time ..now m in office i will try...

@enrico-sorichetti... lots of things are present in the books...tell me one thing i read everything over der thn whts the use of this forum???
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Feb 02, 2010 8:49 pm    Post subject: Reply to: How to read array backward( in reverse order)
Reply with quote

even a stupid google search would have given You the info You asked us to provide..
I just tested googling with cobol perform varying and the first link returned contains this sentence
Quote:
The VARYING phrase increases or decreases the value of one or more identifiers or index-names, according to certain rules. (See Varying Phrase Rules.)


Quote:
tell me one thing i read everything over der thn whts the use of this forum???

not certainly to do manual reading services for lazy people
especially when the manual explanation is quite clear
Back to top
View user's profile Send private message
pradyutonnet
Currently Banned

New User


Joined: 13 Nov 2005
Posts: 29
Location: pune,mumbai

PostPosted: Tue Feb 02, 2010 9:04 pm    Post subject:
Reply with quote

u know enrico lots of other sites( not only google) also present for these things... yesterday when i was coding the program i got stuck in above scenario so i asked this question here,this is not only to get answer of my question but also want to share the things with other programers...bcz before posting the question here, i was searching in this site and i did not get anything....i posted( my lazy stuff) here so that diff people can share diff ideas over here...any forum is not only for question & answer stuffs...

Forum is for "a public meeting or assembly for open discussion"...where we can discuss nything openly..

And if you think its lazy people question then no need to answer... u r not the principle of any organisation...its ur wish to reply(if u like)...

and if this site is only belongs to you then let me know...
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Feb 02, 2010 9:12 pm    Post subject: Reply to: How to read array backward( in reverse order)
Reply with quote

My comments were a related to the lazy question
Quote:
Please provide me syntex for the same.

when the proper syntax had already been provided

Quote:
where we can discuss nything openly..

You were not discussing anything, you were asking

Quote:
u r not the principle of any organisation...

no but I have enough experience to classify laziness when I see it...
and ... I was not judging You I was classifying You
( search a bit by Yourself for the difference between the two actions )

Quote:
and if this site is only belongs to you then let me know...

ah ah ah
Back to top
View user's profile Send private message
pradyutonnet
Currently Banned

New User


Joined: 13 Nov 2005
Posts: 29
Location: pune,mumbai

PostPosted: Tue Feb 02, 2010 9:23 pm    Post subject:
Reply with quote

Quote:
My comments were a related to the lazy question


asking for syntex is may be lazyness for u but idont think d same, i wrote bcz if in future any new programmer comes here for reference he/she can easily understand...wht was wrote and wht would be the solution of my question.



Quote:
You were not discussing anything, you were asking


i guess to discuss ny thing on forum u have to start with asking ny question.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10201
Location: italy

PostPosted: Tue Feb 02, 2010 9:35 pm    Post subject: Reply to: How to read array backward( in reverse order)
Reply with quote

please refrain from using sms writing style or have Your keyboard fixed.
it makes difficult to understand what You try to say

for reference a programmer should look at the manuals
Back to top
View user's profile Send private message
rockish

Active User


Joined: 05 Jun 2009
Posts: 185
Location: Planet Earth

PostPosted: Tue Feb 02, 2010 11:06 pm    Post subject:
Reply with quote

Oooph...
Quote:
Joined: 13 Nov 2005


And after four years, a doubt about how to traverse an array in a reverse order. I guess traversing in an array was something i did in my school days !!!! I am not trying to offend the person who posted this. But being a IT professional and not being able to solve this by themselves and wanted a 'open discussion' on this, I find it crazy. And definitely when (s)he is not able to post the attempts he did and the failures he met when the question was this basic.

I agree that forums are to discuss. But not every B37 and timeout erros we face at work. Or rather syntax mistakes. There are certain things that not many freshers would come to forums for help. And if someone comes with such a thought, he only needs a redirection to manuals. Not until you read IBM manuals, you can know how much information it provides and that too in a clear way. One need not be a owner of a website or principal of any organization to tell this. Anybody who understands the value of IBM manuals and value of the time, which experts spend here can talk about it.

All the above statements are purely my comments on this post and I apologize if it hurts anybody.
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: Wed Feb 03, 2010 12:28 am    Post subject: Reply to: How to read array backward( in reverse order)
Reply with quote

It's good practice (and if possible) to dynamically calculate the max OCCURS of an array beforehand, then it will always be correct. This will save time in the logic (in this example) to find all the code-spots where 15 is being used and if the OCCURS maximum ever changes, WS-TEXT-SUB-MAX will always be correct.

Code:

03  WS-TEXT-SUB PIC S9(08) COMP.
03  WS-TEXT-SUB-MAX PIC S9(08) COMP.
03  WS-TEXT-ARRAY-REC.
    05  WS-TEXT-ARRAY OCCURS 15 TIMES PIC  X(12).

DIVIDE LENGTH OF WS-TEXT-ARRAY-REC BY LENGTH OF WS-TEXT-ARRAY (1) GIVING WS-TEXT-SUB-MAX.

DIVIDE 180 BY 12 and WS-TEXT-SUB-MAX equals 15

Bill
Back to top
View user's profile Send private message
Chirantan Banerjee

New User


Joined: 08 Oct 2009
Posts: 12
Location: Kolkata, India

PostPosted: Thu Feb 11, 2010 3:36 pm    Post subject: Re: Reply to: How to read array backward( in reverse order)
Reply with quote

Thanks Bill, for the good programming practice. Now at least we have something useful for a 'new programmer' of the 'future'. The 'lazy question' and the other posts were getting us nowhere.

Bill O'Boyle wrote:
It's good practice (and if possible) to dynamically calculate the max OCCURS of an array beforehand, then it will always be correct. This will save time in the logic (in this example) to find all the code-spots where 15 is being used and if the OCCURS maximum ever changes, WS-TEXT-SUB-MAX will always be correct.

Code:

03  WS-TEXT-SUB PIC S9(08) COMP.
03  WS-TEXT-SUB-MAX PIC S9(08) COMP.
03  WS-TEXT-ARRAY-REC.
    05  WS-TEXT-ARRAY OCCURS 15 TIMES PIC  X(12).

DIVIDE LENGTH OF WS-TEXT-ARRAY-REC BY LENGTH OF WS-TEXT-ARRAY (1) GIVING WS-TEXT-SUB-MAX.

DIVIDE 180 BY 12 and WS-TEXT-SUB-MAX equals 15

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    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 CICS VSAM RLS READ akodakka CICS 3 Tue Oct 04, 2016 3:09 pm
No new posts Multi row fetch - "for read only... Nileshkul DB2 3 Sun Aug 14, 2016 12:52 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 RFE: Additional compound operators fo... prino PL/I & Assembler 1 Wed Jun 08, 2016 3:31 pm
No new posts To read from Zeke scheduler p.anbuselvan CLIST & REXX 5 Thu Mar 31, 2016 1:13 am


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