Barbara Morris IBM - Gateway/400 · RPG programmer codes a data structure to match the regex_t...

81
© 2017 IBM Corporation Welcome to the Waitless World What’s new for RPG in 7.3 Barbara Morris IBM

Transcript of Barbara Morris IBM - Gateway/400 · RPG programmer codes a data structure to match the regex_t...

© 2017 IBM Corporation

Welcome to the Waitless World

What’s new for RPG in 7.3

Barbara Morris

IBM

© 2017 IBM Corporation

Welcome to the Waitless World

2

Agenda

The most recent enhancements available with 7.3 PTFs, also for earlier releases

Other 7.3 enhancements

Fully free-form RPG (available as 7.1 & 72 PTFs)

Other 7.3 enhancements that were available as 7.1 and 7.2 PTFs

Other enhancements new in 7.3

What was new in 7.2

© 2017 IBM Corporation

Welcome to the Waitless World

3

7.1, 7.2 & 7.3 PTF: Compile from Unicode

Previously, it was not possible to compile from Unicode IFS source.

If you edit your source using Orion, the source is in IFS, and depending on your system's CCSID, that source may be Unicode (UTF-8). (For example, in Japan)

You may prefer to have Unicode source for other reasons.

A new TGTCCSID parameter has been added to CRTBNDRPG and CRTRPGMOD that lets you tell the compiler what CCSID to use to compile your source.

© 2017 IBM Corporation

Welcome to the Waitless World

4

7.1, 7.2 & 7.3 PTF: Compile from Unicode

• TGTCCSID(*SRC) – the default, can't be used with Unicode

• TGTCCSID(*JOB) – compile using the job CCSID

• TGTCCSID(number) – for example TGTCCSID(37)

For CRTSQLRPGI, use the COMPILEOPT parameter along with RPGPPOPT(*LVL1) or *LVL2

CRTSQLRPGI MYLIB/MYPGM SRCSTMF(mypgm.sqlrpgle)RPGPPOPT(*LVL1) COMPILEOPT('TGTCCSID(*JOB)')

© 2017 IBM Corporation

Welcome to the Waitless World

5

7.2 & 7.3 PTF: ON-EXIT

Sometimes you want to run some cleanup code when a procedure ends

• You allocated some storage and you want to deallocate it

• You created a temporary file and you want to delete it

• I’m sure you can think of a million things

Now, you can put that code into the ON-EXIT section of your procedure, and the code will run no matter how your procedure ends

© 2017 IBM Corporation

Welcome to the Waitless World

6

7.2 & 7.3 PTF: ON-EXIT

dcl-proc myproc;dcl-s p pointer;

p = %alloc(10);...average = total / num;...

on-exit;dealloc p;

end-proc;

This code always runs.

The pointer is deallocated even if NUM is zero for the division

© 2017 IBM Corporation

Welcome to the Waitless World

7

7.2 & 7.3 PTF: ON-EXIT

Your procedure might end

• Because it reached the end of its code

• Because it reached a RETURN operation

• Because it crashed due to an unhandled exception

• Because the subsystem ended

• Because you pressed F3 while debugging

• …

No matter why your procedure ended, the code in the ON-EXIT section will run

© 2017 IBM Corporation

Welcome to the Waitless World

8

7.2 & 7.3 PTF: ON-EXIT

When your procedure returns a value, it can return a new value within the ON-EXIT section

If a RETURN operation is not reached in the ON-EXIT section, the original return value is used

x = myproc2 (*off);

doReturn is off, so x = 5

x = myproc2 (*on);

doReturn is on, so x = 6

dcl-proc myproc2;dcl-pi *n packed(5);

doReturn ind const;end-pi;return 5;

on-exit;if doReturn;

return 6;endif;

end-proc;

© 2017 IBM Corporation

Welcome to the Waitless World

9

7.2 & 7.3 PTF: Nested data structures

You can now code data structure subfields directly when using free-form declarations

discount packed(7 : 2);

end-ds;

Nowdcl-ds order_info qualified;

num_orders int(10);dcl-ds orders dim(100);

id char(10);price packed(7 : 2);quantity int(10);

end-ds;discount packed(7 : 2);

end-ds;

discount packed(7 : 2);

end-ds;

Beforedcl-ds orders_t qualified template;

id char(10);price packed(7 : 2);quantity int(10);

end-ds;

dcl-ds order_info qualified;num_orders int(10);orders likeds(orders_t) dim(100);discount packed(7 : 2);

end-ds;

discount packed(7 : 2);

end-ds;Coming soon!

© 2017 IBM Corporation

Welcome to the Waitless World

10

7.2 & 7.3 PTF: Nested data structures

• Nested data structures can only be defined in free-form. LIKEDS must still be used for fixed-form definitions

• The top-level data structure must be qualified

• The nested data structure subfields are automatically qualified

if order_info.orders(3).quantity > MAX_QUANTITY;...

discount packed(7 : 2);

end-ds;

© 2017 IBM Corporation

Welcome to the Waitless World

11

7.2 & 7.3 PTF: Nested data structures

There will still be cases where you will use LIKEDS to define data structure subfields

• When you use the same structure for several different subfields

• When the data structure subfield is also used as a top-level data structure

• …

But now you have a choice!

discount packed(7 : 2);

end-ds;

© 2017 IBM Corporation

Welcome to the Waitless World

12

7.2 & 7.3 PTF: %MAX and %MIN

New built-in functions %MAX and %MIN

max_dim = %MIN(length : height : width);

