Showing posts with label Tutorial AS400. Show all posts
Showing posts with label Tutorial AS400. Show all posts

2009-01-08

Example: Copying an iSeries database file that has packed decimal fields to the QNetWare file system

Note:
Read the Code disclaimer information for important legal information.

Suppose you want to make an iSeries™ database file available to all NetWare users. If the database file is externally defined (using DDS) and has packed decimal fields, you cannot copy it directly to a file in QNetWare file system. You need to first copy it to a physical file; then you can copy it to a file in QNetWare. If fields are in packed decimal format, you need to create a logical file to convert the packed decimal fields to zoned decimal fields. The following example shows how to copy and convert a file that contains packed decimal fields. You can also see an example of how you might do this with an ILE C for iSeries program.

The file in this example is in library DATALIB and has the name CUSTCDT. You can refer to these example displays:

To copy the CUSTCDT database file to the QNetWare file system, you would follow these steps:

  1. Create a directory in the QNetWare file system to use for storing iSeries database files. For example, to create a directory on server SRVNW0A, you would enter:
      MKDIR DIR('/QNetWare/SRVNW0A.SVR/SYS/DTA')
    DTAAUT(*INDIR) OBJAUT(*INDIR) CRTOBJAUD(*NONE)
  2. To convert packed decimal fields to zoned decimal:
    1. Create a logical file CUSTCDTL over CUSTCDT:
      CRTLF FILE(DATALIB/CUSTCDTL) SRCFILE(DATALIB/QDDSSRC)
      CUSTCDTL is the name of the logical file, and DATALIB/QDDSSRC is the source physical file that contains the member CUSTCDTL. Example: DDS for logical file CUSTCDTL shows the DDS definition of such a logical file.

      Optionally, you can select a subset of fields you want to copy to QNetWare. Just put the fields you need into the logical file. You can also specify an ordering sequence on the logical file.

    2. To redefine packed decimal fields as zoned decimal, specify S for the data type for those fields.

      There is no need to specify other field definitions. The logical file is built over the physical file and copies all the field definitions from it.

  3. After you create the logical file, you can use it to copy the data to a program-described physical file. But first you must create the program-described physical file. To do that, you must know the record length of the logical file, because the program-described file must have the same record length. You can find the record length of the logical file by using the command:
    DSPFD FILE(CUSTCDTL) TYPE(*RCDFMT)

    The resulting display for the example logical file CUSTCDTL shows that it has a record length of 60:

                            Record  Format Level
    Format Fields Length Identifier
    CUSREC 11 60 3B84438D4C428
    Text . . . . . . . . . . . . . . . . . . . :
    Total number of formats . . . . . . . . . . : 1
    Total number of fields . . . . . . . . . . . : 11
    Total record length . . . . . . . . . . . . : 60
  4. Create the program-described physical file:

    CRTPF DATALIB/CUSTSTMF RCDLEN(60)

  5. Copy the logical file CUSTCDTL to the program-described physical file CUSTSTMF:

    CPYF FROMFILE(CUSTCDTL) TOFILE(CUSTSTMF) MBROPT(*ADD) FMTOPT(*NOCHK)

    FMTOPT(*NOCHK) is required because the record formats of the database files are different.

  6. Copy the program-described file CUSTSTMF into the QNetWare/SRVNW0A.SVR/SYS/DTA directory of the QNetWare file system that you created in step 1:
    1. On the iSeries command line, type CPYTOSTMF and press F4. The Copy to Stream File (CPYTOSTMF) display appears
    2. In the From database file member field, specify the path name of the CUSTSTMF program-described datasbase file 1 .
    3. In the To stream file field, specify the path name of the stream file 2 .

      In this case you would use the drive letter as a link to CUSTCDT.DAT.

    4. The default value for the Data conversion option causes iSeries to use the coded character set identifier (CCSID) equivalent of the stream file data code page and the database file CCSID to convert the data during the copy operation. To use your own translation table object instead, specify *TBL and enter the table name into the TBL parameter. 3
    5. If your database file has a CCSID of 65535, you must enter a valid CCSID code in the Database file CCSID field for your data to be correctly converted to ASCII. The values 0, 65534, and 65535 are not valid to use with this command. 4
    6. In the Stream file code page field, specify the ASCII code page of the NetWare server to convert the data. To obtain the code page of server SRVNW0A, you would enter:
        DSPMFSINF OBJ('/QNetWare/SRVNW0A.SVR/SYS/DTA')
      This example converts the database file data from CCSID 37 to ASCII code page 850. 5
  7. Now you can access the data from a NetWare workstation. Map a drive to the SYS volume of server SRVNW0A and then change into the DTA directory of the mapped drive.
  8. You can now look at the data in CUSTCDT.DAT (use any DOS editor), and you will see that the file no longer contains any field information. The application that accesses the data must know the record structure. To put more field information into the stream file (such as a field separator character), you must write your own program.
