Skip to main content

Hello all!

 

I realize this isn't strictly a scripting question, but maybe you could give me advice on a better way to do this than I am now with scripts.

We have about a decades worth of old spooled files I need to delete and while I know there are some tools/commands that can do this, I have not been able to get them to work.

An example would be the DLTOLDSPLF, it only let's me specify files up to 999 days old and on top of that won't recognize where my reports are stored in SPYGLASS.

For now, I have a script that goes through this huge list of files marking everything for a certain year for deletion. 

While it is quick, it is slow in comparison to how many reports we actually have. 

 

My script prompts for 2 digit year, and I have it look for anything below that to be marked for deletion.

I have to do this in batches of roughly 1-2 months worth of reports which translates to maybe 200-300 reports, because AS400 will error out if I let it run too lot marking these reports with a 4 for Delete.

These batches are only as big as I feel when I should stop the script so AS400 does not crash.

I am barely in the mid 2005's when I need to delete all reports before 2012.

Doing it this way will be quite tedious.

 

Here is the script i'm currently using so maybe someone can tell me a better way to script it or if there is some command I can use instead.

It's also worth noting that I am excluding any Reports with PRT064 and PRT065.

 

 

Sub Main
'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************
Dim DT as String, MR as String, CF as String, RetC as Integer, NA as String, N as String
Dim User_Name as String, WWR as String, YR as String, EX as String, NP as String, ND as String
SysHide "Timer"
EMConnect "Z"
'*****************************************************************************************************
' Prompt For Year
'*****************************************************************************************************
Title$ = "Filter"
Prompt$ = "Please Type 2 Year For Query"
Default$ = ""
X% = 100
Y% = 100
N = InputBox(Prompt$, Title$, Default$, X%, Y%)
'*****************************************************************************************************
' Main
'*****************************************************************************************************
Do
For i = 9 to 19
EMReadScreen MR, 4, 20, 72
EMReadScreen DT, 2, i, 68
EMReadScreen EX, 7, i, 7
If UCase(MR) = "More" and UCase(DT) < N then
GoSub Check
EMSendkey "<PAGE_DOWN>"
Else
Exit Do
End if
Next i
Loop

Exit Sub
'*****************************************************************************************************
' Subroutine to Check for Expired Spooled Files
'*****************************************************************************************************
Check:
For i = 9 to 19
EMReadScreen DT, 2, i, 68
EMReadScreen NA, 6, i, 7
EMReadScreen EX, 6, i, 7
If UCase(DT) < N and UCase(EX) = "PRT064" or UCase(NA) = "PRT065" then
EMWaitX 1, RetC
Elseif UCase(DT) < N then
EMSetCursor i, 4
EMWaitX 1, RetC
EMSendkey "4"
EMWaitX 1, RetC
End if
Next i
Return
'*****************************************************************************************************
' End
'*****************************************************************************************************
End Sub


#Rumba

Hello all!

 

I realize this isn't strictly a scripting question, but maybe you could give me advice on a better way to do this than I am now with scripts.

We have about a decades worth of old spooled files I need to delete and while I know there are some tools/commands that can do this, I have not been able to get them to work.

An example would be the DLTOLDSPLF, it only let's me specify files up to 999 days old and on top of that won't recognize where my reports are stored in SPYGLASS.

For now, I have a script that goes through this huge list of files marking everything for a certain year for deletion. 

While it is quick, it is slow in comparison to how many reports we actually have. 

 

My script prompts for 2 digit year, and I have it look for anything below that to be marked for deletion.

I have to do this in batches of roughly 1-2 months worth of reports which translates to maybe 200-300 reports, because AS400 will error out if I let it run too lot marking these reports with a 4 for Delete.

These batches are only as big as I feel when I should stop the script so AS400 does not crash.

I am barely in the mid 2005's when I need to delete all reports before 2012.

Doing it this way will be quite tedious.

 

Here is the script i'm currently using so maybe someone can tell me a better way to script it or if there is some command I can use instead.

It's also worth noting that I am excluding any Reports with PRT064 and PRT065.

 

 