earliest_move_in_date = %MIN(electrical_ready: appliances_ready: painting_done: furniture_delivered);

In calculations, there must be at least two operands, and they

can have any type as long as they can be compared to each

other. There is no maximum number of operands.

Coming soon!

© 2017 IBM Corporation

Welcome to the Waitless World

13

7.2 & 7.3 PTF: %MAX and %MIN

In keywords, there can only be two operands and they must be numeric.

dcl-ds ds1 extname('FILE1') end-ds;dcl-ds ds2 extname('FILE2') end-ds;

// Define the file with a record length big enough // to handle data from both FILE1 and FILE2dcl-f testfile disk(%MAX(%size(ds1)

: %size(ds2)));

To handle more than two operands in keywords, nest %MAX:dcl-c max %MAX(a

: %MAX(b : %MAX(c : d)));

© 2017 IBM Corporation

Welcome to the Waitless World

14

7.2 & 7.3 PTF: ALIGN(*FULL)

Use ALIGN(*FULL) to define a data structure the way a C API defines it

Background

The ALIGN keyword causes RPG to position integer and float subfields so that they are aligned on an x-byte storage boundary, where x is the size of the subfield

Pointer subfields are always aligned on a 16-byte boundary

An array of data structures with aligned subfields

sometimes has some padding bytes added at the end

Coming soon!

© 2017 IBM Corporation

Welcome to the Waitless World

15

7.2 & 7.3 PTF: ALIGN(*FULL)

Background continued

Consider this data structuredcl-ds ds1 dim(2) ALIGN qualified;

int_subf int(10);char_subf char(1);

end-ds;

The “int_subf” subfield must be aligned on a 4-byte boundary, so 3 bytes of padding is needed at the end of each element.

Unfortunately, %SIZE(ds1) returns 5, not 8.

To get the actual size of each element, use this ugly code

%SIZE(ds1 : *ALL) / %ELEM(ds1)

© 2017 IBM Corporation

Welcome to the Waitless World

16

7.2 & 7.3 PTF: ALIGN(*FULL)

Use ALIGN(*FULL) to have %SIZE reflect the true size of each element

Consider this data structuredcl-ds ds1 dim(2) ALIGN(*FULL) qualified;

int_subf int(10);char_subf char(1);

end-ds;

Now, %SIZE(ds1) returns 8.

© 2017 IBM Corporation

Welcome to the Waitless World

17

7.2 & 7.3 PTF: ALIGN(*FULL)

What about ordinary data structures that aren’t arrays?

In that case, the data structure does not have the padding bytes at the end.

dcl-ds ds1 ALIGN;int_subf int(10);char_subf char(1);

end-ds;

The actual size of the data structure is 5.

The problem

If this data structure is passed to a C API that expects an aligned data structure, the API might expect the data structure to have a length of 8.

Storage corruption!

© 2017 IBM Corporation

Welcome to the Waitless World

18

7.2 & 7.3 PTF: ALIGN(*FULL)

This is a real issue with the regular-expression APIs. When an RPG programmer codes a data structure to match the regex_tstructure in the C include regex.h, the RPG version of the data structure is 12 bytes too short.

With ALIGN(*FULL), the RPG data structure is correct.

© 2017 IBM Corporation

Welcome to the Waitless World

19

7.2 & 7.3 PTF: ALIGN(*FULL)

Recommendations

• Whenever you code ALIGN, always code ALIGN(*FULL).

• If your data structure has pointers so you don’t need the ALIGN keyword, code ALIGN(*FULL) if

• You are passing the data structure to a program written in C

• The data structure is an array and you are using %SIZE to find out the distance between the elements

© 2017 IBM Corporation

Welcome to the Waitless World

20

Agenda

The most recent enhancements available with 7.3 PTFs, also for earlier releases

Other 7.3 enhancements

Fully free-form RPG (available as 7.1 & 72 PTFs)

Other 7.3 enhancements that were available as 7.1 and 7.2 PTFs

Other enhancements new in 7.3

What was new in 7.2

© 2017 IBM Corporation

Welcome to the Waitless World

21

Fully free-form RPG

Now it is possible to code free-form RPG starting in column 1 and going to the end of the line.

There is no practical limit on the length of a source line.

© 2017 IBM Corporation

Welcome to the Waitless World

22

Fully free-form RPG – source must start with **FREE

**free

ctl-opt main(greeting);

dcl-proc greeting;dsply 'Hello';

end-proc;

Any source member that contains fully-free code must have **FREE in column 1 of the first line of the source.

© 2017 IBM Corporation

Welcome to the Waitless World

23

Fully free-form RPG

• All code in a **FREE source member must be free-form. If you need any fixed-form code, you can put it in a /COPY file

• Source lines must not begin with ** unless they are the special directives for compile-time data, file-translation, or alternate collating sequence.

• /FREE and /END-FREE are not allowed in a **FREE source member

© 2017 IBM Corporation

Welcome to the Waitless World

24

Fully free-form RPG – copy files

• Each copy file has its own source mode

• A copy file is always assumed to have column-limited source mode unless it has **FREE in line 1

© 2017 IBM Corporation

Welcome to the Waitless World

25

Agenda

The most recent enhancements available with 7.3 PTFs, also for earlier releases

Other 7.3 enhancements

Fully free-form RPG (available as 7.1 & 72 PTFs)

Other 7.3 enhancements that were available as 7.1 and 7.2 PTFs

Other enhancements new in 7.3

