Pages

Wednesday, September 21, 2016

Working with IFS in RPGLE

Read IFS file in RPGLE

Working with IFS file has always been one of the important things while programming with RPGLE.

The most common way to deal with IFS file is 
  • Copy the IFS file to Flat file using CPYFRMIMPF/CPYFRMSTMF.
  • Read the Flat file in RPGLE.
Or 
  • Write the Data into File in RPGLE.
  • Copy the File to IFS by using CPYTOIMPF/CPYTOSTMF.
This involves writing additional CL Program or using QCMDEXC API to execute CL Command to copy the data from/to IFS and Creation of Temporary/Permanent Database file. 

Accessing IFS files has become easy by using 'open', 'close', 'read' and 'write' functions.

Below is an Simple Example on how to Read data from IFS and write into Database file.

**Free
     Ctl-Opt DftActGrp(*No) ;

     // ProtoType Declaration for 'open'
     Dcl-PR OpenIfs Int(10) ExtProc('open') ;
       pIfsPath Pointer Value Options(*String) ;
       pFileStatusFlag Int(10) Value ;
       pFilePermission Uns(10) Value Options(*NoPass) ;
       pOutputCcsId Uns(10) Value Options(*NoPass) ;
     End-PR ;

     // ProtoType Declaration for 'read'
     Dcl-PR ReadIfs Int(10) ExtProc('read') ;
       pFileDescriptor Int(10) Value ;
       pIfsData Pointer Value ;
       pBytesRetrieved Uns(10) Value ;
     End-PR ;

     // ProtoType Declaration for 'close'
     Dcl-PR CloseIfs Int(10) ExtProc('close') ;
       pFileDescriptor Int(10) Value ;
     End-PR ;

     // Constants Declaration
     Dcl-C ReadOnly 1 ;
     Dcl-C Text 16777216 ;
     Dcl-C CcsId 32 ;
     Dcl-C GroupAuthority 32 ;
     Dcl-C Path '/home/PREDDY/SampleIfs.txt' ;

     // Stand Alone Variables Declaration
     Dcl-S FileDescriptor Int(10) ;
     Dcl-S Length Int(10) ;
     Dcl-S IfsData Char(100) ;
     Dcl-S IfsRecord Char(100) ;
     Dcl-S StartPos Packed(3) ;
     Dcl-S EndPos Like(StartPos) ;

     // Open IFS File
     FileDescriptor = OpenIfs(Path
                             :ReadOnly + Text + CcsId
                             :GroupAuthority
                             :37) ;

     If FileDescriptor < 0 ;
       Dsply ('Problem While accessing IFS file.') ;
       *InLr = *On ;
       Return ;
     Else ;
       Dow 1 = 1 ;

         // Read IFS File
         Length = ReadIfs(FileDescriptor : %Addr(IfsData) : %Size(IfsData) ) ;
         If Length = 0 ;
           Leave ;
         ElseIf Length < %Size(IfsData) ;
           %SubSt(IfsData : (Length + 1)) = ' ' ;
         EndIf ;

         StartPos = *Zeros ;

         Dow 2 = 2 ;

           // Write Data into IFS file
           EndPos = %Scan(x'25' : IfsData : StartPos + 1) ;
           If EndPos > *Zeros ;
             IfsRecord = %SubSt(IfsData : StartPos + 1 :
                          EndPos - StartPos - 1) ;
             Dsply IfsRecord ;
             StartPos = EndPos ;
           Else ;
             Leave ;
           EndIf ;
         EndDo ;
       EndDo ;
     EndIf ;

     // Close File
     CloseIfs(FileDescriptor) ;
     *InLr = *On ;

This example has been written in Full Free format RPGLE. Declarations has to be modified to Fixed Format, if any restrictions in writing Full Free Format.

Refer to Scott Klement's ebook for detailed info on IFS in RPG.

Thursday, September 15, 2016

Advantages of using Free-format RPGLE

Advantages of Using Free-Format RPGLE


IBM has always been focusing on making the RPG easy for Non-RPG Programmers. One such Important move is introducing the Free-Format into RPG for C-Spec. 

Introducing Eclipse based RDi is another biggest move. This encourages young developers in learning RPG like any other web based languages. RDi has an addition to convert your Fixed Format code to Free-Format. 

Almost after a Decade of Introducing Free-Format, IBM took major Step to Convert RPG into Full-Free format.

As a Core RPG Developer, I can say this as 'Really Huge' change to the way how RPG was being coded and how the RPG has become now. This has changed its way from RPG II, RPG III and to Full-Free Format.

We will have a quick look at the Major advantages of Using Free-Format RPGLE in this article.

  • Readability
  • Efficient use of Space
  • New Features Specific to Free Format
  • Easy to Understand/Maintain

Readability:


  • No need to stick to specific columns and thinking about the limitations of Factor or Extended Factor for writing any calculations.
  • Maintaining Proper Indentation makes easy for Analyzing the code.
  • Declaring Variables with Proper Meaning. E.g.: 'IsPurchaseOrderFulfilled' makes more Sense than 'IsPOfulfld'.  This helps understanding the Purpose of Variable and Logic.

Efficient Use of Space:

  • Biggest Advantage of Full-Free format RPGLE is making efficient use of Space instead of Restricting to work from 6th Position to 80th Position. Code can be written Starting from 1st Position.
  • Free Format Declarations allows to Declaring the large variable names in a single line by avoiding ellipsis (...) in D-Spec.
  • Business Logic will appear clean in Free Format and can save the number of lines coded compared to Fixed Format.

New Features to Free Format:

  • Defining Keys directly in Chain/Setll instead of maintaining the KLIST. This helps eliminating multiple KLIST entries and Code looks cleaner for Modification/Analysis.
  • EXCEPT keyword can be avoided with Free-Format Specific %Fields(). This eliminates the O-Spec and Fields can be mentioned directly with UPDATE Keyword.

Easy to Understand/Maintain:

  • Free-Format File declarations has changed the way of File Declarations in F-Specs. You no longer need to remember the Position & Possible Values. This can be as simple as your Variables Declaration.
  • No need to follow the sequence. Variables can be declared in middle of File Declarations. This helps declaring the Stand alone fields used for file processing to be defined immediately after File Declaration.
Not to Miss, It helps young developer to understand RPG quickly and learn.

Saturday, September 10, 2016

IBM i Updates Android Application

Happy to share the Android Application for this website.

Click Here to download the application.

You might have to allow installation of Third Party Applications to be able to install this app.

Working with 5250 Emulator from IBM Navigator for i

The Web based Navigator for i is a new interface for IBM i. This will change the way you look at IBM i completely.

This advanced Set Target System feature lets you manage any IBM i in your environment from a single browser. But its real power is allowing you to use the newest version of the web console against systems at older releases, including IBM i 6.1 and IBM i 5.4.

The web based console now includes a 5250 Emulator for those times when you just need a good old fashioned command-line interface. The integrated DB2 Database has enhancements on both the web-based and Windows based consoles to improve performance analysis and provide more gradual user access.

Speaking of performance, the Performance Data Investigator continues enhancing its visual yet power fun analysis and reporting interface. Journal now provides a full set of options to display and control journal objects.

I felt very excited to see this change happening in IBM i and looking forward for more such enhancements which will benefit the IBM i's end customers as well as developers :-)

Below screenshots will give you quick steps on how to get started with Web navigator for i.












Source : IBM


Popular Posts