View previous topic :: View next topic |
Author |
Message |
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Thu Aug 12, 2010 10:25 am Post subject: Clear out data in structure in PL1 |
|
|
I read that it is more efficient to define a overlay to clear out data in a structure:
Code: |
DCL 1 RECORD1,
2 FIELD1 CHAR(10),
2 FIELD2 CHAR(8),
2 FIELD3CHAR(10),
......
2 FIEDL20 CHAR(20);
/* OVERLAY occurpeis the same storage area as Record1 */
DCL OVERLAY CHAR(400) DEFINED RECORD1;
.....
.....
/* To clear out Record1 (set all bytes to blank) */
Overlay = '';
|
Without OVERLAY being defined, "Record1 = '';" is equivalent to execute 20 statements:
Code: |
Record1.Field1 = '';
Record1.Field2 = '';
.....
Record1.Field20 = '';
|
How can I tell this is indeed the case from the complied listing? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Thu Aug 12, 2010 10:38 am Post subject: |
|
|
danm,
Try this .Compile your program with LIST and MAP compiler option and see how the Source code is expanded in assembler and variable mapping.
If you see a bunch of MVC for the the OVERLAY = ' ' statement then it is probably doing one field at a time.
Kolusu |
|
Back to top |
|
|
prino Banned
Joined: 01 Feb 2007 Posts: 45 Topics: 5 Location: Oostende
|
Posted: Thu Aug 12, 2010 1:05 pm Post subject: |
|
|
Actually, it very much depends on the compiler and compiler options you use.
Also, using DEF with Enterprise PL/I is something that should be discouraged, it's much better to use UNION, i.e.
Code: |
DCL 1 * UNION,
2 OVERLAY CHAR (400),
2 RECORD1,
3 FIELD1 CHAR(10),
3 FIELD2 CHAR(8),
3 FIELD3CHAR(10),
......
3 FIEDL20 CHAR(20); |
And this keeps overlay and record1 nice and tight together. EPLI also generated better code for UNIONs. |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Tue Aug 17, 2010 1:13 pm Post subject: |
|
|
Quote: |
using DEF with Enterprise PL/I is something that should be discouraged
|
What about using DEF in lieu of multiple substr statements, e.g.
Code: |
DCL DocID CHAR(20),
Date CHAR(10) defined DocID POSITION(1),
Time CHAR(8) defined DocID POSITION(11),
Type CHAR(2) defined DocID POSITION(15);
Then I don't need these 3 statements:
Date = substr(DocID,1,10);
Time = substr(DocID,11,8);
Type = substr(DocID,15,2);
|
|
|
Back to top |
|
|
Nic Clouston Advanced
Joined: 01 Feb 2007 Posts: 1075 Topics: 7 Location: At Home
|
Posted: Tue Aug 17, 2010 2:41 pm Post subject: |
|
|
But why not declare dcoid thus...
Code: |
DCL 01 DocID,
03 Date CHAR(10),
03 Time CHAR(08),
03 Type CHAR(02);
|
_________________ Utility and Program control cards are NOT, repeat NOT, JCL. |
|
Back to top |
|
|
prino Banned
Joined: 01 Feb 2007 Posts: 45 Topics: 5 Location: Oostende
|
Posted: Tue Aug 17, 2010 4:17 pm Post subject: |
|
|
But why not declare dcoid thus...
Code: | dcl 1 * union,
2 dcoid char (20),
2 *,
3 date char (10),
3 time char (8),
3 type char (2); |
Giving you the best of both worlds, and efficient code. |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Wed Aug 18, 2010 9:07 am Post subject: |
|
|
Nic, Thanks. Primo, I can't declare DocID as a structure because DocID is assigned a value by a scalar variable (XML data extracted from XML file via XML parser "plisxb". |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Wed Aug 18, 2010 12:18 pm Post subject: |
|
|
There is one problem with declaring DocID with UNION. Later in the program, I need to reference DocID, date and time as a host variable to insert into DB2 table:
Code: |
Insert into Tabley (col1, col2, col3, col4...) Values (Value1, :DocID,..:Date, :Time..)
Comply error (rc=12):
IBM2027I S variable-name may not be used as a structure qualifier.
|
|
|
Back to top |
|
|
|
|