What was new in 7.2

© 2017 IBM Corporation

Welcome to the Waitless World

26

7.1 & 7.2 PTF: ALIAS is supported for all files

Previously, using the alias names was not available for global files unless the F spec had the QUALIFIED keyword.

Now, the alias names are available for any externally-described file.

A R CUSTRECA CUSTNM 25A ALIAS(CUSTOMER_NAME)A CUSTAD 25A ALIAS(CUSTOMER_ADDRESS)A ID 10P 0

Fmyfile o e DISK ALIAS

customer_name = 'John Smith';customer_address = '123 Mockingbird Lane';id = 12345;write myfmt;

When there is no alternate name for a field, the short name is used.

© 2017 IBM Corporation

Welcome to the Waitless World

27

7.1 & 7.2 PTF: Support for ALIAS names – a limitation

Limitation:

If you code ALIAS for a file, you can't code I specs or O specs for that file.

The compiler will still generate I and O specs into the listing. If the name is too long to fit in the generated spec, the name will be listed on the next line.

12=O COMPANY 6A CHAR 13=O *ALIAS 31A CHAR

MAILING_ADDRESS 14=O STATUS 2A CHAR

© 2017 IBM Corporation

Welcome to the Waitless World

28

7.1 & 7.2 PTF : Easier to use data structures for I/O

The problem:

RPG was very strict about which data structures could be use for I/O:

For an input operation, it had to be defined with *INPUT (the default for LIKEREC)

For a WRITE operation, it had to be defined with *OUTPUT

For an UPDATE operation, it could be defined with either *INPUT or *OUTPUT

© 2017 IBM Corporation

Welcome to the Waitless World

29

7.1 & 7.2 PTF: Easier to use data structures for I/O

Before:

For a file that allowed both READ and WRITE, it could be very awkward to use data structures for I/O to the file.

dcl-f myfile usage(*input : *output);

dcl-ds inDs likerec(myfmt : *input);dcl-ds outDs likerec(myfmt : *output);

read myfmt inDs;...eval-corr outDs = inDs; // copy over the fieldswrite outDs;

© 2017 IBM Corporation

Welcome to the Waitless World

30

7.1 & 7.2 PTF: Easier to use data structures for I/O

Now, with new 7.1 and 7.2 PTFs

Now, if you use LIKEREC with no type parameter for a DISK record, you can use the data structure for any operation.

dcl-f myfile usage(*input : *output);dcl-ds ds likerec(myfmt);

read myfmt ds;...write ds;

(The same PTFs as the ALIAS PTFs)

© 2017 IBM Corporation

Welcome to the Waitless World

31

7.1 & 7.2 PTF: Easier to use data structures for I/O

You can also use a LIKEREC data structure with no type parameter for a PRINTER file.

dcl-f myprtf printer;dcl-ds ds likerec(myprtfmt);

write myprtfmt ds;

© 2017 IBM Corporation

Welcome to the Waitless World

32

7.1 & 7.2 PTF: Easier to use data structures for I/O

If the data structure is defined with *ALL (E-DS or LIKEREC), you can use it for any I/O operation.

dcl-f diskf usage(*update : *output);dcl-f prtf printer;

dcl-ds diskDs extname('DISKF' : *all) end-ds;dcl-ds prtDs extname('PRTF' : *all) end-ds;

read diskfmt diskDs;write diskfmt diskDs;update diskfmt diskDs;

write prtfmt prtDs;

(*ALL was already supported in 6.1 for WORKSTN files, including subfile formats)

© 2017 IBM Corporation

Welcome to the Waitless World

33

7.1 & 7.2 PTF: PCML with mixed-case names

By default, the RPG compiler generates PCML with the names in uppercase.

Anything using the PCML must also use the uppercase names:

pcd.setValue ("NEWORDER.QTY", ... );pcd.setValue ("NEWORDER.ITEMNAME", ... );pcd.callProgram ("NEWORDER");

dcl-proc newOrder export;dcl-pi *n;qty packed(15) const;itemName car(30) const;

<pcml version="4.0"><program name="NEWORDER" entrypoint="NEWORDER"><data name="QTY" type="packed" length="15" ...<data name="ITEMNAME" type="char" length="30"

...

© 2017 IBM Corporation

Welcome to the Waitless World

34

7.1 & 7.2 PTF: PCML with mixed-case names

New: Specify PGMINFO(*DCLCASE) in the H spec to have the PCML generated with the same case as the RPG source

The generated PCML:

<pcml version="4.0"><program name="newOrder" entrypoint="NEWORDER"><data name="qty" type="packed" length="15" ...<data name="itemName" type="char" length="30" ...

The Java code using the PCML can use the same mixed-case names:

pcd.setValue ("newOrder.qty", ... );pcd.setValue ("newOrder.itemName", ... );pcd.callProgram ("newOrder");

© 2017 IBM Corporation

Welcome to the Waitless World

35

7.1 & 7.2 PTF: More granular PCML

By default, the RPG compiler generates PCML for all exported procedures.

Some procedures have parameter or return value types that make it impossible to generate PCML.

This causes the compile to fail.

© 2017 IBM Corporation

Welcome to the Waitless World

36

7.1 & 7.2 PTF:

New: P-spec keyword PGMINFO(*YES | *NO)

Either

Specify PGMINFO(*YES) for all the procedures that should have PCML generated

Or

Specify PGMINFO(*NO) for all the procedures that should not have PCML generated

These PGMINFO keywords are ignored if PCML is not being generated.

