Page 1 of 1

what does this c++ code do??

Posted: Mon Jul 30, 2007 1:48 pm
by Pavan_Yelugula
Hi All
I have a build op with the following code

Code: Select all

DEFINITION SECTION
-------------------------
#include <map>
#include <string>
#include <iostream>
   using namespace std;

map<string, int> mymap;
map<string, int>::iterator mymapit;
string holdkey;
string holdmsg;
string holdacnr;
bool firstrec = true;

PER RECORD SECTION
------------------------
if (KEY_IN != holdkey.c_str())
{
    if (firstrec == false)
    {
       KEY_OUT = holdkey.c_str();
       FBL_AC_NR_OUT = holdacnr.c_str();
       for (mymapit = mymap.begin(); mymapit != mymap.end(); ++mymapit)
         {
            MSG_CD_OUT = mymapit->first.c_str();
         }
       transferAndWriteRecord(0);
       mymap.clear();
    }
    else
      firstrec = false;
    
    holdkey = KEY_IN.data();
    holdacnr = FBL_AC_NR_IN.data();
}

for (int x=0; x < 20; x+=2)
{
   holdmsg = MSG_CD_IN.substring(x,2);
   if (holdmsg != "  ")
      mymap[holdmsg] ++;
}


POST LOOP SECTION
-------------------
KEY_OUT = holdkey.c_str();
FBL_AC_NR_OUT = holdacnr.c_str();
for (mymapit = mymap.begin(); mymapit != mymap.end(); ++mymapit)
 {
    MSG_CD_OUT = mymapit->first.c_str();
 }
transferAndWriteRecord(0);

Can some please give me a clue what it does???


Thanks
Pavan[/code]

Posted: Mon Jul 30, 2007 4:00 pm
by ray.wurlod
Before we do that, do you understand C/C++ syntax at all? And have you read the chapter on programming within parallel jobs?
Please post the pre-loop code (where, for example, the variable called holdkey is initialized).
Please ask more specific questions.

Posted: Mon Jul 30, 2007 6:06 pm
by UPS
ray.wurlod wrote:Before we do that, do you understand C/C++ syntax at all? And have you read the chapter on programming within parallel jobs?
Please post the pre-loop code (where, for example, the variable called holdkey is initialized).
Please ask more specific questions.
Basically this is what we wanted to achieve with this build-op:
Get the unique 2-byte values from the string field with the same key.
Example
Input:
rec# key string (20 byte value)
1 KEY1 aa
2 KEY1 abaa
.
.
10000 KEY1 xxaaab
10001 KEY2 yy

Expected Output:
KEY1 aaabxx
KEY2 yy

Output that we are getting from the above buildop:
KEY1 xx
KEY2 yy

Can someone pls. tell us how to get the expected output?
Instead of getting the concatenation, the latest 2 byte value is overlaying the previous ones in the first two bytes...
I'll post the pre-loop code tomorrow..
Thanks for any help

Posted: Mon Jul 30, 2007 7:17 pm
by DSguru2B
Can you be more specific with the logic of this concatenation please. Post ten records and show us what the expected output should be.

Posted: Tue Jul 31, 2007 7:43 am
by Pavan_Yelugula
Ray,
There is no code in the Pre-Loop.

DSGuru a much more diverse example
InPut
rec# key string (20 byte value)
1 KEY1 aa
2 KEY1 abaa
3 KEY1 acabbbaa
4 KEY1 aa
5 KEY1 ss
6 KEY1 ab
7 KEY1 aa
8 KEY1 aa
9 KEY1 bb
10KEY1 cc

In the above example. The String is a 20 digit value and every 2 digits has some business value to them.so this string can contain 10 value pairs.

From the above example i want to get all unique 2 digit values from my string field. i will take aa from the first record and when i go to the next record i have 2 value pairs ab and aa. As i have already considered aa i will pick ab. similarly when i go to the third i have 4 value pairs ac,ab,bb,aa. in these i will pick ac and bb as i have already considered ab and aa.......

The expected out put in the above example is
KEY1 aaabacbbsscc.

The build op which i have now gives me the following output
KEY1 cc..

There might be other ways of doing this but a build op was coded as there can be millions of entries in the input and there can be 1000's of enteries with the same matching key...

Unfortunetly This buildop is not coded my me and i don't have expertise on c++.

Any help in tweaking it to get what i am expecting will be really great...

Thanks
Pavan

Posted: Tue Jul 31, 2007 7:49 am
by chulett
Pavan_Yelugula wrote:Unfortunetly This buildop is not coded my me and i don't have expertise on c++.
Then - in my humble opinion - you shouldn't be the one posting the issue. Either the original coder or someone who's taken over for them with the C++ experience needed to work with it. Would that be 'UPS'? :?

Posted: Tue Jul 31, 2007 8:08 am
by Pavan_Yelugula
Chulett
It was coded by some IBM Professional and passed on. we came up with a new requirement and wanted to leverage what he has done.

If i can find someone who knows c++ around me They would have been the first person i would have shown this right...

But i am really wondering if this is a really bad idea of posting this on this forum. I was jus looking for someone to point me in the right direction where i can do some research to solve my issue.

I was just taking this as a chance to learn more about c++ and Buildops with this issue.

No Hardfeelings I am neither the original coder nor someone with c++ exp but i don't think i should just give up without trying....
but either you help me in getting me near my goal or u don't respond...what do we achieve with stray comments...

Sorry if u found my reply rude...

Thanks
Pavan
[/quote]

Posted: Tue Jul 31, 2007 8:29 am
by chulett
And these same 'IBM Professionals' not only didn't comment the code but also did not leave you any documentation for it? That's... unfortunate.

No worries, it's a public forum and everyone is entitled to an opinion - however, there's really no place for "put up or shut up" comments. We're not really here to teach someone C++ nor is it something you pick up from a forum post or two - but I would think some of those who do this on a regular basis - DSGuru2B or tinsmith off the top of my head as two recent C++ posters - could be popping in here and helping out should they so desire. Me, that's not something I profess any expertise in so can't help other than to provide 'stray comments'.

I was serious about the 'UPS' question. They posted in this thread, stated that "Basically this is what we wanted to achieve with this build-op" so I was legitimately wondering if they were the resource you / we should be working with since they seemed to have been involved in writing it.

Anyway, good luck. I'll leave you to your own devices.