DEFINE VARIABLE cExpression AS CHARACTER NO-UNDO.
DEFINE VARIABLE c-cgc AS CHARACTER NO-UNDO.
assign c-cgc = "99.999.999/9999-99".
find first estabelec no-lock no-error.
ASSIGN cExpression = "IF 2 + 2 = 4 THEN '1' ELSE '2'". DISP cExpression.
/*OTHERS*/
ASSIGN cExpression = "STRING(string(estabelec.cep),'99999-999')".
ASSIGN cExpression = "c-cgc".
/* How to display 1 or 2 instead --> "IF 2 + 2 = 4 THEN '1' ELSE '2'" */
Remove the quotes around it. If you add quotes, that becomes a string and not an expressions.
ASSIGN cExpression = IF 2 + 2 = 4 THEN '1' ELSE '2'. DISP cExpression.
For the second one, you don't need to call STRING twice.
ASSIGN cExpression = STRING(estabelec.cep,'99999-999')
ASSIGN cExpression = c-cgc.
I can not do it this way because this information is in a table from/to....
Output the dynamic code to a file, and then RUN that file...
Running a non-pre-compiled file will depend on the license available.
Sorry for not putting all the information as suggested by Mr. Maher, I can not generate file and then run by the client version will not run.
Perhaps we could be of more assistance if you would try to describe your original problem in words. The code you posted appears to be a portion of some sort of solution but we do not know to what problem.
> On Dec 16, 2015, at 11:10 AM, savoine wrote:
>
> Update from Progress Community [https://community.progress.com/]
>
> savoine [https://community.progress.com/members/savoine]
>
> Sorry for not putting all the information as suggested by Mr. Maher, I can not generate file and then run by the client version will not run.
>
> View online [https://community.progress.com/community_groups/openedge_development/f/19/p/22027/77317#77317]
>
> You received this notification because you subscribed to the forum. To unsubscribe from only this thread, go here [https://community.progress.com/community_groups/openedge_development/f/19/t/22027/mute].
>
> Flag [https://community.progress.com/community_groups/openedge_development/f/19/p/22027/77317?AbuseContentId=40f10d10-1381-4cae-899f-c2ac9a25fcd0&AbuseContentTypeId=f586769b-0822-468a-b7f3-a94d480ed9b0&AbuseFlag=true] this post as spam/abuse.
Look at this knowledgebase article -> knowledgebase.progress.com/.../P39990
EQN is a language made to be run in the Progress ABL. It was written before Brians Maher's answer above, but it includes symbolic mathematics that can be coded.
It does NOT use "compile on the fly."
It is open source by me... the API is easy to use as shown below, but the internals are pretty knarly. Just be warned.
Sample code:
/* Insert formulas. Note these ARE strings for numbers. */
RUN AddFormula.p (INPUT “@Revenue”, INPUT “10000.00”).
RUN AddFormula.p (INPUT “@Expenses”, INPUT “5000.00”).
RUN AddFormula.p (INPUT “@NetProfit”, INPUT “(@Revenue - @Expenses) / 90”).
/* Compute out a formula with Calc.p */
RUN Calc.p (“@NetProfit”, OUTPUT cResult).
/* cResult should be 55.55555 */
and
/* Enter the expression to evaluate into a string */
ASSIGN cT = “(2 + 3) * 4”.
/* Call into EQN to evaluate via the Calc.p API */
RUN Calc.p (INPUT cT, OUTPUT cR).
/* Convert the result from CHAR to DECIMAL or INTEGER */
ASSIGN dR = DECIMAL (cR).
DEF TEMP-TABLE tt-report FIELD i-id AS INT FIELD i-line AS INT FIELD c-text AS CHAR. DEF TEMP-TABLE tt-client FIELD c-name AS CHAR FIELD c-address AS CHAR FIELD c-cep AS CHAR FIELD i-type AS INT. DEF TEMP-TABLE tt-param FIELD c-from AS CHAR FIELD c-to AS CHAR. DEF VAR i-number AS INTEGER NO-UNDO. ASSIGN i-number = 12345. CREATE tt-report. ASSIGN tt-report.i-id = 1 tt-report.i-line = 1 tt-report.c-text = "CLIENT: #client#, Number: #number#, CEP: #cep#". CREATE tt-report. ASSIGN tt-report.i-id = 1 tt-report.i-line = 2 tt-report.c-text = "Type for this client is #type#". /***************************************************************************/ CREATE tt-client. ASSIGN tt-client.c-name = 'Eduardo' tt-client.c-address = 'Av. Brasil, 235' tt-client.c-cep = '15500000' tt-client.i-type = 1. /***************************************************************************/ CREATE tt-param. ASSIGN tt-param.c-from = "#client#" tt-param.c-to = "tt-client.c-name". CREATE tt-param. ASSIGN tt-param.c-from = "#number#" tt-param.c-to = "i-number". CREATE tt-param. ASSIGN tt-param.c-from = "#cep#" tt-param.c-to = "STRING(tt-client.c-cep,'99.999-999')". CREATE tt-param. ASSIGN tt-param.c-from = "#type#" tt-param.c-to = "IF tt-client.i-type = 1 THEN 'INFORMATION1' ELSE 'INFORMATION2'". /**************************************************************************/ /**** WHERE tt-report - Rows of a report table. tt-client - Data from my client. tt-param - Table from/to the variables useds into report table rows. i-number - any variable In this example I have only one client table but the report may be linked to other tables. ****/ FIND FIRST tt-client NO-ERROR. FOR EACH tt-report WHERE tt-report.i-id = 1: FOR EACH tt-param: /* REPLACE values c-from to c-to */ END. /* DISPLAY RESULT */ END. /* I hope it has become clear my intention */
Almost ready the problem lies in variables into arquivo.p
DEF TEMP-TABLE tt-nf FIELD c-estab AS CHAR FIELD c-serie AS CHAR FIELD c-nr-nota AS CHAR FIELD i-client AS INT. DEF TEMP-TABLE tt-client FIELD i-id AS INT FIELD c-name AS CHAR FIELD c-address AS CHAR FIELD c-cep AS CHAR FIELD c-bairro AS CHAR FIELD i-type AS INT. DEF TEMP-TABLE tt-report FIELD i-id AS INT FIELD i-line AS INT FIELD c-text AS CHAR. DEF TEMP-TABLE tt-param FIELD i-tipo AS INT FIELD c-from AS CHAR FIELD c-to AS CHAR. DEF VAR i-number AS INTEGER NO-UNDO. DEF VAR c-text AS CHAR NO-UNDO. ASSIGN i-number = 12345 c-text = 'xxxxx'. CREATE tt-nf. ASSIGN tt-nf.c-estab = '03' tt-nf.c-serie = '1' tt-nf.c-nr-nota = '0099612' tt-nf.i-client = 10. /***************************************************************************/ CREATE tt-client. ASSIGN tt-client.i-id = 10 tt-client.c-name = 'Eduardo' tt-client.c-address = 'Av. Brasil, 235' tt-client.c-cep = '15500000' tt-client.c-bairro = 'TEST TRIM ' tt-client.i-type = 1. /***************************************************************************/ CREATE tt-report. ASSIGN tt-report.i-id = 1 tt-report.i-line = 1 tt-report.c-text = "Client: #client#, Number: #number#". CREATE tt-report. ASSIGN tt-report.i-id = 1 tt-report.i-line = 2 tt-report.c-text = "District: #bairro#, CEP: #cep#". CREATE tt-report. ASSIGN tt-report.i-id = 1 tt-report.i-line = 3 tt-report.c-text = "Type #text# for this client is #type#". /***************************************************************************/ CREATE tt-param. ASSIGN tt-param.i-tipo = 1 tt-param.c-from = "#client#" tt-param.c-to = "tt-client.c-name". CREATE tt-param. ASSIGN tt-param.i-tipo = 3 tt-param.c-from = "#number#" tt-param.c-to = "i-number". CREATE tt-param. ASSIGN tt-param.i-tipo = 3 tt-param.c-from = "#text#" tt-param.c-to = "c-text". CREATE tt-param. ASSIGN tt-param.i-tipo = 2 tt-param.c-from = "#cep#" tt-param.c-to = "STRING(tt-client.c-cep,'99.999-999')". CREATE tt-param. ASSIGN tt-param.i-tipo = 2 tt-param.c-from = "#bairro#" tt-param.c-to = "TRIM(tt-client.c-bairro)". CREATE tt-param. ASSIGN tt-param.i-tipo = 2 tt-param.c-from = "#type#" tt-param.c-to = "IF tt-client.i-type = 1 THEN 'INFORMATION1' ELSE 'INFORMATION2'". /**************************************************************************/ /**** WHERE tt-report - Rows of a report table. tt-client - Data from my client. tt-param - Table from/to the variables useds into report table rows. i-number - any variable In this example I have only one client table but the report may be linked to other tables. ****/ DEF VAR bh-nf AS HANDLE NO-UNDO. DEF VAR bh-client AS HANDLE NO-UNDO. DEF VAR qh AS HANDLE NO-UNDO. DEF VAR c-consulta AS CHAR NO-UNDO. DEF VAR i-buffers AS INTEGER NO-UNDO. DEF VAR i-fields AS INTEGER NO-UNDO. DEF VAR c-buffer AS CHAR NO-UNDO. DEF VAR c-field AS CHAR NO-UNDO. DEF VAR c-format AS CHAR NO-UNDO. DEF VAR c-result AS CHAR NO-UNDO. DEF VAR d-result AS DECIMAL NO-UNDO. DEF VAR l-result AS LOGICAL NO-UNDO. CREATE BUFFER bh-nf FOR TABLE "tt-nf". CREATE BUFFER bh-client FOR TABLE "tt-client". ASSIGN c-consulta = "FOR EACH tt-nf NO-LOCK " + "WHERE tt-nf.c-estab = '03'" + "AND tt-nf.c-serie = '1'" + "AND tt-nf.c-nr-nota = '0099612'" + "AND tt-nf.i-client = 10, " + "FIRST tt-client NO-LOCK " + "WHERE tt-client.i-id = tt-nf.i-client ". CREATE QUERY qh. qh:SET-BUFFERS(bh-nf, bh-client). qh:QUERY-PREPARE(c-consulta). qh:QUERY-OPEN(). REPEAT: qh:GET-NEXT(). IF qh:QUERY-OFF-END THEN LEAVE. FOR EACH tt-report WHERE tt-report.i-id = 1: FOR EACH tt-param: IF tt-param.i-tipo = 1 THEN DO: tt-report.c-text = REPLACE(tt-report.c-text, tt-param.c-from, qh:GET-BUFFER-HANDLE(ENTRY(1,tt-param.c-to,".")):BUFFER-FIELD(ENTRY(2,tt-param.c-to,".")):BUFFER-VALUE). /*DISP qh:GET-BUFFER-HANDLE(ENTRY(1,tt-param.c-to,".")):BUFFER-FIELD(ENTRY(2,tt-param.c-to,".")):BUFFER-VALUE.*/ END. ELSE IF tt-param.i-tipo = 2 THEN DO: DO i-buffers = 1 TO qh:NUM-BUFFERS: ASSIGN c-buffer = qh:GET-BUFFER-HANDLE(i-buffers):NAME. ASSIGN c-format = tt-param.c-to. DO i-fields = 1 TO qh:GET-BUFFER-HANDLE(i-buffers):NUM-FIELDS: ASSIGN c-field = qh:GET-BUFFER-HANDLE(i-buffers):BUFFER-FIELD(i-fields):NAME. IF INDEX(tt-param.c-to,c-buffer + "." + c-field) > 0 THEN ASSIGN c-format = REPLACE(c-format, c-buffer + "." + c-field, QUOTER(qh:GET-BUFFER-HANDLE(c-buffer):BUFFER-FIELD(c-field):BUFFER-VALUE)). END. /*DISP c-result FORMAT 'x(30)'.*/ /*DISP qh:GET-BUFFER-HANDLE(i-buffers):BUFFER-FIELD(i-fields):BUFFER-VALUE.*/ END. RUN gerar-texto(INPUT c-format). tt-report.c-text = REPLACE(tt-report.c-text, tt-param.c-from, c-result). END. ELSE IF tt-param.i-tipo = 3 THEN DO: RUN gerar-texto(INPUT QUOTER(tt-param.c-to)). tt-report.c-text = REPLACE(tt-report.c-text, tt-param.c-from, c-result). END. END. DISP tt-report.c-text FORMAT 'x(300)' WITH WIDTH 600. END. END. DEFINE TEMP-TABLE tt NO-UNDO /*dummy TT*/ FIELD f1 AS INTEGER. DEF QUERY q FOR tt. /* dummy query, but required */ FUNCTION GetDecimal RETURNS LOGICAL (INPUT dValue AS DECIMAL). d-result = dValue. RETURN TRUE. END FUNCTION. FUNCTION GetChar RETURNS LOGICAL (INPUT cValue AS CHAR). c-result = cValue. RETURN TRUE. END FUNCTION. FUNCTION GetLogical RETURNS LOGICAL (INPUT lValue AS LOGICAL). l-result = lValue. RETURN TRUE. END FUNCTION. PROCEDURE gerar-texto: DEF INPUT PARAMETER pExpression AS CHAR NO-UNDO. ASSIGN c-result = "". QUERY q:QUERY-PREPARE("FOR EACH tt WHERE DYNAMIC-FUNCTION( 'GetChar', " + pExpression + ") = TRUE"). QUERY q:QUERY-OPEN(). QUERY q:QUERY-CLOSE. END PROCEDURE.