© 2017 IBM Corporation

Welcome to the Waitless World

37

7.1 & 7.2 PTF: DCLOPT(*NOCHGDSLEN)

New: H-spec keyword DCLOPT(*NOCHGDSLEN)

By default, RPG has a feature that allows the length of a data structure to be set by a C spec or program-described I spec, or by having a field in an externally-described file with the same name as the data structure.

D ds1 dsD fld1 10a

C move 'x' ds1 20

In the example above, it looks like data structure DS1 should have a length of 10. But the assignment to DS1 in the MOVE operation sets the length to 20.

This means that a data structure cannot be considered to be “defined” until the end of the procedure.

© 2017 IBM Corporation

Welcome to the Waitless World

38

7.1 & 7.2 PTF: DCLOPT(*NOCHGDSLEN)

Free-form declaration statements can use built-in functions as parameters to keywords, as long as the built-in function is defined.

dcl-ds ds1;fld1 char(10);

end-ds;dcl-s fld2 char(%size(ds1)); // not validRNF3320: The keyword parameter is not defined; keyword is ignored.

When %size is encountered, data structure DS1 is not yet defined, so %size cannot be used with the CHAR keyword.

© 2017 IBM Corporation

Welcome to the Waitless World

39

7.1 & 7.2 PTF: DCLOPT(*NOCHGDSLEN)

When new keyword DCLOPT(*NOCHGDSLEN) is added to the Control options, data structure DS1 is defined as soon as all its subfields are defined, and %SIZE can be used.

ctl-opt dclopt(*nochgdslen);

dcl-ds ds1;fld1 char(10);

end-ds;dcl-s fld2 char(%size(ds1)); // valid

© 2017 IBM Corporation

Welcome to the Waitless World

40

Agenda

The most recent enhancements available with 7.3 PTFs, also for earlier releases

Other 7.3 enhancements

Fully free-form RPG (available as 7.1 & 72 PTFs)

Other 7.3 enhancements that were available as 7.1 and 7.2 PTFs

Other enhancements new in 7.3 Note: There are no plans to provide PTFs for earlier releases with these

enhancements.

What was new in 7.2

© 2017 IBM Corporation

Welcome to the Waitless World

41

%SCANR (Scan reverse)

%SCANR(search argument : source string { : start { : length } } )

• %SCANR is similar to %SCAN. They differ only in the direction of the search

• The “start position” represents the beginning of the substring to be searched

• %SCANR starts at the end of the string and searches backwards until it finds a match or it reaches the start position

• The start and length parameters represent a substring in the source string. The “start” parameter doesn’t indicate the starting position for the search.

© 2017 IBM Corporation

Welcome to the Waitless World

42

New “length” parameter for %SCAN

%SCAN(search argument : source string { : start { : length } } )

• An optional “length” parameter has been added to %SCAN. It indicates the length to search in the source string.

• %SCAN and %SCANR are identical except for the direction of the search within the substring identified by the “source string”, “start”, and “length” parameters.

© 2017 IBM Corporation

Welcome to the Waitless World

43

%SCANR example

Find the filename in a path:

path = '/home/mydir/other/whatever/a.txt';lastSlash = %SCANR('/' : path);if lastSlash = 0;

fileName = path;else;

fileName = %subst(path : lastSlash + 1);endif;

lastSlash = 27

fileName = 'a.txt‘

© 2017 IBM Corporation

Welcome to the Waitless World

44

%SCANR example with a start position

Find the filename suffix. First, find the last slash. Then find the last period in the substring starting at the last slash

path = '/home/mydir/other/what.ever/myfile';

p = %SCANR('/' : path);

if p = 0;

p = 1; // start the next search at the beginning

endif;

dot = %SCANR('.' : path : p); // search “/myfile”

if dot = 0;

suffix = '';

else;

suffix = %subst(path : dot + 1);

endif;

suffix = '' because there is no period following the last slash

© 2017 IBM Corporation

Welcome to the Waitless World

45

%SCANR example with a length

Find the final directory: First, find the last slash. Then find the previous slash

path = '/home/mydir/v2/myfile';

p = %SCANR('/' : path); // last slash

if p = 0;

finalDir = ''; // path has no directory

else;

prv = %SCANR('/' : path : 1 : p - 1); // length to search is "p – 1"

if prv = 0; // path starts with the final directory

finalDir = %SUBST(path : 1 : p – 1);

else; // path has more than one directory

finalDir = %SUBST(path : prv + 1 : p - prv - 1);

endif;

endif;

finalDir = "v2"

© 2017 IBM Corporation

Welcome to the Waitless World

46

%SCAN and %SCANR together

Find the last word in a quoted section of a string.

string = 'The message is "The file was not found". The sender is X.';// ....+....1....+....2....+....3....+....4....+....5....+...

// Find the quoted string within the string

p1 = %SCAN('"' : string); // Start quote (16)p2 = %SCANR('"' : string : p1 + 1); // End quote (39)len = p2 - p1 - 1; // Length between quotes (22)

// Find the last word in the quoted string

p3 = %SCANR(' ' : string : p1 + 1 : len); // Last blank between "" (33)len = p2 - p3 - 1; // Length after last blank (5)lastword = %subst(string : p3 + 1 : len); // Last word ("found")

© 2017 IBM Corporation

Welcome to the Waitless World

47

Increased maximum parameters for a bound call

Formerly, the maximum number of parameters for a bound call was 399.

The new maximum is 16,382.

