View previous topic :: View next topic
|
Author |
Message |
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
I am having the following sample records in a file:
record 1 : driver @001 from to @002 to @003
record 2: PB value @002 changed to @001
I need to replace @001, @002 and @0003 with messages and these messages are in the table and these messages are predefined.
05 ws-table occurs 3 times
03 ws-mess pic x(04)
03 ws-message pic (20)
Sample data in a table:
ws-mess ws-message
@001 added
@002 changed
@003 deletes
I need to refer the tables and replace the @ fields in the message . I need to get output message in the following way.
output:
record 1 : driver added from to change to deletes |
|
Back to top |
|
|
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
Could you please let me know how to achieve these |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
INSPECT TALLYING and reference modification are probably the easiest way. Since you have to make multiple passes across the data, you'll need to make sure your changes are kept as you make passes across the data.
Tell us where you are having problems and we can help. However, this is not a WRITE-THE-CODE-FOR-YOU forum so we won't just give you code. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Please use the Code tags when spacing is important.
You could use UNSTRING, DELIMITED BY SPACE, into seven fields for the first and six for the second record.
Then test the appropriate fields, replacing the @nnn with the correct message.
The use STRING to put them together again DELIMITED BY SPACE for fields and SIZE for a blank separator.. |
|
Back to top |
|
|
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
Bill,
In record we don't know how many @messages will come. How can we use "unstring operation wit delimited by space into identifier" for every record we cannot change the identifiers |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, you knew that, we didn't.
If you explain, fully, your possible data, we can see.
Else, you have byte-by-byte, reference-modification, variable-length data.
One thing that is certain is that you can't use INSPECT ... REPLACING, becasue the to/from have to be the same length. |
|
Back to top |
|
|
dharmaraok
New User
Joined: 10 Mar 2011 Posts: 45 Location: india
|
|
|
|
Yes we can do reference modification for the message but how can we replace the message which is there in the occurs table. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You have an input variable and an output variable. For each table occurrence (you showed us three; who knows how many there really are) start at byte one of the input variable (going to the end of the variable), use reference modification to see if the next 4 bytes match your table element; if so, move the table replacement to the output variable and increment the output location by 7 bytes; if not, move the input byte to the output variable using reference modification and increment the output location by 1. After each table occurrence has been scanned, before starting the next one, move the output variable to the input variable and reset the output location to 1. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Depending on whether you are doing other things in the program, FINDREP, a function of SORT, can do what you want. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
No matter how you do this, you will have to make sure the new output length is not longer than lrecl . . . |
|
Back to top |
|
|
|