AS/400: How to add a new column to the file?

85 pts.
Tags:
AS/400
WRKQRY
Is it possible to create/add new column to one file using WRKQRY? Eg: I have a file/table called City and it has some columns like city name, pin code. Now I want to add new column called country with field country name(same country name for all eg IND). Is there anyway for this?

Software/Hardware used:
AS400

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 7  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.
  • CharlieBrowne
    The easiest way is by using the SQL ALTER TABLE command.
    62,340 pointsBadges:
    report
  • azohawk
    Charlie is right. But a direct answer to your question about using WRKQRY the answer is no. There other methods than what Charlie mentioned, but with some of them you will have to concern yourself with getting level check errors.
    3,475 pointsBadges:
    report
  • ToddN2000
    With WRKQRY you could create a new output file with the added column. The problem is it would need to be refreshed every time you want to use it to make sure the data is up to date. Is this to be for a one-time use or be a change to the normal production process?
    102,670 pointsBadges:
    report
  • ToddN2000
    Also remember, if the original file was created with DDS then using the SQL ALTER TABLE will not add this new column/field to the DDS and you will be out of sync. If you ever recompile your DDS you will lose the field you added using the SQL method.
    102,670 pointsBadges:
    report
  • CharlieBrowne

    Per ToddN2000 comment - If file was created with DDS, you can add the field in the DDS, and then use CHGPF command to recreate the table. This would insert the field with blank values. You would still need to recreate and Logicals and recompile programs.

    62,340 pointsBadges:
    report
  • patnam
    ToddN2000 It is for one time use only. Can you please let me know the process how can I do it?
    85 pointsBadges:
    report
  • ToddN2000
    Create you query as normal. Select all the fields from the initial file plus the new field/column with the country value. Run it using F5 to verify these are the results you want. Then put a 1 next to the 'Select output type and output form'. Select option 3 to create a new database file. After pressing enter it will ask where you want the new file to be created. Enter a new filename and library. Set the 'Data in file' to a 2 (in case you want to run again in the future it will replace the file). Then F3 to exit the WRKQRY. You can save it if you ever want to run it again.
    102,670 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: