Writing a custom routine

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
llkirsch
Participant
Posts: 2
Joined: Tue Nov 01, 2005 7:15 am
Contact:

Writing a custom routine

Post by llkirsch »

I am very new to DS and trying to create a custom routine using code a peer wrote, so that it can be accessed from any job. Not having too much luck so far? Why doesn't the compiler like the Ereplace function?
My code is below, followed by the error. I appreciate any help, LLK

Equate RoutineName To 'PROPER'
Common /SDKPROPER /ValueString;
Equate strValue To Arg1

If INDEX(strValue,'-',1) > 0
Then Ereplace(ValueString,'-':Substrings(ValueString,INDEX(strValue,'-',1)+1,1),'-' : Substrings(upcase(ValueString),INDEX(strValue,'-',1)+1,1))
If INDEX(ValueString,'/',1) > 0
Then Ereplace(ValueString,'/':Substrings(ValueString,INDEX(strValue,'/',1)+1,1),'-' : Substrings(upcase(ValueString),INDEX(ValueString,'/',1)+1,1))
Else ValueString;

Compiling: Source = 'DSU_BP/DSU.Proper', Object = 'DSU_BP.O/DSU.Proper'
**
0020 Then Ereplace(ValueString,'-':Substrings(ValueString,INDEX(strValue,'-',1)+1,1),'-' : Substrings(upcase(ValueString),INDEX(strValue,'-',1)+1,1))

^
Intrinsic Function Name unexpected, Was expecting: Array Name, Variable name,
New variable name, ';', Statement label, "ABORT", "ABORTE", "ABORTM",
"BEGIN", "BREAK", "CALL", "CHAIN", "CLEAR", "CLEARCOM", "CLEARDATA",
"CLEARFILE", "CLEARPROMPTS", "CLEARSELECT", "CLOSE", "CLOSESEQ",
"COM", "COMMON", "CONVERT", "CREATE", "CRT", "DATA", "DEBUG",
"DEL", "DELETE", "DELETEU", "DIMENSION", "ECHO", "ERRMSG", "ENTER",
"EQUATE", "EXECUTE", "EXIT", "FILELOCK", "FILEUNLOCK", "FLUSH",
"FOOTING", "FOR", "GET", "GETX", "GOSUB", "GOTO", "GROUPSTORE",
"HEADING", "HEADINGE", "HEADINGN", "IF", "INPUT", "INPUTDP",
"INPUTCLEAR", "INPUTERR", "INPUTIF", "INPUTNULL", "INPUTTRAP", "INS",
"KEYEDIT", "KEYTRAP", "LET", "LOCATE", "LOCATEP", "LOCK", "LOOP",
"MAT", "MATBUILD", "MATPARSE", "MATREAD", "MATREADU", "MATWRITE",
"MATWRITEU", "NAP", "NOBUF", "NULL", "ON", "OPEN", "OPENDEV",
"OPENPATH", "OPENSEQ", "PAGE", "PERFORM", "PRECISION", "PRINT",
"PRINTER", "PRINTERIO", "PRINTERR", "PRINTERRX", "PROCREAD",
"PROCWRITE", "PROMPT", "RANDOMIZE", "READ", "READBLK", "READNEXT",
"READSEQ", "READT", "READU", "READV", "READVU", "RELEASE", "REMOVE",
"RETURN", "REWIND", "SEEK", "uSEEK", "SELECT", "SELECTN", "SELECTV",
"SELECTE", "SLEEP", "SSELECT", "SSELECTN", "SSELECTV", "STATUS",
"STOP", "STOPE", "STOPM", "STORAGE", "TABSTOP", "TTYCTL", "UNLOCK",
"WEOF", "WEOFSEQ", "WRITE", "WRITEBLK", "WRITESEQ", "WRITET",
"WRITEU", "WRITEV", "WRITEVU", "TPRINT", "INPUTDISP", "KEYEXIT",
"TIMEOUT", "FIND", "FINDSTR", "GETLIST", "DELETELIST", "READLIST",
"WRITELIST", "DECLARE", "TTYGET", "TTYSET", "HUSH", "ASSIGN",
"SELIND", "LOOPEOL", "uINPUT", "uINPUTDP", "CONTINUE", "DEFFUN",
"TRANSACTION", "OPENCHECK", "READL", "BSCAN", "REVREMOVE", "SETREM",
"AUTHORIZATION", "PCDRIVER", "READVL", "MATREADL", "RECORDLOCKL",
"RECORDLOCKU", "WRITESEQF", "WORDSIZE", "RECIO", "SETIT", "SEND",
"UPRINT", "AUXMAP"
0022 Then Ereplace(ValueString,'/':Substrings(ValueString,INDEX(strValue,'/',1)+1,1),'-' : Substrings(upcase(ValueString),INDEX(ValueString,'/',1)+1,1))

