Support This Project Get i5/OS Programmer's Toolkit at SourceForge.net. Fast, secure and Free Open Source software downloads

Demos of Subproject as-400

Here're demo programs that utilizing the remote access AS3 classes provided by subproject as-400 to access an IBM i server.

Enqueue a User Queue (USRQ) object at an IBM i server

Flash Program t007.as enqueue a user queue object (USRQ), QGPL/Q007, at an IBM i server. When the apple is clicked, the following event handler method is invoked. The ENQ API is called to enqueue the target USRQ. The DSPQMSG command can be used to check the queue entries being put on USRQ QGPL/Q007.
        private function onBtnClick(evt:MouseEvent) : void {
            // call I5TOOLKIT/ENQ to enqueue target USRQ
            var pgm_call:RemoteCommand =
                new RemoteCommand(i_host.text,
                                  i_user.text,
                                  i_pwd.text,
                                  "I5TOOLKIT",
                                  "ENQ");
            var i:int = 0;
            var exp_id:String = ""; for(i = 0; i < 7; i++) exp_id += String.fromCharCode(0);
            var exp_data:ByteArray = new ByteArray(); for(i = 0; i < 16; i++) exp_data.writeByte(0);
            var argl:Vector.<ProgramArgument> =
                new <ProgramArgument>[new ProgramArgument(new EBCDIC(20),
                                                          ProgramArgument.INPUT,
                                                          "Q007      QGPL"),
                                      new ProgramArgument(new EBCDIC(1),
                                                          ProgramArgument.INPUT,
                                                          String.fromCharCode(2)),
                                      new ProgramArgument(new Bin4(),
                                                          ProgramArgument.INPUT,
                                                          0),
                                      new ProgramArgument(new EBCDIC(1),
                                                          ProgramArgument.INPUT,
                                                          String.fromCharCode(0)),
                                      new ProgramArgument(new Bin4(),
                                                          ProgramArgument.INPUT,
                                                          64),
                                      new ProgramArgument(new EBCDIC(64),
                                                          ProgramArgument.INPUT,
                                                          i_msg.text),
                                      new ProgramArgument(new CompositeType(new Bin4(),
                                                                            new Bin4(),
                                                                            new EBCDIC(7),
                                                                            new EBCDIC(1),
                                                                            new HexData(16)),
                                                          ProgramArgument.INOUT,
                                                          new CompositeData(32,
                                                                            0,
                                                                            exp_id,
                                                                            String.fromCharCode(0),
                                                                            exp_data)
                                                          ) // Qus_EC_t
                                      ];
            pgm_call.callx(this, enq_callback, argl);

        }

        private function enq_callback(rc:int,
                                      argl:Vector.<ProgramArgument>,
                                      msg:String = null) : void {
            trace("Call to ENQ returns ...");

            var ec:CompositeData = argl[6].value as CompositeData;
            var ds:Vector.<Object> = ec.elements;
            trace("ec.bytes-in:", ds[0]); // ec.bytes-in
            if(ds.length > 1) {
                trace("ec.bytes-out:", ds[1]); // ec.bytes-out
                trace("ec.exp_id:", ds[2]);
            } else
                trace("ec.bytes-out NOT returned!!");
        }

Screenshot of t007.swf. A mocked version (does not actually make program call) of t007.swf is here.

t007.png

Call an RPG program that returns the current timestamp of an IBM i server

To call an IBM i host program, one need to cooperate with one of the IBM i host servers, the IBM i remote command server. The full name of this server is, remote command and distributed program call server (according to the IBM i info-center). In as-400, the core class to allow users call an IBM i program is the as400.prototype.RemoteCommand .

The following simple ILE RPG program takes a single CHAR(26) output parameter ts. On return, it set ts to the current timestamp of your IBM i server.

     d la              pr                  extpgm('YY275')
     d     ts                        26a

     d la              pi
     d     ts                        26a

      /free
           ts = %char(%timestamp());

           *inlr = *on;
      /end-free

The following AS3 program test2.as calls RPG program YY275 on your IBM i server.

