RPGIV @ Work

A unique site for RPG and System i Lovers


Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Blog - Content Section Layout
Free-Form Definition Statement
User Rating: / 0
Written by Chamara   

A free-form data definition statement begins with one of the declaration operation codes, followed by a name, or by *N if the item does not have a name, followed by keywords, and finally a semicolon.

DCL-C - Define a named constant
DCL-DS and END-DS - Define a data structure
DCL-PARM - Define a parameter
DCL-PI and END-PI - Define a procedure interface
DCL-PR and END-PR - Define a prototype
DCL-S - Define a standalone field
DCL-SUBF - Define a subfield

DCL-S abcdefghij CHAR(10);

DCL-DS ds1;
       subf1 CHAR(10);

DCL-PR pr1;
     subf1 CHAR(10);

Get the length of data in variable
User Rating: / 0
Written by Chamara   

To get the length of data in variable in CL programming

Dcl Var(&FLD1) Type(*Char) Len(20) Value('THIS IS DATA     ')                                  
Dcl Var(&LEN) Type(*Dec) Len(5 0)                              
RtvMsg MsgID(CPF9897) MsgF(QCPFMSG) +                          
       MsgDta(&FLD1) MsgLen(&LEN) 

Write Comment (0 comments)
Free-Form Control Statement
User Rating: / 0
Written by Chamara   

A free-form control statement begins with CTL-OPT followed by zero or more keywords, followed by a semicolon.

You can mix free-form and fixed-form control statements. Each contiguous group of fixed-form specifications constitutes a single control statement.

When the compilation of a program contains any free-form control statements, the presence of the ACTGRP, BNDDIR, or STGMDL keyword will cause the DFTACTGRP keyword to default to *NO.

The only directives that are allowed within a free-form control statement are /IF, /ELSEIF, /ELSE, and /ENDIF.

ctl-opt datfmt(*iso) timfmt(*iso)

ctl-opt option(*srcstmt)ccsid(*char:*jobrun);

RPG Fully Free now
User Rating: / 0
Written by Chamara   

As part of IBM i 7.1 Technology Refresh 7, a major enhancement to RPG IV is being announced: Free-form control, file-declaration, data-declaration, and procedure statements.

Read the announcement here: http://www-01.ibm.com/common/ssi/cgi-bin/ssialias?infotype=AN&subtype=CA&htmlfid=897/ENUS213-423&appname=USN


This enhancement will be available through a 7.1 PTF in November, 2013. This page will be updated in November with the PTF details.

Here's a little example that illustrates each of the new free-form statement types.

       ctl-opt dftactgrp(*no);

       dcl-pi *n;
          caller_name char(10) const;

       dcl-c RECORD_LEN 80;

       dcl-f qprint printer(RECORD_LEN);

       dcl-ds prtDs len(RECORD_LEN) qualified;
          *n char(6) inz('Hello');
          name char(50);

       prtDs.name = transform(caller_name);
       write qprint prtDs;

       *inlr = '1';

       dcl-proc transform;
          dcl-pi *n varchar(50);
             name varchar(10) const options(*trim);

          return '*** ' + name + ' ***';

A few things to notice about the example:

  • Each statement (except for parameter and subfield declarations) starts with an opcode, either CTL-OPT for control statements, or DCL-x for declarations, and ends with a semicolon. Subfield and parameter declarations also start with an opcode, DCL-SUBF or DCL-PARM, but just like the EVAL and CALLP opcodes, you can omit the opcode for subfields and parameters.
  • The parameter for the "transform" procedure is defined as VARCHAR(10). The VARYING keyword isn't used in free-form. When you look at the full list of data-type keywords, you'll notice that several of them combine the fixed-form data-type value of A, C, D, O, T etc with a fixed-form keyword like VARYING, DATFMT, CLASS, TIMFMT etc.
  • A named constant is used for the record length of the printer file and the length of the data structure.
  • There's no /FREE at the beginning of the code. /FREE and /END-FREE are no longer needed to go between fixed form and free form. The compiler will just ignore them.
  • The procedure interface (PI) is coded before the file declaration in the main procedure. You can mix F and D specs even in fixed form.

It's not possible to explain all the details here. You can read all about the new syntax in an extra PDF that will been added to the 7.1 Info Center on October 8. Look for "PDF File for Updated ILE RPG Reference" in the RPG topic under Programming Languages. I recommend that you start with the "What's New Since 7.1" section. From there you can navigate to the detailed information about all the new features.

Unfortunately, while RPG is a lot freer, it still isn't completely free. There are still some restrictions:

  • Free-form code still has to be coded between columns 8 - 80
  • I and O specs are still only fixed-form.
  • There is no target-release support - it is only for TGTRLS(*CURRENT) on 7.1.

Note: The SQL precompiler will also have full support for the new free-form syntax.

Extraction from IBM Site - https://ibm.biz/BdDMwB

Rules for transferring XML data to RPG variables
User Rating: / 0
Written by Chamara   
  • For integer, unsigned, decimal (packed, zoned, binary) and float fields , the data will be transferred using the same rules as RPG uses for %INT, %UNS, %DEC, %FLOAT for respectively. %INTH, %UNSH and %DECH will be used if the Half-Adjust operation extender is specified on the XML-INTO operation code.
  • For date, time and timestamp fields, the data will be transferred using the same rules as RPG uses for %DATE, %TIME and %TIMESTAMP respectively. The format defaults to *ISO with separators. The format may be specified by an attribute fmt in the element. The value of the attribute must be one of the valid formats for the respective built-in function; the leading asterisk is optional. For formats that allow more than one separator in RPG, the separator defaults to the RPG default separator for the format. For example, for a date field, the following XML fragments are valid:
    <myDate fmt="DMY/">25/12/04</myDate>   <!-- 2004-12-25 -->
    <myDate fmt="Dmy">25.12.04</myDate>    <!-- 2004-12-25 -->
    <myDate fmt="*cymd0">0971123</myDate>  <!-- 1997-11-23 -->
  • For indicator, character and UCS-2 fields, data will be transferred with appropriate CCSID conversion if necessary. Fixed-length fields will be assigned left-adjusted by default. The adjustment can be specified by an attribute adjust in the element, with a value of either "left" or "right". For example, if the RPG variable data is 10 bytes long, the following XML data will cause the value of DATA to be set to '     abcde'.
    <data adjust="right">abcde</data>
  • For graphic fields, data will be transferred using the same rules as the %GRAPH built-in function, with appropriate CCSID conversion if necessary. Fixed-length fields will be assigned left-adjusted by default. The adjustment can be specified by an attribute adjust in the element, with a value of either "left" or "right".
  • Pointer and procedure-pointer subfields are not supported, and are ignored by the XML-INTO operation.
  • The special attributes fmt and adjust will be treated as ordinary attributes if they are not relevant to the assignment of the matching variable, or if the value of the attribute is not valid. For example, the following XML attributes would be treated as ordinary XML attributes:
    "abc" is not a valid format
    "yes" is not a valid value for the "adjust" attribute
    'fmt="mdy/"', if specified for a numeric field
    'adjust=right', if specified for a varying-length field
  • The attributes fmt and adjust and their values must be specified in the case specified by the case option. The following table shows valid examples of the attributes for each value of the case option.
case option fmt, example "*MDY/" adjust, example "right"
not specified
and so on
and so on
<< Start < Previous 1 2 3 4 5 6 7 8 9 10 Next > End >>

Results 21 - 30 of 626