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
 

 

Reverse printing of records.

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

New User


Joined: 26 Nov 2010
Posts: 30
Location: Hyderabad

PostPosted: Mon Jan 31, 2011 11:12 am    Post subject: Reverse printing of records.
Reply with quote

I am pasting the code which i have written.
I am struck in the logic to print the records from reverse order.
EX: IF Input data set has:
My name is Jaffar
Output data set should be having:
raffaJ si eman yM
Please share me the logic and solution to get this.


IDENTIFICATION DIVISION.
PROGRAM-ID. REVERSE.
AUTHOR. JAFFAR HUSSAIN.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INDATA ASSIGN TO DD1.
SELECT OUTDATA ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD INDATA.
01 INREC PIC X(80).
FD OUTDATA.
01 OUTREC PIC X(80).
WORKING-STORAGE SECTION.
01 PRINT.
02 ARRAY PIC X(80) OCCURS 1 TIMES INDEXED BY IDX.
01 X PIC 9(01) VALUE ZERO.
88 END-OF-FILE VALUE 1.
77 I PIC 9(01) VALUE 01.
*77 IDX USAGE IS INDEX.
77 COUNT1 PIC 9(02) VALUE 80.
PROCEDURE DIVISION.
PROGRAM-START.
PERFORM 001-MOVE-PARA.
001-MOVE-PARA.
PERFORM VARYING I FROM 1 BY 1 UNTIL I>1
OPEN INPUT INDATA
OPEN OUTPUT OUTDATA
PERFORM UNTIL END-OF-FILE
READ INDATA
AT END SET END-OF-FILE TO TRUE
END-READ
MOVE INREC TO ARRAY(1)
IF X<1
* PERFORM VARYING IDX FROM 80 BY -1 UNTIL IDX<1
* SET IDX TO 02
* PERFORM UNTIL COUNT1>1
WRITE OUTREC FROM ARRAY(1)
* MOVE -1 TO COUNT1
* DISPLAY 'COUNT1:' COUNT1
* END-PERFORM
* END-PERFORM
END-IF
END-PERFORM
END-PERFORM
CLOSE INDATA
CLOSE OUTDATA
STOP RUN.
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: Mon Jan 31, 2011 11:29 am    Post subject:
Reply with quote

Hello,

At the top of the page is a link to "IBM Manuals". The top of the list is for COBOL. Look in the Language Reference for your release of the compiler for REVERSE. The flashlight/tubelight near the top left is the search feature for the manual.

You might also look in this COBOL part of the forum as this has been discussed before.
Back to top
View user's profile Send private message
jaffarhussain

New User


Joined: 26 Nov 2010
Posts: 30
Location: Hyderabad

PostPosted: Mon Jan 31, 2011 11:44 am    Post subject: Thanks for the reply.
Reply with quote

Thanks for your quick response

I have did it using this function reverse before and I got the output.

But for me the task is without using any function i need to write logic of my own.

Else can you give me the open source of function reverse so that I can go thought it what logic it has in function reverse ?

Thanks a lot in advance
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8054
Location: East Dubuque, Illinois, USA

PostPosted: Mon Jan 31, 2011 4:01 pm    Post subject:
Reply with quote

First, COBOL is not open source.

Second, the function's source code is almost certainly in assembler, written by and maintained by IBM, and not accessible unless you work for IBM in the compiler support group.

Third, there is nothing hard about using reference modification with an input and output variable to reverse the input variable -- so why are you needing source code, anyway?
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Jan 31, 2011 4:18 pm    Post subject:
Reply with quote

Is this a student assignment?

Please use BBcode tags in your posts when you post code. They can also be useful in structuring your text.

You have posted a nice framework above for a start, you only need til fill in the right logic.

Hint:

You need 2 arrays:
    The source array
    The target array (the reversed string)

If you have a loop (perform) counting a source index value down from the highest (max) index value until the lowest, the index value of the target array could be expressed as:
Code:

target-idx = max-idx - source-idx + 1

You first challenge is to think and come up with the right algorithms and logic, then the programming should be easy!
Back to top
View user's profile Send private message
jaffarhussain

New User


Joined: 26 Nov 2010
Posts: 30
Location: Hyderabad

PostPosted: Mon Jan 31, 2011 5:45 pm    Post subject: I got the solution blow is the code worked sucessfully.
Reply with quote

I got the solution blow is the code worked sucessfully


INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INDATA ASSIGN TO DD1.
SELECT OUTDATA ASSIGN TO DD2.
DATA DIVISION.
FILE SECTION.
FD INDATA.
01 INREC PIC X(80).
FD OUTDATA.
01 OUTREC PIC X(80).
WORKING-STORAGE SECTION.
01 X PIC 9(01) VALUE ZERO.
88 END-OF-FILE VALUE 1.
01 Y PIC 9 VALUE 0.
77 I PIC 99 VALUE 80.
77 J PIC 99 VALUE 01.
01 WS-TEMP PIC X(80).
PROCEDURE DIVISION.
PROGRAM-START.
PERFORM 001-MOVE-PARA.
001-MOVE-PARA.
OPEN INPUT INDATA
OPEN OUTPUT OUTDATA
PERFORM UNTIL END-OF-FILE
MOVE 80 TO I
MOVE 01 TO J
READ INDATA
AT END SET END-OF-FILE TO TRUE
END-READ
IF END-OF-FILE
MOVE 1 TO Y
END-IF
PERFORM UNTIL I < 1
MOVE INREC(I:1) TO WS-TEMP(J:1)
* I = I - 1
* J = J + 1
DISPLAY 'I:' I
DISPLAY 'J:' J
SUBTRACT 1 FROM I
ADD 1 TO J
END-PERFORM
IF Y<1
WRITE OUTREC FROM WS-TEMP
END-IF
END-PERFORM
CLOSE INDATA
CLOSE OUTDATA
STOP RUN.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Jan 31, 2011 6:05 pm    Post subject:
Reply with quote

Quote:
Code:
PERFORM UNTIL I < 1
MOVE INREC(I:1) TO WS-TEMP(J:1)
* I = I - 1
* J = J + 1
DISPLAY 'I:' I
DISPLAY 'J:' J
SUBTRACT 1 FROM I
ADD 1 TO J
END-PERFORM

My suggestion was to eliminate the use of J completely:
Code:

PERFORM VARYING I FROM 80 BY -1 UNTIL I < 1
MOVE INREC(I:1) TO WS-TEMP(81-I:1)
DISPLAY 'I:' I
END-PERFORM
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 Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am
No new posts Inserting records based on conditions vickey_dw DFSORT/ICETOOL 9 Wed Feb 22, 2017 1:33 pm


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