Note that this is a general ILE enhancement that RPG supports. It is unlikely to be of interest to RPG programmers, since it is unlikely that RPG programmers have ever even run into the previous limit of 399.

© 2017 IBM Corporation

Welcome to the Waitless World

48

Null-capable fields (background)

A null-capable field has

• Its value, 3.2, 'Jack Sprat' etc.

• An associated value that says whether it is null or not, called a "null indicator"

The I/O buffer for the file has a separate section called the "null-byte map" which has an indicator for each field in the file indicating whether it is null or not.

(If the field is not null-capable, the null-byte-map indicator for that field is always '0'.)

© 2017 IBM Corporation

Welcome to the Waitless World

49

Null-capable fields (background)

Imagine a file with three fields• NAME: not null-capable• DUEDATE: null-capable• PRVBAL: null-capable

Here is the I/O buffer for a sample record

Buffer: Jack Sprat 0001-01-010041.75

Null-byte map: 010

Null-capable field "DUEDATE" has the null-value. Its value of 0001-01-01 is meaningless.

© 2017 IBM Corporation

Welcome to the Waitless World

50

Null-capable fields (background)

When you code the ALWNULL(*USRCTL) keyword in an RPG module, you can work with the null-capable fields in your file

The associated value is an internal variable maintained by the RPG compiler.

• Prior to 7.3, this was always the case.

• Starting in 7.3 this is the default

You refer to the null-indicator using the %NULLIND built-in function

dueDate = curDate + %days(30);%nullind(dueDate) = *off; // not null

© 2017 IBM Corporation

Welcome to the Waitless World

51

Null-capable fields (background)

When you read a record containing null-capable fields

• The buffer values get moved into the program fields

• The null-byte map values get moved into the associated null-indicators of the null-capable fields

Buffer: Jack Sprat 0001-01-010041.75Null-byte map: 010

> EVAL nameNAME = 'Jack Sprat '

> EVAL duedateDUEDATE = '0001-01-01'

> EVAL _QRNU_NULL_DUEDATE_QRNU_NULL_DUEDATE = '1'

> EVAL PRVBALPRVBAL = 41.75

> EVAL _QRNU_NULL_PRVBAL_QRNU_NULL_PRVBAL = '0'

ctl-opt alwnull(*usrctl);

dcl-f custfile;read custrec;

© 2017 IBM Corporation

Welcome to the Waitless World

52

Null-capable fields (background)

When you write or update a record containing null-capable fields

• The program field values get moved into the buffer

• The associated null-indicators of the null-capable fields get moved into the null-byte map. The null-byte map for the non-null-capable fields is set to '0'.

dueDate = curDate + %days(30);%nullind(dueDate) = *off; // not nullupdate custrec;

Buffer: Jack Sprat 2016-06-150041.75Null-byte map: 000

© 2017 IBM Corporation

Welcome to the Waitless World

53

Null-capable fields (background)

Prior to 7.3, the only null-capable fields available for RPG were

• From externally-described files

• From externally-described data structures

You could not define your own null-capable fields

© 2017 IBM Corporation

Welcome to the Waitless World

54

NULLIND: More control over null indicators

Use the NULLIND keyword without a parameter to define the field as null-capable.

dcl-s qty int(10) nullind;

Field qty is null-capable, but the null-indicator is still maintained internally by the RPG compiler.

© 2017 IBM Corporation

Welcome to the Waitless World

55

NULLIND: More control over null indicators

Use the NULLIND keyword to associate your own indicator with another field to represent whether that field is null.

dcl-s qty_is_null ind;dcl-s qty int(10) nullind (qty_is_null);

You can refer to the null indicator using its name, or using %NULLIND. These mean the same thing:

if qty_is_null;

if %nullind(qty);

© 2017 IBM Corporation

Welcome to the Waitless World

56

NULLIND with a data structure

Use the NULLIND keyword to associate a data structure of null indicators with a data structure to represent whether the subfields are null.

The NULLIND data structure represents the null-byte map for the other data structure.

The next enhancement allows you to easily define the data structure of null indicators …

© 2017 IBM Corporation

Welcome to the Waitless World

57

LIKEREC(rec:*NULL) and EXTNAME(file:*NULL)

*NULL defines a null-byte map data structure representing whether the matching fields or subfields are null.

The subfields have the same names as the fields in the file, but all the subfields are indicators.

The NULLIND keyword associates cust_null as the null-byte map for cust_ds.

dcl-ds cust_null likerec(custrec : *null);dcl-ds cust_ds likerec(custrec)

nullind(cust_null);

read custfile cust_ds;if not cust_null.duedate; // duedate is not null

© 2017 IBM Corporation

Welcome to the Waitless World

58

LIKEREC(rec:*NULL) and EXTNAME(file:*NULL)

If the main data structure has a specific extract type (*INPUT etc), define the nullind data structure the same way, adding *NULL.

dcl-ds cust_ds likerec(custrec : *output) nullind(cust_null);dcl-ds cust_null likerec(custrec : *output : *null);

Here, the two data structures represent the output record format.

© 2017 IBM Corporation

Welcome to the Waitless World

59

*NULL – easier to work with trigger parameters

In trigger programs, there is a null byte map for the before and after record.

Before (error prone): dcl-s nullmap1 char(100) based(pNullmap1);

pNullmap1 = %addr(trigger_buffer) + null_offset1;if %subst(nullmap1 : 3 : 1) = '1';

Now:dcl-ds nullmap1 extname('CUSTFILE':*NULL)

