Programming Languages on Power

Power Programming Languages

IBM Power, including the AIX, IBM i, and Linux operating systems, support a wide range of programming languages, catering to both traditional enterprise applications and modern development needs.


#Power


#Servers
#Programminglanguages
 View Only
  • 1.  How to set a variable to null in SPL?

    Posted 09/18/24 04:09 PM

    I have some spl which looks like the following:

    ...

              DECLARE QCTLSBSD VARCHAR(10);

    ...

    SET QCTLSBSD = null;

    ...

    I am trying the create procedure in Run SQL Scripts.  I've debugged the earlier errors and now I'm down to just this one.  On the earlier ones Run SQL Scripts flagged right where the error was occuring.  On this one I have to find some QSYSPRT on the i and see

    ...

              CASE QCTLSBSD
                WHEN NULL THEN

    ...

    Record  *...+... 1
      512    = NULL ; 

    MSG ID  SEV  RECORD  TEXT                                           
    SQL0128  30     512  Position 4 Use of NULL or UNKNOWN is not valid.

    If I try changing 

    SET QCTLSBSD = null;

    to

    SET QCTLSBSD is null;

    Then Run SQL Scripts stops it with

    Message: [SQL0199] Keyword IS not expected. Valid tokens: =.



    ------------------------------
    Robert Berendt IBMChampion
    Business Systems Analyst, Lead
    Dekko
    Fort Wayne
    260-599-3160
    ------------------------------

    #SQL


  • 2.  RE: How to set a variable to null in SPL?

    Posted 09/18/24 05:02 PM

    Turns out it WASN'T the SET line.  I commented that out and continued to get the error.

    I had another section of code which was

              CASE QCTLSBSD
                WHEN NULL THEN
                  SET JOB_COUNT = JOB_COUNT; -- SQL failed, dummy operation.  Replace if desired.
                WHEN 'QCTL' THEN -- Batch subsystem is normally QBATCH
                  SELECT COUNT(*) INTO JOB_COUNT
                  FROM QSYS2.SUBSYSTEM_INFO
                  WHERE SUBSYSTEM_DESCRIPTION = 'QBATCH'
                    AND STATUS = 'ACTIVE';
                  IF JOB_COUNT = 0 THEN
                    CALL QSYS2.QCMDEXC('STRSBS QBATCH');
                  END IF;
                WHEN 'QBASE' THEN -- Batch subsystem is just part of QBASE
                  -- What to do?  Ensure that QBASE is not 'RESTRICTED'?
                  SET JOB_COUNT = JOB_COUNT; -- dummy operation.  Replace if desired
                ELSE  -- This choice location for rent
                  SET JOB_COUNT = JOB_COUNT; -- dummy operation.  Replace if desired.
              END CASE;

    I changed it to

              CASE 
                WHEN QCTLSBSD IS NULL THEN
                  SET JOB_COUNT = JOB_COUNT; -- SQL failed, dummy operation.  Replace if desired.
                WHEN QCTLSBSD = 'QCTL' THEN -- Batch subsystem is normally QBATCH
                  SELECT COUNT(*) INTO JOB_COUNT
                  FROM QSYS2.SUBSYSTEM_INFO
                  WHERE SUBSYSTEM_DESCRIPTION = 'QBATCH'
                    AND STATUS = 'ACTIVE';
                  IF JOB_COUNT = 0 THEN
                    CALL QSYS2.QCMDEXC('STRSBS QBATCH');
                  END IF;
                WHEN QCTLSBSD = 'QBASE' THEN -- Batch subsystem is just part of QBASE
                  -- What to do?  Ensure that QBASE is not 'RESTRICTED'?
                  SET JOB_COUNT = JOB_COUNT; -- dummy operation.  Replace if desired
                ELSE  -- This choice location for rent
                  SET JOB_COUNT = JOB_COUNT; -- dummy operation.  Replace if desired.
              END CASE;

    1 - I've ran into issues before when trying the previous CASE format.

    2 - I read that WHEN NULL acts differently than WHEN IS NULL.  The former continues to do the rest of the WHENs.  The latter does not.  https://sqlundercover.com/2018/11/28/a-curious-case-of-case-when-and-null-values/



    ------------------------------
    Robert Berendt IBMChampion
    Business Systems Analyst, Lead
    Dekko
    Fort Wayne
    260-599-3160
    ------------------------------