Server Routine In parallel Job

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sangi1981
Participant
Posts: 99
Joined: Fri Jun 13, 2008 8:10 am

Server Routine In parallel Job

Post by sangi1981 »

Hi all,
I write a server routine to add months to a date.
I have to use this routine in parallel job, inside a transformer, but it is not possible.

I found that there are following solutions:
*) use basic transformer,
*) create parallel routine, using a c++ file in which make porting of basic code.

What are the steps needed to do second solution?
What Have I to do to implement this solution?
What Have I to know?
Where can I find some explanation or examples?
What can go wrong?

I'm on Sun Solaris Server.

Thanks lot in advance
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: Server Routine In parallel Job

Post by SURA »

You need to create PX Routine using C++ code. You need to use the object file.

Don't imagine much and start to develop, you will get the solution.

DS User
battaliou
Participant
Posts: 155
Joined: Mon Feb 24, 2003 7:28 am
Location: London
Contact:

Post by battaliou »

If you publish your server routine, I could see your rule base and translate it into PX for you. An example transformer algorithim using the INT and MOD functions:

* (YYYY-MM-DD)
YEAR = ExtDate[1,4] + Int((ExtDate[6,2] + #MONTHS#) / 12)
MONTH = Mod((ExtDate[6,2] + #MONTHS#), 12)
3NF: Every non-key attribute must provide a fact about the key, the whole key, and nothing but the key. So help me Codd.
sangi1981
Participant
Posts: 99
Joined: Fri Jun 13, 2008 8:10 am

Post by sangi1981 »

Thanks much.
I implemented a c++ function, compiled with options from administrator, linked *.o file whit a parallel routine: seems to be good.
In this way, I have basic and c++ version....
vinothkumar
Participant
Posts: 342
Joined: Tue Nov 04, 2008 10:38 am
Location: Chennai, India

Post by vinothkumar »

Please post your C++ source code. In case if anyone needed they can refer.
sangi1981
Participant
Posts: 99
Joined: Fri Jun 13, 2008 8:10 am

Post by sangi1981 »

Of course.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>

char* AddMonthRoutine ( char* InDate, int AddMonths ) {

  if ( InDate == NULL || *InDate == '\0' ||
  		 strlen(InDate) == 0 || strlen(InDate) != 8 ) {
  		 char rt[8];
  		 time_t now = time(0);
  		 struct tm *d;
  		 d=localtime(&now);
  		 strftime(rt,15,"%Y%m%d",d);
  	   return rt;
  	   }
  if ( AddMonths < 0 ) return InDate;
  
	char *cyyyy=(char *)malloc(sizeof(char)*4);
	strncpy(cyyyy,InDate,4);
	int yyyy=atoi(cyyyy);
	
	char *cmm=(char *)malloc(sizeof(char)*2);
	strncpy(cmm,InDate+4,2);
	int mm=atoi(cmm);
	
	char *cdd=(char *)malloc(2*sizeof(char));
	strncpy(cdd,InDate+6,2);
	int dd=atoi(cdd);
	
	free(cyyyy); free(cmm); free(cdd);
	
	int OutYear=yyyy+(AddMonths-(AddMonths%12))/12;
	int OutMonth=mm+(AddMonths%12);
	int OutDay=dd;
	
	if ( OutMonth > 12 ) { OutYear+=1; OutMonth-=12; }
	
	if ( OutMonth == 2 ) {
	   if ( OutDay > 28 ) {
	      int rest1=OutYear%400;
	      int rest2=OutYear%100;
	      int rest3=OutYear%4;
	      if ( (rest3 == 0 && rest2 != 0) || rest1 == 0 )
	         OutDay=29;
	      else
	      	 OutDay=28;
	      }
	 }
	 else if ( OutMonth == 4 || OutMonth == 6 || OutMonth == 9 | OutMonth == 11 )
	           if (OutDay > 30) OutDay=30;
   else  if ( OutMonth == 1 || OutMonth == 3 || OutMonth == 5 || OutMonth == 7 || OutMonth == 8 | OutMonth == 10 || OutMonth == 12 );
	
	char cOutYear[5];
	char cOutMonth[3];
	char cOutDay[3];
	char rData[10];
	int zero=0;
	
	sprintf(cOutYear,"%d",OutYear);
	
	if (OutMonth < 10) { sprintf(cOutMonth,"%d%d", zero, OutMonth); }
	else { sprintf(cOutMonth,"%d",OutMonth); }
	
	if (OutDay < 10) { sprintf(cOutDay,"%d%d", zero, OutDay); }
	else { sprintf(cOutDay,"%d",OutDay); }
	
	sprintf(rData,"%s%s%s",cOutYear, cOutMonth, cOutDay);
	
	return rData;
}
Post Reply