last digit of year

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.
3 posts Page 1 of 1

castewa

Posts: 2
Joined: Wed Nov 16, 2011 12:34 pm

Post by castewa » Wed Nov 16, 2011 12:59 pm
In my project, I need to set a variable to the last digit of the current year. This will be used in the file name.

For example, for the date 01/01/2012, I need to pull out just the number 2 to use in a file name.

What functions are available in GoAnywhere to help me with this?

Thanks.

Support_Julie

User avatar
Support Specialist
Posts: 91
Joined: Thu Mar 05, 2009 3:49 pm
Location: Ashland, NE USA

Post by Support_Julie » Wed Nov 16, 2011 5:36 pm
We are anticipating in the next release, the ability to do a substring on a variable. This version is in beta and will allow you to get the desired results.



<project name="try to get final year digit" mainModule="Main" version="2.0">

<module name="Main" logLevel="debug">

<timestamp version="1.0">
<format outputVariable="lastDigit" pattern="y" />
</timestamp>


<print version="1.0">
<![CDATA[this is the last digit : ${Substring(lastDigit, 2, 1)}]]>
</print>

</module>

</project>
Julie Rosenbaum
Sr Support Analyst
e. [email protected]
p. 1.800.949.4696
w. HelpSystems.com

RElliott63

Posts: 14
Joined: Thu Jul 01, 2010 10:42 am

Post by RElliott63 » Thu Nov 17, 2011 11:44 am
Add the following utility (SQL Help) to your project list -- I put them into a "/Utilities" folder as I create them. You can then call the Utility from within your Project like this... (This assumes that ${Year} has been created prior and doesn't matter if it's 2 or 4 or 1000 bytes. It will grab the last digit and return it in the ${Reply} variable)
Code: Select all
    <callProject label="Get Last Digit of Year" version="1.0" 
                       project="/Utilities/SQL Help" 
                       runInSameJob="true" inheritUserVariables="true" 
                       returnUserVariables="true" 
                       onError="setVariable:Error=1">
		  <variable name="SQLStmt" value="( Substring( '${Year}', length( trim( '${Year}' ) ), 1 ) )" />
			<variable name="Reply"   value=" " />
		</callProject>
This allows you to take advantage of ANY Math/Date/String functionality from within SQL and return it back to your Project.

--This instance utilizes the iSeries SysDummy1 table for running reply requests. You will need to have this access any server (Variable "helpServer" below) with any table. You don't actually retrieve any values from the table, you just return the function's reply--
Code: Select all
<!-- ************************************************************************ -->
<!-- Project:             SQL Help                                            -->
<!-- Date Written:        05.27.2011                                          -->
<!-- Scripted by:         Rick Elliott                                        -->
<!-- GoAnywhere Version:  3.5.1                                               -->
<!--                                                                          -->
<!-- Description:  Utilize SQL Functionality within GoAnywhere Project        -->
<!--                                                                          -->
<!-- Called by:    Any project needing String manipulation, variable          -->
<!--               calculations, date manipulation, random numbers, etc.      -->
<!--                                                                          -->
<!-- Vars Used:                                                               -->
<!--  helpServer - Any iSeries Server defined in Resources                    -->
<!--     SQLStmt - Parm Passed for Calculating Value                          -->
<!--       Reply - Return Value from Equation                                 -->
<!--    SubError - Used if Error Occurs                                       -->
<!--                                                                          -->
<!-- ************************************************************************ -->
<project name="SQL Help" mainModule="Main" version="1.0" onError="setVariable:SubError=1" logLevel="debug" >

  <!-- Parms Passed -->
	<variable name="SQLStmt" value=" " description="SQL Statement" />
	<variable name="Reply"   value=" " description="Return value"  />

  <module name="Main" dependsOn="Check Parms,Run Statement">

    <print label="Status - Successful" version="1.0" executeOnlyIf="'${RunJob}' eq 'Yes'">
      <![CDATA[
*==========================================================================*
* SQL Statement Executed:
* 
*   ${SQLStmt}
*   
* Return Value:  ${Reply}
*==========================================================================*
      ]]>
    </print>

    <print label="Status - UnSuccessful" version="1.0" executeOnlyIf="'${RunJob}' ne 'Yes'">
      <![CDATA[
*==========================================================================*
* Calculation was NOT Performed:
* 
*   SQL Statement was either Blank or Empty
*==========================================================================*
      ]]>
    </print>

    <print label="Status - Invalid" version="1.0" executeOnlyIf="${SubError} gt 0">
      <![CDATA[
*==========================================================================*
* Calculation was NOT Performed:
* 
*   ${SQLStmt}
*
*   SQL Statement was invalid or did not execute properly!
*==========================================================================*
      ]]>
    </print>

	</module>
                                                                     
  <module name="Check Parms">

    <setVariable label="Set RunJob"    version="1.0" name="RunJob" value="Yes" />
    <setVariable label="Check SQLStmt" version="1.0" name="RunJob" value="No" executeOnlyIf="( '${SQLStmt}' eq ' ' )"/>
    <setVariable label="Check SQLStmt" version="1.0" name="RunJob" value="No" executeOnlyIf="( '${SQLStmt}' eq ''  )"/>

  </module>

  <module name="Run Statement" executeOnlyIf="( '${RunJob}' eq 'Yes' )">

    <setVariable label="Set SubError" version="1.0" name="SubError" value="0" />
		<sql label="Connect to Server" version="1.0" resourceId="${helpServer}" onError="setVariable:SubError=2" >
			<query label="Calculate Answer" whenNoDataFound="error" outputVariable="OutPut">
				<statement>
			    Select ${SQLStmt} from SysIBM.SysDummy1
        </statement>
			</query>
		</sql>

		<setVariable label="Set Reply" version="1.0" name="Reply" value="${OutPut[1]}" executeOnlyIf="( ${SubError} eq 0 )"/>
    <closeRowSet label="Close Rowset" rowsetVariable="${OutPut}" version="1.0" onError="continue"/>

  </module>

	<variable name="helpServer" value="<Default iServer>" description="iServer to use for Calculation" />

	<description>iServer SQL Help</description>

</project>
3 posts Page 1 of 1