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
#Operatingsystems
#Servers
 View Only
  • 1.  Retrieve a blob field into a data structure

    Posted 03/09/24 03:57 PM

    Hi

    I have a procedure that retrieve the signatures of a service program into a SD like this:

    Dcl-s WWSIGNAT CHAR(16) DIM(100);

    i have the following DS for use in the SQL sentence:

    Dcl-s WWSIGNATURES SQLTYPE(BLOB:1699);

    And the sentence of SQL for retrieve the signatures is:

    Exec SQL

         SELECT EXPORT_SIGNATURES INTO :WWSIGNATURES

                        FROM QSYS2.PROGRAM_INFO

                        WHERE PROGRAM_NAME = :WWPGMNAME

                         FETCH FIRST 1 ROWS ONLY;

    When the SQL statement is processed, the WWSIGNATURES files are populated with the number of signatures and with the data in BINARY format, they are not converted to character format, 

    Does anyone know why binary data is not converted to characters?

    Thank you



    ------------------------------
    Juan Garcia
    ------------------------------


  • 2.  RE: Retrieve a blob field into a data structure

    Posted 03/10/24 05:15 AM

    BLOB means Binary Large Object. When using a BLOB the data is taken as it is, so you can save for example a picture or a PDF document or a music stream in a BLOB.

    If you want to read, share or save character information, you either need a CLOB (Character Large Object) or a DBCLOB (Double Byte Character Large Objects).



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



  • 3.  RE: Retrieve a blob field into a data structure

    Posted 03/11/24 01:24 PM

    Thanks for the reply

      I want to recover the signatures of an SRVPGM, that's why I read the records from the QSYS2.PROGRAM_INFO table and the signatures are in the EXPORT_SIGNATURES field which is BLOB, I can't change the field type but I need to go from blob to characters



    ------------------------------
    Juan Garcia
    ------------------------------



  • 4.  RE: Retrieve a blob field into a data structure

    Posted 03/11/24 06:17 PM

    The EXPORT_SIGNATURES is a BINARY value (BLOB) you  may try to convert/cast it into a Character_Value using TRY_CAST. Then you can fetch the value into a Character Field. If the binary value cannot be converted a NULL value will be returned

    Try_Cast(Export_Signatures as CHAR(32000))



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



  • 5.  RE: Retrieve a blob field into a data structure

    Posted 03/12/24 04:21 AM
    Edited by Juan Garcia 03/12/24 05:34 AM

    I have tried TRY_CAST in a debugging session in RDI and this is what it returns:

    Eval WWEXPCHAR =

    í™íù_a7A– ÿõü`_I ˜÷ç¨ Õ5Oµµf9ñ× ýï”6׌Ãü±b"Â[²» *q‡ú»8}èö²û±îÊ» º™2G}ß9hªí*jŸ¹¥Ò j%`ÂñUžÙæLÐãL ZG°ÊÅR ¶` ?ô¸q; %¤D·ƒî­Ò¨Ðiâ&Hsù \_Ѳ_0/G<L­É‘= a:º/ñ̵ç×\àVŽ B|Š7¦I©‚´ƒˆY”ï  ;äÀ– ҆ËÏ:á–  ;äÀ– ҆ËÏ:á–      VOX”¹Ë(¦¦ÆÃ                                                                                                                                                                                                                                                                                                                                                            This is the SQL statement

        EXEC SQL
                            SELECT 
                                   Try_Cast(EXPORT_SIGNATURES as CHAR(32000))
                                   INTO :WWEXPCHAR
                       FROM QSYS2.PROGRAM_INFO
                              WHERE PROGRAM_NAME = :WWPGMREF.WHFNAM
                                    FETCH FIRST 1 ROWS ONLY;               

    and the definition of the variable that receives the data is:

      Dcl-s WWEXPCHAR   CHAR(32000);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
    ------------------------------
    Juan Garcia
    ------------------------------



  • 6.  RE: Retrieve a blob field into a data structure

    Posted 03/12/24 10:13 AM

    It is a generated Binary value! What did you expect?

    Another option would be to retrieve the HEX Value (using the HEX built-in-function) ... but I have no idea what it could help, because you cannot use it for everying, except converting it back into the original value.



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



  • 7.  RE: Retrieve a blob field into a data structure

    Posted 03/12/24 12:08 PM
    Edited by Juan Garcia 03/12/24 12:47 PM

    I'm going to try a SQLTYPE varbinary value

     Dcl-s WWEXPSIG    SQLTYPE(VARBINARY:32740);    

     the SQL precompiler transforms it into this

      //*      DCL-S WWEXPSIG    SQLTYPE(VARBINARY:32740); 
      DCL-S WWEXPSIG VARCHAR(32740) CCSID(*HEX);      

    I'll post if it works or not    

    Doesn't work, error occurs with the code RNX1251 when displaying the screen
    ------------------------------
    Juan Garcia
    ------------------------------



  • 8.  RE: Retrieve a blob field into a data structure

    Posted 03/12/24 04:34 PM

    SQLTYPE VARBINARY is nothing else than a short BLOB (i.e. NO conversion).



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



  • 9.  RE: Retrieve a blob field into a data structure

    Posted 03/13/24 05:14 AM

    Hi.

    Export signatures are hexadecimal values - even though you can specify character string as the signature in the binder language, they are in reality non-character data.

    Since the data is hexadecimal, it has to be a (small) BLOB.

    You can see this for yourself by issuing the command

    DSPSRVPGM SRVPGM(QC2UTIL1) DETAIL(*SIGNATURE)

    You will see the signature for QC2UTIL1 is shown in hex - and even though you can press F11 to view as character data, not all characters are displayable.

    Your best bet is to keep the binary value and show it in hex by using the HEX SQL function, as Birgitta suggested.



    ------------------------------
    Christian Jorgensen
    IT System Administrator
    Network of Music Partners A/S
    ------------------------------



  • 10.  RE: Retrieve a blob field into a data structure

    Posted 03/15/24 07:59 AM

    Hi

      I have tried this sentence:

                   EXEC SQL
                            SELECT PROGRAM_NAME,
                                   OBJECT_TYPE,
                                   PROGRAM_LIBRARY,
                                   SIGNATURES,
                                   HEX(EXPORT_SIGNATURES) INTO :WW_SIGNAT
                              FROM QSYS2.PROGRAM_INFO
                              WHERE PROGRAM_NAME = :WWPGMREF.WHFNAM
                                    FETCH FIRST 1 ROWS ONLY;   

     

         Dcl-Ds WW_SIGNAT QUALIFIED;
                 PROGRAM_NAME         CHAR(10);
                 OBJECT_TYPE               CHAR(7);
                 PROGRAM_LIBRARY     CHAR(10);
                 SIGNATURES                  INT(10:0);
                 EXPORT_SIGNATURES CHAR(1700);
           End-Ds;                            

     and it works!!!, it has recovered the signatures in hexadecimal, thank you Birgitta and Christian for your help



    ------------------------------
    Juan Garcia
    ------------------------------