Sub Main
'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************
Dim DT as String, MR as String, CF as String, RetC as Integer, NA as String, N as String
Dim User_Name as String, WWR as String, YR as String, EX as String, NP as String, ND as String
SysHide "Timer"
EMConnect "Z"
'*****************************************************************************************************
' Prompt For Year
'*****************************************************************************************************
Title$ = "Filter"
Prompt$ = "Please Type 2 Year For Query"
Default$ = ""
X% = 100
Y% = 100
N = InputBox(Prompt$, Title$, Default$, X%, Y%)
'*****************************************************************************************************
' Main
'*****************************************************************************************************
Do
For i = 9 to 19
EMReadScreen MR, 4, 20, 72
EMReadScreen DT, 2, i, 68
EMReadScreen EX, 7, i, 7
If UCase(MR) = "More" and UCase(DT) < N then
GoSub Check
EMSendkey "<PAGE_DOWN>"
Else
Exit Do
End if
Next i
Loop

Exit Sub
'*****************************************************************************************************
' Subroutine to Check for Expired Spooled Files
'*****************************************************************************************************
Check:
For i = 9 to 19
EMReadScreen DT, 2, i, 68
EMReadScreen NA, 6, i, 7
EMReadScreen EX, 6, i, 7
If UCase(DT) < N and UCase(EX) = "PRT064" or UCase(NA) = "PRT065" then
EMWaitX 1, RetC
Elseif UCase(DT) < N then
EMSetCursor i, 4
EMWaitX 1, RetC
EMSendkey "4"
EMWaitX 1, RetC
End if
Next i
Return
'*****************************************************************************************************
' End
'*****************************************************************************************************
End Sub


#Rumba
Rather than scripting a terminal session, I think you'd be much better off writing a CL program to do this.

Unfortunately it's been many years since I wrote any CL, or did any significant AS/400 or System i development. I'll try to dig up some of my old CL code.

Hello all!

 

I realize this isn't strictly a scripting question, but maybe you could give me advice on a better way to do this than I am now with scripts.

We have about a decades worth of old spooled files I need to delete and while I know there are some tools/commands that can do this, I have not been able to get them to work.

An example would be the DLTOLDSPLF, it only let's me specify files up to 999 days old and on top of that won't recognize where my reports are stored in SPYGLASS.

For now, I have a script that goes through this huge list of files marking everything for a certain year for deletion. 

While it is quick, it is slow in comparison to how many reports we actually have. 

 

My script prompts for 2 digit year, and I have it look for anything below that to be marked for deletion.

I have to do this in batches of roughly 1-2 months worth of reports which translates to maybe 200-300 reports, because AS400 will error out if I let it run too lot marking these reports with a 4 for Delete.

These batches are only as big as I feel when I should stop the script so AS400 does not crash.

I am barely in the mid 2005's when I need to delete all reports before 2012.

Doing it this way will be quite tedious.

 

Here is the script i'm currently using so maybe someone can tell me a better way to script it or if there is some command I can use instead.

It's also worth noting that I am excluding any Reports with PRT064 and PRT065.

 

 

Sub Main
'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************
Dim DT as String, MR as String, CF as String, RetC as Integer, NA as String, N as String
Dim User_Name as String, WWR as String, YR as String, EX as String, NP as String, ND as String
SysHide "Timer"
EMConnect "Z"
'*****************************************************************************************************
' Prompt For Year
'*****************************************************************************************************
Title$ = "Filter"
Prompt$ = "Please Type 2 Year For Query"
Default$ = ""
X% = 100
Y% = 100
N = InputBox(Prompt$, Title$, Default$, X%, Y%)
'*****************************************************************************************************
' Main
'*****************************************************************************************************
Do
For i = 9 to 19
EMReadScreen MR, 4, 20, 72
EMReadScreen DT, 2, i, 68
EMReadScreen EX, 7, i, 7
If UCase(MR) = "More" and UCase(DT) < N then
GoSub Check
EMSendkey "<PAGE_DOWN>"
Else
Exit Do
End if
Next i
Loop

Exit Sub
'*****************************************************************************************************
' Subroutine to Check for Expired Spooled Files
'*****************************************************************************************************
Check:
For i = 9 to 19
EMReadScreen DT, 2, i, 68
EMReadScreen NA, 6, i, 7
EMReadScreen EX, 6, i, 7
If UCase(DT) < N and UCase(EX) = "PRT064" or UCase(NA) = "PRT065" then
EMWaitX 1, RetC
Elseif UCase(DT) < N then
EMSetCursor i, 4
EMWaitX 1, RetC
EMSendkey "4"
EMWaitX 1, RetC
End if
Next i
Return
'*****************************************************************************************************
' End
'*****************************************************************************************************
End Sub


#Rumba

OK, found some old CL, which took a member with a list of filenames and looped over it, copying each file to a destination library. Your program would delete the file rather than copying it. You could add the logic to skip over the files you want to keep (PRT064 and PTR065).