qualified based(pNullmap1) end-ds;

pNullmap1 = %addr(trigger_buffer) + before_null_offset;if nullmap1.duedate;

Bonus: duedate is an indicator, so there is no need to compare it to ‘1’ now.

© 2017 IBM Corporation

Welcome to the Waitless World

60

Agenda

The most recent enhancements available with 7.3 PTFs, also for earlier releases

Other 7.3 enhancements

Fully free-form RPG (available as 7.1 & 72 PTFs)

Other 7.3 enhancements that were available as 7.1 and 7.2 PTFs

Other enhancements new in 7.3

What was new in 7.2

© 2017 IBM Corporation

Welcome to the Waitless World

61

Several enhancements related to “CCSID”

“CCSID” stands for “Coded Character Set ID”

Some character sets:

Latin (European languages including English)

Thai

Chinese

Unicode (characters from every language)

Two basic kinds of character sets:

SBCS (Single byte character set, such as English, Russian…)

DBCS (Double byte character set, such as Chinese, Japanese…)

Unicode (The number of bytes per character varies)

The single byte character sets also include the standard letters such as A-Z, a-z, 0-9, +, - etc

© 2017 IBM Corporation

Welcome to the Waitless World

62

(More about CCSIDs)

The CCSID of a particular file or field tells the computer

The character set of the data

Which character matches each hex value

For example

“CCSID conversion” involves converting data from one CCSID to another

CCSID Type Character set ‘E’ Å

37 EBCDIC Latin X’C5’ X’67’

819 ASCII Latin X’45’ X’C5’

1200 UTF-16 Unicode X’0045’ X’00C5’

© 2017 IBM Corporation

Welcome to the Waitless World

63

6.1 & 7.1 PTFs: Warnings or exceptions for CCSID conversions

Sometimes a CCSID conversion will result in a “substitution” character being placed in the result.

Unicode source data:The Thai word for “house” is “บ้าน”.

The target is an alphanumeric variable with CCSID 37:The Thai word for “house” is “”.

CCSID 37 uses the “Latin” character set, and there are no matching characters for the Thai characters that are in the Unicode variable. Substitution characters are placed in the alphanumeric result.

The original Thai characters are all converted to the same substitution characters, so their value is lost.

© 2017 IBM Corporation

Welcome to the Waitless World

64

6.1 & 7.1 PTFs: Warnings or exceptions for CCSID conversions

Non-error RPG status code 50 is set when the conversion has to use substitution characters.

You have to add code to check whether %status = 50

alphaText = unicodeText;

if %status() = 50;

... there was loss of data

Two problems:

It’s too awkward to check for status code 50 after every statement with a CCSID conversion

It’s not always easy to tell which statements have CCSID conversions

© 2017 IBM Corporation

Welcome to the Waitless World

65

6.1 & 7.1 PTFs: Get an exception when substitution occurs

CCSIDCVT(*EXCP)

Code new H spec keyword CCSIDCVT(*EXCP) to get an exception when a CCSID conversion results in a substitution character.

New status code 00452

In 6.1 and 7.1, you will need to add messages RNX0452 and RNQ0452 to your message file. The cover letter of the PTF for the RPG runtime has CLP code for adding the messages.

© 2017 IBM Corporation

Welcome to the Waitless World

66

6.1 & 7.1 PTFs: Get an list of CCSID conversions

CCSIDCVT(*LIST)

Code new H spec keyword CCSIDCVT(*LIST) to get a list of all the CCSID conversions in the module.

For each conversion, it showsThe source statements using that conversionWhether the conversion might result in substitution characters

If you want both options, code CCSIDCVT(*EXCP:*LIST) or CCSIDCVT(*LIST:*EXCP)

© 2017 IBM Corporation

Welcome to the Waitless World

67

6.1 & 7.1 PTFs: Sample CCSIDCVT summary

C C S I D C o n v e r s i o n s

From CCSID To CCSID References

RNF7361 834 *JOBRUN 15 25

RNF7357 1200 *JOBRUN 27 921 1073

*JOBRUN 1200 28 12 321 426

552 631

RNF7359 835 834 41 302 302

RNF7360 *JOBRUN 834 242 304 305

* * * * E N D O F C C S I D C O N V E R S I O N S * * * *

RNF7357 Conversion from UCS-2 to Alpha might not convert all data.

RNF7358 Conversion from UCS-2 to DBCS might not convert all data.

RNF7359 Conversion from DBCS to DBCS might not convert all data.

RNF7360 Conversion from Alpha to DBCS might not convert all data.

RNF7361 Conversion from DBCS to Alpha might not convert all data.

© 2017 IBM Corporation

Welcome to the Waitless World

68

6.1 & 7.1 PTFs: How to use the CCSIDCVT summary

You can use this information for two purposes:

You can improve performance: Reduce the number of conversions by changing the data types of some of your variables.

You can improve the reliability of your program by eliminating some of the conversions that have the potential to result in substitution characters. For example, if you have conversion from UCS-2 to an alphanumeric variable, and that alphanumeric data is later converted back to UCS-2, you may be able to change the type of the alphanumeric variable to UCS-2, to avoid the potential data loss.

© 2017 IBM Corporation

Welcome to the Waitless World

69

7.2 Support for other CCSIDs for character data

Starting in 7.2, you can code the CCSID keyword for character fields:

All EBCDIC CCSIDs

ASCII CCSIDs

The Unicode CCSID UTF-8 (1208, or *UTF8)

