Skip to main content

Hi Guys,

I have a programmer that is stuggling with a few concepts.  We have InstantSQL configured and working beautifully.  We would like to perform a query and then insert the result of the query into COBOL variables to then compare and do some business logic within Cobol's files.

The below query returns about 50 lines each with 8 columns.  What would be the most efficient way for cobol to use this data and apply business logic for example does the invoice id exist in cobol's data files?

My programmer is going down the track of using a work file for this rather than processing in memory.

Any help with concepts on feeding a result of a query into cobol variables to apply business logic for such things like does the invoice already exist in the cobol data (index seq. files) or not, if not, write to the data to the file.

Regards

Magishme

See below for example code...

--------------------------

01 ws-emp-data.

         05 ws-index          PIC 9(11).  *> index

         05 ws-store          PIC 9(3).  *> store

         05 ws-salesnu        PIC X(20).  *> sales number

         05 ws-invoiceid      PIC 9(5).  *> invoice id

         05 ws-receipt        PIC 9(11).  *> receipt

         05 ws-quantity       PIC 9(11).  *> quantity

         05 ws-discount       PIC 9(10)V99.  *> discount

         05 ws-totalinc       PIC 9(10)V99.  *> totalinc

PROCEDURE DIVISION.

      A.

     *Connect to data source named test.

          SQL CONNECT DATASOURCE sql-ConnectionHandle

              "test"

              "xxxx"

              "xxxxx".

          IF NOT sql-OK

            DISPLAY "<Error connecting to data source.>"

            STOP RUN

          END-IF.

          SQL PREPARE QUERY sql-QueryHandle

               sql-ConnectionHandle

          "SELECT ruginvoices_id, store_number, sales_number, invoice_i

     -    "d, receipt_number, quantity, discount, total_inc_gst FROM tb

     -    "_ruginvoices_rugs JOIN tb_ruginvoices ON ruginvoices_id =  i

     -    "d"

          SQL START QUERY sql-QueryHandle.

          PERFORM WITH TEST AFTER UNTIL NOT sql-OK

            SQL FETCH ROW sql-QueryHandle

            IF sql-OK

              SQL GET DATA sql-QueryHandle

                  "ruginvoices_id"   ws-index   OMITTED

                  "store_number"  ws-store  OMITTED

                  "sales_number" ws-salesnu OMITTED

                  "invoice_id"   ws-invoiceid   OMITTED

                  "receipt_number"  ws-receipt  OMITTED

                  "quantity" ws-quantity OMITTED

                  "discount"  ws-discount  OMITTED

                  "total_inc_gst" ws-totalinc OMITTED

ELSE IF sql-EndOfData

              DISPLAY "<End of data.>"

            ELSE

              DISPLAY "<Error fetching row.>"

              STOP RUN

            END-IF END-IF

          END-PERFORM.

          SQL END QUERY sql-QueryHandle.