× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



hi Jim,

The big problem:

1) You're passing an input parameter longer than 32 chars to your program from the command-line. Unless appropriate precautions are taken, this will result in reading memory that doesn't belong to you. (i.e. garbage in parameter)


Small problem:

2) Although you've coded options(*string) on the prototype (as you should) you're still MANUALLY null-terminatng the string, and passing it's address. Thus, you've said "hey RPG, null-terminate it for me!" then you're turning that off, and doing it by hand. It won't stop it from working, but it looks stupid, and requires extra pointless code in your program.



On 10/1/2010 1:40 PM, Jim Minisce wrote:
It's Friday and I am brain dead. I am sure I am overlooking something but I
do not see it at this point and would appreciate a second set of eyes. My goal
is to test the IFS for file existence and increment the file name if a file
exists in a directory. In this scenario, I know the file exists in the IFS and
I have full rights to the file but the program returns a not found value. Below
is the relevant code in question. I am testing the program with the following
call statement:
call MYPRGM300 parm('/home/gd290jem/PlmExtract.Dat').

Any help would be greatly appreciated.

Jim Minisce
Godiva Chocolatier, Inc

********************************************************************
*
* Program Parameters
*
********************************************************************
*
*
D MYPRGM300 Pr Extpgm('MYPRGM300')
D File_Path 45a Const
*
D MYPRGM300 Pi
D File_Path 45a Const
********************************************************************
*
* API to test for IFS file existance
*
D access Pr 10i 0 extProc('access')
D ptrIFSFile * value Options(*String)
D AccessMode 10i 0 Const
*

D F_OK C Const(0)

*
* Global program variables
*
D mode S 10u 0
D File_Extension S 15a Varying Inz
D POS1 S 5i 0 Inz
D POS2 S 5i 0 Inz
D WriteFilePath S 100a Inz
D WriteFileName S 100a Inz
D Counter S 5i 0 Inz
D Underscore C CONST('_')
D Period C CONST('.')

****************************************************************
* Mainline
****************************************************************
*
/Free

WriteFilePath = %TrimR(File_Path);
WriteFileName = %TrimR(WriteFilePath) + x'00';

// Check for file existence, if the file exists, a zero is
returned.
// If file already exists, increment File_Extension variable so
only
// unique file names are generated. Ex. If file FileName.csv
already
// exists, then set file name to FileName_01.csv and re-test for
existance.
// Keep doing that till a unique name if found.

Dou 1<> 1;
If access(%addr(WriteFileName) : F_OK) = *Zero;
POS1 = %Scan(Period:WriteFilePath);
POS2 = %Scan(Underscore:WriteFilePath);
If POS1> 1 and POS2 = *Zero;
File_Extension = %Subst(%TrimR(WriteFilePath):POS1);
WriteFilePath = %Subst(WriteFilePath:1:POS1 -1);
Endif;
If POS1> 1 and POS2> 1;
File_Extension = %Subst(%TrimR(WriteFilePath):POS1);
WriteFilePath = %Subst(WriteFilePath:1:POS2 -1);
Endif;
Counter += 1;
WriteFilePath = %TrimR(WriteFilePath) + Underscore +
%Editc(Counter:'X') + File_Extension;
WriteFileName = %TrimR(WriteFilePath) + x'00';
Else;
Leave;
Endif;
Enddo;

/End-Free






As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.