source :
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/rzaef/rzaefcpydatabase.htm

2008-12-11

Showcase Article - Report Layout Utility (RLU)

Learning to use the tools on the AS/400 is one of the best ways to leverage your expertise. Managers may be surprised to learn how easy it is to provide users with sample report layouts that can be designed with an on-line tool. This on-line tool is RLU, Report Layout Utility. Because many programmers find its interface to be confusing, not many have become proficient RLU users. Read on and you will learn to create report layouts quickly and easily.

In the early days of RPG, reports were always printed using OUTPUT specifications. With the advent of DDS, it became possible to make print files using DDS. This is similar to the way DDS is used to make display files. The AS/400 provides SDA, Screen Design Aid, as an on-line tool to design display files. Similarly, RLU, is an on-line tool to design reports.

Suppose a user needs a report showing:

1. Customer number
2. Customer name
3. Customer city
4. Annual purchase amount
These fields are in the customer master file, CUST. We will write an RPG program, CUSR005 to read the CUST file and write a print file, CUSW005.

Figure 1 shows the finished report that we will design with RLU. To start RLU, enter the command STRRLU and hit F4. Enter QDDSSRC as the source file. Enter the library name and CUSW005 as the source member. Since this is a narrow report, enter 65 for the page width. For a standard width report, you would use 132 for the page width.

RLU now displays its DESIGN REPORT screen. RLU uses so many function keys that there is a base set of function keys and an alternate set of keys. F22 is used to toggle between the base keys and the alternate keys. Right now RLU shows the word, BASE in the upper left portion of the screen to indicate that the base set of function keys is in use. F22 changes to the alternate keys and the changes the display from BASE to ALT.

The simplest way to use RLU is to define each line as a separate record. To start working with a line of the report, key DR for DEFINE RECORD in the command area on a blank line. When you hit the enter key, RLU names the record with the default name RCD001. After defining a record, enter VF for VIEW FIELDS in the command area of the same line. RLU then adds a line above the record to show the field information.

The heading for the report will be CUSTOMER ANNUAL PURCHASES. On the line with RCD001, key in the heading. Then, convert this string of characters to a constant. Do this by placing the cursor on the first character of the heading and hitting F11 for DEFINE FIELD. Hit F11 again and then ENTER to convert the string of characters to a constant. Finally, center the heading by keying CF for CENTER FIELD on the command portion of the RCD001 line. When you hit ENTER, the heading will center.

Now, create a second record. This will be used to print the customer fields. First insert a line to work with. Key I for INSERT in the command area of the RCD001 line and hit ENTER. Then, as before, key DR to define this as a record and then VF for VIEW FIELDS.

Next, use RLU to retrieve the field definitions from the master file. Hit F10 for DATABASE FIELDS. Key 1 for the option to ADD FIELD. Leave the FIELD value blank. Enter the library name and CUST for the File. Enter the record name of the CUST file. RLU will then retrieve all the fields in the CUST file and list them. Select the fields for the report. Hit ENTER until you return to the DESIGN REPORT screen.

The names of the fields you selected are at the bottom of the screen. Each field is sequentially numbered. To insert the first field in the report, key 1 in the text area of the FLD record above the detail record line. When you hit ENTER, RLU puts that field in the layout. RLU has re-sequenced the remaining fields. Place the remaining fields in the report.

If you overlap fields, RLU can get confusing. The simplest way to recover is to delete the record by keying a D in the command area of the record. Then start the record over. If you want to remove a field, put the cursor on the field and hit F16. If you need to move a field, use F13 to mark where the cursor is positioned and then F15 to move the field to a new location.

