Porting Central
Skip to main content

Porting Central

Porting to ILE C tutorial

Creating an ILE C/400 program

At this point of the tutorial, the user is assumed to have done the following:

  • Installed the appropriate 5250 emulator (part of iSeries Client Access) to allow connection to an iSeries machine
  • Logged on to an iSeries using his/her own user profile

If you have not yet been able to perform these steps, please refer to the 'TCP/IP Overview and Setup' course in Online Education.

ILE C/400 source code

Important Note:
From Version 4 Release 3 forward, source files can be stored as ordinary stream files within the iSeries IFS, appearing as "/u/bob/src/hello.c" for example. This is specified as the SRCSTMF(....) option to CRTCMOD.

The following tutorial is based on the V4R2-and-earlier requirement that source code is stored in the library/object system traditionally used for OS/400.

With OS/400 Version 4, even though source code may be stored in IFS stream files, the resultant *MODULE, *PGM, and *SRVPGM objects must still be stored in the library/object system of OS/400.

The following steps will enable you to start inputting ILE C/400 source code:

Create the pre-requisite entities

As previously mentioned, the ILE C/400 source code is packaged as a member within a physical file stored inside a library. It follows then, that inorder to start inputting the source code for a C program you need to first create a library, and a physical file. In the following example, you create a library FIRST and a physical file QCSRC within that library. Enter the following OS/400 commands.

CRTLIB LIB(FIRST)
Create a library
ADDLIBLE LIB(FIRST)
Add the library to your library list (equivalent to adding a directory to your PATH)
CRTSRCPF FILE(FIRST/QCSRC) 
              TEXT('Sample C Source Code')
Create a source physical file for the C source code
CRTSRCPF FILE(FIRST/H) TEXT('Sample C Headers')
Create a source physical file for the C headers

Create the members

There are, generally, 2 ways to create the members within the source files.

You may elect to create the member directly within an iSeries session by using the following OS/400 command:

STRSEU SRCFILE(FIRST/QCSRC) SRCMBR(HELLO) 
OPTION(2)
Start Source Entry Utility on the member HELLO of the file FIRST/QCSRC. Option 2 specifies EDIT, as opposed to BROWSE.

If you use the enhanced PC5250 emulator, you will want to modify the keyboard configuration so that you may map some characters which are not configured by default by the PC5250 emulator, (i.e., [ , ] ,etc). Otherwise you will need to use trigraphs (ugly representations of [ and ] ). From the PC5250 menu, choose Assist | Keyboard Setup...

You may elect to use a text editor on your workstation (UNIX or PC) to edit the member file and input the source code. After creating the member file and inputting the source code, you can use a file transfer program (FTP for example) to transfer the member from your workstation up to the target iSeries.

With FTP, you have the concept of a current directory (cd) and a local current directory (lcd).

  • The local current directory corresponds to your personal workstation. You may modify the local current directory to traverse your local file system. For example, in OS/2,set the local current directory to a specific directory containing the files that you wish to work with using FTP.
  • The current directory corresponds to the target location (the iSeries). Modifying the current directory allows you to change the current library. For example, cd QSYS makes the current library point to QSYS. For this tutorial you want to set the current directory equal to your user library, FIRST.

Now here comes the tricky part: matching the concept of directory,file name, and file extension with its iSeries counterpart.

For this exercise, assume that you want to create HELLO, a new member, of QCSRC, the physical file we previously created. QCSRC is stored in FIRST, a library which we also prevously created. On your workstation, you have used your favorite text editor to create HELLO.C. The file is stored in a directory named source. Notice how we have used the following subtle convention: The iSeries member name HELLO is used as the file name in your workstation's file system. The file extension .C serves as a reminder that the file is a C source code file. (The file extension is entirely optional, is not used by ILE C/400, but may come in handy in organizing the files on your workstation).

Initiate an FTP session and then transfer the file from your personal workstation to the target iSeries machine by issuing the following FTP commands:




ftp> lcd \source



ftp> cd FIRST



ftp> put T1520ALP.C QCSRC.T1520ALP



ftp> quit



After the file has been transferred to the iSeries, you will want to make some minor, one-time modifications. These modifications are best done by bringing up the Work With Members Using PDM screen with the WRKMBRPDM command. In particular:

WRKMBRPDM FIRST/QCSRC
Work with members of the file FIRST/QCSRC using PDM

       Work with Members Using PDM       PID400A







 File  . . . . . .   QCSRC



   Library . . .   FIRST    Position to  . . .   _____







 Type options, press Enter.



  2=Edit  3=Copy  4=Delete 5=Display  6=Print 7=Rename



  8=Display description  9=Save  13=Change text 
  14=Compile  15=Create module...







 Opt  Member      Type        Text



 5_   TEST______  C__________ Sample test program______




















 Bottom



 Parameters or command



 ===>_________________________________________________________



 F3=Exit F4=Prompt F5=Refresh F6=Create F9=Retrieve



 F10=Command entry F23=More options F24=More keys



Define the Type for the member file HELLO to be C. This is used to define parameters to SEU, the iSeries source code editor, such as case sensitivity and display formatting.

Add the appropriate text description for the member file.

Now, enter a '5' on the Opt (option) line next to the member name. This will display the member, and you can check to see that the transfer worked correctly. You should see something like the screen below.




Columns . . . : 1  71  Browse  FIRST/QCSRC



SEU==> ______________________     HELLO



FMT **  ..+.. 1 ..+.. 2 ..+.. 3 ..+.. 4 

..+.. 5 ..+.. 6 ..+.. 7



*************** Beginning of data **********



0001.00 /* This test program simlpy says 
"Hello World!", then echoes the    */



0002.00 /* command-line args, then prints out 
a macro value from mystuff.h  */



0003.00



0007.00  #include <stdio.h>



0008.00  #include "mystuff.h"



0009.00



0010.00  int main(int argc, char* argv[])



0011.00  {



0013.00     int  i;



0015.00



0042.00     printf("Hello World!\n");



0044.00     printf("Here are the arguments:\n");



0045.00     for (i=0; i < argc; i++)



0046.00       printf("argv[%d]=\"%s\" \n", i, argv[i]);



0048.00     printf("Here is a macro value: %d\n", SOMEVALUE);



0049.00  }







  F13=Change session defaults   F14=Find options



 F15=Browse options            F24=More keys



ILE C/400 C sample program

The sample program described for this tutorial is the same one listed as Figure 1 in Chapter 1 of the 'ILE C/400 Programmer's Guide'. It is included below for your reference.

 
Sample Source Code - FIRST/QCSRC.HELLO



/* This test program simlpy says "Hello World!", then echoes 
the*/



/* command-line args, then prints out a macro 
value from mystuff.h  */







 #include <stdio.h>



 #include "mystuff.h"







 int main(int argc, char* argv[])



 {



    int  i;







    printf("Hello World!\n");



    printf("Here are the arguments:\n");



    for (i=0; i < argc; i++)



      printf("argv[%d]=\"%s\" \n", i, argv[i]);



    printf("Here is a macro value: %d\n", SOMEVALUE);



 }



Sample Source Code - FIRST/H.MYSTUFF



/* This test header file contains a single macro, SOMEVALUE, 
to*/



/* show how headers are stored in ILE C/400. */







#define SOMEVALUE 400



Compiling the ILE C/400 C sample source code

Compiling ILE C/400 source code is accomplished via the Create C Module (CRTCMOD) command.

For the sample source defined previously in Figure 1, the following command invocation of CRTCMOD would create the appropriate ILE C/400 module object:

CRTCMOD MODULE(FIRST/HELLO) SRCFILE(FIRST/QCSRC) SRCMBR(HELLO) OUTPUT(*PRINT) OPTION(*XREF) TEXT('Hello World MODULE') DBGVIEW(*ALL) Create an ILE module from the source code in FIRST/QCSRC.HELLO

Some comments on the parameters of CRTCMOD:

MODULE
Specifies the module name and library for the compiled ILE C/400 module object.

SCRFILE
Specifies the source physical file name and library of the file containing the ILE C/400 source code you want to compile. For this option,there exists a default file SRCFILE of QCSRC.

SRCMBR
Specifies the name of the member containing the ILE C/400 source code. For this option, there exists a default member SRCMBR of *MODULE, (i.e. defaults to value supplied for parameter MODULE).

TEXT
Allows you to enter text that describes the object and its function. The descriptive text must be enclosed in single quotation marks and be no longer than 50 characters. If not specified, the TEXT parameters defaults to the text description associated with the source file member.

OUTPUT
Specifies if the computer listing is required or not. To specifiy yes, use the *PRINT value.

OPTION
Specifies the options to use when the ILE C/400 source code is compiled. There are quite a number of values corresponding to the OPTION parameter. For this tutorial we use *XREF to generate a cross-reference table containing a list of the identifiers in the source code together with the numbers of the lines in which they appear.

DBGVIEW
Specifies which level of debugging is available for the compiled object, and which source views are available for source-level debugging. A value of *ALL enables all of the debug options for debugging the compiled object and produces a source view, as well as a listing view.

Binding the ILE C/400 module object

In the previous section we used the CRCTCMOD command to create the ILE C/400 module object. The last step that remains to be done is the binding of the module object to create an iSeries program object. A program object can then be executed (called).

To bind the ILE C/400 module object use the Create Program command (CRTPGM) as follows:




CRTPGM PGM(FIRST/HELLO) MODULE(FIRST/HELLO)



Create a program object using the module FIRST/HELLO

Some comments on the parameters of CRTPGM:

PGM
Specifies the program name for the resultant program object.

MODULE
Specifies the compiled module object(s) to be bound together.

The CRTPGM commands invokes an OS/400 component referred to as the binder. The binder processes import requests for procedure names and data item names from the specified modules. The binder then tries to find matching exports in the specified modules, service programs, and binding directories.

The program object HELLO is now ready to be executed.

[ Previous | Next ]