package {

    import flash.display.*;
    import flash.system.*;
    import flash.text.*;
    import flash.events.*;

    import as400.prototype.*;

    public class test2 extends Sprite {

        private var host_:TextField;
        private var user_:TextField;
        private var pwd_:TextField;
        private var ts_:TextField;   // current timestamp on the remote server
        private var btn_:UButton;

        public function test2() {

            this.opaqueBackground = new Number(0x8b3a3a);
            load_image();

            // host name
            var host:TextField = new TextField();
            host.width = 200;
            host.alpha     = 0.85;
            host.textColor = 0xff4500;  // orange red
            host.autoSize  = TextFieldAutoSize.RIGHT;
            host.text = "Name of your IBM i server";
            addChild(host);

            host_ = new TextField();
            host_.x = 220;
            host_.width = 200;
            host_.height = 20;
            host_.alpha  = 0.85;
            host_.border = true;
            host_.background = true;
            host_.type   = TextFieldType.INPUT;
            addChild(host_);

            // user name
            var user:TextField = new TextField();
            user.width = 200;
            user.y     = 30
            user.alpha     = 0.85;
            user.textColor = 0xff4500;  // orange red
            user.autoSize  = TextFieldAutoSize.RIGHT;
            user.text = "User name";
            addChild(user);

            user_ = new TextField();
            user_.x = 220;
            user_.y     = 30
            user_.width = 200;
            user_.height = 20;
            user_.alpha  = 0.85;
            user_.border = true;
            user_.background = true;
            user_.type   = TextFieldType.INPUT;
            addChild(user_);

            // password: pwd_.displayAsPassword = true;
            var pwd:TextField = new TextField();
            pwd.width = 200;
            pwd.y     = 60
            pwd.alpha     = 0.85;
            pwd.textColor = 0xff4500;  // orange red
            pwd.autoSize  = TextFieldAutoSize.RIGHT;
            pwd.text = "Password";
            addChild(pwd);

            pwd_ = new TextField();
            pwd_.x = 220;
            pwd_.y     = 60
            pwd_.width = 200;
            pwd_.height = 20;
            pwd_.alpha  = 0.85;
            pwd_.border = true;
            pwd_.background = true;
            pwd_.type   = TextFieldType.INPUT;
            pwd_.displayAsPassword = true;
            addChild(pwd_);

            ts_ = new TextField();
            ts_.x = 100;
            ts_.y = 100;
            ts_.width = 300;
            ts_.height = 20;
            ts_.textColor = 0xadff2f; // green yellow
            ts_.alpha     = 0.8;
            // ts_.autoSize = TextFieldAutoSize.LEFT;
            ts_.antiAliasType = AntiAliasType.ADVANCED;
            ts_.text = "Current timestamp on your IBM i server";
            addChild(ts_);

            btn_ = new UButton();
            btn_.addEventListener(MouseEvent.CLICK, onBtnClick);
            btn_.y = 100;
            addChild(btn_);
        }

        private function onBtnClick(evt:MouseEvent) : void {
            test_call();
        }

        private function pgmcall_callback(rc:int,
                                          argl:Vector.<ProgramArgument>,
                                          msg:String = null) : void {
            if(rc != 0)
                ts_.text = msg;
            else
                ts_.text = String(argl[0].value);
        }

        private function test_call() : void {

            var pgm_call:RemoteCommand
                = new RemoteCommand(host_.text,
                                    user_.text,
                                    pwd_.text,
                                    "QGPL",
                                    "YY275"
                                    );

            // compose the argument list
            var argl:Vector.<ProgramArgument>
                = new <ProgramArgument>[new ProgramArgument(new EBCDIC(26),
                                                            ProgramArgument.OUTPUT)];

            // call target program on host server
            pgm_call.callx(this, pgmcall_callback, argl);
        }

        private function load_image() : void {

            var w:int = assets.HELLO_PNG_W;
            var h:int = assets.HELLO_PNG_H;
            var dta:BitmapData = new BitmapData(w, h, true);
            for(var i:int = 0; i < w; i++)
                for(var j:int = 0; j < h; j++)
                    dta.setPixel32(i, j, uint(assets.HELLO_PNG_DTA[i * h + j]));

            // draw image
            graphics.beginBitmapFill(dta, null, false);
            graphics.drawRect(0, 0, w, h);
            graphics.endFill();
        }

    } // class
} // package

Here's the screenshot when you click the button in the lower left corner.

test2.png

Support This Project
Generated on Wed Jul 20 08:10:53 2011 for i5/OS Programmer's Toolkit: AS-400 by  doxygen 1.5.9