1

I'm having an issue with an SQLRPGLE program which must insert records in a table.

I've been debugging my program with strdbg command and I found out that the problem was caused by a packed decimal field called Mes in my data structure, when trying to insert that value into an integer field.

Source data structure definition (the first field in the DS is the field which hypotetically needs casting):

D DataDS          DS                  QUALIFIED TEMPLATE
D  Mes                           6P 0
D  Unidad                        2P 0
D  Subunidad                     3P 0
D  Grupopas                      8P 0
D  Productor                     8P 0
D  Asegurado                     9P 0
    .                             . .
    .                             . .
    .                             . .

The destination field is an integer.

     P Exportar...
     P                 B
     D                 PI
     D data            DS                  LIKEDS(DataDS)
      /free
        ClrBI();
        CLEAR data;
        EXEC SQL DECLARE B1 CURSOR FOR
          SELECT MES,UNIDAD, SUBUNIDAD, GRUPOPAS,
           PRODUCTOR, ASEGURADO, RAMA, TIPO_MOVIM,
           SUCURSAL,IFNULL(FACULTATIV,' '), CONDIC_IVA,
           UNIDAD_FC, SUBUNID_FC, GRUPOPR_FC,
           MATRICULA, CANALCOBRO, IFNULL(CANALCOBRX,' '),
           PRIMACOB, PREMIOCOB, DEREMICOB,
           RECADMCOB, RECFINCOB, IVACOB,
           PER_IVACOB, ACR_IVACOB, ISSCOB,
           INTERNOCOB, PER_IBRCOB, COMISICOBR,
           COMISIAGEN,COMISIORGA,COMISIOTRS
           COMISITOT
          FROM BICOBRANZA
          WHERE MES = :mes;
        EXEC SQL OPEN B1;
        EXEC SQL FETCH NEXT FROM B1 INTO :data;
        DOW SQLCOD = 0;
          SetBI(data);
          CLEAR data;
          EXEC SQL FETCH NEXT FROM B1 INTO :data;
        ENDDO;
        EXEC SQL CLOSE B1;
      /end-free
     P                 E

This is the first time I see an error like this. Does anyone faced this problem before? I don't know even where to start.

Thanks in advance.

jmarkmurphy
  • 11,030
  • 31
  • 59
Mariela
  • 134
  • 2
  • 13

1 Answers1

3

A six digit number with no decimal digits (6P 0) has a value range of -999999 to 999999.

An small integer column has a value range of -32768 to 32767..

Casting will work just fine, as long as your packed field value fits.

You'll need to have the DB column be a large (4 byte (10 digits)) or big ( 8 bytes (20 digits)) integer.

Charles
  • 21,637
  • 1
  • 20
  • 44