- RE: Using %LOOKUP with an Array Data Structure in SQLRPGLE
- %SCAN Built-In Functions in rpgle
- Idea Details
- Subscribe to RSS
- Free-form RPG support on IBM i
%SCAN Built-In Functions in rpgle
Login or Sign Up. Posts Latest Activity. Page of 1. Filtered by:. Previous template Next. I would like to search array with my search arg. When I do lookup for the first time and array is empty yet, I get decimal data error. When I write sth to array and then do lookup, it works fine. What could be wrong? Or is there any way to search array? Tags: None. March 26th,AM. A decimal data error only occurs when the value being assigned to a numeric field is not valid for example moving spaces to a packed field. Perhaps your file field has an invalid number? Comment Post Cancel. Last edited by michal ; March 26th,AM. That shouldn't even compile. Did you copy and past this or just retyped it? If INVA is empty contains all blanks then the numeric field will also have blanks and you get data decimal errors. It should be a standalone field - missing the 's' in the d-spec. PGM has compiled correctly. This causes the program to initialize the data structure and its sub fields with their default or Inz values when the program starts. Barbara Morris. March 26th,PM. All rights reserved. Yes No. OK Cancel.
Act now. Each free-form statement begins with an operation code and ends with a semicolon. Here is a list of the new operation codes:. RPG syntax in free form is similar to other modern languages and can be understood easily. The new syntax also makes programming easier for existing RPG programmers. This section describes the changes for a control specification H spec. Allowed keywords are the same keywords as an H spec. Multiple control statements are allowed and free-form control statements can be intermixed with fixed-form H specs. Each statement must be a complete statement. Example 2 illustrates an empty control statement. Example 3 illustrates additional control statements. This section describes the changes for declaration statements D spec. There are several types of declaration statements: named constants, stand-alone fields, data structures, procedure prototypes, and procedure interfaces. For those who are familiar with fixed-form definitions, there are a few keyword changes related to data types. This section provides additional details about these keywords. One enhancement related to the declaration statements is that file definitions and data definitions might be intermixed. This new rule also applies to fixed-form F and D specifications. A named constant declaration starts with DCL-Cand is then followed by the name, then by the optional keyword CONSTand then by the value and finally ends with a semicolon. Example 5 illustrates several named constant declarations. A stand-alone field declaration starts with DCL-Sand is followed by the name, then by an optional data type keyword, and then by zero or more keywords, and ends with a semicolon. If a data type keyword is specified, it must be the first keyword. Example 6 illustrates several stand-alone field declarations. If the LIKE keyword is used, there is no data type keyword. An optional second parameter can be specified on the LIKE keyword to do a length adjustment. Example 7 illustrates stand-alone declarations with the LIKE keyword. Named constants can be used within free-form keyword declarations. The named constant must be defined before the definition statement. Example 8 illustrates using named constants within declarations. If the data structure can have program-described subfields, an END-DS statement with an optional name must be specified. Example 9 illustrates several data structure declarations. If the data structure does not have a name, the END-DS statement must be specified without an operand.
Subscribe to RSS
Array Operations. The basic array operations are:. Specifying an Array in Calculations. An entire array or individual elements in an array can be specified in calculation specifications. You can process individual elements like fields. Remember, if an array element is to be used as a result field, the array name with the comma and index cannot exceed 6 characters. To specify an entire array, use only the array name, which can be used as factor 1, factor 2, or the result field. Several other operations can be used with an array element only but not with the array name alone. When specified with an array name without an index, certain operations are repeated for each element in the array. The following rules apply to these operations when an array name without an index is specified:. When factors 1 and 2 and the result field are arrays with the same number of elements, the operation uses the first element from every array, then the second element from every array until all elements in the arrays are processed. If the arrays do not have the same number of entries, the operation ends when the last element of the array with the fewest elements has been processed. When one of the factors is a field, a literal, or a figurative constant and the other factor and the result field are arrays, the operation is done once for every element in the shorter array. The same field, literal, or figurative constant is used in all of the operations. The result field must always be an array. The same field or constant is used in all of the operations. Resulting indicators positions 54 through 59 cannot be used because of the number of operations being processed. Let us see the explanation for each of these basic operations. Search Argument. Array Name, Array Index. ARY, X. The search argument and array element or table element must have the same length and the same format. Resulting indicators can be assigned to equal and low, or equal and high. If only an equal indicator positions is used, the LOKUP operation will search the entire array or table. If your array or table is in ascending sequence and you want only an equal comparison, you can avoid searching the entire array or table by specifying a high indicator. Source field ArrayIndex. Target field ArrayIndex. ARY, Y. In this example, the MOVEA operation is performed on different length arrays having same element length. Both factor 2 and the result field must be defined as character. On a character MOVEA operation, movement of data ends when the number of characters moved equals the shorter length of the fields specified by factor 2 and the result field; therefore, the character MOVEA operation could end in the middle of an array element. Moves are only valid between fields and array elements with the same numeric length defined. Factor 2 and the result field entries can specify numeric fields, numeric array elements, or numeric arrays; at least one must be an array or array element. The numeric types can be binary, packed decimal, or zoned decimal but need not be the same between factor 2 and the result field. Factor 2 can contain a numeric literal if the result field entry specifies a numeric array or numeric array-element:.