READSEQ

873 views
Skip to first unread message

ufuktu

unread,
Jun 15, 2009, 12:47:22 PM6/15/09
to jBASE
Hi, in jbase I am trying to write a routine where it reads a file
under a directory and than pass that information to t24. First I
open the file and than read it using READSEQ. The problem is file I am
reading is a csv with first line having the headers. It is always 2nd
line I am starting and go to the end of the file. IT is like;
test1,test2
1,2
3,4
I want to read 1,2 & 3,4 it really depends on the number of the
transactions smt. it has 100 lines smt. only 5. Can anyone please help
me how to position my program so than it starts from the second line
and goes through all the lines until it reaches to the end. thanks...

Daniel Klein

unread,
Jun 15, 2009, 5:38:23 PM6/15/09
to jB...@googlegroups.com
The simplest thing would be (in pseudo code):
OPENSEQ
READSEQ firstline ;* gets past header
LOOP
    READSEQ nextline ELSE EXIT
    do something clever with 'nextline'
REPEAT
CLOSESEQ
Dan

ufuktu

unread,
Jun 16, 2009, 1:32:39 PM6/16/09
to jBASE
hi, thanks for your reply. that did not work for some reason, if
possible can you provide more details...

Anureka Rajesh

unread,
Jun 16, 2009, 2:14:52 PM6/16/09
to jB...@googlegroups.com
Hi,
 
Be more specific on what dint work and if possible send the part of code you tried.
For whatever Daniel suggested should work fine. May be you are missing out some syntax.
 
Cheers,
Anu :-)

concern shoko

unread,
Jun 17, 2009, 3:39:27 AM6/17/09
to jB...@googlegroups.com
This syntax worked on G13, play around it to suit your needs.

  OPENSEQ '/globus/filename.cvs' TO INFILE ELSE PRINT 'CANNOT OPEN FILE'
 
    LOOP
        READSEQ DATA.REC FROM INFILE ELSE PRINT 'CANNOT READ FILE'
    WHILE DATA.REC NE ''

MSG.CODE = TRIM(FIELD(DATA.REC,',',1)) ; * Get the first value in the line
          
 IF MSG.CODE NE 'HDR' THEN
GOSUB PROCESS
 END
 
      REPEAT

And if openseq is giving you trouble try READ below. It reads a file delimited by pipe (|) and loops through it line by line...

READ FILE.REC FROM FOLDER.NAME,FILE.NAME ELSE FILE.REC = ''

NO.LINES = DCOUNT(FILE1.REC, FM) ; * Get the no. of lines in the file
 
 FOR NN = 1 TO NO.LINES 
 LINE = FILE1.REC<NN> ; * Read 1 line at a time.
 MSG.CODE = TRIM(FIELD(LINE,'|',1)) ; * Get the first value in the line
          
 IF MSG.CODE NE 'HDR' THEN
GOSUB PROCESS
 END 
 
    NEXT NN
REPEAT
Regards
Concern

gabalian

unread,
Jun 17, 2009, 1:45:58 AM6/17/09
to jB...@googlegroups.com
Why don't you use READBLK to read the whole file at once.

OPENSEQ 'MYSLIPPERS', 'PINK' TO FILE.VAR ELSE ABORT
READBLK VAR.DATE FROM FILE.VAR, 50 THEN PRINT VAR.DATA


where 50 is number of bytes that you want to get from the file.

VAR.DATA will be populated with the required data and from there on you can manipulate it according to your need.

Regards,
Imran


On Tue, Jun 16, 2009 at 11:32 PM, ufuktu<ufuk...@btinternet.com> wrote:
>
> hi, thanks for your reply. that did not work for some reason, if
> possible can you provide more details...
>
>


--
Imran Khan
T24 Technical Consultant
+92 334 3545114

Daniel Klein

unread,
Jun 17, 2009, 8:29:21 AM6/17/09
to jB...@googlegroups.com
You need to post your code so that I can show you where you went wrong ;-)
Also, pay no attention to that man behind the curtain. The suggestions to use READ or READBLK, in this situation, are inferior to using READSEQ.
Dan

ufuktu

