IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
#Power
 View Only
Expand all | Collapse all

Yes, you CAN create simple select/omit LF's with a key with DDL.

  • 1.  Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Tue January 30, 2024 02:32 PM

    There seems to be quite a bit of confusion as to whether or not you can create simple select/omit LF's with a key by using DDL.  You can.  This has been around for quite some time.

    Many legacy ERP systems have select/omit logical files which look like this:

    R IPI100IM                  PFILE(IIM       )        
      IID            2A         TEXT('Record ID (IM/IZ)')
                                COLHDG('Rec' +           
                                       'ID' +            
                                       'IM/IZ')          
      IPROD         35O         TEXT('Item Number')      
                                COLHDG('Item' +          
                                       'Number' )        

    ...

    K IPROD                                  
    S IID                       COMP(EQ 'IM')

    Basically, create a key on the item master file by the item number and select only active records.

    To do this with DDL you can use the following:

    CREATE INDEX ROB.IIML01_DDL
        ON ERPLXF.IIM
        (IPROD ASC)
        WHERE IID = 'IM'
        RCDFMT IPI100IM
        ADD IID, IPROD ...
    ;

    Forget about trying to generate this by using generate_sql or even the underlying API, Generate Data Definition Language (QSQGNDDL) API - IBM Documentation



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------


  • 2.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Tue January 30, 2024 02:35 PM

    Yes, you can use RPG to CHAIN by IPROD to this 'index'.



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 3.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Tue January 30, 2024 04:04 PM

    One of the cardinal rules of sql is that you always SELECT FROM a table.

    However if the object is a DDS LF you can select from that.  If you generate that same object using DDL it then knows it is an index and will not allow you to do a select from it.

    One caveat before you undergo a mass conversion.



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 4.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Wed January 31, 2024 10:39 AM

    Probably Its easier to see DDS LF as equivalent to a regular SQL VIEW and a SQL INDEX (when DDS LF is keyed)



    ------------------------------
    Daniel Jose Lema Guanziroli
    ------------------------------



  • 5.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Tue January 30, 2024 04:23 PM

    One thing I'm noticing is that on the LF created the index column(s) will be created at the beginning and your ADD statement cannot be used to put it in the same place as it was in the DDS order.  The exception being if you use ADD ALL COLUMNS.  According to the documentation it's "working as designed".  I agree.  However, it won't replace the LF's as currently designed by the ERP package because of this.



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 6.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Thu February 01, 2024 03:44 AM

    Not sure what's your Problem with the WIZARD in ACS or the GENERATE_SQL stored procedure. For me it works perfectly.

    There are a few things that are not supported in an index.

    Here an article I wrote somtimes ago for IBM:

    https://developer.ibm.com/articles/i-sql-indexs-and-native-io/



    ------------------------------
    Birgitta Hauser
    Database and Software Engineer
    Selfemployed - Modernization-Education-Consulting on IBM i
    Kaufering
    +49 170 5269964
    ------------------------------



  • 7.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Thu February 01, 2024 07:42 AM

    it doesn't return the same number of columns as were on the CREATE statement



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 8.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Fri February 02, 2024 03:24 AM

    I so, you should report a problem to IBM



    ------------------------------
    Birgitta Hauser
    Database and Software Engineer
    Selfemployed - Modernization-Education-Consulting on IBM i
    Kaufering
    +49 170 5269964
    ------------------------------



  • 9.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Tue February 06, 2024 07:54 AM

    I did open a case.

    Here was the sample sparse index I created:

    CREATE INDEX ROB.IIML01
    ON rob.IIM
    (IPROD ASC)
    WHERE IID = 'IM'
    RCDFMT IPI100IM
    ADD IID, IPROD
    ;

    Here is what the generate returned:

    CREATE INDEX ROB/IIML01
    ON ROB/IIM
    ( IPROD ASC )
    WHERE IID = 'IM'
     RCDFMT IPI100IM ADD IID ;

    Notice only one column on the ADD?  You only see IID and not IPROD also.

    However, it was determined that DSPFFD did show both columns.  IPROD was added implicitly to the list of columns by the (IPROD ASC)

    This makes it working as designed.  The only problem is, that it will not replace a bulk of the indexes used by this ERP system.  Which is why I think IBM really came out with this form of sparse index in the first place.  The reason it will not replace them is because it places the columns in the wrong order by putting the index column(s) first and not in the order of the ADD clause.



    ------------------------------
    Robert Berendt IBMChampion
    ------------------------------



  • 10.  RE: Yes, you CAN create simple select/omit LF's with a key with DDL.

    Posted Tue February 06, 2024 11:55 AM

    May be the documentation is a little misleading, but what is specified (and returned) after ADD are the columns that have to be added to the key columns.

    IPROD is a key column and therefore not listed after ADD!.



    ------------------------------
    Birgitta Hauser
    Database and Software Engineer
    Selfemployed - Modernization-Education-Consulting on IBM i
    Kaufering
    +49 170 5269964
    ------------------------------