+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18

Thread: Writing to unknown fields in RPG

  1. #1
    Guest.Visitor Guest

    Default Writing to unknown fields in RPG

    I have read your explanation, but I'm lost as to what you are doing. I understand that the user is describing the fields in the user file, but where are the description for each field? Is it in the FILE you mention? Is there a record for each field? Does each user-described file have a different ILEA? Is this information be used to create a physical file? Do you know the name of the file at the time you execute the program? In ILEA, are you reading this information in fields (i.., FLDNAME, LENGTH, TYPE) and then determining what is to be loaded in the field described in the record? Maybe knowing this will help with an answer. I think I know what you are trying to do, but without information on the output, I stand in the dark. Barry

  2. #2

    Default Writing to unknown fields in RPG

    Barry, when the user enters the field description, my program will write to FILEA with this information (field,length, position,type, & file name). A seperate record will be written for each field decribed. I don't know the name of the file but I was thinking of creating one with a record length of say, 2000 bytes & then have a CL program to a CPYF *nochk to the user file name after the RPG program is run. I the FILEA input I plan on reading the starting position & length to tell where to put the fields. I will be reading another file that has the field names that I will use to chain out to FILEA to get the positions. Did this help clarify? Ron

  3. #3

    Default Writing to unknown fields in RPG

    Ron, I have a program that packs data, and one that unpacks it. I use them with S/36 programs that have to interact with native programs. I published them in TechTalk in June & July 98. Maybe you can use them. convert zoned to packed: http://www.midrangecomputing.com/ftp...98/B980603.txt Another idea is to equate a decimal field & a character field in a data structure. Z-ADD into the decimal field, then move the character field to the output. As for building the output, instead of CAT, it might work better to define the output field as an array and use MOVEA to load the data at the point where you want it. MOVEA FIELD OUT,XX As for whether you should use RPG or not, I've always had to use whatever was available. On the AS/400, that was RPG. On PC's, Qbasic and Perl.

  4. #4
    Guest.Visitor Guest

    Default Writing to unknown fields in RPG

    Ron Define a DS for the External description of the file you are writing to. Then move your values to the DS name. Update or Write the data base file. Remember, there is now way to move values from/to the record format name in RPG. I think this is what you are looking and this will solve your problem. Elan

  5. #5
    Guest.Visitor Guest

    Default Writing to unknown fields in RPG

    Ron, Another option would be to use the Late Bound Copy Numeric Value APIs. These allow you to convert from any numeric format to any nomeric format. I use these extensively in our dynamic applications along with a routine that converts a character value to a known numeric format. Here is the prototype and module for the API wrapper that I created:
     **************************************************  ******************************************** * Proto - CnvNumFmt * * By - David Morris * * Purpose - Convert format of numeric variables. * **************************************************  ******************************************** **************************************************  ******************************************** * CvtNumFmt Convert numeric format. * * Input: * * InpVar Left justified input value. * * InpFmt Input format, P/S/F/I/B/U. Packed/Zoned/Float/Integer/Binary/Unsigned int. * * InpPre Input value precision. * * InpDec Input value decimal positions. * * OutFmt Output format, I/P/S/U/B. * * OptOutPre Output value precision, default is input precision. If not passed, default * * is input precision. * * OptOutDec Output value decimal positions, default in input decimal positions. If not * * passed default is input decimal positions. * * HlfAdj Half adjust output, *ON=Half adjust, default is to truncate. * * Return: * * RtnVal Re-formatted left justified output value. * **************************************************  ******************************************** DCvtNumFmt PR 32A Return value. D InpVar 32A CONST D InpFmt 1A CONST D InpPre 5U 0 CONST D InpDec 5U 0 CONST D OutFmt 1A CONST D OptOutPre 5U 0 CONST OPTIONS(*OMIT: *NOPASS) D OptOutDec 5U 0 CONST OPTIONS(*OMIT: *NOPASS) D OptHlfAdj 1N CONST OPTIONS(*NOPASS) **************************************************  ******************************************** * HlfAdj Half adjust value and return result. * * Input: * * InpVar Left justified input value. * * InpFmt Input format, P/S/F/I/B/U. Packed/Zoned/Float/Integer/Binary/Unsigned int. * * InpPre Input value precision. * * InpDec Input value decimal positions. * * OptOutDec Output value decimal positions, default in input decimal positions. If not * * passed, default is zero. * * Return: * * RtnVal Half adjusted value left-adjusted. * **************************************************  ******************************************** DHlfAdj PR 32A Return value. D InpVar 32A CONST D InpFmt 1A CONST D InpPre 5U 0 CONST D InpDec 5U 0 CONST D OptOutDec 5U 0 CONST OPTIONS(*NOPASS) /TITLE CnvNumFmt - Convert the format of numeric values. **************************************************  ******************************************** * Module - CntNumFmt * * By - David Morris * * Purpose - Convert the format of numeric values. * * Compile - CRTRPGMOD MODULE(objlib/CntNumFmt) * * SRCFILE(srclib/QRPGLESRC) * * SRCMBR(CnvNumFmt) * * DBGVIEW(*SOURCE) * **************************************************  ******************************************** H NoMain H OPTION(*SRCSTMT) /COPY QPROTOSRC,CEEDOD /COPY QPROTOSRC,CEETSTA /COPY QPROTOSRC,CnvNumFmt **************************************************  ******************************************** * LBCpyNV C library function Late bound copy numeric value. * **************************************************  ******************************************** DLBCpyNV PR extproc('_LBCPYNV') D PR_pTgtVal * VALUE D PR_TgtTmp CONST LIKE(DPATmp) D PR_pSrcVal * VALUE D PR_SrcTmp CONST LIKE(DPATmp) **************************************************  ******************************************** * LBCpyNVR C library function Late bound copy numeric value with rounding. * **************************************************  ******************************************** DLBCpyNVR PR extproc('_LBCPYNVR') D PR_pTgtVal * VALUE D PR_TgtTmp CONST LIKE(DPATmp) D PR_pSrcVal * VALUE D PR_SrcTmp CONST LIKE(DPATmp) ********************** * Numeric descriptor * ********************** DDPATmp DS BASED(pDPATmp) D DPATyp 1A D DPAPre 5I 0 D DPADec 1A OVERLAY(DPAPre) D DPAReserved 10I 0 /TITLE CvtNumFmt - Convert numeric format. **************************************************  ******************************************** * *CvtNumFmt - Convert numeric format. * **************************************************  ******************************************** PCvtNumFmt B EXPORT DCvtNumFmt PI LIKE(RtnVar) D InpVar CONST LIKE(RtnVar) D InpFmt 1A CONST D InpPre 5U 0 CONST D InpDec 5U 0 CONST D OutFmt 1A CONST D OptOutPre 5U 0 CONST OPTIONS(*OMIT: *NOPASS) D OptOutDec 5U 0 CONST OPTIONS(*OMIT: *NOPASS) D OptHlfAdj 1N CONST OPTIONS(*NOPASS) ***************** * Return string * ***************** DRtnVar S 32A INZ(*LOVAL) ****************** * Work variables * ****************** DOutPre S LIKE(OptOutPre) DOutDec S LIKE(OptOutDec) DHlfAdj S LIKE(OptHlfAdj) DSrcVar S LIKE(InpVar) ************************** * Convert to single byte * ************************** D DS D CvtNum 5U 0 D CvtByt 1A OVERLAY(CvtNum: 2) ********************** * Numeric descriptor * ********************** DSrcTmp S LIKE(DPATmp) DTgtTmp S LIKE(DPATmp) ************************ * Define numeric types * ************************ DSIGNED C x'00' DFLOAT C x'01' DZONED C x'02' DPACKED C x'03' DUNSIGNED C x'0A' C* Set output decimal precision, default is input precision. C IF %PARMS >= 6 C CALLP CEETSTA(ArgPas: 6: *OMIT) Precision passed? C END C IF ArgPas = 1 AND C %PARMS >= 6 C EVAL OutPre = OptOutPre C ELSE C EVAL OutPre = InpPre C END C* Set output decimal places, default is input decimals. C IF %PARMS >= 7 C CALLP CEETSTA(ArgPas:7:*OMIT) Decimal Pos passed? C END C IF ArgPas = 1 AND C %PARMS >= 7 C EVAL OutDec = OptOutDec C ELSE C EVAL OutDec = InpDec C END C* Set half adjust, default to truncate. C IF %PARMS >= 8 C EVAL HlfAdj = OptHlfAdj C ELSE C EVAL HlfAdj = *OFF C END C* C* Setup source template. C EVAL pDPATmp = %ADDR(SrcTmp) C SELECT C WHEN InpFmt = 'P' C EVAL DPATyp = PACKED C WHEN InpFmt = 'S' C EVAL DPATyp = ZONED C WHEN InpFmt = 'F' C EVAL DPATyp = FLOAT C WHEN InpFmt = 'I' OR C InpFmt = 'B' C EVAL DPATyp = SIGNED C WHEN InpFmt = 'U' C EVAL DPATyp = UNSIGNED C OTHER C ENDSL C* C EVAL DPAPre = InpPre C EVAL CvtNum = InpDec C EVAL DPADec = CvtByt C EVAL DPAReserved = *ZEROS C* C* Setup target template. C EVAL pDPATmp = %ADDR(TgtTmp) C SELECT C WHEN OutFmt = 'P' C EVAL DPATyp = PACKED C WHEN OutFmt = 'S' C EVAL DPATyp = ZONED C WHEN OutFmt = 'F' C EVAL DPATyp = FLOAT C WHEN OutFmt = 'I' OR C OutFmt = 'B' C EVAL DPATyp = SIGNED C WHEN OutFmt = 'U' C EVAL DPATyp = UNSIGNED C OTHER C ENDSL C* C EVAL DPAPre = OutPre C EVAL CvtNum = OutDec C EVAL DPADec = CvtByt C EVAL DPAReserved = *ZEROS C* C EVAL SrcVar = InpVar C* C IF HlfAdj C CALLP LBCPYNVR( C %ADDR(RtnVar): C TgtTmp: C %ADDR(SrcVar): C SrcTmp) C ELSE C CALLP LBCPYNV( C %ADDR(RtnVar): C TgtTmp: C %ADDR(SrcVar): C SrcTmp) C END HlfAdj C* C RETURN RtnVar PCvtNumFmt E /TITLE HlfAdj - Half adjust numeric value. **************************************************  ******************************************** * *HlfAdj - Half adjust numeric value. * **************************************************  ******************************************** PHlfAdj B EXPORT DHlfAdj PI LIKE(RtnVar) D InpVar CONST LIKE(RtnVar) D InpFmt 1A CONST D InpPre 5U 0 CONST D InpDec 5U 0 CONST D OptOutDec 5U 0 CONST OPTIONS(*NOPASS) ***************** * Return string * ***************** DRtnVar S 32A INZ(*LOVAL) DOutDec S LIKE(OptOutDec) INZ(*ZEROS) C IF %PARMS >= 5 C EVAL OutDec = OptOutDec C ENDIF C* C EVAL RtnVar = CvtNumFmt( C InpVar: C InpFmt: C InpPre: C InpDec: C InpFmt: C InpPre: C OutDec: C *ON) C* C RETURN RtnVar PHlfAdj E
    For converting character values to string, I based my code on something published in the RPG Building Block section of Midrange Computing back in 1998. I beleive that Barbara Morris has posted a more up to date and efficient version in this forum. David Morris

  6. #6

    Default Writing to unknown fields in RPG

    Elan, I do not know the field names of the file I am writing to at the time I create the program Ron

  7. #7

    Default Writing to unknown fields in RPG

    Wed, I tried your packed data program. I used RPG IV instead of RPG III. At first in would not compile because of the sub field P...1..160PACK31 has a length of 31 which is > 30, the ax size on the AS/400. I'm not sure how you got that to work. I just commented it out to compile. I tried moving my input field into the ZONED data structure but got a data decimal error. You have however, given me some good ideas. Using an array works much better. What I can also do, is move my field into ZONE01, Zone02 .... or Zone30, depending on the length of the field I need for output. Then, -add the zoned field, into the Packed field. I use a data structure you suggested to redefine the field as alpha. Then MOVE the Alpha field into the array. The only problem I still have now is, all my Alpha input fields have a length of 80 and numeric fields a length of 30. My output fields can be any length. The MOVE operation will move the input 30 or 80 length into the array. I have control of the starting position but not the length. I suppose, I can have 80 subroutine, one for each output length and define 80 seperate fields to MOVE into the array. This is probably my best bet, unless someone has a better idea. Thank you. on

  8. #8

    Default Writing to unknown fields in RPG

    Ted, I tried your packed data program. I used RPG IV instead of RPG III. At first in would not compile because of the subfield P...1..160PACK31 has a length of 31 which is > 30, the max size on the AS/400. I'm not sure how you got that to work. I just commented it out to compile. I tried moving my input field into the ZONED data structure but got a data decimal error. You have however, given me some good ideas. Using an array works much better. What I can also do, is move my field into ZONE01, Zone02 .... or Zone30, depending on the length of the field I need for output. Then, z-add the zoned field, into the Packed field. I use a data structure you suggested to redefine the field as alpha. Then MOVEA the Alpha field into the array. The only problem I still have now is, all my Alpha input fields have a length of 80 and numeric fields a length of 30. My output fields can be any length. The MOVEA operation will move the input 30 or 80 length into the array. I have control of the starting position but not the length. I suppose, I can have 80 subroutines, one for each output length and define 80 seperate fields to MOVEA into the array. This is probably my best bet, unless someone has a better idea. Thank you. Ron

  9. #9
    Guest.Visitor Guest

    Default Writing to unknown fields in RPG

    Thanks for the explanation, on. Sorry the editor cut out the "I" in the ILEA words. The posting by Lean and Wed will probably be all you need. I'd first take the file descriptions and first create a physical file to write the data to. Then there are several methods you can use to convert the data. Wed mentions a couple and already has programs that you can create to complete the task. If there is any way you can set any standards that the users use to enter the data, it would greatly support your effort and make it simpler. Take a look at the raw data to help you determine what you will need to do to convert the numeric data. If you can get a number into a character field without the editing, you can easily put it into a numeric field. With the numeric fields you'll should first determine if there is editing (i.., periods, commas, negative signs, etc.) and weed them out using SCAN and CHECK to find the numbers. Then move those numbers to character variables to concatenate to create a character representation of the number the user entered; I'd not worry with the leading zeros if they aren't present. Move the field to a numeric field of 30,0 packed, then add that to the field in the file.

  10. #10

    Default Writing to unknown fields in RPG

    Ron, CPYF could do this for you with FMTOPT(*MAP), assuming the user-file has the same field names as the input file. CPYF will even handle different field lengths. Barbara

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 11
    Last Post: 12-02-2003, 12:23 PM
  2. Time Stamp Fields to mmddyy and hhmmss fields
    By S.Mildenberger in forum RPG
    Replies: 2
    Last Post: 10-01-2003, 03:01 AM
  3. Replies: 0
    Last Post: 08-29-2003, 05:24 PM
  4. Unknown host, www.......... Problem
    By J.Panzenhagen in forum Networking
    Replies: 3
    Last Post: 05-21-2001, 10:16 AM
  5. Unknown SRC at IPL Time !!
    By Guest.Visitor in forum IBM i (OS/400, i5/OS)
    Replies: 1
    Last Post: 02-02-2001, 04:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts