SOUL $functions: Difference between revisions

From m204wiki
Jump to navigation Jump to search
Line 825: Line 825:
===Line ends===
===Line ends===
<p>
<p>
Text that is part of the header and body can include EBCDIC CRLF strings (X'0D25') that are translated to ASCII along with the rest of the text.</p>
In text that is part of the header and body, you can enter line ends by including EBCDIC CRLF strings (X'0D25') that are translated to ASCII along with the rest of the text.</p>


If you do not enter line ends, your images might display all on one line, depending on your email viewer.  
If you do not enter line ends, your images might display all on one line, depending on your email viewer.  


The comments added to this snippet from [[SOUL $functions#Example 4|Example 4]] highlight the use of line ends:
The comments and bold text added to this snippet from [[SOUL $functions#Example 4|Example 4]] highlight the use of line ends:
<p class="code">  PREPARE IMAGE BODY
<p class="code">  PREPARE IMAGE BODY
%Y = $X2C('0D25') /? EBCDIC CRLF character is moved to %Y ?/
<b>%Y = $X2C('0D25')</b>    /? EBCDIC CRLF character is moved to %Y ?/
%S = 'EXAMPLE 1'  
%S = 'EXAMPLE 1'  
%BODY:BODY1 = %Y WITH 'THIS IS BODY1 WHICH IS PART OF AN IMAGE' /? %Y will be translated to ASCII CRLF ?/
%BODY:BODY1 = <b>%Y WITH</b> 'THIS IS BODY1 WHICH IS PART OF AN IMAGE'   /? %Y will be translated to ASCII CRLF ?/
%BODY:BODY2 = %Y WITH 'SO THE BODY TEXT CAN BE MORE THAN 255 BYTES LONG'
%BODY:BODY2 = <b>%Y WITH</b> 'SO THE BODY TEXT CAN BE MORE THAN 255 BYTES LONG'
%RC = $SNDMAIL(%S,'RCPTTO','BODY',%FROM,%TO,,,'EMAILD')</p>
%RC = $SNDMAIL(%S,'RCPTTO','BODY',%FROM,%TO,,,'EMAILD')</p>



Revision as of 22:20, 21 September 2015

Some operations are inefficient or impossible to code in a high-level programming language like User Language. To overcome this difficulty, SOUL provides a variety of $functions. Many of these functions are in favor of an OO API method. When that is the case, the $function page notes the matching method.

The mathematical $functions, and those $functions central to a Model 204 product (and which require authorization of that product) are listed separately; you can find links to those sets of $functions in the following table:

$Function setDescription
$xxxmathMathematical $functions
$Ftp_xxxJanus FTP Server $functions
$Sock_xxxJanus Sockets $functions
$Web_xxxJanus Web Server $functions

List of standard $functions

The following table lists the standard SOUL $functions in alphabetical order.

See also:

$FunctionDescription
$AbbrevDetermine if string is abbreviation within list of words
$AccountAccount under which the user is logged in.
$AcctUser ID under which the user is logged in.
$AlphaWhether a string is composed of only the letters A through Z.
$AlphNumWhether a string is composed of only the letters A through Z and digits 0 through 9.
$Arr_FindFind value within array
$Arr_InitInitialize every element of array to specific value
$Arr_MaxFind maximum value in array
$Arr_MinFind minimum value in array
$ArrSizeNumber of elements in a particular dimension of an array.
$AsciiInput string, converted from EBCDIC to ASCII.
$A2ETranslate ASCII to EBCDIC
$Base64_DecodeConvert from base 64 to byte string
$Base64_EncodeConvert byte string to base 64
$BgPurgeCancel "long" sdaemon request initiated with $CommBg
$BgQueryList of "long" sdaemon requests initiated via $CommBg
$BinaryA number converted into fixed-point binary.
$Bind_ListReturn list of bound semaphores onto a $list
$BindFast, easy synchronization of system wide resource
$BitAndBitwise AND of two integers
$BitOrBitwise OR of two integers
$BldProcEnables a request to build a temporary procedure.
$Buffer_PositionCurrent Universal Buffer position.
$Buffer_SizeSize of user's Universal Buffer.
$Buffer_UsedAmount of data currently in Universal Buffer
$BumpBump a user
$CenqCtNumber of unused entries within the resource enqueuing table.
$CenterCenter string
$CfStatLList of statistics for users holding critical file resources
$ChkModWhether the terminal operator entered data in any full-screen input field.
$ChkPatSyntax of a pattern.
$ChkpInfInformation about checkpoints
$ChkTagWhether any erroneous full-screen input has been entered by the end user.
$CloseClose file or group in User Language request
$CmsDetermine if online is running under CMS
$CodeEncoding facility.
$CommandExecute Model 204 command on sdaemon, results to image
$CommBgExecute Model 204 commands on sdaemon
$CommndLExecute Model 204 command on sdaemon, results to $list
$ContextDetermine if string is name of open file or group
$CurfileName of the file from which the current record has been selected.
$CurrecInteger equal to the internal number of the current record.
$C2DConvert binary byte string to integer
$C2XA translation of each byte within a character string to its two-byte hexadecimal representation.
$DaemonMasterNumberGet user number of master thread
$DaemonParentNumberGet user number of parent thread
$Date
Current date in yy-mm-dd format.
$DateChgSpecified number of days, added to or subtracted from a given date.
$DateChkWhether a given date is valid.
$DateCnvDate converted to a format specified by the user.
$DateDifDifference in days between two dates.
$DatePCurrent date in "dd mon yy" format.
$DAYDay name of the input day-number.
$DayINumber reflecting current day of the week.
$DeblankSubstring of a string, with leading and trailing blanks removed.
$DecodeDecoding facility.
$DeflateCompress a longstring with Deflate
$DelChRemove characters from string, compress and strip blanks
$Delg_SubsysDelete subsystem-wide global
$Delg_SysDelete system-wide global
$DelimrInsert delimiter string into input string at regular positions
$DscrDecoding facility.
$DsnData set name when you specify a file's DD name and the ordinal number.
$DsnNumTotal number of data sets defined for a file when you specify the file's DD name.
$D2CBinary byte representation of integer
$D2XHex representation of integer
$EbcdicConvert input string from ASCII to EBCDIC
$EcbDGetGet string data associated with an Event Control Block (ECB)
$EcbDSetSet string data associated with an Event Control Block (ECB)
$EcbTestCheck an Event Control Block (ECB) to see if it is posted
$EcfStatReturns the detailed completion code from the previous EXTERNAL statement.
$EditEdited numeric and alphanumeric text
$EdScanScan list of entities in online
$EformatExponent notations from converted numeric values
$EncryptA one-way encryption of a character string.
$Ent_PrintSet automatic character entity substitution
$Ent_Tabretrieve/modify character entity substitution table
$EntDo character entity substitution
$EnterEfficient terminal dialogue with users of data entry applications.
$ErrClrClears the error message text returned by the $Errmsg and $Fsterr functions.
$ErrmsgPrefix and text of the last counting error or request cancellation message received.
$ErrSetIncrement or clear number of counting errors, set $Errmsg
$E2ATranslate EBCDIC to ASCII
$FakeEntPrepare fake ENTER to automatically satisfy next full screen read
$FDefString that describes the attributes of a field in a Model 204 file.
$Field_ImageReturn field values into an image
$Field_ListReturn field values into a $list
$Field_ListIReturn field values into a $list mapped to an image
$FieldgroupIdThe ID of the current field group. (Available as of Model 204 version 7.5.)
$FieldgroupOccurrenceThe current occurrence number of the field group. (Available as of Model 204 version 7.5.)
$FIniTimFile initialization YYDDDMMHHSSTH
$FiStatRetrieve file's statistics into string
$FiStatLRetrieve set of files' statistics into list
$FldLenLength of a field.
$FloatFloating-point to a 4-byte string without conversion (4-byte floating point number to a 4-byte string).
$FloatDFloating-point to a 4-byte string without conversion (8-byte floating point number to an 8-byte string).
$FlsAccUser's access rights to a particular field.
$FlsChkWhether a given set of field level security accesses is valid for a field.
$FreeOptFree optional file or group from subsystem
$FsterrVariable-length string containing the prefix and the first counting error message or request cancellation message received by the user since the last time the count was reset to zero.
$FunForcCancel running or waiting Fast/Unload request
$FunImgRetrieve data from active Fast/Unload request into image
$FunList$list of active and enqueued Fast/Unload requests
$FunLoadFast/Unload records in Model 204 list or found set
$FunPurgPurge running or waiting Fast/Unload request
$FunSkipSkip to next output record for $FunImg, $FunsStr
$FunsStrRetrieve data from active Fast/Unload request into string
$FunWaitWait until asynchronous Fast/Unload request completes
$GetgInformation stored by a $SETG function.
$GetLLine number of the current line on the page on the user's terminal or on the output data set specified by a USE command.
$GetPPage number currently on the user's terminal or on the output data set specified by a USE command.
$GrmLocLocation of a missing member.
$GrmNameFile name of a missing member.
$GrnLeftNumber of optional files that may fail before MAXFAIL is exceeded.
$GrnMissNumber of missing members.
$GunZipDecompress a longstring with GUNZIP
$GZipCompress a longstring with GZip
$HexAConvert hexadecimal string to EBCDIC equivalent
$HPageString of special characters whose length is equal to the value specified as the $HPage argument.
$HshA hash value from a converted string value. A hash value is a distinct numeric representation of a given string value.
$IHexAConvert EBCDIC string to hexadecimal equivalent
$ImgInfRetrieve image item by variable name
$ImgOvlReplace image item value
$IncrgPerforms simple arithmetic on global variables.
$IncStatIncrement local system statistic
$IndexAfter comparing two strings, a number equal to the first position within the first string at which the second string appears; the same function as $SCAN.
$InflateDecompress a longstring with inflate
$ItsopenWhether or not a file is open.
$ItsremoteWhether the current file or group is remote or scattered.
$JobAuthDetermine if user has authorization for USE $JOB
$JobcodeAllows a request that is part of one step of a Model 204 batch run to communicate with a subsequent step.
$JpStatRetrieve Janus port's statistics into string
$LangSpcString containing the binary value of a character in a specified language.
$LangSrtA binary string translated to sort according to the NLSORT macro for the specified language.
$LangUstPreviously $LangSrt'ed string translated back to its original form.
$LenLength of a value in a field.
$List_Add_OrderedAdd an item to an ordered $list
$List_Add_Unique_OrderedConditionally add an item to an ordered $list
$List_Add_UniqueConditionally add an item to a $list
$List_CaptureCapture print data to $list
$List_Conv_ItemConvert $list to single delimited $list item
$List_Copy_ItemsCopy items between $lists
$List_Diff_ItemDifferences between $list and delimited $list item
$List_Global and $List_SessionAccess/create global/session $list
$List_Global_Del and $List_Session_DelDelete global/session $lists
$List_Global_List and $List_Session_ListList global/session $lists
$List_MaxILReturn maximum $list item length
$List_PrintDisplay contents of a $list
$ListAdd_LstrAdd longstring as new $list item
$ListAddAdd string as new $list item
$ListAddIAdd image as new $list item
$ListAdjAdjust length of $list item
$ListChkValidate a $list identifier
$ListCmpCompare two $lists and produce $list describing differences
$ListCntNumber of items in $list
$ListCpyCopy $list
$ListDelRelease CCATEMP storage used for $list
$ListFindFind string in $list
$ListFindI and $ListFindI_UpFind image item in $list
$ListFindI_SubBuild $list subset based on image item
$ListILnLength of $list item
$Listimg_CopyCopy a $list's image association
$ListImgAssociate an image with a $list
$ListInf_LstrRetrieve $list item into longstring
$ListInfRetrieve $list item into string
$ListInfIRetrieve $list item into image
$ListIns_LstrInsert string into a $list
$ListInsInsert string into a $list
$ListInsIInsert image into a $list
$ListLocLocate string in $list
$ListLupLocate string in $list, searching backwards
$ListMoveMove a $list
$ListNewCreate empty $list
$ListNewACreate array of empty $lists
$ListNewAICreate array of empty $lists associated with image
$ListNewICreate empty $list associated with image
$ListOvlOverlay part of $list item with string
$ListOvlIOverlay part of $list item with image item
$ListRemRemove item from $list
$ListRep_LstrReplace a $list item with a longstring
$ListRepReplace a $list item with a string
$ListRepIReplace $list item with an image
$ListRstRestore global $list
$ListSav and $ListSaveSave global $list
$ListSavLCount and names of available global $lists
$ListSort and $ListSrtSort $list
$ListSubCreate $list that is subset of input $list
$ListUpdProduce $list from input $list using $list of updates
$LowcaseA lower case string translated from an uppercase or mixed case string
$LstFldField names in a file, along with their field descriptions, into an image.
$LstProcInformation that is stored for a procedure.
$Lstr_Add_UserBufferAdd longstring to user buffer
$Lstr_Base64_DecodeConvert from base 64 to byte string
$Lstr_Base64_EncodeConvert byte string to base 64
$Lstr_C2XConvert byte string to hexadecimal
$Lstr_Get_Image and $Lstr_Set_ImageLongstring to/from image
$Lstr_Get_UserbufferGet user buffer contents to a longstring
$Lstr_Global and $Lstr_SessionBind to global/session longstring
$Lstr_Global_Del and $Lstr_Session_DelDelete global or session longstring
$Lstr_Global_Get and $Lstr_Session_GetGet global or session longstring
$Lstr_Global_Set and $Lstr_Session_SetSet global or session longstring
$Lstr_IndexFind a string inside a longstring
$Lstr_LeftLeftmost characters of a longstring
$Lstr_LenLength of a longstring
$Lstr_ParsePart of longstring preceding character in delimiter set
$Lstr_ParseXPart of longstring following character in delimiter set
$Lstr_RightRightmost characters of a longstring
$Lstr_Set_UserBufferSet user buffer to longstring value
$Lstr_SubstrSubstring of a longstring
$Lstr_SubWordSubstring of a longstring using word counts
$Lstr_TranslateTranslate longstring
$Lstr_UnblankRemove extraneous blanks from longstring
$Lstr_WindexReturn the position of a word within a long string
$Lstr_WordReturn a word from a long string
$Lstr_WordsReturn the number of words in a long string
$Lstr_X2CConvert from hexadecimal to byte string
$LstrTreat a string as longstring
$MisGrupGroup name if the error occurred in group context, null if in file context.
$MisLocLocation of a missing member or file.
$MisNameFile name of a missing member or file.
$MisNumNumber of files that failed in a group.
$MisStmtStatement that caused the ON unit to be entered.
$ModRemainder that results when one argument is divided by the another argument.
$OccursWhether a field has the OCCURS attribute.
$OneofTable lookup that can replace a series of IF conditions.
$PackPacked decimal representation of a string.
$PadDesignated character padded to the left.
$PadRDesignated character padded to the right
$ParsePart of string preceding character in delimiter set
$ParseXPart of string following character in delimiter set
$PostIndicates that an event has occurred; the thread waiting on an ECB can resume processing.
$PrcLEx$list of information about procedures in file
$PrcLExG$list of information about procedures in group or file
$PriortyChange a user's priority
$Proc_List$list of information about procedures in file
$Proc_ListG$list of information about procedures in group or file
$Proc_TouchChange a procedure's last-update date and user
$ProcClsClose procedure before reaching end
$ProcDatAdd lines from procedure to $list
$ProcGetNext line of procedure
$ProcLocLocate any of set of strings in procedure
$ProcOpnOpen procedure for $ProcDat, $ProcGet, $ProcLoc
$Random_SeedBuild seed specifying series of $Random results
$RandomGet next random number
$RdProcLines of a User Language procedure, retrieved in sequential order, that is stored in a Model 204 file.
$ReadAn echo of the data a user enters as a request is evaluated
$ReadInvPerforms the same function as $READ, except that input from the terminal is not echoed.
$ReadLcAn echo of the data a user enters as a request is evaluated, except that case translation is deactivated, regardless of the current *UPPER or *LOWER setting.
$RegexMatchWhether string matches regex
$RegexReplaceReplace matching strings
$RemoteVTAMNAME value of the originating Model 204 region when using SNA Communications Server (formerly VTAM) TRANSFER to transfer between Model 204 regions.
$ResetnReset or view M204 parameter
$ReverseReversed order of a string.
$RlcFileName of the file in which the last record locking conflict occurred.
$RlcRecInternal record number for which the last record locking conflict occurred.
$RlcUidID of the user who caused an ON FIND CONFICT or ON RECORD LOCKING CONFLICT. If the conflicting user is on a remote node, $RLCUID also returns the name of the node.
$RlcUsrUser number of the user with which the request conflicted when the last record locking conflict occurred.
$RoundNumber, rounded to a specified number of decimal places.
$ScanAfter comparing two strings, a number equal to the first position within the first string at which the second string appears; the same function as $INDEX.
$SclassCurrent user's subsystem user class.
$ScrHideHide lines in SCREEN
$ScrSizeChange size of field on SCREEN
$ScrWideAllow SCREEN to accept fields wider than 79
$Session, $Session_Id, $Session_Owner,   
and $Session_Timeout
Return values for currently open session
$Session_CloseClose an open session
$Session_CreateCreate a new session
$Session_DeleteDelete a session
$Session_ListGet list of sessions
$Session_OpenOpen a session
$Setg_Subsys_ListGet list of subsystem-wide globals
$Setg_SubsysSet subsystem-wide global
$Setg_Sys_ListGet list of system-wide globals
$Setg_SysSet system-wide global
$SetgA created or changed entry in the global variable section of GTBL.
$SetLSets the current line counter for the output device currently in effect.
$SetPSets the current page number for the output device currently in effect.
$SetStatSet local system statistic
$Sir_Date
Get current datetime
$Sir_DateFmtValidate datetime format
$Sir_DateN
Current date and time as number of seconds/300
$Sir_DateNDCurrent date as number of days
$Sir_DateNMCurrent date and time as number of milliseconds
$Sir_DateNSCurrent date and time as number of seconds
$Sir_Date2NConvert datetime string to number of seconds/300
$Sir_Date2NDConvert datetime string to number of days
$Sir_Date2NMConvert datetime string to number of milliseconds
$Sir_Date2NSConvert datetime string to number of seconds
$Sir_LoginPerform secured web or sockets login
$Sir_ND2DateConvert datetime number of days to string
$Sir_NM2DateConvert datetime number of milliseconds to string
$Sir_NS2DateConvert datetime number of seconds to string
$Sir_N2DateConvert datetime number of seconds/300 to string
$Sir_WildTest string against a wildcard string
$SirJGetPlace audit trail data on $list
$SirMsgLine of current $SirMsgP procedure
$SirMsgPLoad procedure for retrieval via $SirMsg
$SirParmSet user-specific value, controlling Sirius products
$SirProdDetermine availability of Sirius product or capability
$SirSiteCurrent Sirius customer site ID
$SirTimeCurrent time as YYDDDHHMISSXX
$SirVerCurrent version number of Sirius product
$SirWarnSend warning or message to user(s)
$SlstatsResets the recording of since-last statistics anywhere within a request.
$SndMailSend an email message
$SndxSOUNDEX code of an argument.
$SquareA number multiplied by itself.
$SsStatRetrieve subsystem's statistics into string
$SsStatLRetrieve statistics for set of subsystems into $list
$StatCurrent value of any user statistic.
$StatDCalculate differences and rates for statistics strings
$StatLDCalculate differences and rates for statistics $lists
$StatusThe success or failure of the last executed external I/O or program communication statement.
$StatusDMore detailed description of a condition returned by $STATUS.
$StrTreat a longstring as string
$StrAndBit-wise AND two strings
$StripA number with suppressed leading zeros.
$StrOrBit-wise OR two strings
$StrXorBit-wise exclusive OR two strings
$SubCntCount occurrences of one string in another
$SubErsRemove occurrence of one string from another
$SubInsInsert string inside another string
$SubRepReplace occurrences of string
$SubstrSubstring of a string.
$SubsysStatus of an APSY subsystem.
$SyStatRetrieve system statistics into string
$TableCInformation provided by TABLEC command
$TermIdTerminal ID of current user thread
$TimeCurrent time in hh:mm:ss format.
$TkStatRetrieve task's statistics into string
$TkStatLRetrieve statistics for all tasks into $list
$TsoAttAttach program in user's TSO address space
$TsoCallCall program in user's TSO address space
$TsoCanCancel program invoked via $TsoAtt
$TsoCmdInvoke command in user's TSO address space
$TsoExecInvoke CLIST in user's TSO address space
$TsoExitTerminate TSO full screen interface session, stack command
$TSOIdTSO userid user's thread
$TSOStatStatus of program invoked via $TsoAtt
$TSOWaitWait for program invoked via $TsoAtt to complete
$UnbinValue converted from binary to string representation.
$Unbind_and_$UnbindW$Unbind and $UnbindW: Unbind resource previously bound via $Bind
$UnblankContents of an argument, removing leading and trailing blanks, and compressing multiple embedded blanks to one blank character.
$UnfloatCharacter string that represents a numeric counted string of 4 or 8 bytes, which contains a floating point.
$UnpackUnpacked decimal data
$UnPostResets a specified Event Control Block (ECB) to an unposted state.
$UnqRec

In the case of a uniqueness violation, returns the file-relative record number of the record that already contains the field name = value pair

If no uniqueness violation occurred. returns -1.

$UnSpaceNormalize spaces and quotes
$UpcaseAn uppercase string converted from a lower or mixed case string.
$UpdateName of the group update file or the current file.
$UpdFileName of the file in which a field level constraint violation has occurred, or a blank if no violation occurred.
$UpdFldName of the field for which a field level constraint violation has occurred, or a blank if no violation occurred.
$UpdLocLocation name (node name) of the current update unit (Parallel Query Option/204 only).
$UpdOvalValue of the original field occurrence causing a constraint violation, when invoked from an ON FCC unit following the detection of an AT-MOST-ONE field-level constraint conflict.
$UpdRecFile-relative record number of the record whose update caused a field level constraint violation, or -1 if no violation occurred.
$UpdStatNumeric value denoting the type of field level constraint violation that has occurred, or 0 if no violation occurred.
$UpdStmtType of User Language updating statement causing a field level constraint violation, or a blank if no violation occurred.
$UpdValField value causing a field level constraint violation, or a blank if no violation occurred.
$UseASAPrevent carriage control in USE output
$UserUser's user number.
$UseridUser ID under which the user is logged in.
$UsrPrivWhether a user ID has been granted specific Model 204 privileges.
$UsStatRetrieve user's statistics into string
$UsStatLRetrieve statistics for set of users into $list
$VerifyWhether every character in one string is present in a second string.
$ViewValue of a parameter.
$VnumWhether a given argument is in a valid format for a SORT BY VALUE NUMERICAL statement or for any type of mathematical operation.
$WaitSuspend a user until an Event Control Block (ECB) is posted.
$WakeUpPause user until specified time
$Web_xxxList of Janus Web Server $functions
$WindexWord number of first occurrence of word in phrase
$WordP word in a specified string, delimited by a blank or optionally specified character.
$WordsNumber of words in a specified string, delimited by a blank or optionally specified character.
$X2COne-byte EBCDIC characters translated from a string of 2-byte hexadecimal character.
$X2DConvert hex string to integer

Using functions

You can use functions in several ways, including, as a term in:

  • An expression in a variable assignment statement, for example:

%X=$EDIT(2573,'99999')

  • The specifications in a PRINT statement

A PRINT statement can include a function call anywhere a field name can be used. For example:

PRINT $EDIT(2573,'99999')

  • An expression in a conditional statement, for example:

IF $EDIT(2573,'99999') EQ 02573 THEN...

  • An expression which serves as the argument to another function, for example:

%L=$LEN($EDIT(2573,'99999'))

The direct use of function calls in some statements, such as FIND, results in compilation errors.

Comparing successful and unsuccessful $function code

If your request is coded as follows:

BEGIN $EDIT(2573,'99999') END

The following error is your result:

*** 1 M204.0229: INVALID STATEMENT $EDIT(2573,'99999')

However, if you code your request as follows, it works properly:

BEGIN PRINT $EDIT(2573,'99999') * Or * * %X=$EDIT(2573,'99999') * END

Function return values

Each function returns a single value to the calling request. For example, this function sets %A equal to the user's login account name:

%a = $account

This function causes the length of the current value of the FULLNAME field to be compared to 10:

IF $LEN(FULLNAME) GT 10 THEN . . .

Function arguments

Some functions require one or more arguments which allow you to pass information to the subroutine. Some functions take no arguments. Arguments must be enclosed in parentheses and separated by commas. For example:

IF $READ('CONTINUE?') EQ 'YES' THEN . . . %X = $mod(COUNT IN CT, %BASE)

Rules for function arguments

Function arguments follow the normal rules for arithmetic expressions. Arguments can include other function calls and can perform any type of computation. See the section Expressions for detailed information on expression syntax.

Argument evaluation and conversion

Model 204 evaluates each argument to a function as either a string or a number. When this data type conflicts with the data type required by the function, the following rules apply:

  • If an argument is expected to be numeric but is a string, Model 204 converts the string to a number according to the conversion rules described in the assignment statement discussion in Relationship between %variable assignment and declaration and Conversion.
  • If an argument is expected to be a string but is numeric, Model 204 converts the number to a string.
  • If the original number contains decimal places, they are lost during the conversion.

Sending email messages via $SndMail

The SOUL $SndMail function simplifies sending an email message to issuing a single function call. You can easily send an email message using SOUL without writing a procedure and without having an extensive knowledge of sockets or SMTP protocol.

Internet Protocol (IP) addressing

On z/OS systems only, Model 204 supports both IPv6 and IPv4 addressing.

Limitations of $SndMail under z/VM and z/VSE

$SndMail is supported with the following exceptions:

  • The SMTPCADD and SMTPSADD addresses must be supplied in internet protocol (IP) address protocol, not as domain names. You must supply IPv4 (dotted-decimal) internet addresses for the SMTPCADD and SMTPSADD parameters.
  • Likewise, if the client and server names are specified using the SMAILD image rather than using the CCAIN parameters SMTPCADD and SMTPSADD, the SERVERDDNAME and CLIENTDDNAME values must be supplied rather than the SERVERNAME and CLIENTNAME values.
  • Model 204 does not support IPv6 addressing on z/VM or z/VSE systems.

Enabling $SndMail

The first requirement for enabling the use of $SndMail is to set the following four required CCAIN parameters:

Parameter SMTP purpose
SMTPCADD SMTP client address. The client is the Model 204 address space.

On z/OS systems:

Set this parameter to one of the following:

  • Symbolic name, such as MYMVS1, or SMTP.MYDOMAIN.COM.
  • Dotted decimal address, such as 182.148.55.206.
  • IPV6 address, with up to 8 halfwords separated by colons, such as C0:12:46:F0:00:00:00:01, which can also be written as C0:12:46:F0::01. In other words, the double colon shows that there are missing halfwords of binary zeros.

On z/VM or z/VSE systems:

Set this parameter to the dotted decimal address, such as 182.148.55.206.

SMTPCPRT SMTP client port. The default value is 7700.
SMTPSADD SMTP server address.

On z/OS systems:

Set this parameter to one of the following:

  • Symbolic name, such as MYMVS1, or SMTP.MYDOMAIN.COM.
  • Dotted decimal address, such as 182.148.55.206.
  • IPV6 address, with up to 8 halfwords separated by colons, such as C0:12:46:F0:00:00:00:01, which can also be written as C0:12:46:F0::01.

On z/VM or z/VSE systems:

Set this parameter to the dotted decimal address, such as 182.148.55.206.

SMTPSPRT SMTP server port. The default value is 25, which is standard for most SMTP servers.

Your system manager can dynamically reset these parameters while the run is up. If you use the domain name for either SMTPCADD or SMTPSADD, you must have the following DD allocated to the Online:

//SYSTCPD DD DSN=TCPIP.PROFILE(TCPDATA),DISP=SHR

This is the TCP/IP profile data set required to support the resolution of IP domain names.

On some SMTP servers, a valid email address is required for the %from argument in the $SndMail function. Most SMTP activity requires a valid SMTP server.

$SndMail and BATCH204

$SndMail is supported in BATCH204 if you relink BATCH204 with the following objects after V7R4 installation:

  • TC62 (or TC62DOS on z/VSE systems)
  • TCIU
  • TCSE
  • LU62
  • FUNR (or FUNRDOS on z/VSE systems)

After relinking you need to ensure that the following SMTP parameters are set in the ONLINE and BATCH204 CCAIN:

  • SMTPCADD
  • SMTPSADD
  • SMTPCPRT
  • SMTPSPRT

$SndMail syntax

The $SndMail function sends an email message using the values you enter for the $SndMail arguments. $SndMail lets you send an email message with an optional attachment.

The syntax for the $SndMail function is:

$SndMail(%subj, %rcpt, %body, %from, %to, %cc, %bcc, 'EMAILD', %attach, 'C')

Where:

  • %SUBJ, which is optional, specifies a %variable or literal that contains the topic line.
  • %RCPT, which is optional, specifies a %variable or an image that contains the destination addresses, separated by commas.

    If %RCPT is omitted, the destination addresses are taken from the %TO, %CC and %BCC arguments.

    If %RCPT is an image, the image name must be enclosed within quotation marks, for example 'DEPT-ADDR'.

  • %BODY specifies a %variable or an image that contains the text of the message. If %BODY is an image, the image name must be enclosed in quotation marks, for example 'MSG-TXT'.
  • %FROM specifies a %variable that contains the FROM header field of up to 255 bytes. Although %FROM is optional, you should supply it, otherwise messages could fail when speaking to another SMTP server. If %FROM is omitted, the logged-on user ID is used. The email server may append the domain name to the given %FROM value.
  • %TO, %CC, and %BC, which are optional, specify a %variable that contains the TO, CC, and BCC header fields, respectively, of up to 255 bytes each.

    Address must be enclosed in carets (<>), for example: M204-help <M204support@rocketsoftware.com>.

  • 'EMAILD', which is optional, specifies image data. The parameter provides the ability to override the values specified in CCAIN for SMTPSPRT, SMTPCPRT, SMTPSADD, and SMTPCADD. If 'EMAILD' is present, it must be in the following format, with the items in the following order:

    * EMAILD - IMAGE WITH SMTP PARAMETERS IMAGE EMAILD SERVERPORT IS BINARY LEN 4  ;*SMTPSPRT CLIENTPORT IS BINARY LEN 4  ;*SMTPCPRT SERVERNAME IS STRING LEN 255  ;*SMTPSADD CLIENTNAME IS STRING LEN 255  ;*SMTPCADD SERVERDD IS STRING LEN 15  ;*Server dotted decimal address IPv4 format (optional) CLIENTDD IS STRING LEN 15  ;*Client dotted decimal address IPv4 format (optional) SERVERIPV6 IS STRING LEN 45  ;*Server dotted decimal address IPv6 format (optional) CLIENTIPV6 IS STRING LEN 45  ;*Client dotted decimal address IPv6 format (optional) END IMAGE

    The SERVERIPV6 and CLIENTIPV6 fields are provided for the IPv6 colon-separated network addresses. These two fields are optional, to provide backward compatibility.

  • %ATTACH, which is optional, specifies a %variable or literal with the name of an attachment that will be appended to the message. The attachment is assumed to be in the Universal Buffer at offset 0 (also called position 1). The length of the attachment is defined by the $Buffer_Used value. If the %ATTACH parameter is omitted, there is no attachment.

    The function encodes the attachment using Base64 encoding, and may also translate it depending on the 10th argument.

  • 'C', which is optional and is available as of Model 204 version 7.5, specifies that the object in the buffer will be translated to ASCII before being attached to the email. Alternatively, you can set this parameter to a percent variable with the value 'C'. For example, translation to ASCII could be useful if the $SndMail attachment is a CLOB (CHARACTER-LARGE-OBJECT) such as a text document. If this argument is not specified with the value 'C' or 'c', the attachment is sent as binary, that is, without translation.

    In this example, the CLOB.TXT attachment will be translated to ASCII before being attached to the email:

    %RC = $SndMail(%SUBJECT,,%BODY,%FROM,%TO,,,,'CLOB.TXT','C')

Setting CCAIN parameters for $SndMail

You can set the following CCAIN parameters as default values for $SndMail.

  • SMTPCADD is the default SMTP client address, the TCP/IP domain for the operating system, for $SndMail. You can sp ecify SMTPCADD as:
    • (z/OS, z/VM, or z/VSE) Internet Protocol (IP) address, IPv4 format.
    • (z/OS) Domain name of up to 255 bytes. If the first character of the address is an alphabetic character (A to Z), it is automatically evaluated as a domain name.
    • (z/OS) IPV6 address, with up to 8 halfwords separated by colons, such as: C0:12:46:F0:00:00:00:01, which can also be written as C0:12:46:F0::01. In other words, the double colon shows that there are missing halfwords of binary zeros.

    You can override SMTPCADD for a specific call by entering a different value in the EMAILD argument of the $SndMail function call.

  • SMTPCPRT is the default SMTP client port for the $SndMail function. The value can be any value in the user range — normally above 4095 and up to 32767.

    You can override SMTPCPRT for a specific call by entering a different value in the EMAILD argument of the $SndMail function call.

  • SMTPSADD is the default SMTP server address for $SndMail. You can specify SMTPSADD as:
    • (z/OS, z/VM, or z/VSE) Internet Protocol (IP) address, IPv4 format.
    • (z/OS) Domain name of up to 255 bytes. If the first character of the address is an alphabetic character (A to Z), it is automatically evaluated as a domain name.
    • (z/OS) IPV6 address, with up to 8 halfwords separated by colons, such as: C0:12:46:F0:00:00:00:01, which can also be written as C0:12:46:F0::01. In other words, the double colon shows that there are missing halfwords of binary zeros.

    You can override SMTPSADD for a specific call by entering a different value in the EMAILD argument of the $SndMail function call.

  • SMTPSPRT is the default SMTP server port for $SndMail. SMTPSPRT is normally set to the standard SMTP value of 25. You can override SMTPSPRT for a specific call by entering a different value in the EMAILD argument of $SndMail.

Examples of running $SndMail

Example 1

%FROM = 'me@mydomain.com' %TO = 'My Friend <you@yourdomain.com>' %BNAME = 'mypicture.jpg' MODIFY BUFFER CLEAR IN LOBSVR FOR 1 RECORD WHERE SVRKEY = %SVRKEY %ISIZE = $LOBLEN(SVRLOB) PRINT 'SIZE OF ' WITH %SVRKEY WITH ' IS ' WITH %ISIZE BUFFER, 1, %ISIZE = SVRLOB, 1, %ISIZE END FOR PRINT 'BUFFER USED IS ' WITH $buffer_used %SUBJECT = 'THIS SENDS A JPG FROM LOBSVR - ' WITH %SVRKEY %BODY = 'THIS BODY CONTAINS ' WITH %SVRKEY %RC = $SNDMAIL(%SUBJECT,,%BODY,%FROM,%TO,,,,%BNAME)

In the previous example, a binary object (BLOB) is retrieved from the database and placed at position 1 in the buffer. $SndMail sends this as a Base64-encoded attachment.

Note: The second parameter (the RCPTTO addresses) is omitted. The function creates this using the %TO parameter.

Example 2

%TO ='JANE <YOU@YOURCORP.COM>' %BODY='See you at 9:30 AM tomorrow in the conference room' %RC =$SNDMAIL(,,%BODY,,%TO)

Example 3

The EMAILD argument is used to override the default domain names and ports.

IMAGE EMAILD SERVERPORT IS BINARY LEN 4  ;*SMTPSPRT CLIENTPORT IS BINARY LEN 4  ;*SMTPCPRT SERVERNAME IS STRING LEN 255  ;*SMTPSADD CLIENTNAME IS STRING LEN 255  ;*SMTPCADD END IMAGE PREPARE IMAGE EMAILD %EMAILD:SERVERNAME = 'MAIL.SERVER.COM' %EMAILD:CLIENTNAME = 'MYMVSSYSTEM' %EMAILD:SERVERPORT = 25 %EMAILD:CLIENTPORT = 5601 %FROM = 'ME@MYCORP.COM' %TO = 'JANE <YOU@YOURCORP.COM>' * RCPTTO is defined as an image here, allowing the string of * addressees to be more than 255 bytes long. IMAGE RCPTTO EMRCPT1 IS STRING LEN 255 END IMAGE PREPARE IMAGE RCPTTO %RCPTTO:EMRCPT1 = 'YOU@YOURCORP.COM' IMAGE BODY BODY1 IS STRING LEN 240 BODY2 IS STRING LEN 240 END IMAGE PREPARE IMAGE BODY %S = 'EXAMPLE 1' /? SUBJECT LINE  ?/ %BODY:BODY1 = 'THIS IS BODY1 WHICH IS PART OF AN IMAGE' %BODY:BODY2 = 'SO THE BODY TEXT CAN BE MORE THAN 255 BYTES LONG' %RC = $SNDMAIL(%S,'RCPTTO','BODY',%FROM,%TO,,,'EMAILD')

Example 4

This example illustrates using EMAILD in an IPV6 environment. The lines that differ from Example 3 are shown in bold.

IMAGE EMAILD SERVERPORT IS BINARY LEN 4  ;*SMTPSPRT CLIENTPORT IS BINARY LEN 4  ;*SMTPCPRT SERVERNAME IS STRING LEN 255  ;*SMTPSADD CLIENTNAME IS STRING LEN 255  ;*SMTPCADD SERVERDD IS STRING LEN 15  ;*Server dotted decimal address IPv4 format (optional) CLIENTDD IS STRING LEN 15  ;*Client dotted decimal address IPv4 format (optional) SERVERIPV6 IS STRING LEN 45  ;*Server dotted decimal address IPv6 format (optional) CLIENTIPV6 IS STRING LEN 45  ;*Client dotted decimal address IPv6 format (optional) END IMAGE PREPARE IMAGE EMAILD %EMAILD:SERVERPORT = 25 %EMAILD:CLIENTPORT = 5601 %EMAILD:SERVERNAME = 'MAIL.SERVER.COM' %EMAILD:CLIENTIPV6 = 'C0:12:46:F0::01' %FROM = 'ME@MYCORP.COM' %TO = 'JANE <YOU@YOURCORP.COM>' * RCPTTO is defined as an image here, allowing the string of * addressees to be more than 255 bytes long. IMAGE RCPTTO EMRCPT1 IS STRING LEN 255 END IMAGE PREPARE IMAGE RCPTTO %RCPTTO:EMRCPT1 = 'YOU@YOURCORP.COM' IMAGE BODY BODY1 IS STRING LEN 240 BODY2 IS STRING LEN 240 END IMAGE PREPARE IMAGE BODY %Y = $X2C('0D25') /? EBCDIC CRLF character is moved to %Y ?/ %S = 'EXAMPLE 1' /? SUBJECT LINE ?/ %BODY:BODY1 = %Y WITH 'THIS IS BODY1 WHICH IS PART OF AN IMAGE' /? %Y will be translated to ASCII CRLF ?/ %BODY:BODY2 = %Y WITH 'SO THE BODY TEXT CAN BE MORE THAN 255 BYTES LONG' %RC = $SNDMAIL(%S,'RCPTTO','BODY',%FROM,%TO,,,'EMAILD')

ASCII translation

All text, except an optional binary attachment, is translated from EBCDIC to ASCII before sending.

Line ends

In text that is part of the header and body, you can enter line ends by including EBCDIC CRLF strings (X'0D25') that are translated to ASCII along with the rest of the text.

If you do not enter line ends, your images might display all on one line, depending on your email viewer.

The comments and bold text added to this snippet from Example 4 highlight the use of line ends:

PREPARE IMAGE BODY %Y = $X2C('0D25') /? EBCDIC CRLF character is moved to %Y ?/ %S = 'EXAMPLE 1' %BODY:BODY1 = %Y WITH 'THIS IS BODY1 WHICH IS PART OF AN IMAGE' /? %Y will be translated to ASCII CRLF ?/ %BODY:BODY2 = %Y WITH 'SO THE BODY TEXT CAN BE MORE THAN 255 BYTES LONG' %RC = $SNDMAIL(%S,'RCPTTO','BODY',%FROM,%TO,,,'EMAILD')

Reserved names

$SndMail uses Interface names CCAEM000 through CCAEM999. The user does not specify these names — the link name is generated by the function.

Socket limits

Up to 31 sockets are available on each link. If no more sockets are available on a particular link (CCAEM000, for example), the next link is tried. Thus, a maximum of 31,000 simultaneous email threads is theoretically possible.

Size of email message

The FROM, TO, CC, BCC, RCPTTO addresses, and body length, excluding the optional binary attachment, must total less than 27454 bytes.

Return code

$SndMail returns a fixed full word binary return code. See Handling error condition return codes for possible values.

RCPTTO parameter

If the $SndMail EMAILD argument is omitted, the RCPTTO addresses are constructed from the addresses contained in the %TO, %CC, and %BCC arguments.

The sum of the lengths of the RCPTTO address string, (If supplied) and the body text cannot exceed 30,700.

Using quotation marks

You must enclose the names of images within quotation marks, for example: 'BODY'. However, do not enclose the percent variable values within quotation marks, for example: %SUBJECT, not '%SUBJECT'.

Server and client names in the EMAILD parameters

In the EMAILD image, on a z/OS system, you can specify either or both the server and client names as domain names, for example: SMTPSERVER.YOURDOMAIN.COM or as an Internet Protocol (IP) address. If you specify the domain name, a TCP/IP call looks up the IP address.

  • If one field is present, all fields must be present, even if the optional fields are left blank.
  • If a name or port field is absent, it is taken from the CCAIN parameters SMTPSADD, SMTPCADD, SMTPSPRT, and SMTPCPRT.

The two port parameters have defaults: the SMTPSPRT default is 25; the SMTPCPRT default is 7700.

The two address parameters, SMTPSADD and SMTPCADD, can be specified either as domain names of up to 255 bytes or as IP addresses. If the address begins with an alphabetic character (A to Z), it is automatically evaluated as a domain name.

The four CCAIN default parameters SMTPSADD, SMTPCADD, SMTPSPRT, and SMTPCPRT can be examined using VIEW and changed using RESET.

References

For more information about the standards used in this function, please refer to these Internet Request for Comments documents:

  • RFC822, Standard for the format of ARPA Internet Text Messages
  • RFC2821, Simple Mail Transfer Protocol
  • RFC3548, The Base16, Base32, and Base64 Data Encoding

Error codes for $SndMail

$SndMail issues a return code. An error in $SndMail gives a return code of -1, and it is $StatusD that contains the error code.

The negative error codes starting with -999 are listed in Handling error condition return codes.

It is also possible that $SndMail will return a positive error code, which comes from TCP/IP and is documented in the IBM TCP/IP documentation, TCP/IP V3.2 for MVS: API Reference, Appendix D. For example, an error code of 60 means that the connection attempt timed out. $SOCKET calls give the same errors.

However, in the case of a non-zero (error) return code, the following message is issued to the user:

M204.2799: $SndMail error errortext

When an attempt is made to set or reset the SMTPCADD or SMTPSADD parameters and the address translation fails, Model 204 issues the following messages:

RESET SMTPCADD CCAGGGG *** M204.2834: ADDRESS LOOKUP FAILED FOR CCAGGGG *** 1 M204.1123: PARAMETER SMTPCADD NOT RESET

Handling error condition return codes

Handling error condition return codes lists the possible $SOCKET return codes.

$Socket return codes
SMTP Error text Numeric value Meaning
ERBADARG -999 BAD ARGUMENT
ERNOTOPN -998 NOT OPEN
ERNOSTOR -997 NO STORAGE
ERIMAGER -996 IMAGE FAILURE
ERBADLNK -995 BAD LINK
ERNOTREL -994 SOCD NOT RELEASED
ERPHYERR -993 LINK DEAD
ERNOLINK -992 LINK UNKNOWN
ERTRUNC -991 VARIABLE TRUNCATION (READ CALL)
ERNOSOCK -990 SOCKET NOT FOUND
ERTRUNC2 -989 TRUNCATION ERROR ON IMAGE
EROPSYS -988 FUNCTION UNSUPPORTED ON THIS OPSYS
  -987 Not used
ERNOSRCD -986 NO SRCD
ERFDSLIM -985 TOO MANY SOCKETS
ERBADUBN -984 UNIVERSAL BUFFER NOT THERE
ERBADUBL -983 UNIVERSAL BUFFER LENGTH ERROR
ERBADUBA -982 UNIVERSAL BUFFER ALLOCATION ERROR
EREMREAD -981 ERROR WITH EMAIL SERVER READ
EREMWRIT -980 ERROR WITH EMAIL SERVER WRITE
ERGHBERR -979 SKIP=0 ERROR ON GETHOST CALL
ERGHERR1 -978 T1 LT 0 ERROR ON GETHOST CALL
ERGHERR2 -977 NO ADDRESSES RETURNED

When an error message (with code 5xx) is returned from the SMTP server, the following error message is displayed:

M204.2796: 'SMTP %C'

where %C is the error message returned by SMTP.

For the other error codes above, the following error message is returned, in addition to $StatusD being set.

M204.2799: '$SndMail error errorText'

where %C is listed in the following table:

Error text message possibilities for M204.2799
%C in message 2799 $StatusD code(s)
IN PARAMETER 999
- SOCKET NOT FOUND 990
- FUNCTION NOT SUPPORTED ON THIS SYSTEM 998
- NO SRCD 986
- TOO MANY SOCKETS 985
WITH UNIVERSAL BUFFER 984, 983, 982
Reading from SMTP server 981
Writing to SMTP server 980
Using GETHOSTBYNAME lookup 979, 978, 977
GETTING STORAGE 997
IN IMAGE PROCESSING 996
WITH TCP LINK 995, 998, 993, 992
- SOCD NOT RELEASED 994
READING DATA - TRUNCATION 991

User-written functions

In addition to the functions provided by SOUL, some customer sites write their own functions based on their particular needs. Before using any user-written functions, make sure that your site's FUNU module has been reassembled with the macro library supplied with the current release. Also, please be sure to carefully test your user-written functions before your system goes into production.

Notes:

  • It is recommended that all user-written functions use the STMG/LMG Assembly Language instructions to save and restore any registers that are modified.
  • The RESULT macro does not work in Model 204 Version 5.1 and later. Change any use of the RESULT macro in $functions to use the standard LEAVENUM, LEAVEF0 and LEAVESTR macros.
  • In addition to the above considerations, see the installation instructions relating to FUNU.

Customers are individually responsible for any functions they write. Rocket Software takes no responsibility for user-written functions or their documentation.