unread,
Jun 17, 2009, 9:01:24 AM6/17/09
to jBASE
Hi, thanks for all recommended solution, I am sending you my code,
hope you can tell me where it went wrong...
**********************************************************************************************************************************
Y.SELECT.FILES = "SELECT " : DC.IN.DIR
CALL EB.READLIST(Y.SELECT.FILES, Y.FILE.ID.LIST, '', YSEL,'')
LOOP
REMOVE Y.FILE.ID FROM Y.FILE.ID.LIST SETTING YID.POS
WHILE Y.FILE.ID:YID.POS
Y.FILE = DC.IN.DIR : "/" : Y.FILE.ID
OPENSEQ Y.FILE READONLY TO F.DC.IN ELSE F.DC.IN = ""
Y.RECORD.FOUND = 1
LINE.CTR = 1
START.DETAIL.LINE = 2
LOOP
READSEQ Y.REC.DETAILS FROM F.DC.IN ELSE Y.RECORD.FOUND = 0
UNTIL NOT( Y.RECORD.FOUND )
IF LINE.CTR >= START.DETAIL.LINE THEN
CONVERT ',' TO FM IN Y.REC.DETAILS
Y.TTYPE = Y.REC.DETAILS<1>
Y.LOCAL.DATE = Y.REC.DETAILS<2>
Y.TLOGID = Y.REC.DETAILS<4> ;*TRANS ID
Y.FT.DETAILS<-1> =
Y.TTYPE:"_":Y.LOCALDATE:"_":Y.TLOGID
END
LINE.CTR = LINE.CTR + 1
CRT Y.FT.DETAILS
REPEAT
CLOSESEQ F.DC.IN
Y.ARCH.FILE.LIST<-1> = Y.FILE.ID
REPEAT ;REM < End of reading file list>
CALL BATCH.BUILD.LIST("",Y.FT.DETAILS)
RETURN ;* Finish PROCESS.FILES

Daniel Klein

unread,
Jun 17, 2009, 10:49:20 AM6/17/09
to jB...@googlegroups.com
You did not follow the example at all. You need to get rid of all of
the flags and counters that just clutter up the code.

Here's what you should be doing, assuming that all of the rest of code
is correct...

0001 Y.SELECT.FILES = "SELECT " : DC.IN.DIR
0002 CALL EB.READLIST(Y.SELECT.FILES, Y.FILE.ID.LIST, '', YSEL,'')
0003 LOOP
0004 REMOVE Y.FILE.ID FROM Y.FILE.ID.LIST SETTING YID.POS
0005 WHILE Y.FILE.ID:YID.POS
0006 Y.FILE = DC.IN.DIR : "/" : Y.FILE.ID
0007 OPENSEQ Y.FILE READONLY TO F.DC.IN ELSE F.DC.IN = ""
0008 * Next line gets past the header, iow the first line of the sequential file
0009 READSEQ Y.REC.DETAILS FROM F.DC.IN THEN ;* If there is
a header then continue on
0010 LOOP
0011 READSEQ Y.REC.DETAILS FROM F.DC.IN ELSE EXIT
0012 CONVERT ',' TO FM IN Y.REC.DETAILS
0013 Y.TTYPE = Y.REC.DETAILS<1>
0014 Y.LOCAL.DATE = Y.REC.DETAILS<2>
0015 Y.TLOGID = Y.REC.DETAILS<4> ;*TRANS ID
0016 Y.FT.DETAILS<-1> =
0017 Y.TTYPE: "_":Y.LOCALDATE:"_":Y.TLOGID
0018 CRT Y.FT.DETAILS
0019 REPEAT
0020 END
0021 CLOSESEQ F.DC.IN
0022 Y.ARCH.FILE.LIST<-1> = Y.FILE.ID
0023 REPEAT ;REM < End of reading file list>
0024 RETURN ;* Finish PROCESS.FILES


Dan

concern shoko

unread,
Jun 17, 2009, 10:18:12 AM6/17/09
to jB...@googlegroups.com
What error message are you getting?
--
C. Shoko
Temenos GLOBUS Developer
|Nedbank Africa|South Africa|

ufuktu

unread,
Jun 17, 2009, 1:42:22 PM6/17/09
to jBASE
Thanks for the advice and correction to my code, that worked apart
from the fact that it is now duplicating the entries... It looks like
it is going through each line twice. I am using multi threaded routine
and linking it to a tsa.service in t24... I do not really understand
why this happens... Any idea why this happens? Any suggestions...
Appreciate your help.

