Creating dynamic temp table from dynamic Buffer - progress-4gl

Here is my issue:
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hBuffer).
hQuery:QUERY-PREPARE("/*my conditions*/").
hQuery:QUERY-OPEN().
hBuffer is my buffer handle.
I want to create a temp-table from this hBuffer.How?Pls help

See "CREATE TEMP-TABLE statement" in on-line help. An example is shown and i believe you can just replace the static table buffers with your dynamic buffer handle....
CREATE TEMP-TABLE tth.
tth:CREATE-LIKE(hBuffer).
tth:TEMP-TABLE-PREPARE("MyTT").
ttbh = tth:DEFAULT-BUFFER-HANDLE.
/* populate */
ttbh:BUFFER-CREATE.
ttbh:BUFFER-COPY(hBuffer).

Related

progress 4gl :i want to avoid error messages while running the program

DEFINE TEMP-TABLE ttservice NO-UNDO
FIELD ad-num AS CHARACTER
INDEX ttprimary AS UNIQUE ad-num .
ASSIGN ttservice.ad-num = vehicles.ad-num NO-ERROR
In this, how to avoid error messages when i am adding duplicate records,
situation is:
when i try to add the duplicate records in temp table it doesnot accept,it is ok ,but it display error messages while running a program,iwant to suppres that error messages.,and avoid the duplicate adding records
You can test for the existence of a duplicate key before you try to create it.
(Filling in the blanks.)
DEFINE TEMP-TABLE ttservice NO-UNDO
FIELD ad-num AS CHARACTER /* you have a "num" field defined as character? that's misleading */
INDEX ttprimary AS UNIQUE ad-num .
for each vehicle no-lock: /* perhaps ad-num is non-unique in the vehicle table? */
find ttservice where ttservice.ad-num = vehicles.ad-num no-error.
if available ttservice then
do:
message "oops!". /* or whatever it is you want when a duplicate occurs... */
end.
else
do:
create ttservice.
ASSIGN ttservice.ad-num = vehicles.ad-num.
end.
end.
Here's another way to get unique ad-num values from the vehicles table:
DEFINE TEMP-TABLE ttservice NO-UNDO
FIELD ad-num AS CHARACTER
INDEX ttprimary AS UNIQUE ad-num .
FOR EACH vehicles NO-LOCK
BREAK BY vehicles.ad-num:
IF FIRST-OF(vehicles.ad-num) THEN
DO:
CREATE ttservice.
ASSIGN ttservice.ad-num = vehicles.ad-num.
END.
END.
Two valued answers have already been added by great professionals but i would like to add mine with minor changes.
def TEMP-TABLE ttservice NO-UNDO
FIELD iservid AS INT
INDEX tt-primary AS UNIQUE iservid.
VEHICLELOOP:
for each vehicles use-index <index-name>
NO-LOCK:
IF CAN-FIND(first ttservice
where ttservice.iservid = vehicles.iservid)
THEN
NEXT VEHICLELOOP.
ELSE DO:
create ttservice.
ASSIGN ttservice.iservid = vehicles.iservid.
END. /* VEHICLELOOP */
So I read the answers and think they're sufficient to fix your particular issue. But here's the general way of thinking you should assume when coding for Progress OpenEdge:
Adding no-error to statements (when they allow it) will "suppress errors", though sometimes they're inevitable and suppressing does no good to the stability of your application, always think of treating them (and displaying errors is a part of this).
Whether you choose to check for existence of a record prior to creation or just set your query to not iterate for undesired (repeated) records is up to you. I advise you to check for performance with different approaches (especially in doing a for each for a large table) to see which one is more satisfactory.
So here's my personal suggestion:
for each vehicles no-lock:
if can-find(first ttService where ttService.ad-num = vehicles.ad-num) then
next.
create ttService.
assign ttService.ad-num = vehicles.ad-num no-error.
if error-status:error then
message "Something went horribly wrong:" + error-status:get-message(1)
view-as alert-box error.
end.
In my example above, the error will only be shown if the assign actually fails. It is not likely to happen, I just wanted to show how the usage of no-error (and its treatment) works.
Anyway, hope it helps!

OpenEdge 102a export table to xml file

