| Author |
Message |
darakhshan
New User
Joined: 03 Mar 2008 Posts: 6 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:
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 |
|
 |
References
|
Posted: Thu May 08, 2008 4:45 pm Post subject: Re: Unstring and insert |
 |
|
|
 |
ashimer Warnings : 1 Active User
Joined: 13 Feb 2004 Posts: 108
|
|
|
|
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
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 |
|
 |
|
|