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

Reverse printing of records.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Mon Jan 31, 2011 11:29 am
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Jan 31, 2011 4:01 pm
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top