Progress OpenEdge simple utility with input parameter - progress-4gl

I have a .p file and I run it in unix console. and i love it . because it just a simple utility to run. It is simple and helps me learn.
Now I started to get more fancy. I am wondering if I can do an input parameter to a .p file?
this is how I usually run my .p file.
Now if test.p needs 2 parameter .. how do I do it in the .p? and how do I run it in the console?
This is what I have in the test.p and dOrd and dLocation is the input parameter I want.
output to /usr2/appsrv/test/test.txt.
def var dOrd like Ord.Ord.
def var dLocation like Ord.Ord.
find OrdCSRef no-lock where OrdCSRef.Ord = dOrd and OrdCSRef.Loc = dLocation no-error.
if available OrdCSRef then do:
put unformatted OrdCSRef.CSOrdRef skip.
end.
else
put unformatted "Create CSOrdRef" skip.
end.
output close.
I have tried the following syntax in the unix console. but obviously it will not work.

INPUT parameters is what you are looking for. Change test.p as follows and then run it as "RUN /usr2/appsrv/test/test.p ("ARG1", "ARG2")"
output to /usr2/appsrv/test/test.txt.
def input parameter dOrd like Ord.Ord.
def input parameter dLocation like Ord.Ord.
find OrdCSRef no-lock where OrdCSRef.Ord = dOrd and OrdCSRef.Loc = dLocation no-error.
if available OrdCSRef then do:
put unformatted OrdCSRef.CSOrdRef skip.
end.
else
put unformatted "Create CSOrdRef" skip.
end.
output close.

Related

How to run a single macro for all xls/xlsx files for libreoffice

Is it possible to run a single macro for all xls/xlsx files and if so how. The macro shown below scales the excel file to fit to single page which is necessary as the number of columns is 19 and is needed to convert it to pdf using lo cli.
Libre office version: 6.0.6
Macro has been recorded with libreoffice and can be seen below:
REM ***** BASIC *****
sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
vrem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:PageFormatDialog", "", 0, Array())
end sub
Please let me know if any info is needed regarding the tests.
Got the answer from one of the developers at Libreoffice and it works like a charm, so sharing it here. The link to the answer can be found here
Mike's Solution
First: your recorded macro wouldn't work: it doesn't apply changes, it just opens a dialog. Please always test recorded macros :-)
You may use this macro instead:
Sub FitToPage
Dim document As Object, pageStyles As Object
document = ThisComponent
pageStyles = document.StyleFamilies.getByName("PageStyles")
For i = 0 To document.Sheets.Count - 1
Dim sheet As Object, style As Object
sheet = document.Sheets(i)
style = pageStyles.getByName(sheet.PageStyle)
style.ScaleToPagesX = 1
Next
On Error Resume Next
document.storeSelf(Array())
document.close(true)
End Sub
It operates on the current document, and after setting the scale, it saves (overwrites!) and closes the document.
To use this macro from a command line, you need to save it to some of libraries, e.g. Standard. In my example below, I use Module1 to store it.
You may use this macro on a single document like this:
'path/to/LibreOffice/program/soffice' path/to/excelfile.ext macro:///Standard.Module1.FitToPage
To use it on multiple documents, you need to make this in a loop (mentioning multiple filenames as arguments to a single soffice invocation, like with shell globbing on Linux using *, will not work - actually, it will only run the macro for the last document, keeping the others open and unmodified). A loop for Windows could be like this:
for %f in (*.xls) do start /wait "" "C:\Program Files\LibreOffice\program\soffice.exe" "%f" macro:///Standard.Module1.FitToPage

How to copy one text file to another text file with changes (editing df files)

I am fairly new to progress 4gl. I am trying to copy the contents of one df file into another file where I want to copy everything except the areas of the df file. this is what I have so far.
define stream mystream.
input from "C:\OpenEdge\WRK\df file\sample.df".
do while true on endkey undo, leave:
output to "C:\OpenEdge\WRK\df file\test1.df".
end.
output close.
display "finished".
I would first like to copy all the contents of the first df file into another df file, but right now I'm getting a blank file. Please let me know where I am going wrong.
This is what I do:
grep -v AREA < dbname.df > dbname.df2
If you are stuck with on OS that lacks "grep" or if you just have an urge to do it with 4gl code I'd do something like:
define variable lineIn as character no-undo.
input from "dbname.df".
output to "dbname.df2".
repeat:
import unformatted lineIn. /* read the data a whole line at a time */
if lineIn begins " AREA" then next. /* skip lines that start with " AREA" */
put unformatted lineIn skip. /* spit the input line back out */
if lineIn = "" then put unformatted skip(1). /* yes, this is a weird thing */
end.
To copy all the contents of first df file to another df file, use this code:
DEFINE VARIABLE TEXT-STRING AS CHARACTER FORMAT "X(76)".
INPUT FROM "C:\OPENEDGE\WRK\CMD-LOG.DF".
OUTPUT TO "C:\OPENEDGE\WRK\MY.DF".
DO WHILE TRUE ON ENDKEY UNDO, LEAVE:
IMPORT UNFORMATTED TEXT-STRING.
MESSAGE TEXT-STRING .
END.
INPUT CLOSE.
OUTPUT CLOSE.

