View previous topic :: View next topic |
Author |
Message |
yugee Beginner
Joined: 17 Sep 2005 Posts: 25 Topics: 8
|
Posted: Fri May 25, 2007 4:57 am Post subject: Help with INSPECT |
|
|
Hi,
I have an input XML string with many fields. I need to get the value of a particular field. Can it be done using the INSPECT?
for example:
Input file:
fild1 fld2 fld3 - not the actual record, just for reference
ABC 123 {NAME^KUMAR KRISHNA^string}{PHONE^XXX-XXX^string}
ABD 124 {PHONE^YYY-YYY^string}
ABE 125 {NAME^RAJ^string}
I want the output file as (need only phone from field3)
ABC 123 XXX-XXX
ABD 124 YYY-YYY
ABE 125
Field3 is of variable length. Phone number may be or may not be there in the field3 and it can start in any position.
Could some one help me with this? |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri May 25, 2007 5:26 am Post subject: |
|
|
Yes, INSPECT can be used to find the location of 'PHONE' in field3.
is the format of the PHONE entity always the same? UNSTRING could be used to extract the phone number.
You should use BBCode to enable readers to better understand your data. For example:
Code: |
fild1 fld2 fld3 - not the actual record, just for reference
ABC 123 {NAME^KUMAR KRISHNA^string}{PHONE^XXX-XXX^string}
ABD 124 {PHONE^YYY-YYY^string}
ABE 125 {NAME^RAJ^string}
|
you can find BBCode FAQ by clicking on the BBCode link under Options to the left of an Edit Posting screen. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
yugee Beginner
Joined: 17 Sep 2005 Posts: 25 Topics: 8
|
Posted: Fri May 25, 2007 5:58 am Post subject: |
|
|
Hi,
The format of the PHONE entity will always be the same. If the customer has entered the phone number, then the field3 will always have the PHONE string in the below format:
{PHONE^XXX-XXX^string} |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri May 25, 2007 6:57 am Post subject: |
|
|
Ok. Where I have lived (about 13 countries) phone number was never xxx-xxx.
that aside,
you can UNSTRING Field3 delimited by } into however many fields-groups that could be contained in Field3. If PHONE is always in the 1st or 2nd you've got it made. I picked an arbitrary length of 50. if these subgroups can be larger, use that value.
Want to make each UNSTRING receiving object large enough that you don't have to deal with overflow/underflow problems.
Code: |
01 WORK-AREAS-FOR-UNSTRING.
05 WK-FIELD-1 PIC X(50).
05 WK-FIELD-2 PIC X(50).
|
Code: |
UNSTRING FIELD3
INTO WK-FIELD-1
DELIMITED BY '}'
INTO WK-FIELD-2
DELIMITED BY '}'
|
Then INSPECT each WK-FIELD looking for PHONE. You could redefine these WK-FIELDs to use LEVEL 88's.
once you have found 'PHONE' with the INSPECT you have a starting point - you know which WK-FIELD contains the PHONE number.
Is this char '^' always present at relative 6 from the 'P' in PHONE? and at the end of the phone number - xxx-xxx
Code: |
-0123456789012345678901
{PHONE^XXX-XXX^string}
---------0123456789012345678901
|
you could then UNSTRING the WK-FIELD delimited by '^' which would isolate your phone number. If it is always PHONE^xxx-xxx^string, your phone number will be in the second receiving item of the UNSTRING.
There are other ways to do it, but I like UNSTRING because your working-storage sorta documents what you are doing.
have a good week-end. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
yugee Beginner
Joined: 17 Sep 2005 Posts: 25 Topics: 8
|
Posted: Fri May 25, 2007 7:43 am Post subject: |
|
|
Hey, I have just put a sample string for the phone number. Actually the field I am lookin is some thing else. Sorry for confusion, I should have used some realistic values. The only disadvantage with UNSTRING is, I don't know the position of Phone number Field. The Field3 is a dynami XML message, it depends on the number of fields user enters. This XML data is passed to us by an online application, on which user can enter their information. Some times he may not even enter the phone number. In this case, the XML will not contain the tag for phone number and I need to pass spaces in the output file for this record. This makes the problem bit complex. I was trying to solve this using EASYTRIEVE, but I couldn't succeed. |
|
Back to top |
|
|
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Fri May 25, 2007 9:38 am Post subject: |
|
|
yugee wrote: | The only disadvantage with UNSTRING is, I don't know the position of Phone number Field. | That should be no problem, you could unstring delimited by "{PHONE^" into trashcan savearea.
If savearea was preloaded with spaces, anything there would be the phone number. Either move just the 7 bytes (or make savearea only 7 bytes long) or unstring delimited by "^" into phonenumber.
With EZT, if you are just scanning the input, byte by byte, you should be able to to it - EZT allows that type of data manipulation.
A perform checking for the "{" followed by additional IFs for the rest of the word "PHONE" should be a snap. |
|
Back to top |
|
|
yugee Beginner
Joined: 17 Sep 2005 Posts: 25 Topics: 8
|
Posted: Fri May 25, 2007 9:53 am Post subject: |
|
|
Hi,
The above approach will work if the Phone string is in the XML. Is there any way I can move spaces it we don't have the phone number?
Thanks a lot for your help .
Yugee |
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Fri May 25, 2007 9:56 am Post subject: |
|
|
i guess you could INSPECT... TALLYING... and if the result is 0 then you move spaces otherwise you extract as indicated. _________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Fri May 25, 2007 2:52 pm Post subject: |
|
|
yugee wrote: | \The above approach will work if the Phone string is in the XML. Is there any way I can move spaces it we don't have the phone number? | Usually, I'd preload the negitive answer and them solve for the positive, acting only on a hit while the miss is already taken care of. Kind of makes it self-solving....
In the first, if no phone string, the area where the number would have been put already is spaces.
In the second, if you don't find the phone string, you fall out the bottom of the do loop. |
|
Back to top |
|
|
|
|