View previous topic :: View next topic
|
Author |
Message |
rvshetttigar
New User
Joined: 13 Oct 2009 Posts: 6 Location: US
|
|
|
|
Hi
I give a COBOL example..I need the same functionality in EZTRIEVE.
MYSUBSTRING = MYSTRING(POS, 4096) ..
That means I need 4096 bytes from position POS (a variable)
out of field MYSTRING.
POS variable can have any value during runtime. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Define the input/output areas as arrays of 1-byte entries and code a loop to move 4096 bytes from position n in the "input" to position 1 of the "output" and increment both arrays each time thru the loop. |
|
Back to top |
|
|
Ajay Baghel
Active User
Joined: 25 Apr 2007 Posts: 206 Location: Bangalore
|
|
|
|
Hi Rvshettigar,
The below piece of code works for me:
Here is sample EZPLUS logic that searches a string for the location of a word.
Code: |
//STEP1 EXEC ...
//INFILE DD *
THIS IS MY VERY LONG STRING
THIS ASDF ASDF ASDF ASDF IS ASDF ASFD ASDF VERY ASFD ASDF ASDF
ASFD ASFD ASFD ASFD ASFD
//SYSIN DD *
FILE INFILE
INPUT-4-BYTES 1 4 A INDEX IDX1
HOLD-POINTER W 2 P 0 MASK '999'
FILE ALTRPT PRINTER
JOB
IDX1 = 1
HOLD-POINTER = 0
DO WHILE IDX1 LT 80
IF INPUT-4-BYTES EQ 'VERY'
HOLD-POINTER = IDX1
IDX1 = IDX1 + 80
END-IF
IDX1 = IDX1 + 1
END-DO
DISPLAY ALTRPT 'RECORD #' RECORD-COUNT ' HAS THE WORD "VERY"' +
' AT POSITION:' HOLD-POINTER |
Code'd
It is given at below link:
Do not post links to other forums. . .
I modified it a bit, and it worked for me as well.
Thanks,
Ajay |
|
Back to top |
|
|
rvshetttigar
New User
Joined: 13 Oct 2009 Posts: 6 Location: US
|
|
|
|
Thanks Ajay and d.sch |
|
Back to top |
|
|
Javier Rodríguez
New User
Joined: 18 Mar 2010 Posts: 10 Location: Spain
|
|
|
|
There is a nice solution in Eztrieve to the string-substring problem:
Code: |
MYSTRING W 12004 A
MYSUBSTRING MYSTRING 4096 A INDEX POS
|
For POS = 10 you obtain in MYSUBSTRING the same value as with
substr(MYSTRING,11,4096) |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Thank you for the suggestion
For this to be more useful for people with a similar requirement, but little Easytrieve experience, a more detailed explanation would help. . . |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Code: |
MYSTRING W 1 A OCCURS 28672 INDEX(POS)
MYSUBSTR W 4096 A
*
POS = 0
MOVE MYSTRING 4096 TO MYSUBSTR 4096
POS = 22
MOVE MYSTRING 4096 TO MYSUBSTR 4096
|
Max value of POS = 24576 (28672 - 4096).
POS is relative to zero. |
|
Back to top |
|
|
Javier Rodríguez
New User
Joined: 18 Mar 2010 Posts: 10 Location: Spain
|
|
|
|
Hello Peter:
Note that my solution is different than yours.
I am redefining MYSTRING with MYSUBSTR, so I don't need any MOVE to obtain de substring I need in MYSUBSTR, except update addecuatelly POS.
MYSUBSTR is a mask overlapping MYSTRING.
Next code is part of a running program. For each input record (REGENT) I obtain in WCADENA, calling EXTRAE-CADENA appropiatelly, some substrings I need, substrings delimited by CRLF characters (the input record is a SWIFT MT message):
Code: |
FILE FE01
REGENT 1 12004 A
SCAN-EX1 REGENT 1 A INDEX PUNTERO-ENT
SCAN-EX2 REGENT 2 A INDEX PUNTERO-ENT
CRLF W 2 A VALUE X'0D25'
WCADENA W 35 A
SCAN-WCADENA WCADENA 1 A INDEX PUNTERO-WCADENA
JOB INPUT FE01
MOVE ZEROS TO PUNTERO-ENT
...
PERFORM EXTRAE-CAMPO
...
EXTRAE-CAMPO. PROC
PUNTERO-WCADENA = 0
MOVE SPACES TO WCADENA
DO WHILE SCAN-EX2 NQ CRLF AND SCAN-EX2 NQ '-}'
MOVE SCAN-EX1 TO SCAN-WCADENA
* DISPLAY ' SCAN-EX1 = ' SCAN-EX1
* DISPLAY ' WCADENA = ' WCADENA
PUNTERO-ENT = PUNTERO-ENT + 1
PUNTERO-WCADENA = PUNTERO-WCADENA + 1
END-DO
END-PROC
|
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Hello Javier,
Quote: |
Note that my solution is different than yours.
I am redefining MYSTRING with MYSUBSTR, so I don't need any MOVE to obtain de substring I need in MYSUBSTR, except update addecuatelly POS.
MYSUBSTR is a mask overlapping MYSTRING.
|
That will not work cause the lenght of your MYSUBSTR is 4096, so with
POS = 10 the index will be POS * (length of element) |
|
Back to top |
|
|
Javier Rodríguez
New User
Joined: 18 Mar 2010 Posts: 10 Location: Spain
|
|
|
|
Hello Peter:
I think you are mixing your solution with mine. Let me remember you that I have not defined any array (OCCURS clause) in my solution, so it makes no sense the calculation you are indicating ("index will be POS * (length of element)").
I think the Easytrieve Programmer Guide manual explains my technic in the paragraph Data Strings.
I suggest that you test my example. Of course don't doubt to ask me any question you could have.
Pleasure to discuss this item with you. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Javier,
first im mixing nothing.
Your working program is indexing a 1-byte field so updating the index
will point to the next byte.
Your first example defines a 4096 byte length field, updating the index
will point to the next field of 4096 bytes.
I dont have to test your example, cause 1 byte indexing is child play.
On the other hand indexing fields larger than 1 byte is quite another
story.
To illustrate my point an excerpt from the manual :
Any data field definition can contain the INDEX attribute. An index can be used
to reference data fields which occur multiple times. If you do not use an index,
you must either use subscripts or assign individual field names to multiple field
occurrences.
The data field starting location is adjusted by the contents of its indexes to
determine the desired field occurrence. The INDEX indexname value is set to:
(desired occurrence number - 1) * (length of element) |
|
Back to top |
|
|
Javier Rodríguez
New User
Joined: 18 Mar 2010 Posts: 10 Location: Spain
|
|
|
|
Dear Peter, yes, you are mixing both solutions. Please don't get ungry with this affirmation. The only thing I pretend is to let you see the difference between your solution and mine.
The calculation of the index makes sense when you have elements, and you have elements when you have the OCCURS clause. You need to calculate the index when you need to reference the right element.
My working program uses, as well, a two-byte mask to scan the input file, indexed by the same index: PUNTERO-ENT. But I have used this technic extensively, with any needed length. For example, 4096. It works fine, if you don't go through the boundaries of the redefined field.
I hope to have been more clear! Sorry for my difficulties with english. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Javier,
for the last time. If you update PUNTERO-ENT by 1 the internal ponter will point to the next 2 bytes of SCAN-EX2 cause the length is 2. Has nothing to do with an OCCURS clause, so if the length is 4096 an index update by 1 will result in the next 4096 bytes.
Thats how Easytrev works. |
|
Back to top |
|
|
Javier Rodríguez
New User
Joined: 18 Mar 2010 Posts: 10 Location: Spain
|
|
|
|
Great, Peter.
I agree you.
Nice to discuss with you... a pleasure!
Till next time. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Javier,
thanks.
See you around. |
|
Back to top |
|
|
|