Consultor Eletrônico



Kbase 19065: ADM2 - How To Access SDO Data For Printing
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   17/12/2004
Status: Verified

GOAL:

If you need to access a SmartDataObject (SDO) so that you can print reports using the data the SDO provides and want to make certain that your code can run across an AppServer, you can use the following code as an example.

GOAL:

How To Access SDO Data For Printing?

FACT(s) (Environment):

Progress 9.x

FIX:

The following sample code makes the following assumptions:
- You have a SmartWindow (SW).

- You have an SDO embedded on the SW.

- You have a Simple SmartObject (SSO) embedded on the SW and it only contains a button labeled "Print Report".

- There is a link between the SDO and the SSO called "Print".

- You are accessing the Sports2000.Customer table and want to print the CustNum, Name and CreditLimit fields.

Add the following code to the CHOOSE trigger for the button labeled "Print Report" in the SSO:

DEFINE VARIABLE cSDO AS CHARACTER NO-UNDO.
DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cNames AS CHARACTER NO-UNDO.
DEFINE VARIABLE cValues AS CHARACTER NO-UNDO.
DEFINE VARIABLE iColPosition AS INTEGER NO-UNDO EXTENT 3.
DEFINE VARIABLE iEntry AS INTEGER NO-UNDO.
DEFINE VARIABLE hSDO AS HANDLE NO-UNDO.

ASSIGN cSDO = DYNAMIC-FUNCTION("linkHandles", "Print-Source")
hSDO = WIDGET-HANDLE(cSDO).

IF VALID-HANDLE(hSDO) = FALSE THEN
DO:
MESSAGE "No 'Print' Link Found" VIEW-AS ALERT-BOX.
RETURN NO-APPLY.
END.

ASSIGN cNames = DYNAMIC-FUNCTION("getDataColumns" IN hSDO).

DO iEntry = 1 TO NUM-ENTRIES(cNames):
ASSIGN cName = ENTRY(iEntry,cNames).
CASE cName:
WHEN "CustNum" THEN ASSIGN iColPosition[1] = iEntry + 1.
WHEN "Name" THEN ASSIGN iColPosition[2] = iEntry + 1.
WHEN "CreditLimit" THEN ASSIGN iColPosition[3] = iEntry + 1.
END CASE.
END.

RUN fetchFirst IN hSDO.

OUTPUT TO SomeFile.TXT.

REPEAT:
ASSIGN cValues = DYNAMIC-FUNCTION("colValues" IN hSDO, cNames).

/* Beginning of Code to Manipulate the Data Values Goes Here */
DISPLAY ENTRY(iColPosition[1],cValues,CHR(1))
ENTRY(iColPosition[2],cValues,CHR(1))
ENTRY(iColPosition[3],cValues,CHR(1)).
/* End of Code to Manipulate the Data Values Goes Here */

IF DYNAMIC-FUNCTION("getQueryPosition" IN hSDO) NE "LastRecord" OR
DYNAMIC-FUNCTION("getQueryPosition" IN hSDO) NE "OnlyRecord" THEN
RUN fetchNext IN hSDO.
ELSE
LEAVE.
END.

OUTPUT CLOSE.
A Progress customer has provided the following code fragment to work around a problem that exists in Versions 9.0A and 9.0B where the fetch* routines are not properly dealing with the situations where there is only zero or one record in the query:

{fn openQuery h_coapplsdo0}.

DEFINE VARIABLE VcPreviousSDORowIdent AS CHARACTER NO-UNDO.

IF {fn getQueryPosition h_coapplsdo0} <> "NoRecordAvailable" THEN
REPEAT:
ASSIGN
VcPreviousSDORowIdent = {fn getRowIdent h_coapplsdo0}
VcAppCode = {fnarg columnStringValue 'coApp_Code'
&nbsp.; h_coapplsdo0}
VcAppDesc = {fnarg columnStringValue 'coApp_Desc'
h_coapplsdo0}
.

/* Start of Code to Manipulate the Data Values Goes Here */

MESSAGE "Current record:" SKIP
VcAppCode SKIP VcAppDesc SKIP(1)
VcPreviousSDORowIdent
VIEW-AS ALERT-BOX.

RUN fetchNext IN h_coapplsdo0.
IF {fn getRowIdent h_coapplsdo0} = VcPreviousSDORowIdent THEN
LEAVE.

END.
ELSE
MESSAGE "No records" VIEW-AS ALERT-BOX.
.