Working with Adabas LB Fields and Natural for Ajax

Hello,

I would like to know how work with Adabas LB fields using Natural for Ajax.
If I have access to some programs models, it will be very good.
Some detailed documentation will help me, too.

Thank you!
Neila Bueno

Neila,

what are you trying to use LOBs for ?

  • Display images ?
  • Up / download arbitrary “files” stored in Adabas ?
  • … ???

Best regards,

   Wolfgang

Hi Wolfgang,

I would like to know how to store/retrieve “files” (like images, .pdf, .doc, .xls, etc) into/from Adabas LB fields.

Thank you,
Neila

Neila, I only found one example for displaying a LB as an image,
which involves writing the LB to a workfile and pass it to an image
control.

I’ll keep looking and let you know if I find something.

Wolfgang,

Thank you for the feedback.

I’ve consulted the Empower System (empower.softwareag.com) and I found one example like this you are telling me.
Studying the NJX documentation and SYSEXNJX library demo I found references about the follow controls: NJX:OBJECTS, NJX:NJXFILEUPLOAD2, NJX:NJXFILEDOWNLOAD, but I’m still in doubt about how to work with adabas LB fields using NJX, so I’ll keep studying the question too.

Neila

My experience with Natural for AJAX is a bit outdated, but I can provide some generic information with examples in Natural for Windows.

  1. create a file/FDT which includes LOBs (fields with Length set to 0 and Long Alpha set to LB)
  2. when creating the Adabas file, specify a second file as the associated LOB file
  3. run Adarep to verify that the LOB files exists
  4. create a DDM, ensuring that the LOBs are defined as Dynamic and with Format Option LB
  5. in the Natural Configuration Utility set the Database Type to ADA2 to support LOBs
  6. create a Natural program to populate the file
DEFINE WORK FILE 1 'dir\filename.ext' TYPE "UNFORMATTED"
READ WORK 1 ONCE VIEW.PICTURE
STORE VIEW
  1. create a Natural program to retrieve and display the LOBs
  2. a. a standard program writes the image to a WORK file and invokes a Browser to display it (example attached)
  3. b. a Natural for Windows program can use a Dialog to display the image from a Work file
  4. c. NJX or Natural ONE can display the image on a Web page

The sample program, tested with Natural for Windows, retrieves images from the EMPLOYEES file supplied with SAG’s Demo database. As the report is being displayed, double-click a data line to render the associated image in Internet Explorer.

DEFINE DATA LOCAL
1 EMP    VIEW EMPLOYE1
  2 PERSONNEL-ID
  2 FIRST-NAME
  2 NAME
  2 L@PICTURE
1 PIC    VIEW EMPLOYE1
  2 PICTURE
1 #N (U20)
1 #M (I4)          CONST <10>
1 #PID (A8/#M)
1 #RES (A250) INIT <'C:\ProgramData\Software AG\Natural\Natapps\Fuser\'>
1 #DIR (A250)
1 #CMD (A250)
1 #I (I4)
1 #J (I4)
END-DEFINE
SET KEY PF3 = '%.'
COMPRESS #RES
         *LIBRARY-ID
         '\res\'
    INTO #RES LEAVING NO SPACE
READ EMP BY PERSONNEL-ID
      WHERE L@PICTURE <> 0
  AT END OF DATA
    NEWPAGE
  END-ENDDATA
  ADD 1 TO #I
  ASSIGN #PID (#I) = EMP.PERSONNEL-ID
  #N := EMP.NAME
  DISPLAY
          EMP.PERSONNEL-ID
          EMP.NAME
          EMP.FIRST-NAME
          EMP.L@PICTURE
  IF  #I = #M
    THEN
      NEWPAGE
  END-IF
  AT END OF PAGE
    INPUT (AD=O IP=F) 'Select employee'
    ASSIGN #J = *CURS-LINE - 6
    IF  #J = 1 THRU #M
      THEN
        COMPRESS #RES
                 #PID (#J)
                 '.jpg'
            INTO #DIR LEAVING NO SPACE
        DEFINE WORK FILE 1 #DIR TYPE "UNFORMATTED" ATTRIBUTES "NOAPPEND"
        FIND PIC WITH PERSONNEL-ID = #PID (#J)
          WRITE WORK 1 VARIABLE PIC.PICTURE
          OPTIONS TQMARK=OFF
          COMPRESS 'cmd.exe /c '
                 - '"C:\Program Files\Internet Explorer\iexplore.exe"'
                   #DIR
              INTO #CMD
          OPTIONS TQMARK=ON
          CALL "SHCMD" #CMD "ASYNCH" "NOSCREENIO"
        END-FIND
    END-IF
    RESET #I
          #PID (*)
  END-ENDPAGE
