× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




I want to know if this will work.  I have a main program calling a
subprogram (XCPRIC) that I am prototyping.  The parms are external data
structures.  The prototype (copied in to main program and subprogram) looks
like this:

    D XCPRIC          PR                  ExtPgm('XCPRIC')
    D  pCustDS                            LikeDS(CustDS)
    D  pItemDS                            LikeDS(ItemDS)
    D  pInvDS                             LikeDS(InvDS)

The only stumbling block I can think of with this approach is that the LIKEDS() statements create a dependency on those data structures. That means that every single calling program will have to define a CustDS, ItemDS and InvDS -- and you'd better make sure that those names always correspond to the same data structures, or you'll have real problems!


To solve this problem I suggest:

a) You include the data structures in the /COPY member with the prototype so that they're always there.

b) You use a "prefix" of sorts to make sure that you won't have a name conflict. Names like "CustDS" and "ItemDS" are very easy to conflict with since they tend to be common names.

So I suggest that the /COPY book with the prototype look like this:

      /if defined(XCPRIC_COPYBOOK)
      /eof
      /endif
      /define XCPRIC_COPYBOOK

     D XCPRIC_Cust   E DS                  ExtName(DMCUSMST)
     D XCPRIC_Item   E DS                  ExtName(DMITMMST)
     D XCPRIC_Inv    E DS                  ExtName(ININFODS)

     D XCPRIC          PR                  ExtPgm('XCPRIC')
     D  pCustDS                            LikeDS(XCPRIC_Cust)
     D  pItemDS                            LikeDS(XCPRIC_ItemDS)
     D  pInvDS                             LikeDS(XCPRIC_InvDS)

That way, when you /COPY this member into your programs:

  a) it'll always use the same definitions

  b) You won't having naming conflicts (since other programs presumably
      won't be called XCPRIC)

  c) The /define logic prevents the copybook from coming in more than
      once (even if the copybook is /copy-ed into another copybook!)

If you wanted to be a little more deluxe, you could use BASED() on the data structure definitions so that no memory would be allocated to them, and they'd only be used as "templates", but that's not really necessary.

The calling program logic doesn't need to change at all. In the "subprogram" (you're only one step away from using a service program, you know!) for some reason you're making copies of the data structures:

The following code duplicates the subprocedures:

     /FREE
     CustDS = pCustDS;
        ItemDS = pItemDS;
        InvDS = pInvDS;

I don't understand why you'd want to do that. It requires extra CPU time and I don't see what it's accomplishing. I could see doing this if you wanted to keep an alternate copy of it for some reason... maybe if you wanted a "before and after" image of the data or something. But if not, why waste the CPU moving the data back & forth?


Instead, just reference the contents of the parameters directly:

         pCustDs.Name = whatever;
         pCustDs.Addr = whatever;
         pCustDs.Terms = 'NET/30';

When you do it that way, there's no reason to copy them back & forth.


Some of the subfields in InvDS are updated. Will this work?


The code that you posted would work, but I think my suggestions (above) will improve it a little bit.


Just my opinion, of course.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.