PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Composite Strings & BBx® Templates in objects  (Read 274 times)

Peter.Higgins

  • Gold Member
  • ****
  • Posts: 78
    • View Profile
Composite Strings & BBx® Templates in objects
« on: January 27, 2021, 03:35:38 PM »
I've used Composite Strings & BBx® Templates in objects to keep record data separate for many years with SAGE and INFOR code.  I find  with pxplus Ver 2017 this does not work and guessing it may have only worked in the forked versions.

When a template or iolist is used to DIM the record variable's "Structure" it loads the record and explodes the internal IOLIST variables but not as record prefixed variables. I have tested this many ways without any change.
How can I keep different records with random matching field names separate in objects?

4760 dim AR1: "CUST_DIV:C(2),CUST_CODE:C(8)"
or
4760 dim AR1$:iol(AR1:*)

4770 READ DATA FROM objar1'readrecord$(shipto$),REC=ar1$ TO IOL=objar1'iolist$
or
4770 AR1$=objar1'readrecord$(shipto$)
3}?AR1.CUST_DIV$

3}?CUST_DIV$
00

Peter.Higgins

  • Gold Member
  • ****
  • Posts: 78
    • View Profile
Re: Composite Strings & BBx® Templates in objects
« Reply #1 on: January 27, 2021, 08:51:23 PM »
Just found that some Composite Strings work and some don't work.
Still working on why, but it appears that when the variables have a local definition in the declaration, the Composite String record access is prevented. 

Devon Austen

  • Staff
  • Diamond Member
  • *****
  • Posts: 277
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: Composite Strings & BBx® Templates in objects
« Reply #2 on: January 28, 2021, 08:17:28 AM »
Not sure exactly what the issue is here but looking at your example code it doesn't exactly match what is described in the documentation. Maybe reading though these will help answer your questions. In the example your first DIM sort of looks like a structured string DIM with only 1 colon instead of 2. The second DIM looks like a composite string DIM but using IOL() instead of IOL=

Composite String doc: https://manual.pvxplus.com/?PxPlus%20User%20Guide/Language%20Elements/Data%20Types,%20Literals%20and%20Variables/Composite%20Strings.htm
Structured String doc: https://manual.pvxplus.com/?directives/dim_struct.htm
Software Developer for PVX Plus Technologies LTD.

Peter.Higgins

  • Gold Member
  • ****
  • Posts: 78
    • View Profile
Re: Composite Strings & BBx® Templates in objects
« Reply #3 on: January 28, 2021, 09:02:39 AM »
Welcome to the rabbit hole of the most confusing and feature rich area of Pxplus.
The documentation is at best a glossy magazine page for the functionality and permutations of ways that these concepts can be strung together.  BBx template functionality is almost entirely undocumented.  I keep a note document of around 20 different undocumented examples of how IOLs and templates can be used with arrays, fixed strings, and records.

Dimming a Composite:
Dim Var$:compiled iol  [iol=, iol(), cpl("iolist ...")]
Listing a Composite: ? LST(IOL(var$))

Dimming a BBx style template
Dim Var$: text template 
Listing a Composite: ? XFA(Var$)

Below are a few date parsing routines, one of which I contributed to the list a while back.

! Parse Fixed String to numbers with BBx style Template (dim again using xfa(Dt$) in Pxplus to use with read record)
1 DIM Dt$:"Y:N(4),M:N(2),D:N(2)"
2 Dt$="20191105"
3 ?Dt.Y
4 ?Dt.M
5 ?Dt.D

! Parse Fixed String to numbers with Dynamic IOL
1 DIM Dt$:CPL("IOLIST Y:[NUM(4)],M:[NUM(2)],D:[NUM(2)]")
2 !
3 Dt$="20191105"
4 ?Dt.Y
5 ?Dt.M
6 ?Dt.D

! Parse Fixed String to numbers with using Documentation.
1 IOL.dt: IOLIST Y:[NUM(4)],M:[NUM(2)],D:[NUM(2)]
2 DIM Dt$:iol=iol.dt
3 DTM06$="20191105"
4 Dt$=DTM06$,DayOfWeek=NUM(DTE(JUL(Dt.Y,Dt.M,Dt.D):"%W"))
5 ? DayOfWeek




Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3416
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Composite Strings & BBx® Templates in objects
« Reply #4 on: January 28, 2021, 01:12:43 PM »
Peter

There are two type of "Pseudo" strings. 

The first is a composite string which in technical terms isn't really a true string.  Instead its a dynamically generated string based on a list of variables and formats.  For example if you have a composite string called TODAY$ with a descriptor of "Y:N(4),M:N(2),D:N(2)", whenever you reference TODAY$ the system will take the contents of TODAY.Y for four characters, TODAY.M for 2 characters, and TODAY.D for 2 characters, string them together and return that string.  When you set TODAY$. the values you set will be parsed out into the respective variables.  Technically there never really is a string called TODAY$ in the system.   This is similar to what BBx does. 

Technically PxPlus converts the format you provided into an IOLIST as you can see below:

->DIM Dt$:"Y:N(4),M:N(2),D:N(2)"
->print LST(IOL(DT$))
IOLIST Y:[LEN(4)],M:[LEN(2)],D:[LEN(2)]
->DT$="20210128"
->print dt.y
 2021
->print dt.m
 1
->print dt.d
 28


The second is a structured string where the string itself does exist, but references to the elements inside the string are mapped to the section of the string.  This is done using the :: operator as shown below:

->DIM D$::"Y:N(4),M:N(2),D:N(2)"
->D$="20210128"
->print d::y
 2021
->print d::m
 1
->print d::d
 28


Structured string have the advantage that they include additional format specifications for binary data and OS values such as Handles on windows where the size of the element varies if running on a 32 vs 64 bit platform.

You can chose which ever you prefer based on your needs.  If you need a physical string in memory to exchange information with OS calls then structured strings are what you probably need.