Focal Point
[SOLVED] Keep a variable as macro variable

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8547047196

September 30, 2019, 10:35 AM
Kykyn
[SOLVED] Keep a variable as macro variable
Hi,

To begin i would lik eto apologize for my bad English, i try to do my best but sorry for the erros :-).

So, what i want to do don't seem to be difficult, but i didnt have a big formation on focus so to me it's a big problem.

I would like to keep value on a variable i have in a table to use it as a macro variable on the rest of my code.

This is an exemple :

TABLE FILE mytable
PRINT VAR1 VAR2 VAR3
END

How may i keep the value of VAR1 in a macro variable (&mavar) to use it on an other table.

i tried with a define like that :

DEFINE FILE mytable
-SET &MAVAR = VAR1;
END

TABLE FILE mytable
..END

But infortunately, &mavar returne 'VAR1' instead of the value of VAR1.

I hope i am enough clear

Thks a lot for your help!

Cedric

This message has been edited. Last edited by: FP Mod Chuck,


WebFocus 8.2, Windows
September 30, 2019, 10:51 AM
BabakNYC
  
-SET &VAR1='COUNTRY';
TABLE FILE CAR
PRINT CAR
BY &VAR1
END


https://infocenter.information...%2Fsource%2Fdm64.htm


WebFOCUS 8206, Unix, Windows
September 30, 2019, 11:03 AM
MartinY
TABLE FILE myTable
PRINT VAR1 VAR2 VAR3
-* Assuming that myTable only has one record, no need to perform a filter (WHERE) otherwise multiple lines will be returned
WHERE myTable.myFld EQ cond;
ON TABLE HOLD AS TMP
END
-RUN

-READFILE TMP
-RUN
-* TO AVOID VARIABLE'S PROMPTING
-DEFAULTH &VAR1 = ''
-DEFAULTH &VAR2 = ''
-DEFAULTH &VAR3 = ''

TABLE FILE oTable
PRINT ABC
BY XYZ
WHERE oTable.tstFld1 EQ &VAR1;
WHERE oTable.tstFld2 EQ &VAR2;
WHERE oTable.tstFld3 EQ &VAR3;
END
-RUN



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
September 30, 2019, 12:02 PM
FP Mod Chuck
Kykyn

First of all welcome to Focal Point. It is a great place to get answers to your development questions.

If you want these variables to be available to other reports run in the same user session then you will need to use global variarbles with 2 &&'s

-SET &&VAR1 = 'COUNTRY'


Thank you for using Focal Point!

Chuck Wolff - Focal Point Moderator
WebFOCUS 7x and 8x, Windows, Linux All output Formats
October 01, 2019, 02:32 AM
Kykyn
HI,

Thanks a lot for your answers.
But, unfortunately, i think i didnt have explained correctly my problem :-)

So, to begin i have a table in which one i count the number of lines :

TABLE FILE STEP1
SUM CNT.MYVAR
END

I would like to keep the value of my count in a dialogue manager variable, in order to use it later in my code.
For example, we say there is 10 lines in my table STEP1
I need this value to make a loop on an other table.
As there is 10 lines in STEP1, i need to do a 10 times loop...

I hope this time my explanations are clear :-)

Thks
Ced


WebFocus 8.2, Windows
October 01, 2019, 04:34 AM
Kykyn
Finally, after having looking it for a while in the forum, i found what i wanted!!

http://forums.informationbuild...327037906#7327037906

Thks a lot!!


WebFocus 8.2, Windows
October 01, 2019, 05:50 AM
Kykyn
So, Unfortunately, my last answer make me to come back with an other question...

In the beginning of my code i have kept then number of distinct variable (nb of towns)

TABLE FILE TOWNS
SUM
CNT.DST.TOWNS
ON TABLE SAVE
END
-RUN
-READ SAVE &CNT_TOWNS.I9.
-TYPE &CNT_TOWNS

==> i have 5 towns so the value of &CNT_TOWS is 5


And now, i work with another table, which contains the name of roads.
theres are 10 lines in this table with 10 distinct values.

For each of these 10 distinct values, i would having on my final table, 5 lines (&CNT_TOWNS) with the same value (name of road). So i will have finally 50 lines in my table.

I m sure ma ask is not very clear so this is an exemple :

&COD_FED_CNT = 5

Table ROAD
NAME_OF_ROAD
Name1
Name2
Name3
Name4
Name5
Name6
Name7
Name8
Name9
Name10

Table ROAD2 (5 Lines per distinct road)
NAME_OF_ROAD2
Name1
Name1
Name1
Name1
Name1
...
Name10
Name10
Name10
Name10
Name10


I tried to do that with a loop, but i dont know how to write in my table at each loop.

If i do that :

DEFINE FILE ROAD

-SET &CPT=1;
-MALOOP

NAME_OF_ROAD2/A30 = NAME_OF_ROAD;

-SET &CPT=&CPT+1;
-IF (&CPT GT &CNT_TOWNS) THEN GOTO FINLOOP;
-GOTO MALOOP
-FINLOOP

END

TABLE FILE ROAD
PRINT
NAME_OF_ROAD2
END


==> I have only 10 lines because the data are written only at the end of the loop.

thks a lot for your help


WebFocus 8.2, Windows
October 01, 2019, 07:41 AM
MartinY
Yes, it's not clear what you are attempting to perform.

What are you trying to perform :
- have each Road with their Town ?
- repeat each Road's name as many time you have Town ? So, as you stated : you have 5 Towns and 10 Roads so you want 5 X 10 = 50 lines in output.

Can you just JOIN the two tables together ?
If no commun field exist between the two tables, you can JOIN them using a Dummy field such as below

-*-* TMP1 includes up to 5 Countries
TABLE FILE CAR
BY TOTAL COMPUTE DUMMY /I1 = 1;
BY COUNTRY
WHERE RECORDLIMIT EQ 5;
ON TABLE HOLD AS TMP1
END

-*-* TMP2 includes up to 10 Cars
TABLE FILE CAR
BY TOTAL COMPUTE DUMMY /I1 = 1;
BY CAR
WHERE RECORDLIMIT EQ 10;
ON TABLE HOLD AS TMP2
END

-*-* Since TMP1 and TMP2 have no commun field, we use a DUMMY one to create a JOIN and produce cartesian result
JOIN   DUMMY IN TMP1 TAG T1
TO ALL DUMMY IN TMP2 TAG T21 AS J1
END

TABLE FILE TMP1
BY CAR
BY COUNTRY
END
-RUN



As a note : always use the code tag when posting sample code and/or data
It's the last icon on the ribbon that looks like the below
</>



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 01, 2019, 10:37 AM
Kykyn
Yes it was the second choice.

Finally, i did it with a concatenation.

One more time, thks all for your help


WebFocus 8.2, Windows