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
 

 

Eztrieve- Get substring. But Position is dynamic

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CA Products
View previous topic :: :: View next topic  
Author Message
rvshetttigar

New User


Joined: 13 Oct 2009
Posts: 6
Location: US

PostPosted: Tue Oct 13, 2009 7:19 pm    Post subject: Eztrieve- Get substring. But Position is dynamic
Reply with quote

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

dick scherrer

Site Director


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

PostPosted: Tue Oct 13, 2009 7:25 pm    Post subject:
Reply with quote

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

Active User


Joined: 25 Apr 2007
Posts: 205
Location: Bangalore

PostPosted: Tue Oct 13, 2009 8:23 pm    Post subject:
Reply with quote

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

New User


Joined: 13 Oct 2009
Posts: 6
Location: US

PostPosted: Tue Oct 13, 2009 9:45 pm    Post subject:
Reply with quote

Thanks Ajay and d.sch
Back to top
View user's profile Send private message
Javier Rodríguez

New User


Joined: 18 Mar 2010
Posts: 10
Location: Spain

PostPosted: Fri Aug 13, 2010 6:15 pm    Post subject:
Reply with quote

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

Site Director


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

PostPosted: Fri Aug 13, 2010 8:31 pm    Post subject:
Reply with quote

Hello,

Thank you for the suggestion icon_smile.gif

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

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Sat Aug 14, 2010 11:11 am    Post subject:
Reply with quote

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

New User


Joined: 18 Mar 2010
Posts: 10
Location: Spain

PostPosted: Tue Aug 17, 2010 12:43 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Aug 17, 2010 12:55 pm    Post subject:
Reply with quote

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

New User


Joined: 18 Mar 2010
Posts: 10
Location: Spain

PostPosted: Tue Aug 17, 2010 1:14 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Aug 17, 2010 1:51 pm    Post subject:
Reply with quote

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

New User


Joined: 18 Mar 2010
Posts: 10
Location: Spain

PostPosted: Tue Aug 17, 2010 2:15 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Aug 17, 2010 2:50 pm    Post subject:
Reply with quote

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

New User


Joined: 18 Mar 2010
Posts: 10
Location: Spain

PostPosted: Tue Aug 17, 2010 2:53 pm    Post subject:
Reply with quote

Great, Peter. icon_razz.gif

I agree you. icon_biggrin.gif

Nice to discuss with you... a pleasure!

Till next time.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Tue Aug 17, 2010 2:56 pm    Post subject:
Reply with quote

Javier,

thanks.

See you around.
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 -> CA Products All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Creating a dynamic sort card in JCL u... ChitraChhabra DFSORT/ICETOOL 4 Wed Aug 03, 2016 6:15 pm
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts Query using SUBSTRING on a column of ... sasanka DB2 5 Mon Jul 04, 2016 1:01 pm
No new posts Need to create file with Dynamic Name... kapil27 JCL & VSAM 4 Wed May 25, 2016 9:45 am
No new posts DB2 Stored Procedure - Dynamic SQL - ... GuyC DB2 2 Wed Feb 17, 2016 5:10 pm


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