I am new to openedge and i am trying to export initially a table to xml file.
My final aim is to export three tables to xml file.
I have tried to export in a simple delimited and is working.
I have tried
For txt
OUTPUT TO c:\temp\file.txt.
FOR EACH cGrSIRVATNBR:
EXPORT DELIMITER ";" cGrSIRVATNBR.
END.
OUTPUT CLOSE.
For xml
cGrSIRVATNBR:WRITE-XML("FILE","c:\temp\tt.xml", TRUE).
For xml i thing is only supported from 102b. That's why i am taking error (Unable to understand after -- cGrSIRVATNBR:) when using WRITE-XML.
I will appreciate any help.
This works fine for me:
define temp-table ttCust no-undo like customer.
for each customer no-lock where custNum = 1:
create ttCust.
buffer-copy customer to ttCust.
end.
temp-table ttCust:write-xml( "file", "cust.xml", true ).
You cannot directly write a db table to XML. You have to copy the records that you want into a temp-table first.

Dynamically reference temp-table column values in Progress

I am using Progress 4GL
I have a spreadsheet of data containing several columns called data1....50.
I have created a temp table which holds all the values.
Now I would like to loop through the temp table columns and do various calculations
So I need something like this:
for each record loop thru cols_in_temp_table .
if col_value = "XYZ" then
do calcs and stuff
end.
So how do I reference the temp_table cols ?
Ok, didn't resolve the original query, but found a workaround. Split the data up and put into separate tables, long winded, but does the trick.
Depending on your version, this is one way to do it:
DEFINE VARIABLE h-cols AS HANDLE NO-UNDO.
h-cols = tt-cols:BUFFER-HANDLE.
FOR EACH tt-cols
NO-LOCK:
IF h-cols::col-name = "some value" THEN
RUN do-something.
END.
For versions that can't do the "::" operator, do this:
FOR EACH tt-cols
NO-LOCK:
IF h-cols::buffer-field("col-name"):buffer-value = "some value" THEN
RUN do-something.
END.

Specifying a DB table dynamically? Is it possible?

I am writing a BSP and based on user-input I need to select data from different DB tables. These tables are in different packages. Is it possible to specify the table I want to use, based on its path, like this:
data: path1 type string value 'package1/DbTableName',
path2 type string value 'package2/OtherDbTableName',
table_to_use type string.
if some condition
table_to_use = path1.
elseif some condition
table_to_use = path2.
endif.
select *
from table_to_use
...
endselect
I am new to ABAP & Open SQL and am aware this could be an easy/silly question :) Any help at all would be very much appreciated!
You can define the name of the table to use in a variable, and then use the variable in the FROM close of your request :
data tableName type tabname.
if <some condition>.
tableName='PA0001'.
else.
tableName='PA0002'.
endif.
select * from (tableName) where ...
there are a few limitation to this method, as the stable can not contains fields of type RAWSTRING, STRING or SSTRING.
as for the fact that the table are in different package, i don't think it matters.
Regards,

How To Send a PDF File to a Progress AppServer?

I have a PDF file at client and i want to send this PDF file on AppServer. How can i send this pdf file at AppServer?
define temp-table ttFileList no-undo
field file-id as integer
field file-content as blob.
create ttFileList.
assign ttFileList.file-id = 1.
copy-lob from file("pdffilename") to ttFileList.file-content.
run DoSomethingWithAPDF on hAppServer
( input table ttFileList ).
This depends on the version of progress you are using, if you are using v9 then you will need to use small chunks of raw data streamed in segments. With OpenEdge (might have been 10.1B) we got CLOB and BLOB support, you can create a procedure which takes a temp-table as an argument.
It also depends on your calling language. For .NET and Java this will get translated into a byte array.
For your app-server create a procedure similar to the following:
def temp-table ObjectTransfer no-undo
field Code as char
field Number as int
field DataContent as blob
field MimeType as char.
procedure AddObjectData:
def input param table for ObjectTransfer.
def var k as int no-undo.
for each ObjectTransfer:
find last ObjectTable no-lock
where ObjectTable.Code = ObjectTransfer.Code
no-error.
if avail ObjectTable then
k = ObjectTable.Number + 1.
else
k = 1.
create ObjectTable.
assign
ObjectTable.Code = ObjectTransfer.Code
ObjectTable.Number = k
ObjectTable.MimeType = ObjectTransfer.MimeType
ObjectTable.DataContent = ObjectTransfer.DataContent
.
end.
end procedure.
Generate proxies, you will now call this from .NET and Java using a simple byte array as an input temp-table data-type.
Use raw datatype, you might need to send the file in chunks. Another alternative is to use character+BASE64.