Now that you have placed the fields in a detail record, create headings for the detail line. Insert a line above the detail line. As always, key DR for DEFINE RECORD and then VF to VIEW FIELDS. Simply key the headings in the text area of the blank record that you inserted. Then convert each field to a constant by putting the cursor on the first character of each literal and hitting F11 twice.

To help visualize the report, create some sample data lines. Make 5 copies of the detail line by keying SD5 on the command line of the detail line.

Now, add a line at the bottom of the report for the total annual purchases. Do this by keying I in the command line of the last record on the screen. As always, key DR and then VF in the command area of the record.

Key the word TOTAL in the text area of the record. Convert the word to a constant by placing the cursor on the first letter of the word and hitting F11 twice. Now, add a new field for the accumulated total. This can get confusing.

Place the cursor where you want the total amount to print. Hit F11 to DEFINE FIELD. On the DEFINE FIELD INFORMATION screen, change the name of the field from the default FLD001 to TOTPUR. Change the length of data to 9. Hit PAGE DOWN. Change the data type to 2 for ZONED and enter 2 for decimal positions. Then hit F10 to WORK WITH KEYWORDS. Select EDTCDE by keying 2 next to it. Hit ENTER and key 1 for the EDTCDE value. Hit ENTER a few times and you will see that you have added a field for the total purchases.

Finally, add the date and page counter to the first heading line. Do this by adding a field of the appropriate length, converting it to a constant and then selecting the appropriate keyword. Also, rename the records by using F18 for RECORD KEYWORDS and then F10 to rename the record.

Exit RLU with F3. You can save the DDS, compile it and generate a prototype report all from the exit screen.

Figure 2 shows the complete RPG program to print the report.



Figure 1 - This is the finished report designed by RLU.


FLD1 <........> <.......................> <..> <...>
HDG1 01/04/2001 CUSTOMER ANNUAL PURCHASES Page 9,999
FLD1 <..> <...........> <..> <..........>
HDG2 CUS# CUSTOMER NAME CITY ANNUAL PURCH
00004 +
FLD1 <....> <.......................> <.............> <.......>
DTL 999999 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 99,999.99
00006 S 999999 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 99,999.99
00007 S 999999 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 99,999.99
00008 S 999999 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 99,999.99
00009 S 999999 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 99,999.99
00010 S 999999 XXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXX 99,999.99
FLD1 <...> <..........>
TOTL TOTAL 9,999,999.99



Figure 2 - This is the complete RPG program to print the report.

FCUST IF E K DISK
FCUSW005 O E PRINTER OFLIND(*In99)
C Move *On *In99
C Read CUST 90
C *In90 DoWEq *Off
C *In99 IfEq *ON
C Write HDG1
C Write HDG2
C Move *Off *In99
C EndIf
C Add CUSAP TOTPUR
C Write DTL
C Read CUST 90
C EndDo
C Write TOTL
C Eval *INLR = *On
C Return

source : www.texas400.com

2008-11-28

What is the purpose of indicators in RPG?

It is generally used to indicate the result of an operation or to condition (or control) the processing of an operation. Indicators are defined either by an entry on the specification or by the RPG IV program itself. The positions on the specification in which you define an indicator determine how the indicator is used. An indicator that has been defined can then be used to condition calculation and output operations. An indicator can be control level indicator, resulting, record identifying etc.

fungsi indicator AS400

http://www.time2ask.com

2008-11-25

Tutorial Membuat Sub File di AS400

Sebelumny kita harus mengetahui, apa itu sub file. Sub File digunakan untuk menampilkan data banyak
berbentuk table. berikut contoh gambar Sub File :

X SCRNO CSNO NAMA ACNO STATUS
X 0000000001 0000000 YADI 0000000000 0
0000000011 0000000 DENI 0000000000 0
X 0000000007 0000000 Salemet 0000000000 0