END-READ
END

The images are written as “resources” in the current Natural library. (By default this is where Dialogs expect to find them.)

NB This example is not intended to provide production-ready logic, but to demonstrate image retrieval in as small a program as possible.
lob.docx (338 KB)

Thank you, Ralph!
I executed the examples you sent using Employees and I’m implementing a similar code using NJX for test.

Hi!

I managed to store and retrieve a image file into adabas LB field using NJX:OBJECTS and NJX:NJXFILEUPLOAD2 controls. See the source code bellow. But, update and delete doesn’t work. Some tip about this question?

  • Natural Source Header 000000

  • :Mode S
  • :CP
  • <Natural Source Header
    /** Main program generated for
    /** adapter <:link TESTE/PAGE1-A>.
    /*
    /** :author nbue
    /** :version Generated by Natural for Ajax.
    /*
    DEFINE DATA LOCAL
    1 ID_IMAGEM (A) DYNAMIC
    1 INFO (A) DYNAMIC
    1 IMAGEURL (A) DYNAMIC /INIT <‘C:\Neila’>
    /

    1 XCIOBJECTS (1:*)
    2 CONTENT (B) DYNAMIC
    2 CONTENTID (A) DYNAMIC
    2 CONTENTTYPE (A) DYNAMIC

1 UPLOAD_IMAGEM
2 CEXT (A) DYNAMIC
2 CNAME (A) DYNAMIC
2 CONTENTID (A) DYNAMIC
2 CPATH (A) DYNAMIC
*
1 BLOB (B) DYNAMIC
1 URL (A) DYNAMIC
*
1 LOB VIEW OF FILE-5
2 AA-1 /* A 5 N D
2 LA-1 /* A N LA/NB/NV
2 LB-1 /* A N LOB/NB/NV
*
END-DEFINE
*
PROCESS PAGE USING “PAGE1-A”
*
DECIDE ON FIRST *PAGE-EVENT

VALUE U’nat:page.end’
/* Page closed.
IGNORE

VALUE U’onUpdate’

F0. FIND(1) LOB WITH AA-1 = ID_IMAGEM
MOVE INFO TO LOB.LA-1
UPDATE(F0.)
END TRANSACTION
END-FIND
/*
END TRANSACTION
RESET ID_IMAGEM INFO XCIOBJECTS(*) BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’onSearch’
FIND(1) LOB WITH AA-1 = ID_IMAGEM
MOVE LOB.LA-1 TO INFO
MOVE LOB.LB-1 TO BLOB
CALLNAT “MAKEURL” XCIOBJECTS(*) BLOB URL
IMAGEURL := URL
END-FIND
PROCESS PAGE UPDATE FULL

VALUE U’onDelete’
F2. FIND(1) LOB WITH AA-1 = ID_IMAGEM
DELETE (F2.)
END TRANSACTION
END-FIND
RESET ID_IMAGEM INFO XCIOBJECTS(*) BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’onExit’
STOP

VALUE U’onInsert’
MOVE ID_IMAGEM TO LOB.AA-1
MOVE INFO TO LOB.LA-1
STORE LOB
END TRANSACTION
RESET ID_IMAGEM INFO XCIOBJECTS(*) BLOB URL IMAGEURL UPLOAD_IMAGEM

PROCESS PAGE UPDATE FULL

VALUE U’onLimpar’
RESET ID_IMAGEM INFO XCIOBJECTS(*) BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’upload_imagem.onUploadFinished’
MOVE XCIOBJECTS.CONTENT(1) TO LOB.LB-1
PROCESS PAGE UPDATE FULL

NONE VALUE
PROCESS PAGE UPDATE

END-DECIDE
*
END

I can only assume your FINDs don’t return the record you are looking for,
i.e. AA-1 doesn’t contain ID_IMAGEM as expected, or your program doesn’t
receive ID_IMAGEM correctly, you will have to debug these aspects.

Hi,

I think I found a way to working with Adabas LB Fields and NJX.
On this page I use the follow NJX controls: NJX:OBJECTS, NJX:NJXFILEUPLOAD2
See the basic source code main program bellow.
If somebody has a better solution, please post it here.

  • Natural Source Header 000000

  • :Mode S
  • :CP
  • <Natural Source Header
    /** Main program generated for
    /** adapter <:link TESTE/PAGE1-A>.
    /*
    /** :author nbue
    /** :version Generated by Natural for Ajax.
    /*
    DEFINE DATA LOCAL
    1 ID_IMAGEM (A) DYNAMIC
    1 INFO (A) DYNAMIC
    1 IMAGEURL (A) DYNAMIC /INIT <‘C:\Neila’>
    /

    1 XCIOBJECTS (1:*)
    2 CONTENT (B) DYNAMIC
    2 CONTENTID (A) DYNAMIC
    2 CONTENTTYPE (A) DYNAMIC

1 UPLOAD_IMAGEM
2 CEXT (A) DYNAMIC
2 CNAME (A) DYNAMIC
2 CONTENTID (A) DYNAMIC
2 CPATH (A) DYNAMIC
*
1 BLOB (B) DYNAMIC
1 URL (A) DYNAMIC
*
1 LOB VIEW OF FILE-5
2 AA-1 /* A 5 N D
2 LA-1 /* A N LA/NB/NV
2 LB-1 /* A N LOB/NB/NV
*
END-DEFINE
*
PROCESS PAGE USING “PAGE1-A”
*
DECIDE ON FIRST *PAGE-EVENT

VALUE U’nat:page.end’
/* Page closed.
IGNORE

VALUE U’onUpdate’
*
F0. FIND(1) LOB WITH AA-1 = ID_IMAGEM
MOVE INFO TO LOB.LA-1
MOVE BLOB TO LOB.LB-1
UPDATE(F0.)
END TRANSACTION
END-FIND
/*
END TRANSACTION
RESET ID_IMAGEM INFO BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’onSearch’

FIND(1) LOB WITH AA-1 = ID_IMAGEM
MOVE LOB.LA-1 TO INFO
MOVE LOB.LB-1 TO BLOB
CALLNAT “MAKEURL” XCIOBJECTS(*) BLOB URL
IMAGEURL := URL
END-FIND
PROCESS PAGE UPDATE FULL

VALUE U’onDelete’

F2. FIND(1) LOB WITH AA-1 = ID_IMAGEM
DELETE (F2.)
END TRANSACTION
END-FIND
RESET ID_IMAGEM INFO XCIOBJECTS(*) BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’onExit’
STOP

VALUE U’onInsert’

MOVE ID_IMAGEM TO LOB.AA-1
MOVE INFO TO LOB.LA-1
MOVE BLOB TO LOB.LB-1
STORE LOB
END TRANSACTION
RESET ID_IMAGEM INFO BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’onReset’
RESET ID_IMAGEM INFO XCIOBJECTS(*) BLOB URL IMAGEURL UPLOAD_IMAGEM
PROCESS PAGE UPDATE FULL

VALUE U’upload_imagem.onUploadFinished’
MOVE XCIOBJECTS.CONTENT(1) TO BLOB
CALLNAT “MAKEURL” XCIOBJECTS(*) BLOB URL
IMAGEURL := URL
PROCESS PAGE UPDATE FULL

NONE VALUE
PROCESS PAGE UPDATE

END-DECIDE
*
END