IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to read array backward( in reverse order)


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
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
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
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

Moderator Emeritus


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

PostPosted: Tue Feb 02, 2010 3:37 am
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 02, 2010 2:41 pm
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

Moderator Emeritus


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

PostPosted: Tue Feb 02, 2010 8:34 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 02, 2010 8:49 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 02, 2010 9:12 pm
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Feb 02, 2010 9:35 pm
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Feb 03, 2010 12:28 am
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
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. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Rotate partition-logical & physic... DB2 0
No new posts Random read in ESDS file by using RBA JCL & VSAM 6
No new posts VSAM return code 23 - for a Random read COBOL Programming 4
No new posts ICETOOL to Read records SMF CEF it is... DFSORT/ICETOOL 4
Search our Forums:

Back to Top