Here's an outline:

  1. You want to get a list of the files to be deleted into a member of a datafile, one per record (line). I think you can do that with a LISTF command.
  2. You declare the input member (list of files to delete) with a DCLF command. My program was actually run by another program which would find the member containing the list, then use the OVRDBF command to assign the name "LISTFILE" to it; so in my program this just appears as DCLF(LISTFILE) followed by DCL &LISTFILE *CHAR 10 to define the record. You could put the OVRDBF in the same program, like this:

    OVRDBF FILE(LISTFILE) TOFILE(SOMELIB/SOMEFILE) MBR(SOMEMBR)
    DCLF(LISTFILE)
    DCL &LISTFILE *CHAR 10
  3. A loop processes the records in the input file (which lists the files you want to delete). Sample code below.

 NEXT:       RCVF /* Get next record */
             MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF)) /* Handle end of file */

             /* Process this record (name of file to copy) */
          /* SNDUSRMSG  MSG('LISTFILE is ' || &LISTFILE) MSGTYPE(*INFO) */

             /* Skip certain files */
             IF         COND((&LISTFILE = "PRT064") *OR (&LISTFILE = "PRT065"))
                        THEN(GOTO CMDLBL(NEXT))

             /* Delete file */
             DLTF FILE(SOMELIB/&LISTFILE)

             /* Continue with next file */
             GOTO CMDLBL(NEXT)

EOF:         ENDPGM

Please note that's untested. Use with caution. In particular, you might want to try a SNDUSRMSG in place of the actual DLTF on a trial run, to make sure the commands are correct.