Daniel Klein

unread,
Jun 17, 2009, 5:45:11 PM6/17/09
to jB...@googlegroups.com

ufuktu

unread,
Jun 18, 2009, 8:25:19 AM6/18/09
to jBASE
Thanks for all your help, I have written a multithreaded routine with
load, select and processing routines... The bit I was struggling was
when I was reading the CSV file which has a header and more than 1
lines,,, thanks for the samples and correction to my code, that is all
been fixed... Then I had this duplicated entries created,,, debugged
my routine and realized that in the processing routine I missed
"return" statement where the program looped and tried to create the
same transaction for the same line again. This is all been sorted out
now, I appreciate all your help.... Best Regards, Ufuk

Mike Preece

unread,
Jun 18, 2009, 11:39:11 PM6/18/09
to jBASE
is=>has
is+>has
calls well

Crusader Sterling Pensions

unread,
Sep 3, 2009, 6:36:41 AM9/3/09
to jB...@googlegroups.com
 
I am trying to read from a CSV file, below is my program:
 

SUBROUTINE CSP.UPLOAD.EMPLOYER

*

$INSERT I_EQUATE

$INSERT I_COMMON

$INSERT I_F.CUSTOMER

$INSERT I_F.CATEGORY

$INSERT I_F.PF.EMPLOYER

*

GOSUB INITIALIZE

GOSUB PROCESS.REC

RETURN

*

INITIALIZE:

*

FN.PF.EMPLOYER = 'F.PF.EMPLOYER$NAU'

F.PF.EMPLOYER = ''

CALL OPF(FN.PF.EMPLOYER,F.PF.EMPLOYER)

DEBUG

*

FILE.NAME = 'employer_rc':'.csv'

* Modification of Initial Program to open upload folder

F.FOLDER = ''

F.FOLDER = 'CUSTREG.FILES'

OPEN F.FOLDER TO F.SEQ.FILE.PATH ELSE RETURN

RETURN

*

PROCESS.REC:

YF.COUNT = 0

F.FOLDER = F.FOLDER:'/'

DEBUG

OPEN F.FOLDER TO F.IN.QUEUE THEN

SEL.CMD = "SELECT ": F.FOLDER:" WITH @ID UNLIKE ...-..."

CALL EB.READLIST (SEL.CMD, SEL.LIST,'',Y.RECNO,RET.CODE)

IF Y.RECNO LT '1' THEN

PRINT "ERROR"

RETURN

END

LOOP

 

REMOVE Z.YID FROM SEL.LIST SETTING Y.POS

YF.COUNT += 1

YREC.NO = 0

WHILE Z.YID DO

YR.ASCII.ID = Z.YID

IF NOT (INDEX(YR.ASCII.ID,'-',1)) AND YR.ASCII.ID NE '' THEN

READ YR.ASCII.REC FROM YF.ASCII.FILE, YR.ASCII.ID THEN

WRITE YR.ASCII.REC TO YF.ASCII.FILE, YR.ASCII.ID

WRITE YR.ASCII.REC TO YF.ASCII.OUT, YR.ASCII.ID

DELETE YF.ASCII.FILE, YR.SCII.D

END

YOFS.REC = ''

TT1.CNT = 0

TT1.CNT = DCOUNT(YR.ASCII.REC,FM)

DEBUG

FOR TT1 = 1 TO TT1.CNT

YR.ASCII.ENT = YR.ASCII.REC<TT1>

EMP.ID = YR.ASCII.ENT[',',1,1]

NEXT TT1

 

 

