|
<snip> Does anybody has a sample program that write data to user space? I've written several apps to retrieve data from it but has never try to write data to it. </snip> Here are two examples. One accesses the data in the user space using pointers and the other one using a multiple occurrence data structure. Both of these programs using my User Space API to create and get pointers into the user spaces. I do this to just encapsulate any complexity of using the User Space API's. Anyone wanting a copy of the service program, let me know and I will send it out. Too much to stick in here. Stuff at top is for my make tool available at http://www.think400.dk/downloads. I also have an example available that accesses the object API and ILE program API which both output to user space and then walk through the result. The command is called GETSRCDATA and retrieves the source file name, library and member for both RPG III and RPG IV programs (From modules) and writes to a file for SQL'ing. The rpg code is at the bottom. A lot of code. Most just the data structure definitions. If you want a full copy of the program, let me know. ________________________________________________________________________ _ This version calculates index using pointer math to walk through the list. *_> CNLLSTSPLF SRCFILE(@2/@1) SRCMBR(@3) *_> DLTMOD MODULE(QTEMP/@4) *_> DLTPGM PGM(@5/@4) *_> CRTRPGMOD MODULE(QTEMP/@4) SRCFILE(@2/@1) SRCMBR(@3) + *_> DBGVIEW(@9) OPTIMIZE(@8) INDENT('| ') *_> CRTPGM PGM(@5/@4) MODULE(QTEMP/@4) + *_> ENTMOD(QTEMP/@4) + *_> BNDSRVPGM(XVUSPC XVERRH) ACTGRP(QILE) h /copy *libl/qptypesrc,CB_STD_CON /copy *libl/qptypesrc,cb_StdType /copy *libl/qptypesrc,XVUSPC_PR /copy *libl/qptypesrc,XVERRH_PR d CalculateIndex... d pr Like(StdPtr) d PR_InPointerToBase... d Like(StdPtr) d Value d PR_InCurrentIndex... d Like(StdInt) d Value d PR_InStructureSize... d Like(StdInt) d Value d cUsrSpcNam c const('TESTUSP') d cUsrSpcLib c const('QTEMP') d cText c const('Work User Space') d MessageId... d s Like(StdMsgId) d QMessageFileName... d s Like(StdQNam) d MessageData... d s 1024 Varying d TestDs... d ds Qualified d Based(ptrToTestDs) d Index... d Like(StdInt) d Field01... d Like(StdNam) d Field02... d Like(StdInt) d Field03... d Like(StdChr) d X... d s Like(StdInt) d ptrToBase... d s Like(StdPtr) d Inz(*Null) /Free USPC_CreateUserSpace(cUsrSpcNam : cUsrSpcLib : %Size(TestDs): cTrue : cText : '*ALL' : '*YES' : 5 : '1' ); ptrToBase = USPC_GetPointerToUserSpace(cUsrSpcNam: cUsrSpcLib); For x = 1 to 10000; ptrToTestDs = CalculateIndex(ptrToBase : X : %Size(TestDs)); TestDs.Index = x; TestDs.Field01 = 'My Duck'; TestDs.Field02 = x * 3; TestDs.Field03 = 'X'; EndFor; For x = 1 to 10000; ptrToTestDs = CalculateIndex(ptrToBase : X : %Size(TestDs)); EndFor; USPC_DeleteUserSpace(cUsrSpcNam: cUsrSpcLib); *InLR = *On; Return; /End-Free p CalculateIndex... p b d pi Like(StdPtr) d InPointerToBase... d Like(StdPtr) d Value d InCurrentIndex... d Like(StdInt) d Value d InStructureSize... d Like(StdInt) d Value /Free Return InPointerToBase + ((InCurrentIndex - 1) * InStructureSize); /End-Free p e ________________________________________________________________________ ____ This version using multiple occurrence data structures to walk through the user space. *_> CNLLSTSPLF SRCFILE(@2/@1) SRCMBR(@3) *_> DLTMOD MODULE(QTEMP/@4) *_> DLTPGM PGM(@5/@4) *_> CRTRPGMOD MODULE(QTEMP/@4) SRCFILE(@2/@1) SRCMBR(@3) + *_> DBGVIEW(@9) OPTIMIZE(@8) INDENT('| ') *_> CRTPGM PGM(@5/@4) MODULE(QTEMP/@4) + *_> ENTMOD(QTEMP/@4) + *_> BNDSRVPGM(XVUSPC XVERRH) ACTGRP(QILE) h /copy *libl/qptypesrc,CB_STD_CON /copy *libl/qptypesrc,cb_StdType /copy *libl/qptypesrc,XVUSPC_PR /copy *libl/qptypesrc,XVERRH_PR d cUsrSpcNam c const('TESTUSP') d cUsrSpcLib c const('QTEMP') d cText c const('Work User Space') d MessageId... d s Like(StdMsgId) d QMessageFileName... d s Like(StdQNam) d MessageData... d s 1024 Varying d TestDs... d ds Occurs(32767) d Qualified d Based(ptrToTestDs) d Index... d Like(StdInt) d Field01... d Like(StdNam) d Field02... d Like(StdInt) d Field03... d Like(StdChr) d X... d s Like(StdInt) /Free USPC_CreateUserSpace(cUsrSpcNam : cUsrSpcLib : %Size(TestDs): cTrue : cText : '*ALL' : '*YES' : 5 : '1' ); ptrToTestDs = USPC_GetPointerToUserSpace(cUsrSpcNam: cUsrSpcLib); For x = 1 to 10000; %Occur(TestDs) = x; TestDs.Index = x; TestDs.Field01 = 'My Duck'; TestDs.Field02 = x * 3; TestDs.Field03 = 'X'; EndFor; For x = 1 to 10000; %Occur(TestDs) = x; EndFor; USPC_DeleteUserSpace(cUsrSpcNam: cUsrSpcLib); *InLR = *On; Return; /End-Free ------------------------------------------------------------------------ ---- *_> CNLLSTSPLF SRCFILE(@2/@1) SRCMBR(@3) *_> DLTMOD MODULE(@5/@4) *_> CRTSQLRPGI OBJ(@5/@4) + *_> SRCFILE(@2/@1) SRCMBR(@3) + *_> OBJTYPE(*MODULE) COMMIT(*NONE) OPTION(*EVENTF) + *_> DBGVIEW(*SOURCE) CLOSQLCSR(*ENDACTGRP) + *_> TOSRCFILE(@2/QSQLTEMP1) * --------------------------------------------------------------- * Module.: XV0016_M01 Project.....: * Author.: A. Campin Date written: 12/01/2006 * Purpose: CPP for GETSRCDATA. * --------------------------------------------------------------- * Called by: Command GETSRCDATA * --------------------------------------------------------------- * Revision history: * Project # Pgmr Date Desc * * End Revision History * --------------------------------------------------------------- h Option(*Srcstmt:*Nodebugio) /copy *libl/qsrcf,cb_StdType /copy *libl/qsrcf,cb_Std_Con /copy *libl/qsrcf,cb_Std_Em /copy *libl/qsrcf,cb_Api_Hdr /copy *libl/qsrcf,xverrh_pr /copy *libl/qsrcf,xvuspc_pr d ProgramEntrance... d pr ExtPgm('XVILES') d PR_InLibraryList... d LikeDs(TD_LibraryList) d MainLine... d pr d ProcessILE... d pr d PR_InLibraryName... d Like(StdNam) d Value d ProcessOPM... d pr d PR_InLibraryName... d Like(StdNam) d Value d BuildUserSpace... d pr Like(StdPtr) d WriteRecord... d pr d PR_InSourceRecord... d LikeDs(TD_SourceRecord) d cUserSpaceName... d c 'XVAPIOUT ' d cUserSpaceLibrary... d c 'QTEMP ' d cUserSpaceText... d c 'Output User Space for APIs.' d TD_LibraryList... d ds Qualified d Based(StdNulPtr) d Count... d Like(StdIntSml) d Library... d Like(StdNam) d Dim(10) d TD_SourceRecord... d e ds ExtName(XVSRCLIST) d Qualified d Based(StdNulPtr) d ProgramEntrance... d pi d InLibraryList... d LikeDs(TD_LibraryList) /Free MainLine(); *InLR = *On; Return; /End-Free *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * MainLine * Process list of libraries. * In Parms - None. * In/Out Parms - None. * Out Parms - None. * Return - None *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = p MainLine... p b d pi d x... d s Like(StdInt) c/Exec Sql + Delete From XV_SOURCE_LIST c/End-Exec /Free For x = 1 to InLibraryList.Count; ProcessILE(InLibraryList.Library(x)); ProcessOPM(InLibraryList.Library(x)); EndFor; /End-Free p e *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * ProcessILE * Process all ILE programs for given library. Results are written * to table XV_SOURCE_LIST (XVSRCLIST) for use in querying. * In Parms - Library Name. * In/Out Parms - None. * Out Parms - None. * Return - None *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = p ProcessILE... p b d pi d InLibraryName... d Like(StdNam) d Value d ProgramInformationAPI... d pr ExtPgm('QBNLPGMI') d PR_UserSpaceName... d Like(StdQNam) d Const d PR_FormatName... d 8a Const d PR_ILEProgramName... d Like(StdQNam) d Const d PR_APIError... d LikeDs(TD_StdErrorModel) d TD_DateTime... d ds Qualified d Based(StdNulPtr) d CenturyCode... d Like(StdChr) d YYMMDD... d 6a d HHMMSS... d 6a d dsUserSpaceHeader... d ds Qualified d Based(ptrUserSpaceHeader) d GenericHeader... d LikeDs(TD_Api_Hdr) d dsModuleInformation... d ds Qualified d Based(ptrModuleInformation) d ProgramName... d Like(StdNam) d ProgramLibraryName... d Like(StdNam) d BoundModuleName... d Like(StdNam) d BoundModuleLibraryName... d Like(StdNam) d SourceFileName... d Like(StdNam) d SourceFileLibrary... d Like(StdNam) d SourceFileMember... d Like(StdNam) d ModuleAttribute... d Like(StdNam) d ModuleCreateDateTime... d LikeDs(TD_DateTime) d SourceFileUpdateDateTime... d LikeDs(TD_DateTime) d SortSequenceTableName... d Like(StdNam) d SortSequenceTableLibrary... d Like(StdNam) d LanguageId... d Like(StdNam) d OptimizationLevel... d Like(StdInt) d MaximumOptimization... d Like(StdInt) d DebugData... d Like(StdNam) d ReleaseModuleCreatedOn... d 6a d ReleaseModuleCreatedFor... d 6a d Reserved01... d 20a d UserModified... d Like(StdChr) d LicensedProgram... d 13a d PTFNumber... d 5a d APARId... d 6a d CreationData... d Like(StdChr) d ModuleCCSID... d Like(StdInt) d ObjectControlLevel... d 8a d EnablePerformanceCollection... d Like(StdChr) d ProfilingData... d Like(StdNam) d Reserved02... d Like(StdChr) d NumberOfProcedures... d Like(StdInt) d NumberOfProcedureBlockReordered... d Like(StdInt) d NumberOfProcedureBlockOrderMeasured... d Like(StdInt) d TeraSpaceStorageEnabled... d Like(StdChr) d StorageModel... d Like(StdChr) d Reserved03... d 74a d NumberOfSQLStatements... d Like(StdInt) d RelationalDatabase... d 18a d CommitmentControl... d Like(StdNam) d AllowCopyOfData... d Like(StdNam) d CloseSQLCursors... d Like(StdNam) d NamingConvention... d Like(StdNam) d DateFormat... d Like(StdNam) d DateSeparator... d Like(StdChr) d TimeFormat... d Like(StdNam) d TimeSepartor... d Like(StdChr) d DelayPrepare... d Like(StdNam) d AllowBlocking... d Like(StdNam) d DefaultCollectionName... d Like(StdNam) d SQLPackageName... d Like(StdNam) d SQLPackageLibrary... d Like(StdNam) d DynamicUserProfile... d Like(StdNam) d SQLSortSequenceTableName... d Like(StdNam) d SQLSortSequenceLibraryName... d Like(StdNam) d SQLLangageIdentifier... d Like(StdNam) d ConnectionMethod... d Like(StdNam) d SQLPathLength... d Like(StdInt) d SQLPath... d 3483a d dsSource... d ds LikeDs(TD_SourceRecord) d API_Error... d ds LikeDs(TD_StdErrorModel) d QualLibrary... d s Like(StdQNam) d x... d s Like(StdInt) /Free ptrUserSpaceHeader = BuildUserSpace(); QualLibrary = '*ALL ' + InLibraryName; ProgramInformationAPI(cUserSpaceName + cUserSpaceLibrary: 'PGML0100' : QualLibrary : API_Error ); If API_Error.BytesAvailable > 0; Return; EndIf; For x = 1 to dsUserSpaceHeader.GenericHeader.NumberOfListEntries; ptrModuleInformation = ptrUserSpaceHeader + dsUserSpaceHeader.GenericHeader.OffsetToListDataSection + (x - 1) * %Size(dsModuleInformation); dsSource.ODOBNM = dsModuleInformation.ProgramName; dsSource.ODLBNM = dsModuleInformation.ProgramLibraryName; dsSource.ODOBTP = '*PGM'; dsSource.ODOBAT = dsModuleInformation.ModuleAttribute; dsSource.ODSRCF = dsModuleInformation.SourceFileName; dsSource.ODSRCL = dsModuleInformation.SourceFileLibrary; dsSource.ODSRCM = dsModuleInformation.SourceFileMember; dsSource.ODSRCD = dsModuleInformation.SourceFileUpdateDateTime.YYMMDD; dsSource.ODMODNAM = dsModuleInformation.BoundModuleName; dsSource.ODMODLIB = dsModuleInformation.BoundModuleLibraryName; WriteRecord(dsSource); EndFor; Return; /End-Free p e *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * ProcessOPM * Process all OPM programs for given library. Results are written * to table XV_SOURCE_LIST (XVSRCLIST) for use in querying. * In Parms - Library Name. * In/Out Parms - None. * Out Parms - None. * Return - None *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = p ProcessOPM... p b d pi d InLibraryName... d Like(StdNam) d Value d ObjectInformationAPI... d pr ExtPgm('QUSLOBJ') d PR_UserSpaceName... d Like(StdQNam) d Const d PR_FormatName... d 8a Const d PR_ObjectName... d Like(StdQNam) d Const d PR_ObjectType... d Like(StdNam) d Const d PR_APIError... d LikeDs(TD_StdErrorModel) d TD_DateTime... d ds Qualified d Based(StdNulPtr) d CenturyCode... d Like(StdChr) d YYMMDD... d 6a d HHMMSS... d 6a d dsUserSpaceHeader... d ds Qualified d Based(ptrUserSpaceHeader) d GenericHeader... d LikeDs(TD_Api_Hdr) d dsOBJL0400Format... d ds Qualified d Based(ptrOBJL0400Format) d ObjectNameUsed... d Like(StdNam) d ObjectLibraryNameUsed... d Like(StdNam) d ObjectTypeUsed... d Like(StdNam) d InformationStatus... d Like(StdChr) d ExtendedObjectAttribute... d Like(StdNam) d TextDescription... d Like(StdTxt) d UserDefinedAttribute... d Like(StdNam) d Reserved01... d 7a d ASPNumber... d Like(StdInt) d ObjectOwner... d Like(StdNam) d ObjectDomain... d 2a d CreationDateTime... d 8a d ChangeDateTime... d 8a d Storage... d Like(StdNam) d ObjectCompressionStatus... d Like(StdChr) d AllowChangeByProgram... d Like(StdChr) d ChangedByProgram... d Like(StdChr) d ObjectAuditingValue... d Like(StdNam) d DigitallySigned... d Like(StdChr) d DigitallySignedByTrusted... d Like(StdChr) d DigitallySignedMoreThanOnce... d Like(StdChr) d Reserved02... d 2a d LibraryASPNumber... d Like(StdInt) d SourceFileName... d Like(StdNam) d SourceFileLibrary... d Like(StdNam) d SourceMemberName... d Like(stdNam) d SourceFileUpdated... d LikeDs(Td_DateTime) d CreaterUserProfile... d Like(StdNam) d SystemWhereCreated... d 8a d SystemLevel... d 9a d Compiler... d 16a d ObjectLevel... d 8a d UserChanged... d 1a d LicensedProgram... d 16a d PTF... d Like(StdNam) d APAR... d Like(StdNam) d PrimaryGroup... d Like(StdNam) d Reserved03... d 2a d OptimumSpaceAlignment... d Like(StdChr) d AssociatedSpaceSize... d Like(StdInt) d Reserved04... d 4a d dsSource... d ds LikeDs(TD_SourceRecord) d API_Error... d ds LikeDs(TD_StdErrorModel) d QualLibrary... d s Like(StdQNam) d x... d s Like(StdInt) /Free ptrUserSpaceHeader = BuildUserSpace(); QualLibrary = '*ALL ' + InLibraryName; ObjectInformationAPI(cUserSpaceName + cUserSpaceLibrary: 'OBJL0400' : QualLibrary : '*PGM' : API_Error ); If API_Error.BytesAvailable > 0; Return; EndIf; For x = 1 to dsUserSpaceHeader.GenericHeader.NumberOfListEntries; ptrOBJL0400Format = ptrUserSpaceHeader + dsUserSpaceHeader.GenericHeader.OffsetToListDataSection + (x - 1) * %Size(dsOBJL0400Format); If dsOBJL0400Format.SourceFileName = *Blank Or dsOBJL0400Format.ExtendedObjectAttribute = 'DFU'; Iter; EndIf; dsSource.ODOBNM = dsOBJL0400Format.ObjectNameUsed; dsSource.ODLBNM = dsOBJL0400Format.ObjectLibraryNameUsed; dsSource.ODOBTP = '*PGM'; dsSource.ODOBAT = dsOBJL0400Format.ExtendedObjectAttribute; dsSource.ODSRCF = dsOBJL0400Format.SourceFileName; dsSource.ODSRCL = dsOBJL0400Format.SourceFileLibrary; dsSource.ODSRCM = dsOBJL0400Format.SourceMemberName; dsSource.ODSRCD = dsOBJL0400Format.SourceFileUpdated.YYMMDD; dsSource.ODMODNAM = *Blanks; dsSource.ODMODLIB = *Blanks; WriteRecord(dsSource); EndFor; Return; /End-Free p e *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * BuildUserSpace * Build User Space for API output. * In Parms - None. * In/Out Parms - None. * Out Parms - None. * Return - Pointer To User Space. *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = p BuildUserSpace... p b d pi Like(StdPtr) /Free // Create user space to hold data. USPC_CreateUserSpace(cUserSpaceName : cUserSpaceLibrary: 10240 : cTrue : cUserSpaceText : '*ALL' : '*YES' : 5 : '1' ); Return USPC_GetPointerToUserSpace(cUserSpaceName : cUserSpaceLibrary); /End-Free p e *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = * WriteRecord * Write record to XV_SOURCE_LIST. * In Parms - Source Record. * In/Out Parms - None. * Out Parms - None. * Return - None *= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = p WriteRecord... p b d pi d InSourceRecord... d LikeDs(TD_SourceRecord) c/Exec Sql + Insert Into XV_SOURCE_LIST + Values(:InSourceRecord) c/End-Exec p e
As an Amazon Associate we earn from qualifying purchases.
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.