/copy rpgnextlib/qrpglesrc,cp_hspecs h option(*srcstmt:*nodebugio) bnddir('QC2LE':'FREDBP/FREDDIR') * Prototypes /copy rpgnextlib/qrpglesrc,cp_longprs /copy rpgnextlib/qrpglesrc,cp_ifs /copy fredbp/qrpglesrc,cp_protos d writeLine pr like(RC) d lineData 32000a const varying options(*nopass) d addTag pr d tagName 100a const varying d tagValue 32000a const varying d attName 100a const varying options(*nopass) d attValue 100a const varying options(*nopass) d shutDown pr d initialize pr n d getIndent pr 24a varying d writeData pr d BPRSLTXML pr * Arrays and Data Structures d names ds d 20a inz('Pass') d 20a inz('Reschedule') d 20a inz('Fail') d 20a inz('Clear') d 20a inz('Cancel') d 20a inz('Not Justified') d 20a inz('No Violation') d 20a inz('Approved') d 20a inz('Disapproved') d 20a inz('Approved As Noted') d resultDescs 20a dim(10) overlay( names ) d codes ds d 1a inz('P') d 1a inz('R') d 1a inz('F') d 1a inz('C') d 1a inz('X') d 1a inz('J') d 1a inz('V') d 1a inz('A') d 1a inz('D') d 1a inz('N') d resultCodes 1a dim(10) overlay( codes ) * Standalone Fields d fileDesc s 10i 0 inz d Oflag s 10i 0 inz d mode s 10i 0 inz d buffer s 32000a inz( ' ' ) d bufferPtr s * inz( %addr( buffer ) ) d RC s 10i 0 d indent s 2a inz( ' ' ) d indentLevel s 5i 0 d codePage s 10u 0 inz( 819 ) d null s 1a inz( x'00' ) d toStreamFile s 1024a varying d inz( '/masi/results.xml' ) d writeStr s 32000a varying * Constants /copy rpgnextlib/qrpglesrc,cp_const d CRLF c x'0D25' d xmlHeader c const('') d schema c const('' ) d BPRSLTXML pi /free if initialize(); writeData(); endif ; shutDown(); *inlr = *on ; /end-free *------------------------------------------------------------ * initialize routine *------------------------------------------------------------ p initialize b d initialize pi n d noError s n inz( *on ) /free Oflag = O_CREATE + O_RDWR + O_CODEPAGE + O_TRUNC ; mode = S_IRWXU + S_IRWXG + S_IROTH + S_IXOTH ; toStreamFile = toStreamFile + null ; fileDesc = open( %trimr( toStreamFile ) : oflag : mode : codePage ); if fileDesc <> -1 ; RC = close( fileDesc ); if RC <> -1 ; RC = open( %trimr( toStreamFile ) : O_TEXTDATA + O_RDWR ); if RC <> -1 ; writeLine( xmlHeader + CRLF ); writeLine( schema + CRLF ); indentLevel = 1 ; else ; noError = *off ; endif ; endif ; endif ; return noError ; /end-free p initialize e *------------------------------------------------------------ * writeData subroutine - writes the * block in the XML file *------------------------------------------------------------ p writeData b d writeData pi d i s 10i 0 inz /free for i=1 to %elem( resultCodes ); // New writeStr = '' ; writeStr = writeStr + CRLF ; // result detail addTag( 'code' : resultCodes( i ) ); writeStr = writeStr + CRLF ; addTag( 'codeDescription' : %trimr( resultDescs( i ) ) ); writeStr = writeStr + CRLF ; // writeStr = writeStr + '' ; writeStr = writeStr + CRLF ; writeLine( writeStr ); endfor ; return ; /end-free p writeData e *------------------------------------------------------------ * writeLine subproc - writes a line to the current stream * file *------------------------------------------------------------ p writeLine b d writeLine pi like(RC) d lineData 32000a const varying options(*nopass) d RCwrite s like(RC) /free if %parms() = 0 ; buffer = CRLF ; else ; buffer = %trimr( lineData ) + CRLF ; endif ; RCwrite = write( fileDesc : bufferPtr : %len( %trimr( buffer ) ) ); return RCwrite ; /end-free p writeLine e *------------------------------------------------------------ * addTag - creates the tag string and writes it. *------------------------------------------------------------ p addTag b d addTag pi d tagName 100a const varying d tagValue 32000a const varying d attName 100a const varying options(*nopass) d attValue 100a const varying options(*nopass) d tagString s 32000a varying inz /free tagString = '<' + tagName ; if %parms() > 2 ; tagString = tagString + ' ' + attName + '=' + attValue ; endif ; tagString = tagString + '>' + tagValue + '' ; writeStr = writeStr + tagString ; /end-free p addTag e *------------------------------------------------------------ * getIndent - returns the current indent value *------------------------------------------------------------ p getIndent b d getIndent pi 24a varying d spaces s 24a varying d i s 5i 0 /free for i=1 to indentLevel ; spaces = spaces + indent ; endfor ; return spaces ; /end-free p getIndent e *------------------------------------------------------------ * shutDown routine; *------------------------------------------------------------ p shutDown b d shutDown pi /free writeLine( CRLF + '' + CRLF + CRLF + '' + CRLF ); RC = close( fileDesc ); /end-free p shutDown e