* Read and process each line of the file in loop

 Y.TRANS.CNT = 0

 YEOF = 0

 LOOP

 READSEQ R.SEQ.REC FROM F.SEQ.FILE.PATH ELSE YEOF = 1

 WHILE NOT(YEOF) DO

 EMP.ID = FIELD(R.SEQ.REC,',',1)

 EMP.NAME = FIELD(R.SEQ.REC,',',2)

 EMP.SHORT = FIELD(R.SEQ.REC,',',3)

 EMP.REG.ADD1 = FIELD(R.SEQ.REC,',',4)

 EMP.REG.ADD2 = FIELD(R.SEQ.REC,',',5)

 EMP.STATE = FIELD(R.SEQ.REC,',',6)

 EMP.COUNTRY = FIELD(R.SEQ.REC,',',7)

 EMP.NO = FIELD(R.SEQ.REC,',',8)

 EMP.SECTOR = FIELD(R.SEQ.REC,',',9)

 EMP.IND = FIELD(R.SEQ.REC,',',10)

 EMP.WEB = FIELD(R.SEQ.REC,',',11)

 EMP.CONTRIB1 = FIELD(R.SEQ.REC,',',12)

 EMP.CONTRIB2 = FIELD(R.SEQ.REC,',',13)

PF.REC = ""

PF.ID = EMP.ID

PF.REC<PF.EMP.EMPLOYER.NAME> = EMP.NAME

PF.REC<PF.EMP.SHORT.NAME> = EMP.SHORT

PF.REC<PF.EMP.REG.ADDRESS> = EMP.REG.ADD1

PF.REC<PF.EMP.EMPLOYER.LGA> = EMP.REG.ADD2

PF.REC<PF.EMP.EMPLOYER.STATE> = EMP.STATE

PF.REC<PF.EMP.COUNTRY> = EMP.COUNTRY

PF.REC<PF.EMP.NO.EMPLOYEE> = EMP.NO

PF.REC<PF.EMP.SECTOR> = EMP.SECTOR

PF.REC<PF.EMP.INDUSTRY> = EMP.IND

PF.REC<PF.EMP.WEBSITE> = EMP.WEB

PF.REC<PF.EMP.PER.COY.CONTRIB> = EMP.CONTRIB1

PF.REC<PF.EMP.PER.EMP.CONTRIB> = EMP.CONTRIB1

PF.REC<PF.EMP.RECORD.STATUS> = 'INAU'

PF.REC<PF.EMP.CURR.NO> = '1'

PF.REC<PF.EMP.INPUTTER> = '32_EYOANWAN'

PF.REC<PF.EMP.DATE.TIME> = '0903111530'

PF.REC<PF.EMP.CO.CODE> = 'NG0010001'

 

 CALL F.WRITE(FN.PF.EMPLOYER,EMP.ID,PF.REC)

 CALL JOURNAL.UPDATE(EMP.ID)

 REPEAT

END


Pls what am doing wrong......
 
Thanks
 

Kevin Powick

unread,
Sep 3, 2009, 5:19:47 PM9/3/09
to jBASE

On Sep 3, 6:36 am, Crusader Sterling Pensions
<crusadersterlingale...@gmail.com> wrote:

> I am trying to read from a CSV file, below is my program:
>
> SUBROUTINE CSP.UPLOAD.EMPLOYER
>
> Pls what am doing wrong......

Hey world. Here is some code. Figure it out and fix it please.

How about putting a little effort into it.

1) What do you expect/want the code to do?
2) What is it actually doing? State the problem, errors, etc.
3) What have you done to try and figure this out yourself?
4) What version of jBASE is this?
5) What operating system?
6) Is it an African or European Swallow?

--
Kevin Powick

Jim Idle

unread,
Sep 3, 2009, 5:39:28 PM9/3/09
to jb...@googlegroups.com, jBASE
European.

Also, please do not hijack old threads, start a new one and take a
read through the posting guidelines - they will help you to help
yourself and stop Kevin telling you off ;)

We need the OS and the errors your getting at a minimum; lots of
people are willing to help with that info supplied.

Jim

raphael olapade

unread,
Sep 4, 2009, 5:08:54 AM9/4/09
to jb...@googlegroups.com
hi, 

could you please tell us what is the issue and probably the error(s) your code is returning?.

thank u.

rgds


rafael

2009/9/3 Crusader Sterling Pensions <crusaderste...@gmail.com>



--
Raphael

Bruce Willmore

unread,
Sep 4, 2009, 9:27:58 AM9/4/09
to jb...@googlegroups.com
You opened F.SEQ.PATH using an OPEN statement instead of with an OPENSEQ

Crusader Sterling Pensions

unread,
Sep 8, 2009, 5:58:19 AM9/8/09
to jb...@googlegroups.com
Thank you all
 
The issue as been resolved !!

 
Reply all
Reply to author
Forward
0 new messages