Are you sure there is a binary zero at the end? I've never seen that in a variable length field. Typically there is a two byte prefix for the data length which would explain the 128 field length with a 130 byte buffer.
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Patrik Schindler
Sent: Thursday, May 15, 2025 11:24 AM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Restructuring program to cope with modern database layouts
Hello,
I have a bunch of applications in positional RPGLE who need some rework to be adapted to a new database table layout.
Before, said application opened an LF readonly and did a CHAIN with a given customer number ("KUNR") to look up the customer name ("FIRMA"). The LF pointed to an export of customer master data being copied via ODBC to a PF, DDS derived. Nothing fancy, just the usual character field (no VARYING!) in the native charset of IBM i (1141, German with €).
Because of ongoing issues with national characters, a decision was agreed upon to migrate all the data to SQL created tables, using "modern" features like varchar fields, and CSSID 1208, UTF-8. This should enable transparent passthrough of textual data for ODBC based clients, and transparent conversion for local 5250 based applications. The database layout is now handled by other people, and I agreed to rewrite the applications so they are compatible with the new database definitions. Looking at the new database data with interactive SQL works fine, and umlaut conversion is taking place as expected.
I have created a DDS based logical file pointing to the new database tables, just renaming the fields from their new-database-names to the old ones (KUNR, and FIRMA), and adding a key to be able to CHAIN by KUNR. No other definitions are taking place. A test run with interactive SQL successfully worked. Dspffd for the LF shows a field length of 128 chars, and a buffer length of 130 for the customer name field. I guess to leave space for the zero termination if the string reaches maximum length?
I'm referring the described LF in the F specs:
FCUSBYCUSNOIF E K DISK
I know that I need to convert C strings to fixed length by stating
EVAL FIRMA$=%STR(FIRMA).
Note: FIRMA$ is the field definition from the display file.
Compilation of this fails with RNF0343: The first parameter for %STR is not valid; %STR is ignored. The first parameter for built-in function %STR must be of type basing pointer.
Okay, input variable somewhat bonkers. I defined FIRMA# as 130 characters string and gave this to %STR, with the same compilation error.
Finally I decided to just use EVAL FIRMA$=FIRMA. This compiled and works. But I'm not sure what happens with the binary zero. Does EVAL convert the C string to fixed length? If yes, what is %STR good for?
I'm not very fluent with pointers in RPGLE, but I presume that even a string variable has an address. Google doesn't really know about RNF0343. Anyone cares to shed some light on this? Thank you!
Note: I'm using positional syntax.
:wq! PoC
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.
As an Amazon Associate we earn from qualifying purchases.