Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Unstring and insert

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Thu May 08, 2008 4:45 pm    Post subject: Unstring and insert
Reply with quote

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
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu May 08, 2008 5:09 pm    Post subject:
Reply with quote

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
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Thu May 15, 2008 11:28 am    Post subject:
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Thu May 15, 2008 11:31 am    Post subject:
Reply with quote

Hello,

Reformat those fields to the format you need after the unstring. Use the re-formatted fields for the insert.
Back to top
View user's profile Send private message
darakhshan

New User


Joined: 03 Mar 2008
Posts: 32
Location: India

PostPosted: Thu May 15, 2008 2:59 pm    Post subject:
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 15, 2008 4:09 pm    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Insert Lines in JCL with Rexx after a... Willy Jensen CLIST & REXX 3 Tue Aug 30, 2016 4:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Unstring list of values into an array. Roshnii COBOL Programming 8 Mon Jun 27, 2016 6:25 pm
No new posts How do I right justify a string in an... rakesh17684 DB2 1 Wed Jun 08, 2016 8:01 pm
No new posts insert the same records but chancing ... danylele74 DB2 6 Mon May 02, 2016 7:22 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us