Announcement

Collapse
No announcement yet.

Problem with null fields in RPGLE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with null fields in RPGLE

    HI all,

    For a specific reason I have some null field in a table, here's the table:

    Code:
    Create Table Testnull (Field1 Int, Field2 Varchar(100) Ccsid 280 Default Null)
      Rcdfmt Testnullr;
    And the rpg-program:

    Code:
    **FREE
    Ctl-Opt
    DftName(TESTNULL01)
    dftactgrp(*no) actgrp(*New)
    option(*nounref :*srcstmt :*nodebugio)
    datfmt(*iso) timfmt(*iso)
    DecEdit('0.')
    debug
    Text('Test for null field')
    alwnull(*usrctl);
    
    dcl-f Testnull Usage(*output);
    
    Dcl-s Idx Int(5);
    
    For Idx = 1 to 4;
      Clear TestNullR;
      Field1 = Idx; 
      If %Rem(Idx :2) = 1;
        Field2 = 'Odd number';
      Else;
        %NullInd(Field2) = *on;
      EndIf;
      Write TestNullR;
    EndFor;
    
    *inlr = *on;
    The response is this:

    Click image for larger version

Name:	Schermata 2021-01-11 alle 17.26.23.png
Views:	243
Size:	6.7 KB
ID:	154715
    When I put %NullInd(Field2) set to *on, it always remains *on, I expect then clear of the record.

    Do I have to reset the %Nullindicator every time? This is an example, but my program have dozens of fields.

    Many thanks.

  • #2
    Starting in 7.3, you can define a data structure to hold the null indicators for another data structure. https://www.ibm.com/support/knowledg...dkwnullind.htm

    In this program, recDsNull is defined to hold the null indicators for recDs using the NULLIND keyword. recDsNull is defined the same as recDs with *NULL added.

    To set the null indicators for the subfields of recDs, you can either use %NULLIND or you can use the NULL_x subfields of recDsNull.

    Since all the null indicators are in recDsNull, you can just clear that data structure.

    Code:
        ctl-opt alwnull(*usrctl);                                      
        dcl-f testnull usage(*output);                                   
        dcl-ds recDs extname('TESTNULL' : *ALL) nullind(recDsNull)       
                  end-ds;                                              
        dcl-ds recDsNull extname('TESTNULL' : *ALL : *NULL)              
                  prefix('NULL_') end-ds;                              
    
        clear recDsNull;                                               
        field1 = '1 1';                                               
        %nullind(field1) = *on;    // It will change NULL_FIELD1                           
        field2 ='1 2';                                               
        write TestNullR;                                 
    
        clear recDsNull;                                               
        field1 = '2 1';
        field2 ='2 2';                                               
        %nullind(field2) = *on;    // It will change NULL_FIELD2                                                                       
        write TestNullR;          
        *inlr = '1';
    Here's how the calculations would look if you use the nullind subfields directly:
    Code:
        clear recDsNull;                                               
        field1 = '1 1';                                               
        null_field1 = *on;    // It will change %NULLIND(field1)
        field2 ='1 2';                                               
        write TestNullR;

    Comment


    • #3
      Hi Birgitta,

      perfect it works!!!

      Many thanks

      Comment

      Working...
      X