© 2017 IBM Corporation

Welcome to the Waitless World

70

7.2 Support for other CCSIDs for character data

Assume that the getData procedure returns UTF-8 data (CCSID 1208).

Prior to 7.2, you would call an API to convert the data to UCS-2:

D stringA S 10000A D stringC S 10000C VARYINGD getData PR 10000A VARYING

stringA = getData ();stringC = convert(stringA: %len(stringA): 1208: 13488);

Remember not to use the data for ordinary RPG statements because RPG thinks the data is in the job CCSID.

if string = *blanks; // BUG!...

© 2017 IBM Corporation

Welcome to the Waitless World

71

7.2 Support for other CCSIDs for character data

In 7.2, you can say that the data is UTF-8.

D stringA S 10000A CCSID(*UTF8)D getData PR 10000A VARYING CCSID(*UTF8)

stringA = getData ();

You can use the data in ordinary RPG statements because RPG knows that it is UTF-8 data.

if stringA = *blanks; // OK!...

© 2017 IBM Corporation

Welcome to the Waitless World

72

7.2 Avoid CCSID conversions for database files

By default, for a database file

When you read a record, database converts the alphanumeric data from the field CCSID to the job CCSID

When you write or update a record, database converts the alphanumeric data from the job CCSID to the field CCSID

Use DATA(*NOCVT) for a file to open the file so these conversions do not happen at the database level. Any CCSID conversions will be performed in the RPG program if necessary.

Use H spec OPENOPT(*NOCVTDATA) to default this behaviourfor all database files.

© 2017 IBM Corporation

Welcome to the Waitless World

73

7.2 More support for CCSIDs for character data

There are several other CCSID-related enhancements in 7.2 for RPG, such as using CCSID(*EXACT) to define a data structure so the character subfields have the same CCSID as the field in the file instead of the job CCSID.

I won't discuss them here, but if you are interested in CCSIDs you can read about them in the What's New section of the ILE RPG Reference.

http://www-01.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzasd/rpgrelv7r2.htm

© 2017 IBM Corporation

Welcome to the Waitless World

74

7.2 Control the length for %SUBDT

By default, %SUBDT returns an integer value. This makes it inconvenient if you want to edit it into a string.

s = %editc(%subdt(t : *hours) : 'X')+ ':'+ %editc(%subdt(t : *minutes) : 'X');

// s = '0000000013:0000000047'

Use the third parameter of %SUBDT to specify the number of digits

s = %editc(%subdt(t : *hours : 2) : 'X')+ ':'+ %editc(%subdt(t : *minutes : 2) : 'X');

// s = '13:47'

© 2017 IBM Corporation

Welcome to the Waitless World

75

7.2 Timestamps with 0 – 12 fractional seconds

Starting in 7.2, timestamps can have zero to twelve fractional seconds.

They still default to 6 (microseconds).

RPG still only sets milliseconds with %TIMESTAMP.

Free-form syntax:dcl-s datetime timestamp(0);dcl-s max timestamp(12);

Fixed-form syntax:D datetime S Z 0D max S Z12

© 2017 IBM Corporation

Welcome to the Waitless World

76

7.2 Handle seconds and microseconds together

You can get the difference between timestamps as a number of seconds with decimal places by specifying the number of decimal places you want.

elapsed = %diff(finish : start : *SECONDS : 3);

// elapsed = 1922.483

You can add or subtract seconds and microseconds together with %SECONDS by specifying a value with decimals

start = %timestamp();target = start + %seconds(1.5);

// start = '2014-01-15-14.25.03.123000'// target = '2014-01-15-14.25.04.623000'

© 2017 IBM Corporation

Welcome to the Waitless World

77

Where to find out about PTF enhancements for RPG

Subscribe to the blog in the RPG Cafe

• Whenever we provide an enhancement through PTFs, we post a blog entry in the Cafe blog

• The blog entry will usually point to a new page in the Cafe wiki

Regularly check the “welcome” page in the RPG Cafe wiki. There is a section for “Enhancements delivered through PTFs”, and the “Announcement” section at the top will have information about the most recent enhancement.

Regularly check the “What’s New Since …” section in the ILE RPG Reference

• Starting in 7.2, the ILE RPG manuals are updated with enhancements delivered through PTFs. If there are PTFs for 7.1, refer to the 7.2 documentation for that enhancement.

© 2017 IBM Corporation

Welcome to the Waitless World

78

Where to request enhancements for RPG

RPG is now part of the RFE (Request for Enhancements) process.

• You can submit requirements

• You can vote on requirements that others have requested

• Votes aren’t the only consideration when IBM decides which RFEs to work on, but they are important

• Be careful not to vote for too many RFEs. Just vote on the ones that you need the most

• The TGTCCSID enhancement was RPG’s first delivered RFE.

Here is a link to the current RFEs for the RPG compiler: http://ibm.biz/rpg_rfe

Brand: Servers and Systems SoftwareProduct family: Power SystemsProduct: IBM iComponent: Languages - RPG

© 2017 IBM Corporation

Welcome to the Waitless World

79

© Copyright IBM Corporation 2017. All rights reserved.

The information contained in these materials is provided for informational purposes only, and is provided AS IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, these materials. Nothing contained in these materials is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. References in these materials to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in these materials may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a comm itment to future product or feature availability in any way.

IBM, the IBM logo, the on-demand business logo, Rational, the Rational logo, and other IBM products and services are trademarks of the International Business Machines Corporation, in the United States, other countries or both. Other company, product, or service names may be trademarks or service marks of others.