CL programs are executed with the CALL command (unless you create a new command to run them, and there's no reason to do that in this case).


Hello all!

 

I realize this isn't strictly a scripting question, but maybe you could give me advice on a better way to do this than I am now with scripts.

We have about a decades worth of old spooled files I need to delete and while I know there are some tools/commands that can do this, I have not been able to get them to work.

An example would be the DLTOLDSPLF, it only let's me specify files up to 999 days old and on top of that won't recognize where my reports are stored in SPYGLASS.

For now, I have a script that goes through this huge list of files marking everything for a certain year for deletion. 

While it is quick, it is slow in comparison to how many reports we actually have. 

 

My script prompts for 2 digit year, and I have it look for anything below that to be marked for deletion.

I have to do this in batches of roughly 1-2 months worth of reports which translates to maybe 200-300 reports, because AS400 will error out if I let it run too lot marking these reports with a 4 for Delete.

These batches are only as big as I feel when I should stop the script so AS400 does not crash.

I am barely in the mid 2005's when I need to delete all reports before 2012.

Doing it this way will be quite tedious.

 

Here is the script i'm currently using so maybe someone can tell me a better way to script it or if there is some command I can use instead.

It's also worth noting that I am excluding any Reports with PRT064 and PRT065.

 

 

Sub Main
'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************
Dim DT as String, MR as String, CF as String, RetC as Integer, NA as String, N as String
Dim User_Name as String, WWR as String, YR as String, EX as String, NP as String, ND as String
SysHide "Timer"
EMConnect "Z"
'*****************************************************************************************************
' Prompt For Year
'*****************************************************************************************************
Title$ = "Filter"
Prompt$ = "Please Type 2 Year For Query"
Default$ = ""
X% = 100
Y% = 100
N = InputBox(Prompt$, Title$, Default$, X%, Y%)
'*****************************************************************************************************
' Main
'*****************************************************************************************************
Do
For i = 9 to 19
EMReadScreen MR, 4, 20, 72
EMReadScreen DT, 2, i, 68
EMReadScreen EX, 7, i, 7
If UCase(MR) = "More" and UCase(DT) < N then
GoSub Check
EMSendkey "<PAGE_DOWN>"
Else
Exit Do
End if
Next i
Loop

Exit Sub
'*****************************************************************************************************
' Subroutine to Check for Expired Spooled Files
'*****************************************************************************************************
Check:
For i = 9 to 19
EMReadScreen DT, 2, i, 68
EMReadScreen NA, 6, i, 7
EMReadScreen EX, 6, i, 7
If UCase(DT) < N and UCase(EX) = "PRT064" or UCase(NA) = "PRT065" then
EMWaitX 1, RetC
Elseif UCase(DT) < N then
EMSetCursor i, 4
EMWaitX 1, RetC
EMSendkey "4"
EMWaitX 1, RetC
End if
Next i
Return
'*****************************************************************************************************
' End
'*****************************************************************************************************
End Sub


#Rumba
Thank you Michael, while I believe this could put me on the right track, it looks like this program would need to have the file names to be delete manually entered correct?
If that's the case, we have far too many files to name them off one by one.
Perhaps there is something like this, but delete by creation date instead?
Also, the only reason i'm currently skipping reports PRT064 and PRT065, is because I lack the access to delete them at the moment which is currently being looked into.

I do thank you for you for your input though.

Hello all!

 

I realize this isn't strictly a scripting question, but maybe you could give me advice on a better way to do this than I am now with scripts.

We have about a decades worth of old spooled files I need to delete and while I know there are some tools/commands that can do this, I have not been able to get them to work.

An example would be the DLTOLDSPLF, it only let's me specify files up to 999 days old and on top of that won't recognize where my reports are stored in SPYGLASS.

For now, I have a script that goes through this huge list of files marking everything for a certain year for deletion. 

While it is quick, it is slow in comparison to how many reports we actually have. 

 

My script prompts for 2 digit year, and I have it look for anything below that to be marked for deletion.

I have to do this in batches of roughly 1-2 months worth of reports which translates to maybe 200-300 reports, because AS400 will error out if I let it run too lot marking these reports with a 4 for Delete.

These batches are only as big as I feel when I should stop the script so AS400 does not crash.

I am barely in the mid 2005's when I need to delete all reports before 2012.

Doing it this way will be quite tedious.

 

Here is the script i'm currently using so maybe someone can tell me a better way to script it or if there is some command I can use instead.

It's also worth noting that I am excluding any Reports with PRT064 and PRT065.

 

 

Sub Main
'*****************************************************************************************************
' Set Variables
'*****************************************************************************************************
Dim DT as String, MR as String, CF as String, RetC as Integer, NA as String, N as String
Dim User_Name as String, WWR as String, YR as String, EX as String, NP as String, ND as String
SysHide "Timer"
EMConnect "Z"
'*****************************************************************************************************
' Prompt For Year
'*****************************************************************************************************
Title$ = "Filter"
Prompt$ = "Please Type 2 Year For Query"
Default$ = ""
X% = 100
Y% = 100
N = InputBox(Prompt$, Title$, Default$, X%, Y%)
'*****************************************************************************************************
' Main
'*****************************************************************************************************
Do
For i = 9 to 19
EMReadScreen MR, 4, 20, 72
EMReadScreen DT, 2, i, 68
EMReadScreen EX, 7, i, 7
If UCase(MR) = "More" and UCase(DT) < N then
GoSub Check
EMSendkey "<PAGE_DOWN>"
Else
Exit Do
End if
Next i
Loop

Exit Sub
'*****************************************************************************************************
' Subroutine to Check for Expired Spooled Files
'*****************************************************************************************************
Check:
For i = 9 to 19
EMReadScreen DT, 2, i, 68
EMReadScreen NA, 6, i, 7
EMReadScreen EX, 6, i, 7
If UCase(DT) < N and UCase(EX) = "PRT064" or UCase(NA) = "PRT065" then
EMWaitX 1, RetC
Elseif UCase(DT) < N then
EMSetCursor i, 4
EMWaitX 1, RetC
EMSendkey "4"
EMWaitX 1, RetC
End if
Next i
Return
'*****************************************************************************************************
' End
'*****************************************************************************************************
End Sub


#Rumba

No, I meant you should use some mechanism to generate the list of filenames programmatically. The whole point was to get away from trying to select the files manually or by screen-scraping.

I thought there was some CL command with a name like "LISTF" that would generate a list of files according to some criteria, but I've been skimming the i documentation and apparently I imagined it.

I think you could do a DSPLIB with output to *PRINT and then write a simple program to extract the file names from the spooled output file, or simply write a program using the appropriate APIs to generate the filename list.

Hmm. Doing some more digging... a better approach to generate the list of files might be something like:

DSPFD FILE(SOMELIB/*ALL) TYPE(*BASATR) OUTPUT(*OUTFILE) OUTFILE(MYLIB/MYPF)

The generated file member (the first member in the file specified by OUTFILE) will have more in it than just filenames, so you'll have to change the script from my previous post to accommodate its format.

One of the major benefits of scripting this, in addition to working around problems with screen-scraping, is that it's repeatable (you can use it again) and can be documented. Documented, repeatable administration processes are always better than ad hoc ones.