MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Clear out data in structure in PL1

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Thu Aug 12, 2010 10:25 am    Post subject: Clear out data in structure in PL1 Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Aug 12, 2010 10:38 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
prino
Banned


Joined: 01 Feb 2007
Posts: 45
Topics: 5
Location: Oostende

PostPosted: Thu Aug 12, 2010 1:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Tue Aug 17, 2010 1:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
Nic Clouston
Advanced


Joined: 01 Feb 2007
Posts: 1075
Topics: 7
Location: At Home

PostPosted: Tue Aug 17, 2010 2:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
prino
Banned


Joined: 01 Feb 2007
Posts: 45
Topics: 5
Location: Oostende

PostPosted: Tue Aug 17, 2010 4:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Wed Aug 18, 2010 9:07 am    Post subject: Reply with quote

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
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Wed Aug 18, 2010 12:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group