© 2017 IBM Corporation

Welcome to the Waitless World

80

Special noticesThis document was developed for IBM offerings in the United States as of the date of publication. IBM may not make these offerings

available in other countries, and the information is subject to change without notice. Consult your local IBM business contact for information

on the IBM offerings available in your area.

Information in this document concerning non-IBM products was obtained from the suppliers of these products or other public sources.

Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products.

IBM may have patents or pending patent applications covering subject matter in this document. The furnishing of this document does not

give you any license to these patents. Send license inquires, in writing, to IBM Director of Licensing, IBM Corporation, New Castle Drive,

Armonk, NY 10504-1785 USA.

All statements regarding IBM future direction and intent are subject to change or withdrawal without notice, and represent goals and

objectives only.

The information contained in this document has not been submitted to any formal IBM test and is provided "AS IS" with no warranties or

guarantees either expressed or implied.

All examples cited or described in this document are presented as illustrations of the manner in which some IBM products can be used

and the results that may be achieved. Actual environmental costs and performance characteristics will vary depending on individual client

configurations and conditions.

IBM Global Financing offerings are provided through IBM Credit Corporation in the United States and other IBM subsidiaries and divisions

worldwide to qualified commercial and government clients. Rates are based on a client's credit rating, financing terms, offering type,

equipment type and options, and may vary by country. Other restrictions may apply. Rates and offerings are subject to change, extension

or withdrawal without notice.

IBM is not responsible for printing errors in this document that result in pricing or information inaccuracies.

All prices shown are IBM's United States suggested list prices and are subject to change without notice; reseller prices may vary.

IBM hardware products are manufactured from new parts, or new and serviceable used parts. Regardless, our warranty terms apply.

Any performance data contained in this document was determined in a controlled environment. Actual results may vary significantly and

are dependent on many factors including system hardware configuration and software design and configuration. Some measurements

quoted in this document may have been made on development-level systems. There is no guarantee these measurements will be the

same on generally-available systems. Some measurements quoted in this document may have been estimated through extrapolation.

Users of this document should verify the applicable data for their specific environment.

© 2017 IBM Corporation

Welcome to the Waitless World

81

Special noticesIBM, the IBM logo, ibm.com AIX, AIX (logo), AIX 6 (logo), AS/400, BladeCenter, Blue Gene, ClusterProven, DB2, ESCON, i5/OS, i5/OS (logo), IBM

Business Partner (logo), IntelliStation, LoadLeveler, Lotus, Lotus Notes, Notes, Operating System/400, OS/400, PartnerLink, PartnerWorld, PowerPC,

pSeries, Rational, RISC System/6000, RS/6000, THINK, Tivoli, Tivoli (logo), Tivoli Management Environment, WebSphere, xSeries, z/OS, zSeries, AIX

5L, Chiphopper, Chipkill, Cloudscape, DB2 Universal Database, DS4000, DS6000, DS8000, EnergyScale, Enterprise Workload Manager, General

Purpose File System, , GPFS, HACMP, HACMP/6000, HASM, IBM Systems Director Active Energy Manager, iSeries, Micro-Partitioning, POWER,

PowerExecutive, PowerVM, PowerVM (logo), PowerHA, Power Architecture, Power Everywhere, Power Family, POWER Hypervisor, Power Systems,

Power Systems (logo), Power Systems Software, Power Systems Software (logo), POWER2, POWER3, POWER4, POWER4+, POWER5, POWER5+,

POWER6, POWER6+, System i, System p, System p5, System Storage, System z, Tivoli Enterprise, TME 10, Workload Partitions Manager and X-

Architecture are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both. If

these and other IBM trademarked terms are marked on their first occurrence in this information with a trademark symbol (® or ™), these symbols

indicate U.S. registered or common law trademarks owned by IBM at the time this information was published. Such trademarks may also be registered

or common law trademarks in other countries. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at

www.ibm.com/legal/copytrade.shtml

The Power Architecture and Power.org wordmarks and the Power and Power.org logos and related marks are trademarks and service marks licensed by

Power.org.

UNIX is a registered trademark of The Open Group in the United States, other countries or both.

Linux is a registered trademark of Linus Torvalds in the United States, other countries or both.

Microsoft, Windows and the Windows logo are registered trademarks of Microsoft Corporation in the United States, other countries or both.

Intel, Itanium, Pentium are registered trademarks and Xeon is a trademark of Intel Corporation or its subsidiaries in the United States, other countries or

both.

AMD Opteron is a trademark of Advanced Micro Devices, Inc.

Java and all Java-based trademarks and logos are trademarks of Sun Microsystems, Inc. in the United States, other countries or both.

TPC-C and TPC-H are trademarks of the Transaction Performance Processing Council (TPPC).

SPECint, SPECfp, SPECjbb, SPECweb, SPECjAppServer, SPEC OMP, SPECviewperf, SPECapc, SPEChpc, SPECjvm, SPECmail, SPECimap and

SPECsfs are trademarks of the Standard Performance Evaluation Corp (SPEC).

NetBench is a registered trademark of Ziff Davis Media in the United States, other countries or both.

AltiVec is a trademark of Freescale Semiconductor, Inc.

Cell Broadband Engine is a trademark of Sony Computer Entertainment Inc.

InfiniBand, InfiniBand Trade Association and the InfiniBand design marks are trademarks and/or service marks of the InfiniBand Trade Association.

Other company, product and service names may be trademarks or service marks of others.