Skip to content

Instantly share code, notes, and snippets.

@phpdave
Last active February 16, 2020 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave/a8c2c3128c1afd1aaecc to your computer and use it in GitHub Desktop.
Save phpdave/a8c2c3128c1afd1aaecc to your computer and use it in GitHub Desktop.
IBMi convert file members to stream files for git 1) Create Physical File triggers on the libraries you want to monitor 2) Triggers run ConvertAllMembersToStreamFiles.PGM which runs 3) CopyMembersToStreamFiles.php which is a PHP script that runs through an array of file members to run through CPYTOSTMF
CALL PGM(QP2SHELL) PARM('/usr/local/zendsvr/bin/php-cli batchphp/CopyMembersToStreamFiles.php')
<?
$lib = "MYLIB"; //The library the file members are in
$file = "QRPLESRC"; // The file the file members are in
$outfile = "$lib/ALLMEMBERS"; // The output file that contains all the members of $lib/$file after the DSPFD command is ran
$membersArray = array();
//Comment line below if you want to hardcorde the members you want to pull
//$membersArray = array('MyMember1','MyMember2','MyMember3');
//Below will take all members under $lib/$file and put it into the output file $lib/$outfile
//::Alternative:: user OVRDBF or Create Alias over every member file http://www-01.ibm.com/support/docview.wss?uid=nas8N1018261
$toolkit->runCL("DSPFD FILE( $lib/$file ) TYPE( *MBR ) OUTPUT(*OUTFILE) OUTFILE( $lib/$outfile )");
//read the outputfile to get the file members
$outfilecontent = readfile("$lib/$outfile");
//parse $outfilecontent to get all the members in $file
foreach($outfilecontent as $line) {
$membersArray[] = $line ;
}
//PHP IBMi toolkit that lets you call CL
$toolkit = new IBMiToolkit();
//loop through each file member and copy it to a stream file using CPYTOSTMF
foreach($membersArray as $srcmember)
{
$toolkit->runCL("CPYTOSTMF FROMMBR('/QSYS.LIB/$lib.LIB/$file.FILE/$srcmember.MBR') TOSTMF('$srcmember.TXT') STMFCCSID(1208)");
}
// Ending message that the process has worked and completed.
echo "I'm done copying Source Members to stream files";
ADDPFTRG FILE(MYLIB/QRPLESRC) TRGTIME(*AFTER) TRGEVENT(*INSERT) PGM(MYLIB/ConvertAllMembersToStreamFiles)
ADDPFTRG FILE(MYLIB/QRPLESRC) TRGTIME(*AFTER) TRGEVENT(*UPDATE) PGM(MYLIB/ConvertAllMembersToStreamFiles)
@nurettin
Copy link

This may copy files to disk when a program is saved. But how do you push the program back to IBMi when it is changed on the disk (e.g. after merging someone else's changes with yours)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment