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

How to Read a input file line by line and write 2 an output


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 9:51 am
Reply with quote

Hi,

I got stuck with a simple code, just want to know :
the syntax for reading the content of a dataset line by line and writing to another output dataset.
actually I want to take value from a dataset and use it as input to my program and after processing, its write to output dataset.
And after writing the pointer comes to second line and take the second input and append the second output with the first result in the same output dataset.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Nov 06, 2008 9:58 am
Reply with quote

This is very basic and you should be able to get your answer from the COBOL Language Reference Manual. A READ statement makes a line (record) available to your program. A WRITE statement writes a record to your output data set. This combination of READ and WRITE statements in effect transfers information from the input data set to the output data set. There's a bit more to it than that, but that should get you started.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Nov 06, 2008 9:59 am
Reply with quote

Sorry -- just noticed this was in the REXX/CLIST forum. As Emily Lattela would say, "Never mind!"
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Thu Nov 06, 2008 10:01 am
Reply with quote

Terry,

I guess the TS was asking for a REXX solution. I would suggest going through the REXX reference materials the link to which is at the top of this page. Goodluck
Back to top
View user's profile Send private message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 10:02 am
Reply with quote

I want it in REXX, am just the beginner.please help
I want to take data from a dataset as a input and write it in OUTPUT FILE,
and again it should take the input frm second line of the input file and write the output by appending with the first output.
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Thu Nov 06, 2008 10:13 am
Reply with quote

Read the rexx reference for the EXECIO command to read and write.

Search this forum for EXECIO. There are several examples.
Back to top
View user's profile Send private message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 10:29 am
Reply with quote

******my input file: TEST.SHARE.GDG.INPUT***********

ASDFGTHY QWER
CDERFDER YUIK
ZXCVBNMS TSCR
FGTHYUJI SJOS
CDFRTGBB DDAF

******MY PROGRAM *********

/* REXX */
A='TEST.REXX.TEMPLATE.GDG'
ADDRESS ISPEXEC "LIBDEF ISPSLIB DATASET ID('"A"')"
B='TEST.SHARE.GDG.INPUT'
/*HERE ITS GIVING ERROR CANNOT LOCATE THE B DATASET */

ADDRESS ISPEXEC "LIBDEF ISPSLIB DATASET ID('"B"')"

/*i IS THE LINE NUMBER OF THE INPUT I WANT IT TO GET INCREAMENTED EACH TIME IT COMES TO INPUT FILE AFTER WRITING THE OUTPUT.*/

RC = LINEOUT( B, , i);

JBNAME = Substr( 'RC', 3, 10 ) ---this will take 1st input from input file
SYM = Substr( 'RC', 19, 22 )---this will take the 2nd input frm the input file
/* SHARE USER ID AND PACKAGE ID */
UNAME = USERID()
PARSE VALUE DATE('S') WITH YEAR +4 MONTH +2 DAY
DAT = DATE(USA)
NOW = TIME()
"ISPEXEC VPUT (SYM) SHARED"
"ISPEXEC VPUT (JBNAME) SHARED"
"ISPEXEC VPUT (DAT) SHARED"
"ISPEXEC VPUT (NOW) SHARED"
ARG CSYM CJBNAME
"ALLOCATE FILE(ISPFILE) DATASET('TEST.SHARE.NEW.GDG(NEWGDG)') MOD "
ADDRESS ISPEXEC "FTOPEN"
ADDRESS ISPEXEC "FTINCL GDGNEW"
ADDRESS ISPEXEC "FTCLOSE NAME(NEWGDG)"
"FREE FI(ISPFILE)"
/* HERE THE CONDITION WILL COME FOR EOF.
RETURN
EXIT

I WANT IT TO PROCESS TILL THE INPUT ENDS IN MY INPUT FILE.
IS THERE eof SYNTAX IN REXX?
I WANT THE OUTPUT TO APPEND WITH THE LAST DATA,MINE IT IS REPLACING.



******this is present in my template: TEST.REXX.TEMPLATE.GDG*****

)SET CSYMB = &CSYM
)SET CNUMB = &CNUM
)SET USERID = &UNAME
)SET MM = &MON
)SET DD = &DATE
)SET YY = &YEA
)SET TI = &NOW
/* &MM/&DD/&YY &TI &USERID */
DEF GDG(NAME(yyyy.bbbc.&CNUMB..&CSYMB..asdfg) LIM(24) SCR)
/* &MM/&DD/&YY &TI &USERID */
DEF GDG(NAME(zzzz.cccc.&CNUMB..&CSYMB..qwert) LIM(24) SCR)
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Nov 06, 2008 12:34 pm
Reply with quote

DO NOT post the same question in a slightly different format because you are not getting exactly what you want from this thread. The second thread has been deleted

Where is the EXECIO statement to perform the read / write operations.

Pedro has suggested to go look at the EXECIO instruction in the manual, have you done that yet ? - The manuals can be reached by the "IBM Manuals" button at the top of each page.

Failing that - google is your friend !
Back to top
View user's profile Send private message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 4:19 pm
Reply with quote

Hi,

I did all the things now my program taking input line by line from the input dataset and processing
but I cannot append it, its taking the last input and displaying in the output.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Nov 06, 2008 4:26 pm
Reply with quote

Are you trying to get all of the lines into the ISPFILE ?

If so, once it has been allocated and opened, do not close it until you have finished, and close it only once after all the processing has completed.

Every time that you close and open the file it will start to write from the begining again, and not append to watever else is in there already.
Back to top
View user's profile Send private message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 4:32 pm
Reply with quote

