View previous topic :: View next topic
|
Author |
Message |
darakhshan
New User
Joined: 03 Mar 2008 Posts: 32 Location: India
|
|
|
|
I have the following to do:
I get a record INSERT-REC as input to my program.
This record looks like count|rec1fld1,rec2fld2,rec3fld3;rec2fld1,rec2fld2,rec3fld3;...
the count indicates the number of records in the insert-record and it could be upto 50 but is actually variable.
what i thought was this:
1) separate the count value first by using unstring delimited by '|'
2) separate each record delimited by ';' in INSERT-REC(2:count)
3) separate every field delimited by ',' and insert it into the table
my problem is that i do not know the number of records except until at run time.
so if i declare a table of length upto 50(occurs depending on) how do i use this within the unstring syntax? The below is obviously wrong:
Code: |
PERFORM VARYING INSERT-IND FROM 1 BY 1
UNTIL INSERT-IND >= WS-COUNT
UNSTRING INSERT-REC DELIMITED BY ';'
INTO
WS-STRING (INSERT-IND)
TALLYING IN RECORD-COUNT
END-UNSTRING
END-PERFORM. |
Pls help. |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
are you sure one record will have only 3 fields ???
i am assuming count to be the count of records ...
so if 50 is the count that means a total of 50 * 3 fields are present
Code: |
01 WS-COUNT PIC 9(4).
01 WS-TAL-COUNT PIC 9(4).
01 WS-REC PIC X(200).
01 WS-FILE-REC X(50).
01 SAMPLE-TABLE.
05 SAMPLE-RECORD OCCURS 150 TIMES DEPENDING ON WS-COUNT INDEXED BY WS-INDEX.
10 SAMPLE-FLD-1 PIC X(10).
10 SAMPLE-FLD-2 PIC X(10).
10 SAMPLE-FLD-3 PIC X(10).
INSPECT INSERT-REC TALLYING WS-TAL-COUNT FOR FIRST '|'
MOVE INSERT-REC(1:WS-TAL-COUNT) TO WS-COUNT
MOVE INSERT-REC(WS-TAL-COUNT+1: LENGTH OF INSERT-REC - WS-TAL-COUNT+1) TO WS-REC
SET WS-INDEX T0 1
PERFORM UNTIL WS-REC = SPACES
INSPECT WS-REC REPLACING FIRST ';' BY '#'
UNSTRING WS-REC DELIMITED BY #
INTO WS-FILE-REC
WS-REC
END-UNSTRING
UNSTRING WS-FILE-REC DELIMITED BY ','
INTO SAMPLE-FLD-1(WS-INDEX)
SAMPLE-FLD-2(WS-INDEX)
SAMPLE-FLD-3(WS-INDEX)
END-UNSTRING
SET WS-INDEX UP BY 1
END-PERFORM |
|
|
Back to top |
|
|
darakhshan
New User
Joined: 03 Mar 2008 Posts: 32 Location: India
|
|
|
|
thanks.. i could do the above with slight modifications..
like instead of using a char i used level 49 variables to avoid calculating the length..
my prob now is that i would need to insert these stings into the table.. some of the fields are of type s9(9)V etc..
if i unstring into a char type.. say x(10) and then move it into this variable.. which is to be inserted, i'm not getting the right data..
can anyone help.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Reformat those fields to the format you need after the unstring. Use the re-formatted fields for the insert. |
|
Back to top |
|
|
darakhshan
New User
Joined: 03 Mar 2008 Posts: 32 Location: India
|
|
|
|
my record looks somethin like this:
Code: |
02|202224,ABC,0,2008-05-13,State,9999-12-31,13265,63209;202225,DEF,0,2008-05-13,State,9999-12-31,13265,63209; |
i'm fetching field1 into x(11) and then moving it to s9(11)V comp.
after moving from char to comp type, my field1 looks like this:
Code: |
FIELD1202224000000
FIELD2NATCD
FIELD30000000000
FIELD42008-05-13
FIELD5State
FIELD69999-12-31
FIELD70132650000
FIELD8X023305
FIELD913863500000
|
as u see, the data itself is wrong here-its appended 6 zeros.
and this is wat i get when i try and insert:
SQLCODE = -310, DECIMAL HOST VARIABLE OR PARAMETER 1 CONTAINS NON-DECIMAL DATA |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
please, learn to use BBCODE
FETCH is a db2 term. it means return 1 row from results table to a cursor definition. has nothing todo with files and records.
suggest you use NUMVAL to move the char data to comp.
compute comp-field = function numval(char field) end-compute. |
|
Back to top |
|
|
|