untuk membuat Sub File ada beberapa File yang harus di siapkan, diantaranya adalah :
1. Buat File *.pf <-- sebagai data base yang akan di akses 2. Buat File *.dspf <-- yang akan menangani masalah tampilan. 3. Buat File *.rpg/rpgle <-- sebagai program utama 1. File DSPF
0000.10 A*%%TS SD 20081114 144536 MULYADI REL-V5R3M0 5722-WDS
0000.20 A* 90/05/03 12:22:01 SYSTEK REL-R02M00 5728-PW1
0000.30 A*%%EC
0000.40 A DSPSIZ(24 80 *DS3)
0000.50 A REF(*LIBL/TRLBTOT)
0000.60 A CHGINPDFT(CS)
0000.70 A PRINT(*LIBL/QSYSPRT)
0000.80 A R SFLREC SFL
0000.90 A*%%TS SD 20081114 144536 MULYADI REL-V5R3M0 5722-WDS
0001.00 A TEXT('SUB FILE FORMAT KEYWORD')
0001.10 A CRDLIM 15S 0H
0001.20 A PILIH 1A I 8 9VALUES('X' ' ')
0001.30 A NAME R O 8 14REFFLD(SUBFIL/NAME LIBY/CUSMSTL)
0001.40 A ADDR R O 8 26REFFLD(SUBFIL/ADDR LIBY/CUSMSTL)
0001.50 A CUST R O 8 37REFFLD(SUBFIL/CUST LIBY/CUSMSTL)
0001.60 A R SFLCTL SFLCTL(SFLREC)
0001.70 A*%%TS SD 20081114 143714 MULYADI REL-V5R3M0 5722-WDS
0001.80 A SFLSIZ(0100)
0001.90 A SFLPAG(0010)
0002.00 A CA03(03 'EXIT_PROGRAM')
0002.10 A OVERLAY
0002.20 A 20N40 SFLDSP
0002.30 A N40 SFLDSPCTL
0002.40 A 40 SFLCLR
0002.50 A N39 SFLEND
0002.60 A RECNUM 1S 0H
0002.70 A 20 6 4' PILIH NAMA -
0002.80 A ALAMAT '
0002.90 A COLOR(WHT)
0003.00 A CTR 1S 0H
0003.10 A 5 3'==================================-
0003.20 A ======================='
0003.30 A 7 3'==================================-
0003.40 A ======================='
0003.50 A 4 3'MASUKAN NAMA'
0003.60 A SNAMA 10A I 4 19
0003.70 A 1 3'PROGRAM LATIHAN YADI'
0003.80 A R FUNCKY
0003.90 A*%%TS SD 20081103 164843 MULYADI REL-V5R3M0 5722-WDS
0004.00 A 21 4'F3-EXIT'
0004.10 A 20 4'==================================-
0004.20 A ====================== '
0004.30 A 20 21 44'pageup/pagedown'
0004.40 A COLOR(RED)
0004.50 A R NEWPAGE
0004.60 A*%%TS SD 20081103 165309 MULYADI REL-V5R3M0 5722-WDS
0004.70 A 4 7'NAMA TERPILIH :'
0004.80 A 5 7'ALAMAT TERPILIH :'
0004.90 A NAMAMU 10A O 4 29
0005.00 A CITYMU 10A O 5 29
0005.10 A 3 3'|'
0005.20 A 4 3'|'
0005.30 A 5 3'|'
0005.40 A 6 3'|'
0005.50 A 7 4'-----------------------------------
0005.60 A ---'
0005.70 A 3 41'|'
0005.80 A 4 41'|'
0005.90 A 5 41'|'
0006.00 A 6 41'|'
0006.10 A 2 4'-----------------------------------
0006.20 A ---'
****************** End of data ******************************************************

2. File *.pf
*************** Beginning of data **************************************************
0001.00 A R EMPLTES
0003.00 A DNAME 30A
0004.00 A DKATEGORI 1A
0005.00 A DLOCATION 28A
0006.00 A DUSRID 13A
0007.00 A DAGE 2S
****************** End of data *****************************************************