This is my code, actually its taking input frm the input dataset and writing into the output file the last value.
i have 14 files in input dataset,its displaying the last value in the output file its not appending.
Please help



/* REXX */
/* PROGRAM TO CREATE GDG */
I = 1
/*ADDRESS ISPEXEC "LIBDEF ISPSLIB DATASET ID('TEST.SHARE.GDG.INPUT')"*/
"ALLOCATE FILE(INPGDG) DATASET('TEST.SHARE.GDG.INPUT') SHR REUSE "
"EXECIO * DISKR INPGDG (STEM LINE. FINIS"
DO UNTIL I > LINE.0
JBNAME = Substr( LINE.I, 1, 8)
SYM = Substr( LINE.I, 14, 4 )
SAY 'CREATION OF GDG IN PROGRESS ...'
/* SHARE USER ID AND PACKAGE ID */
UNAME = USERID()
PARSE VALUE DATE('S') WITH YEAR +4 MONTH +2 DAY
DAT = DATE(USA)
NOW = TIME()
text1.I = '/* '||dat||' '||now||' '||uname||' */'
text2.I= 'DEF GDG(NAME(WGTP.NONX.'||jbname||'.'||sym||'.PULLCNT)'||,
' LIM(24) SCR)'
text3.I= '/* '||dat||' '||now||' '||uname||' */'
text4.I= 'DEF GDG(NAME(WGTP.NONX.'||jbname||'.'||sym||'.AUDRPT)'||,
' LIM(24) SCR)'
TEXT.1 = TEXT1.I
TEXT.2 = TEXT2.I
TEXT.3 = TEXT3.I
TEXT.4 = TEXT4.I
I = I+1
END
"ALLOC f(iS1FILE) DA('TEST.SHARE.NEW.GDG(INPGDG)') SHR REUSE"
"execio * diskw is1file ( stem text. "
EXIT
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Nov 06, 2008 4:49 pm
Reply with quote

because at every iteration You overlay the text. stem

use a different index and You will see that the problem will disappear

Code:
.....
j = 0

....

j = j+1
TEXT.j = TEXT1.I
j = j+1
TEXT.j = TEXT2.I
j = j+1
TEXT.j = TEXT3.I
j = j+1
TEXT.j = TEXT4.I



also why bother to hand increment i ??
Code:
do i = 1 to to line.0
Back to top
View user's profile Send private message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 4:59 pm
Reply with quote

Hi,
Now i changed the code to this :
but same problem its writing the last input but not appending icon_sad.gif




/* REXX */
/* PROGRAM TO CREATE GDG */
/*ADDRESS ISPEXEC "LIBDEF ISPSLIB DATASET ID('TEST.SHARE.GDG.INPUT')"*/
"ALLOCATE FILE(INPGDG) DATASET('TEST.SHARE.GDG.INPUT') SHR REUSE "
"EXECIO * DISKR INPGDG (STEM LINE. FINIS"
DO I = 1 TO LINE.0
JBNAME = Substr( LINE.I, 1, 8)
SYM = Substr( LINE.I, 14, 4 )
SAY 'CREATION OF GDG IN PROGRESS ...'
/* SHARE USER ID AND PACKAGE ID */
UNAME = USERID()
PARSE VALUE DATE('S') WITH YEAR +4 MONTH +2 DAY
DAT = DATE(USA)
NOW = TIME()
text1.I = '/* '||dat||' '||now||' '||uname||' */'
text2.I= 'DEF GDG(NAME(WGTP.NONX.'||jbname||'.'||sym||'.PULLCNT)'||,
' LIM(24) SCR)'
text3.I= '/* '||dat||' '||now||' '||uname||' */'
text4.I= 'DEF GDG(NAME(WGTP.NONX.'||jbname||'.'||sym||'.AUDRPT)'||,
' LIM(24) SCR)'
J = 1
TEXT.J = TEXT1.I
J = J+1
TEXT.2 = TEXT2.I
J = J+1
TEXT.3 = TEXT3.I
J = J+1
TEXT.4 = TEXT4.I
I = I+1
"ALLOC f(iS1FILE) DA('TEST.SHARE.NEW.GDG(INPGDG)') SHR REUSE"
"execio * diskw is1file ( stem text. "
EXIT
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Nov 06, 2008 5:08 pm
Reply with quote

I wonder what is going on
the rexx as You posted will not even run...
the DO does not have the relative END
and no need to increment the i by hand,
DO will do it for You

You did not read my post ,
the j must be initialized to 0 outside of the loop

Your rexx behaves exactly like the previous one if You read it carefully
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Nov 06, 2008 5:13 pm
Reply with quote

Instead of
Code:

text2.I= 'DEF GDG(NAME(WGTP.NONX.'||jbname||'.'||sym||'.PULLCNT)'||,
' LIM(24) SCR)'


Why not
Code:

'  DEF GDG(NAME(WGTP.NONX.'||jbname||'.'||sym||'.PULLCNT)'||,
' LIM(24) SCR)'

to execute the command within the REXX itself ?
Back to top
View user's profile Send private message
honestsoul

New User


Joined: 05 Nov 2008
Posts: 23
Location: delhi

PostPosted: Thu Nov 06, 2008 6:06 pm
Reply with quote

THANX A LOT FRNDS FOR UR SUPPORT FINALLY GOT IT icon_smile.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Nov 06, 2008 6:13 pm
Reply with quote

Even if your problem is solved, I advice you to add FINIS to the diskw,
so the file is correctly closed.
Code:
"execio * diskw is1file ( stem text. FINIS"
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 -> CLIST & REXX

 


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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
Search our Forums:

Back to Top