Move all fields in a record format at once.

15 pts.
Tags:
RPG
Subfile Record Format
How can I move all the fields of a single record format at once? I need to move fields totalling 712 positions to a single flat-file record that is also 712 positions long. I really don't want to move one-field-at-a-time into a data structure if I can help it.
1

Answer Wiki

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

You can use a technique called a “Program Described File.”

Basically, you tell RPG to use the format you describe within your RPG. And in your case, you’d tell RPG that your externally described input file was one 712 length record and write that record to your flat file. See examples.

Best wishes: Craig

References

——

You can also externally describe a data structure

Ddsname E DS EXTNAME(filename:rcdfmt:*ALL)

This will create a data structure with all the fields in your file as subfields in the data structure. When you read your file, the data structure will be populated. Then you can do whatever you like with the data structure like moving it to a single field that can be written to your flat file.

======================================================

Do you need to do this in RPG? Would a simple CPYF command be acceptable or is this part of a larger RPG program? If a program-described file is a useful solution, then it seems that a program isn’t even needed.

As for the alternative DS method… Note that if you create a DS that holds the structure of an externally described file, you might not need to ‘move’ anything. You might be able to also define a 712-byte field that overlays the DS. Simply use that field rather than moving the DS to a separate field.

Tom

Discuss This Question: 13  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.
  • Mahler2
    This is my first time using this forum, so I'm not sure if this is the proper place to respond to ElTerrifico, but I wanted thank him (her?) for the tip. It worked great! Who knew that going "old school" and processing an externally-described file as a program-described file would be the easy answer? ElTerrifico, that's who! Thanks again.
    15 pointsBadges:
    report
  • ElTerrifico
    While I'd like to credit, that part of the answer was provided by Chatmaker (Craig), not myself. My suggestion was to use an externally described data structure. I am also new to ths forum and didn't realize that by adding to Craig's answer, it would appear that the whole answer came from me. I didn't intend to take Craig's answer, I just wanted to offer an alternative. And yes, sometimes the old ways work quite well.
    620 pointsBadges:
    report
  • MarkProgrammer
    What examples? Where?
    50 pointsBadges:
    report
  • ToddN2000
    DDSNAME         E DS                  EXTNAME(FILENAME:RECORDNAME:*ALL)
    129,715 pointsBadges:
    report
  • ToddN2000
    @MarkProgrammer: Use the sample above then just move your DSNAME to the field in your flat file. 
    That should be all you need to do.
    129,715 pointsBadges:
    report
  • TheRealRaven
    If it's going to a "flat file" (which depends on your definition of "flat file"), be aware that proper character translation may be the most difficult part. The target platform needs to be considered. And if numeric fields are involved at all, it gets significantly more complex.
    33,670 pointsBadges:
    report
  • WoodEngineer
    If data needs to be converted from decimal to character before writting to your flat tile check out RPG's EVAL-CORR and qualified data structures.  This should provide the ability to move all fields with one statement.  However, the results may be longer than 712.
    8,225 pointsBadges:
    report
  • TheRealRaven
    EVAL-CORR works. One minor issue is that it does require creating a fully described target DS. IMO, that's a good thing, though.
    33,670 pointsBadges:
    report
  • MarkProgrammer
    Trying to do the opposite and it's not working. Want to take a record from a flat file and write it to a file that has the detailed fields. I get 'types of the right and left hand side do not match..... "
    50 pointsBadges:
    report
  • ToddN2000
    @MarkProgrammer: You may have field in the flat file that you cannot use a MOVE for if the file has the field defined as packed decimal.For those you may have to use some of the %BIF to convert the data. If you can provide some details on the file layout and how the fields are delimited in the flat file we can help more. 
    129,715 pointsBadges:
    report
  • MarkProgrammer
    the flat file is all character..   the TO file is all character....

    Saw something similar to this elsewhere, but it's an oversimplification of what i need - it's reading/writing the same file:

    D CO_Data         ds                  qualified                 
    D  DataIn                             likerec(RELTFIL:*input)   
    D  DataOut                            likerec(RELTFIL:*output)  
    D                                     overlay(DataIn)           

    50 pointsBadges:
    report
  • ToddN2000
    @MarkProgrammer: try something like this. You need 2 seperate DS

    DDATAIN         E DS                  EXTNAME(INPUTFILE:RECNAME:*ALL)
    DDATAOUT        E DS                  EXTNAME(OUTPUTFILE:RECNAME:*ALL)
    Then just move one DS to the other and write your output record.
    129,715 pointsBadges:
    report
  • MarkProgrammer
    Great. Tells me I was on the right road - I was trying something similar, (and now finding out that the data isn't 'clean', so my results MAY be right, but don't LOOK right.)

    Thanks SO much. Really appreciate it.
    50 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.

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

Following

Share this item with your network: