%PARSER (parser {: options})
%PARSER is used as the third operand of the DATA-INTO operation code to specify the program or procedure to do the parsing, and any options supported by the parser. %PARSER does not return a value, and it cannot be specified anywhere other than for the DATA-INTO operation code.
- A procedure pointer expression
- The %PADDR built-in function
- A character expression identifying a program. It must be in one of the following forms
- MYPGM
- MYLIB/MYPGM
- *LIBL/MYPGM
- A character expression identifying a procedure in a service program. It must be in one of the following forms
- MYSRVPGM(myProcedure)
- MYLIB/MYSRVPGM(myProcedure)
- *LIBL/MYSRVPGM(myProcedure)
The second operand specifies options that are passed directly to the parser. The parser determines the nature of the options that it supports.
If the second operand is the name of a variable which can be modified, the address of the variable is passed directly to the parser.
If the second operand is a character expression, including the name of a character variable that cannot be modified, a pointer to a null-terminated string containing the content of the expression is passed to the parser.
The parser receives information that indicates whether the pointer the pointer is a null-terminated string.
Examples of %PARSER
DATA-INTO myfld %DATA(document) %PARSER('MYPARSER');
DCL-DS parserOptions LIKEDS(myParserOpts_T);
DATA-INTO myDs %DATA('myData.txt' : 'doc=file')
%PARSER('MYPARSERS(myProcedure)' : parserOptions);
DCL-S p POINTER(*PROC);
DCL-S sep CHAR(1) INZ(',');
DATA-INTO myds %DATA('myData.txt' : 'doc=file')
%PARSER(p : 'sep=' + sep);
DCL-PI *N;
constParm VARCHAR(20) CONST;
END-PI;
DATA-INTO myds %DATA('myData.txt' : 'doc=file')
%PARSER(%PADDR(myProc) : constParm);
For more examples of %PARSER, and more information about the DATA-INTO operation, see DATA-INTO (Parse a Document into a Variable).
See the Rational Open Access: RPG Edition topic for information on writing an parser.