reading parant segment with child segment's data



IBM's hierarchical database management system with a Database Manager (IMS DB) and a Transaction Manager(IMS DC)

reading parant segment with child segment's data

Postby Aswarth K » Mon Nov 18, 2013 6:13 pm

Hi All,
I am new to IMS DB, I have a requirements like

1.Fetch data from child segment without using or bypassing root segment key or data.
2.Fetch data from root segment by using child segment key or data.

Could you please advise,Can we achive above requirements.

Thanks,
Aswarth.
Aswarth K
 
Posts: 2
Joined: Mon Nov 18, 2013 5:39 pm
Has thanked: 0 time
Been thanked: 0 time

Re: reading parant segment with child segment's data

Postby NicC » Mon Nov 18, 2013 7:19 pm

If you have an alternate index with that child as the key then yes. But why not ask the person who made the requirement. They should know that you are new to IMS and should be helping you as should other members of your team and the DBAs.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: reading parant segment with child segment's data

Postby Ed Goodman » Mon Nov 18, 2013 7:57 pm

Not sure what you mean, except MAYBE that you have a search field on the child that lets you find the ones you need. Then once you find one, you also need information from that child's parent segment. If that's the case, then you can do it VERY easily using what's known as a 'path' call.

A path call is when you read all of the segment in the hierarchical path in one read. You can use a combination of qualified and unqualified SSA to do the read.

So let's say you need to find all ILLNESS segments where the symptom was 'COUGH'. The root is PATIENT, and the ILLNESS segment is a child of patient. Your call can look like this:

CALL 'CBLTDLI' USING GN
   db-pcb
   WS-PATIENT-ILLNESS
   PATIENT
   ILLNESS(SYMPTOM EQ COUGH)


What will happen is that IMS will return both the parent and the child into the WS-PATIENT-ILLNESS working storage area. So you have to set up those segments as contiguous:

01 WS-PATIENT-ILLNESS.
05 PATIENT.
05 ILLNESS.

So when you do the call, you cam just check the ILLNESS segment for what you want, then if it's a match, simply read the fields from the parent segment, because it's ALREADY THERE!!!

And don't let some schmuck try and cry that it's going to cause a lot more IO, because it doesn't. The real IO is from reading the child segments, which you'd have to do anyway.

The important thing is to make good use of the search fields so that you don't actually return any segments that aren't close to what you're looking for.

The only weirdness with this is to expect some unusual PCB status codes. Since you'll be hopping over hierarchical boundaries, you get normal return codes GA and GK. These are valid for this kind of strategy, so code for them. You'll get GE/GB at the end of DB.
Ed Goodman
 
Posts: 341
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: reading parant segment with child segment's data

Postby Aswarth K » Tue Nov 19, 2013 4:37 pm

Hi,

Thanks for your suggestions. Please have a look on below scenario and let me know for your suggestions.

Ex: Segment A is the parent segment of segment B. Segment A has different occurences like A1, A2 and A3. Segment B has different occurences like B1, B2 and B3. If B1 is the child of all A1, A2, A3 and if we know the key of B1 then is it possible to get A1, A2 and A3 segments?

Thanks,
Aswarth.
Aswarth K
 
Posts: 2
Joined: Mon Nov 18, 2013 5:39 pm
Has thanked: 0 time
Been thanked: 0 time

Re: reading parant segment with child segment's data

Postby NicC » Tue Nov 19, 2013 7:24 pm

I do believe a child can only have ONE parent. It can have siblings and children of its own but ony one parent. Have you ever seen a hierarchical diagram showing anything else? I have not.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: reading parant segment with child segment's data

Postby Ed Goodman » Tue Nov 19, 2013 9:39 pm

Oh my...have you created an upside down DBD/PSB combination? I hate those. Very confusing.

A child had one and only one parent. In your example above, B! can ONLY belong to A1 or A2 or A3. It can not be a child of any other parents.

however, with a correctly defined Secondary Index, you can get a list of all the segments that have the same key as B1, then get all of their parents. The DBD would have the target segment equal to the parent. What you end up seeing in your program is the Root is now B, with A as the children.
Ed Goodman
 
Posts: 341
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times


Return to IMS DB/DC

 


  • Related topics
    Replies
    Views
    Last post