External data structure retrieve field data types

55 pts.
Tags:
AS/400
RPG
In RPG I am trying to move a External DS (based on a file, filled on input) to a character string and convert all decimal (packed) values to their character representation while doing so. I need to repeat this action on multiple files so a simple or generic solution is what I'm aiming for. Since this does not seem to work for me ( due to a lack of knowledge ;-) ), it seemed to me I should post a question (or possibly two): 1. Is it at all possible to do this with a few simple statements? 2. If not, I thought to create a procedure or program to determine which fields in the E DS are decimal and convert these seperately. How can I do this? iOS level V5R4

Answer Wiki

Thanks. We'll let you know when a new response is added.

<i>2. If not, I thought to create a procedure or program to determine which
fields in the E DS are decimal and convert these seperately. How can I
do this?</i>

for the above,
u can use, DSPFFD and store the o/p in a file (need to clear 1st everytime u run the cmd).
Read the file sequentially, till your field, and check the type
WHFLDT = ‘P’ (for packed)

Discuss This Question: 12  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • deepu9321
    So, All the External files are having similar field structure? Pradeep.
    4,290 pointsBadges:
    report
  • MvandenBrink
    Not really no, I am trying to find a generic way to output the data in several (differently formatted) files to a character field length 2048. So I read each file, want to output it to the field, use the field, clear the field, read the next file, and so on...
    55 pointsBadges:
    report
  • philpl1jb
    Why RPG??? CPYTOIMPF might do it all for you. Phil
    51,345 pointsBadges:
    report
  • TomLiotta
    ...a simple or generic solution... Unfortunately, a simple solution is very unlikely to be generic. Nor will any generic solution be simple. You could create a reasonably "simple" solution for each specific file. You might even combine all of those into a single large program that would have a reasonably simple structure. Or you could create a "generic" process that handled any (externally-described) file, but I sure wouldn't call it "simple". Overall, Phil probably has the best suggestion. Just use tools that already exist. CPYTOIMPF is a very good possibility. Tom
    125,585 pointsBadges:
    report
  • MvandenBrink
    Phil, Tom, Thanks, however working with CPYTOIMPF, requires me to make a selection of the record I want to use first, push it to a single record temp file and then copy this temp file. Or do you know of a way to combine a copy to import file with a selection on the "source" file? Martijn
    55 pointsBadges:
    report
  • Yorkshireman
    You could use one of the query tools. build a query which selects the records you want, and define an output field as being concatenated fields from the input. you can define a result field and convert the packed data to character within query/400 for example.
    5,580 pointsBadges:
    report
  • philpl1jb
    Yes, I don't unserstand your objection. But I also don't understand your objective. You might populate the temp file with a cpyf or an sql insert. Since it matches the original file it's pretty simple to create it an populate it. Phil
    51,345 pointsBadges:
    report
  • MvandenBrink
    I don't have any objections to using query sql or imp files or a combination of those. I just thought this should also be possible by using RPG, and preferably using just a few simple statement I did not know existed. My objective is to have a program into which I input any record (format based on any file), this program should then find (possibly with some help of pointers or a stored DSPFFD) and convert any fields with a numeric data type, and in the end return the record to my calling program as a character string.
    55 pointsBadges:
    report
  • philpl1jb
    Here's my quick and dirty logic Input field - file name Input field - data to be decoded received as a flat record of xxxx bytes Output field - flat field of xxxx bytes CL runs DSPFFD to outfile RPG reads each record from dspffd outfile -- each record is a field - takes appropriate bytes from the input string - put bytes into a wrkfld of the correct format - may need formats for each field type and size -- extracts data as sting - pastes onto end of return sting I'm sure this can be simplified. Personally, I would still the CPYTOIMPF to do the heavy lifting Phil
    51,345 pointsBadges:
    report
  • MvandenBrink
    Phil, That was the logic I was leaning towards ..... At the moment there's no pressure, so I can figure out a "fancy" solution, maybe even throw in a few api's to get the field data and retrieve it from the user space..... and of course devide them into need little chunks of coding..... (don't know how long this moment of relative peace lasts though, so in the end I might still go with the cpytoimpf).
    55 pointsBadges:
    report
  • MvandenBrink
    and of course i meant neat little chunks not need little chunks ;-)
    55 pointsBadges:
    report
  • TomLiotta
    - put bytes into a wrkfld of the correct format - may need formats for each field type and size For those parts, consider using various APIs. Bruce Vining has provided some useful examples at The API Corner: Dynamically Editing a Numeric Value and The CL Corner: More on ILE CEE Time APIs. Those provide an introduction to a couple useful APIs for this kind of work. The Edit Function APIs can also provide some help. If you use DSPFFD, you'll have probably everything needed to know how to handle individual fields, including start-/end-positions in the input buffer and data type. (You might use the List Fields (QUSLFLD) API instead.) Overall, you will have a "generic" process. But it will have a bunch of little parts, each of which will be a potential learning experience. Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following