Is there a way to tell if a default stream is open?

There is a line in a library that I can't take out:
put oResults format "x(80)" skip.
I have a program that is calling the library that doesn't have a default output so this line errors out.
I know I can just send output in my program somewhere but I want to fix it so you don't have to have a output. Seek function maybe?
EDIT: 10.2b
I only get an error in unix.
In a unix environment this line:
put oResults format "x(80)" skip.
errors out.
but if you put a:
if seek(output) <> ? then
put oResults format "x(80)" skip.
it doesn't error.
in a unix environment line:
put oResults format "x(80)" skip.
errors out.
but if you put a:
if seek(output) <> ? then
put oResults format "x(80)" skip.
it doesn't error.
You are running in batch mode. You should always be redirecting your output at the OS level when you run in batch mode. Something like this:
bpro -p test.p > errors.out 2>&1
Not redirecting output will pretty much always lead to the error that you are seeing.
If you are embedding the bpro, mbpro or _progres -b or whatever command in a script that needs to show that output or otherwise work with it you would typically use "cat" or "tail -f" on the output file.

Piping gdalinfo.exe to matlab/octave with system() does not return any output

I am trying to use the system() function to pipe the output of the gdalinfo (version 1.10 x64) utility directly to Matlab/Octave. The function consistently returns status=0, but does not return any output. For example:
[status output] = system('"C:\Program Files\GDAL\gdalinfo.exe" "E:\DATA\image.tif"')
will only return:
status =
0
output =
''
Any idea why no output is returned?
It appears there is something strange about `gdalinfo.exe'. Several people have reported difficulty piping the output of the program to a textfile - see for example http://osgeo-org.1560.x6.nabble.com/GDALINFO-cannot-pipe-to-text-file-td3747928.html
So the first test would be - can you do something like this:
"C:\Program Files\GDAL\gdalinfo.exe" "E:\DATA\image.tif" > myFile.txt
and see whether the file is created and has any content? If it doesn't, it may be that the program is using a different way to produce output (for example, using stderr instead of stdout). If it is possible to get data into a text file but not directly to matlab, I suppose a workaround would be to write to file, then read that file in separately:
tempFile = tempname; % handy built in function to create temporary file name
execCmd = '"C:\Program Files\GDAL\gdalinfo.exe ';
targetFile = '"E:\DATA\image.tif"';
status = system([execCmd targetFile ' > ' tempFile]);
output = textread( tempFile, '%s' );
system(['del ' tempFile);
Now the output variable will be a cell array with one cell per line in the input file.
This works on my Windows machine if I am in the Octave directory:
[status output] = system('ls bin')
I was having the same issue trying to pipe the output from within C#. It turns out that the ECW plugin breaks the capability (I don't know how). If this plugin is not crucial to you, go into the plugins directory and delete gdal_ECWJP2ECW.dll. You should be able to use '>' and other stuff to dump your output to a file.

How to list text files in a directory in Progress 4GL?

I have a folder in c drive,whicn contain 1000 txt file,i want
to get the list of all these txt file. How can i get this list?
Use the OS-DIR() function.
For example:
DEFINE STREAM dirlist.
DEFINE VARIABLE filename AS CHARACTER FORMAT "x(30)" NO-UNDO.
INPUT STREAM dirlist FROM OS-DIR(".").
REPEAT:
IMPORT STREAM dirlist filename.
DISPLAY filename.
END.
INPUT CLOSE.
For example: ipcPath = "C:\temp\
DEFINE INPUT PARAMETER ipcPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE chFiles AS CHARACTER NO-UNDO.
INPUT FROM OS-DIR(ipcPath).
REPEAT:
IMPORT UNFORMATTED chImport NO-ERROR.
DISPLAY chFiles FORMAT "X(75)".
END.
INPUT CLOSE.
chFiles is a spacedelimeted list and contains the filename, the path, and an 'F' or 'D' tag.
I have a directory-tools program which enable a developer to do all kinds of fun things with file systems. You can get the code here: http://communities.progress.com/pcom/docs/DOC-16578