Include C program

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
kavuri
Premium Member
Premium Member
Posts: 161
Joined: Mon Apr 16, 2007 2:56 pm

Include C program

Post by kavuri »

Hi ,
I had written a C program which converts a bigint into string field.
i.e I need to take input argument as bigint and return the value as string of fixed length.

My code is something like following.

#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
char Convert(int);
int main()
{
long long Value = 9223372036854775807LL ;
int part = 0;
char strOut[12] = {0};
for(int i = 0; i < 11; i++)
{
//printf("%d \n", sizeof(Value));
//printf("%d \n", sizeof(part));
part = (int)(Value & 0x3F);
Value = Value >> 6;
//printf("Value = %d \n", Value);
//printf("Part = %d \n", part);
//printf("%d \n", sizeof(part));
strOut[10 - i] = Convert(part);
//printf("String Value = %s \n", strOut);
}
strOut[11] = '\0';
printf("String Value = %s \n", strOut);
return 0;
}
char Convert(int nPart)
{
char chCode = ' ';
switch(nPart)
{
case 0 :
chCode = '*';
break;

case 1 :
chCode = '+';
break;

case 2 :
chCode = ',';
break;
.
.
.
.
.


I completed the remaining case structure.


Now how can I include this in Transformer stage? How to pass arguments?

How to create object file? Do I need to change anything in my original C file?

How to link the object file?

Please give me some hints.

Thanks
Kavuri
benny.lbs
Participant
Posts: 125
Joined: Wed Feb 23, 2005 3:46 am

Post by benny.lbs »

You may create a parallel routine to hold your C program. Then this routine can be called within Transformer.
kavuri
Premium Member
Premium Member
Posts: 161
Joined: Mon Apr 16, 2007 2:56 pm

Post by kavuri »

Hi Benny,

I tried but I dont weather I included everything correct or not, I got some errors, can you or somebody can help me in resolving the errors?

Errors:
Output from transformer compilation follows:

##I TFCN 000001 11:18:41(000) <main_program>
Ascential DataStage(tm) Enterprise Edition 7.5.1A
Copyright (c) 2004, 1997-2004 Ascential Software Corporation.
All Rights Reserved


##I TUTL 000031 11:18:41(001) <main_program> The open files limit is 2000; raising to 2147483647.
##I TOSH 000002 11:18:41(002) <main_program> orchgeneral: loaded
##I TOSH 000002 11:18:41(003) <main_program> orchsort: loaded
##I TOSH 000002 11:18:41(004) <main_program> orchstats: loaded
##I TFSC 000001 11:18:41(007) <main_program> APT configuration file: /medstat/advantage/common/Ascential/DataStage/Configurations/default.apt
##I TLIC 000002 11:18:41(000) <APT_LicenseCheckOp in APT_LicenseOperator,0> Node 'thusmiannadv21' has 20 physical processors.
##W TLIC 000003 11:18:41(001) <APT_LicenseCheckOp in APT_LicenseOperator,0> DataStage has found more CPU's on your system than your current license allows.
##W TLIC 000004 11:18:41(002) <APT_LicenseCheckOp in APT_LicenseOperator,0> Please contact Ascential Client Support or your Ascential Account Manager.
##W TCOS 000049 11:18:41(008) <main_program> Parameter specified but not used in flow: DSPXWorkingDir
##W TFCP 000000 11:18:42(000) <transform> Error when checking composite operator: The number of reject datasets "0" is less than the number of input datasets "1".
##E TFCP 000017 11:18:42(001) <transform> Error when checking composite operator: Invalid value for function name: string; [line 6, character 13].
##E TFCP 000038 11:18:42(002) <transform> Error when checking composite operator: Expected semi-colon; [line 6, character 19].
##E TFCP 000024 11:18:42(003) <transform> Error when checking composite operator: Incomplete function call ; [line 6, character 22].
##E TFCP 000038 11:18:42(004) <transform> Error when checking composite operator: Expected semi-colon; [line 6, character 22].
##E TFCP 000038 11:18:42(005) <transform> Error when checking composite operator: Expected semi-colon; [line 6, character 34].
##E TFCP 000038 11:18:42(006) <transform> Error when checking composite operator: Expected semi-colon; [line 9, character -1].
##E TFCP 000038 11:18:42(007) <transform> Error when checking composite operator: Expected semi-colon; [line 9, character 11].
##E TFCP 000038 11:18:42(008) <transform> Error when checking composite operator: Expected semi-colon; [line 10, character 0].
##E TFCP 000038 11:18:42(009) <transform> Error when checking composite operator: Expected semi-colon; [line 10, character 13].
##E TFCP 000027 11:18:42(010) <transform> Error when checking composite operator: Expected an operand; [line 29, character 12].
##E TFCP 000038 11:18:42(011) <transform> Error when checking composite operator: Expected semi-colon; [line 29, character 14].
##E TFCP 000038 11:18:42(012) <transform> Error when checking composite operator: Expected semi-colon; [line 29, character 20].
##E TFSR 000019 11:18:42(013) <main_program> Could not check all operators because of previous error(s)
##E TCOS 000029 11:18:42(014) <main_program> Creation of a step finished with status = FAILED. (testjob2.Transformer_6)

*** Internal Generated Transformer Code follows:
0001: //
0002: // Generated file to implement the V0S6_repos_Transformer_6 transform operator.
0003: //
0004:
0005: // define external functions used
0006: extern string string.o(int64 ROLLNO);
0007:
0008: // define our input/output link names
0009: inputname 0 DSLink3;
0010: outputname 0 DSLink4;
0011:
0012: initialize {
0013: // define our row rejected variable
0014: int8 RowRejected0;
0015:
0016: // define our null set variable
0017: int8 NullSetVar0;
0018:
0019: }
0020:
0021: mainloop {
0022: // initialise our row rejected variable
0023: RowRejected0 = 1;
0024:
0025: // declare our intermediate variables for this section
0026: string InterVar0_0;
0027:
0028: // evaluate columns (no constraints) for link: DSLink4
0029: InterVar0_0 = string.o(DSLink3.ROLLNO);
0030: DSLink4.ROLLNO = InterVar0_0;
0031: writerecord 0;
0032: RowRejected0 = 0;
0033: }
0034:
0035: finish {
0036: }
0037:
*** End of Internal Generated Transformer Code

I had given Routine Name : string
External Subroutine name : string.o
Library Path : /home/bhi/
Return Type : char*
Object type : Object
Arguments : roll no, long


Thanks
Kavuri
Kirtikumar
Participant
Posts: 437
Joined: Fri Oct 15, 2004 6:13 am
Location: Pune, India

Post by Kirtikumar »

After creating C program for function, you need to create the object file from it.

The program that you compile to create the object file should be without main() function.

Then create the routine in PX and link that routine to this object file and it should work.
Regards,
S. Kirtikumar.
kavuri
Premium Member
Premium Member
Posts: 161
Joined: Mon Apr 16, 2007 2:56 pm

Post by kavuri »

Hi,
I removed main() and placed like the following.
#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
char Convert(int);
char* string(long long Value)
{
//long long Value = 9223372036854775807LL ;
int part = 0;
char strOut[12] = {0};
for(int i = 0; i < 11; i++)


and the compiled as
cc -c string.cpp
and created the parallel routine. But I am getting the errors. Please give me some hint.\

Thanks
Kavuri
kavuri
Premium Member
Premium Member
Posts: 161
Joined: Mon Apr 16, 2007 2:56 pm

Post by kavuri »

Hi,
I still modofied my program and I had some changes, Still I am having compilation error in the job.

Modified code:

#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
char Convert(int);
char * string(long long Value)
{
//long long Value = 9223372036854775807LL ;
int part = 0;
char * strOut = {0};
strOut=(char*)malloc(12*sizeof(char));
for(int i = 0; i < 11; i++)
{
//printf("%d \n", sizeof(Value));
//printf("%d \n", sizeof(part));
part = (int)(Value & 0x3F);
Value = Value >> 6;
//printf("Value = %d \n", Value);
//printf("Part = %d \n", part);
//printf("%d \n", sizeof(part));
strOut[10 - i] = Convert(part);
//printf("String Value = %s \n", strOut);
}
strOut[11] = '\0';
printf("String Value = %s \n", strOut);
return strOut;
free(strOut);
}
char Convert(int nPart)
{
char chCode = ' ';
switch(nPart)
{
case 0 :
chCode = '*';
break;

case 1 :
chCode = '+';
break;

case 2 :
chCode = ',

And the changes I made are

I had given Routine Name : string
External Subroutine name : string
Library Path : /home/bhi/
Return Type : char*
Object type : Library
Arguments : roll no, long


Now the error I am getting while compiling as

*** Internal Generated Transformer Code follows:
0001: //
0002: // Generated file to implement the V0S6_testjob2_Transformer_6 transform operator.
0003: //
0004:
0005: // define external functions used
0006: extern string string(int64 ROLLNO);
0007:
0008: // define our input/output link names
0009: inputname 0 DSLink3;
0010: outputname 0 DSLink4;
0011:
0012: initialize {
0013: // define our row rejected variable
0014: int8 RowRejected0;
0015:
0016: // define our null set variable
0017: int8 NullSetVar0;
0018:
0019: }
0020:
0021: mainloop {
0022: // initialise our row rejected variable
0023: RowRejected0 = 1;
0024:
0025: // declare our intermediate variables for this section
0026: string InterVar0_0;
0027:
0028: // evaluate columns (no constraints) for link: DSLink4
0029: InterVar0_0 = string(DSLink3.ROLLNO);
0030: DSLink4.ROLLNO = InterVar0_0;
0031: writerecord 0;
0032: RowRejected0 = 0;
0033: }
0034:
0035: finish {
0036: }
0037:
*** End of Internal Generated Transformer Code



Thanks
Kavuri
Post Reply