3. File rpgle
0000.01 F**************************************************************************
0000.02 F* VALIDASI DATA NASABAH U SWASYS
0000.03 F* YADI MULYADI
0000.04 F**************************************************************************
0000.05 F*
0001.03 FCUSMSTL IF E K DISK
0001.04 FCLDUSRC CF E WORKSTN
0001.05 F RECNUMKSFILE SFLREC
0001.06 C*
0001.07 C* DECLARE KEY FOR SEARCHING
0001.08 C NMKEY KLIST
0001.09 C KFLD SNAMA
0001.12 C*
0001.13 C *IN03 DOWEQ'0'
0001.14 C* SNAMA DSPLY
0001.15 C* *IN30 DSPLY
0001.16 C* *IN20 DSPLY
0001.17 C WRITEFUNCKY
0001.19 C EXFMTSFLCTL
0001.20 C *IN03 IFEQ '0'
0001.21 C *IN20 IFEQ '0'
0001.24 C EXSR SFLFIL
0001.25 C ELSE
0001.26 C *IN30 IFEQ '1'
0001.27 C SNAMA ANDNE*BLANK
0001.30 C 'NKEY' DSPLY
0001.31 C ELSE
0001.32 C EXSR CEK
0001.34 C ENDIF
0001.35 C ENDIF
0001.36 C ENDIF
0001.37 C ENDDO
0001.38 C SNAMA DSPLY
0001.39 C *IN03 DSPLY
0001.40 C *IN20 DSPLY
0001.41 C *IN30 DSPLY
0001.42 C SETON LR
0001.43 C*-------------------------------------------------------------------------
0001.44 C* SUB FILE SFLFIL
0001.45 C*-------------------------------------------------------------------------
0001.46 C SFLFIL BEGSR
0001.47 C NMKEY SETLLSUBFIL
0001.48 C *IN21 DOWEQ'0'
0001.49 C READ SUBFIL 71
0001.50 C *IN71 IFEQ '1'
0001.51 C MOVE '1' *IN21
0001.52 C ELSE
0001.53 C ADD 1 RECNUM
0001.54 C WRITESFLREC
0001.55 C END
0001.56 C ENDDO
0001.57 C RECNUM IFGT 0
0001.58 C SETON 20
0001.59 C ENDIF
0001.60 C ENDSR
0001.61 C*-------------------------------------------------------------------------
0001.62 C* SUB FILE SFLCLR
0001.63 C*-------------------------------------------------------------------------
0001.64 C SFLCLR BEGSR
0001.65 C MOVE '1' *IN40
0001.66 C WRITESFLCTL
0001.67 C MOVE '0' *IN40
0001.68 C MOVE '0' *IN20
0001.69 C MOVE '0' *IN21
0001.70 C Z-ADD*ZERO RECNUM
0001.71 C ENDSR
0001.61 C*-------------------------------------------------------------------------
0001.62 C* SUB FILE SFLCLR
0001.63 C*-------------------------------------------------------------------------
0001.64 C SFLCLR BEGSR
0001.65 C MOVE '1' *IN40
0001.66 C WRITESFLCTL
0001.67 C MOVE '0' *IN40
0001.68 C MOVE '0' *IN20
0001.69 C MOVE '0' *IN21
0001.70 C Z-ADD*ZERO RECNUM
0001.71 C ENDSR
0001.72 C*-------------------------------------------------------------------------
0002.00 C* SUB FILE CEK
0003.00 C*------------------------------------------------------------------------
0004.00 C CEK BEGSR
0004.01 C* Z-ADDRECNUM SAVRRN
0004.02 C READCSFLREC 30
0004.07 C*
0004.12 C *IN30 DOWNE'1'
0004.17 C PILIH IFEQ 'X'
0004.18 C MOVE NAME NAMAMU
0004.19 C MOVE CITY CITYMU
0004.20 C EXFMTNEWPAGE
0004.21 C UPDATSFLREC
0004.22 C ENDIF
0004.23 C READCSFLREC 30
0004.24 C ENDDO
0004.25 C SNAMA IFEQ *BLANK
0004.26 C 'NKEY' DSPLY
0004.27 C ENDIF
0004.28 C EXSR SFLCLR
0005.00 C ENDSR
0006.00 C*------------------------------------------------------------------------
****************** End of data ************************************************

jalankan dengan memasukan perintah sebagai berikut :
call namaLibrary/namaprogram
misal
Call ciamis/yadiProgram

2008-11-17

Tutorial : Hello World AS400 by me

Tutorial 1

Hello World

To start the tutorial we will start by creating a simple Hello World program. Input program such as the image below.

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

C 'HALLO YADI?' DSPLY

C SETON LR

C RETURN

****************** End of data *************************************************

Describe The Program

DSPLY function is used as a function that displays the message / variables to the screen.

SETON function of the program showed that the line is the final part of the program. SETON LR function and the Return is a function that should be there in each program when the program is created.