^
Intrinsic Function Name unexpected, Was expecting: Array Name, Variable name,
New variable name, ';', Statement label, "ABORT", "ABORTE", "ABORTM",
"BEGIN", "BREAK", "CALL", "CHAIN", "CLEAR", "CLEARCOM", "CLEARDATA",
"CLEARFILE", "CLEARPROMPTS", "CLEARSELECT", "CLOSE", "CLOSESEQ",
"COM", "COMMON", "CONVERT", "CREATE", "CRT", "DATA", "DEBUG",
"DEL", "DELETE", "DELETEU", "DIMENSION", "ECHO", "ERRMSG", "ENTER",
"EQUATE", "EXECUTE", "EXIT", "FILELOCK", "FILEUNLOCK", "FLUSH",
"FOOTING", "FOR", "GET", "GETX", "GOSUB", "GOTO", "GROUPSTORE",
"HEADING", "HEADINGE", "HEADINGN", "IF", "INPUT", "INPUTDP",
"INPUTCLEAR", "INPUTERR", "INPUTIF", "INPUTNULL", "INPUTTRAP", "INS",
"KEYEDIT", "KEYTRAP", "LET", "LOCATE", "LOCATEP", "LOCK", "LOOP",
"MAT", "MATBUILD", "MATPARSE", "MATREAD", "MATREADU", "MATWRITE",
"MATWRITEU", "NAP", "NOBUF", "NULL", "ON", "OPEN", "OPENDEV",
"OPENPATH", "OPENSEQ", "PAGE", "PERFORM", "PRECISION", "PRINT",
"PRINTER", "PRINTERIO", "PRINTERR", "PRINTERRX", "PROCREAD",
"PROCWRITE", "PROMPT", "RANDOMIZE", "READ", "READBLK", "READNEXT",
"READSEQ", "READT", "READU", "READV", "READVU", "RELEASE", "REMOVE",
"RETURN", "REWIND", "SEEK", "uSEEK", "SELECT", "SELECTN", "SELECTV",
"SELECTE", "SLEEP", "SSELECT", "SSELECTN", "SSELECTV", "STATUS",
"STOP", "STOPE", "STOPM", "STORAGE", "TABSTOP", "TTYCTL", "UNLOCK",
"WEOF", "WEOFSEQ", "WRITE", "WRITEBLK", "WRITESEQ", "WRITET",
"WRITEU", "WRITEV", "WRITEVU", "TPRINT", "INPUTDISP", "KEYEXIT",
"TIMEOUT", "FIND", "FINDSTR", "GETLIST", "DELETELIST", "READLIST",
"WRITELIST", "DECLARE", "TTYGET", "TTYSET", "HUSH", "ASSIGN",
"SELIND", "LOOPEOL", "uINPUT", "uINPUTDP", "CONTINUE", "DEFFUN",
"TRANSACTION", "OPENCHECK", "READL", "BSCAN", "REVREMOVE", "SETREM",
"AUTHORIZATION", "PCDRIVER", "READVL", "MATREADL", "RECORDLOCKL",
"RECORDLOCKU", "WRITESEQF", "WORDSIZE", "RECIO", "SETIT", "SEND",
"UPRINT", "AUXMAP"
WARNING: Variable 'Ans' never assigned a value.

2 Errors detected, No Object Code Produced.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

I think you are getting the ways an IF-THEN-ELSE is used in a DataStage job confused with how it look in a program or subroutine.

In your code the IF-THEN-ELSE construct won't compile because the compiler is expecting a statement in the THEN as well as the ELSE clauses.

In jobs this type of syntax will work, since whatever you have in the constraint or derivation is, in reality, the right side of an equation and is evaluated to some value which is then assigned to a variable.

For example, if you have a derivation for Trans1.OutCol that reads "IF @INROWNUM=1 THEN 1 ELSE 2" what the DataStage engine actually does is create basic code that read "{internalVariableName for Trans1.OutCol} = IF @INROWNUM=1 THEN 1 ELSE 2". The IF-THEN-ELSE statement is evaluation to some value and assigned to a variable. I also noted that you terminated your last statement with a PL/1 or Pascal ";" and you don't need to do that (the compiler interprets a semicolon as a new line separator) and you also haven't assigned a return value for the routine. This is the variable "Ans"...


Back to your code, you have a statement that reads

Code: Select all

If INDEX(strValue,'-',1) > 0 
Then Ereplace(ValueString,'-':Substrings(ValueString,INDEX(strValue,'-',1)+1,1),'-' : Substrings(upcase(ValueString),INDEX(strValue,'-',1)+1,1))


The compiler parses the IF {condition} THEN {statement} but the part of the THEN keyword is not a valid statement, you need to change it to read "VariableName = Ereplace..." in order to compile.

Of course, now you need to figure out what you want to do with this variable in your program... :D
ray.wurlod
Participant
Posts: 54595
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

If INDEX(strValue,'-',1) > 0 
Then
Ans = Ereplace(ValueString,'-':Substrings(ValueString,INDEX(strValue,'-',1)+1,1),'-' : Substrings(upcase(ValueString),INDEX(strValue,'-',1)+1,1))
End

would also solve the problem of the return variable (named Ans) not being assigned a value by your code.

Have you programmed in any other language? Name it, and we can probably find an analogous example.

There is a class called Programming with DataStage BASIC (for beginners). Though it's not on the schedule it is, I believe, still available.

What exactly did you want to achieve with this code? As written it replaces the first "-" with three characters; the character preceding the "-", a "-", and the character following the "-" with its upper case variant. So that "Sarbanes-oxley" would become "Sarbaness-Ooxley". Is that correct behaviour?

You might be looking for something like:

Code: Select all

Temp = Convert("-", @FM, TheString) ; * convert to dynamic array
Temp = Oconvs(Temp, "MCT")  ; * title case
Ans = Convert(@FM, "-", Temp)  ; * convert from dynamic array
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply