Thread: C / C++ ILE IBM I-Series / AS400 Question from a RPGILE programmer

  1. #1
    Registered User
    Join Date
    May 2016
    Location
    TN
    Posts
    2

    Question C / C++ ILE IBM I-Series / AS400 Question from a RPGILE programmer

    Morning.

    I am new to the forums and currently learning C/C++/C# Programming. I am sort of new to the C Family of programming but not new as a programmer in general. I have 20 years of IBM RPGILE programming behind me both in the old methods and the more modern /FREE methods. I did take a couple of classes in C programming in my college days but that was ummm yeah late 90s. So I have been taking the very basics/fundementals of C# at present. And yes I understand it's methods are a little different than C/C++......especially when looking at ILE C/C++ on the IBM I-Series.


    Now what I am trying to do. Basically learning hands on. I want to write a very basic C program that will take the number and name from one file, go out to a cross reference file to get the new number for the account, and then write to a output file containing the new number from the cross reference (x-ref) and the name that came from the incoming file. Simple enough right?
    I'll code the DDS for the physical files below being used. And I will provide an example of how this would be done in RPG /FREE method. I just need to see how this could be done in C.


    Files being used:
    inPatDemo -- incoming patient demographic file
    OutPatDemo -- the outgoing patient demo file.
    XRMED -- The medical record number x-ref.


    The DDS for both in/out files will be the same with the only difference is the record format and field names.


    InPatDemo -- DDS
    A UNIQUE
    A InREC01fm
    A inMed# 9s 0 COLHDG('Med Rec #')
    A inPname 35a COLHDG('Patient Name')
    A k inMed#


    OutPatDemo -- DDS
    A UNIQUE
    A OutRec01fm
    A oMed# 9s 0 COLHDG('Med Rec #')
    A oPname 35a COLHDG('Patient Name')
    A k oMed#


    XRMED -- DDS
    A UNIQUE
    A XMEDFM
    A XOLDNUM 9s 0 COLHDG('Original MEDREC #')
    A XNEWNUM 9s 0 COLHDG('New MEDREC #')
    A K XOLDNUM


    In the incoming file we will have the following information with only 1 record:
    inMed# = 1000
    inPname = Daffy Duck


    OutPatDemo is an empty file


    XRMED has the following
    XOLDNUM = 1000
    XNEWNUM = 401557803


    Sample RPG Program minus all the F and D specs. Just the process:
    /FREE
    reset outrec01fm;
    chain inmed# xrmed;
    if %found;
    chain xnewnum outpatdemo;
    if not %found;
    omed# = xnewnum;
    opname = inpname;
    write outrec01fm;
    endif;
    endif;
    /END-FREE


    Now I did not include any validations nor error handling. Just kept this very simple. So with the above example. How would I do this in C?


    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by mstrozier View Post
    Morning.
    Howdy. Welcome to the forum.

    Quote Originally Posted by mstrozier View Post
    How would I do this in C?
    Do you know C? Have you made any attempt to write this program yourself?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  3. #3
    Registered User
    Join Date
    May 2016
    Location
    TN
    Posts
    2
    I don't know enough of C yet. I know the very basics, string, date handling, methods etc all coming from C# online courses. But not enough to understand yet on file structures, reading, writing etc. Bouncing a head and I find it better to learn hands on vs watching videos and reading it in guides. Just keying it in and seeing it process. I have this code insert from one of IBM manuals but I don't follow the _Read syntax. And how to read/open a 2nd file, to grab the information from one record. or to update an existing record etc etc.

    **edit**

    The forum is not liking my copy/paste of source code. Updating here in a second.

    Code:
    /* This program illustrates how to copy records from one file to */
    /* another file, using the _Rreadn(), and _Rwrite() functions. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <recio.h>
    #define _RCDLEN 300
    int main(void)
    {
    _RFILE *in;
    _RFILE *out;
    _RIOFB_T *fb;
    char record[_RCDLEN];
    /* Open the input file for processing in arrival sequence. */
    if ( (in = _Ropen("*LIBL/T1520ASI", "rr, arrseq=Y")) == NULL )
    {
    printf("Open failed for input file\n");
    exit(1);
    };
    /* Open the output file. */
    if ( (out = _Ropen("*LIBL/T1520ASO", "wr")) == NULL )
    {
    printf("Open failed for output file\n");
    exit(2);
    };
    /* Copy the file until the end-of-file condition occurs. */
    fb = _Rreadn(in, record, _RCDLEN, __DFT);
    while (fb->num_bytes != EOF )
    {
    _Rwrite(out, record, _RCDLEN);
    fb = _Rreadn(in, record, _RCDLEN, __DFT);
    };
    _Rclose(in);
    _Rclose(out);
    }
    Last edited by mstrozier; 05-25-2016 at 11:36 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick question on geometric series'
    By bevin in forum C Programming
    Replies: 8
    Last Post: 11-14-2014, 06:48 AM
  2. Series Question
    By Raekwon1 in forum C Programming
    Replies: 5
    Last Post: 04-16-2007, 08:03 PM
  3. Programmer sought for update to classic racing series
    By Jason1083 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-27-2004, 07:45 PM
  4. as400
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-21-2002, 05:50 AM
  5. A question to old programmer?
    By blackwyvern in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 03-19-2002, 12:02 PM

Tags for this Thread