Techs


White Board

Most programmers claim to understand but can’t explain it. The vendors I dealt with in China and Dubai claims to able to do it, and then repented.

I don’t get it. What is so hard about IBM packed fields?

Packed field is an efficient way to store numbers, maybe not as efficient as an int but it’s commonly used on the IBM AS/400 platform.

Digits 123 can be represented in ASCII hex 313233 or in EBCDIC hex as F1F2F3. Packed field stores the number directly as hex 123F, which is neither ASCII nor EBCDIC. This shortens the size required to store digits. The last nibble (half of a byte) can be either D or F representing a negative or positive integer.

The obvious benefit is of course, if you’re paying your bandwidth by the number of bytes you’re transmitting, you’d want the data compressed. Packed fields keep numeric fields’ size small.

Someone asked me, assuming you know it’s a packed field with certain length, how do you test for a valid packed value?

This is what I came up with in ILE RPG:

 *
H BndDir('QC2LE')
 *
D getHex          Pr                  ExtProc('cvthc')
D                                1A
D                                1A
D                               10I 0 Value
 *
 * Use with entry parameters
D pValue          S             20A
D pResult         S              1N
 *
 * Use with working fields
D                 Ds
D  xHex                         40A   Inz(*Blanks)
D  xHexS                         2S 0 Dim(20) Overlay(xHex:1)
D  xHexA                         2A   Dim(20) Overlay(xHex:1)
 *
D xLen            S              5U 0 Inz(*Zeros)
D xPos            S                   Like(xLen) Inz(*Zeros)
D xVal            S                   Like(xLen) Inz(*Zeros)
 *
D cNumeric        C                   Const('0123456789')
D cYes            C                   Const(*On)
D cNo             C                   Const(*Off)
 *
C     *Entry        Plist
C                   Parm                    pValue
C                   Parm                    pResult
 *
C                   Movel(P)  cNo           pResult
C                   Eval      xLen = %CheckR(' ':pValue)
 *
C                   If        (xLen > *Zeros)
C                   CallP     getHex(xHex:pValue:%Size(xHex))
 *
C                   For       xPos = 1 By 1 To xLen
 *
C                   Eval      xVal = %Check(cNumeric:xHexA(xPos):1)
 *
C                   If        (xVal > *Zeros) And (xPos < xLen)
 *                  Not last byte and value contains non-numeric.
C                   Leave
 *
C                   ElseIf    (xPos = xLen) And
C                             ((%Subst(xHexA(xPos):2:1) <> ‘D’) And
C                              (%Subst(xHexA(xPos):2:1) <> ‘F’))
 *                  Last byte and value contains non-acceptable
 *                  non-numeric.
C                   Leave
 *
C                   ElseIf    (xPos = XLen)
C                   Move      cYes          pResult
 *
C                   Else
 *                  Try to ridicule the compiler.
C                   Monitor
C                   If        ((xHexS(xPos) > 99) And (xPos < xLen))
C                   Leave
C                   EndIf
C                   On-Error
C                   Leave
C                   EndMon
C                   EndIf
 *
C                   EndFor
 *
C                   EndIf
 *
C                   Return
 *

So the final else condition isn’t really necessary, but I never did test this piece of code and I rather play it safe.

The code should be self-explained. Convert the value to hex, and start comparing byte by byte whether it contains valid numerical digits. Except for the last nibble, it must have either hex of D or F. Anything else is invalid.

Program returns true if given value is a valid packed field candidate.

OPCAT Mac OS X

I’m currently in Singapore attending an advanced session on OPCAT (Object Process Case Tool), a modeling tool based on OPM (Object Process Methodology).

A recent OPCAT upgrade from version 2.xx to version 3.00 also requires a JRE upgrade from JRE 1.5 to JRE 1.6. As of Mac OS X 10.4.10 the standard is still JRE 1.5. Mac OS X users would need to download Java SE 6.0 from ADC website.

After installing JRE 1.6 you need to set JRE 1.6 as the default Java Runtime version. To do this, go to Applications -> Utilities -> Java SE 6 and click on Java Preferences. Under Java Applications Runtime settings under General tab, drag Java SE 6 to be the first one on the list. Your other JREs are still on the system and you may revert if necessary.

Next, having installed (proper .exe decompression) OPCAT in my Windows VM I copied the entire folder to my Mac OS X environment. Since OPCAT is written in Java it would run cross-platform, but unlike previous OPCAT version some minor tweaking is required to get it running smooth on Mac and Linux.

There are four environment variables that must be set manually. If you ran OPCAT installer on Windows, check your system variables and you should see the following:

  • OPCAT_BACKUP_HOME=C:\Program Files\Opcat
  • OPCAT_COLORS_HOME=C:\Program Files\Opcat
  • OPCAT_HOME=C:\Program Files\Opcat
  • OPCAT_PROJECTS_HOME=C:\Documents and Settings\…
  • To set environment variables in Mac OS X, you could run command shell and use env command. For lazy bumps there’s a free RCEnvironment utility which allow users to control their environment variables in GUI from the Preferences pane.

    I have mine set like this:

  • OPCAT_BACKUP_HOME=/Users/datacrush/Opcat
  • OPCAT_COLORS_HOME=/Users/datacrush/Opcat
  • OPCAT_HOME=/Users/datacrush/Opcat
  • OPCAT_PROJECTS_HOME=/Users/datacrush/Documents
  • If this doesn’t work for Linux users, here’s a clue: The OPCAT Java class responsible for loading paths is using System.getenv().get("OPCAT_HOME"). Go figure.

    Of course, you’re free to move your OPCAT folder anywhere you want on the system, even under Applications if you wish. I would recommend that you keep OPCAT_HOME and OPCAT_PROJECTS_HOME separated to simplify any future upgrades. Just make sure your environment variables are set accordingly.

    A system restart is not necessary at this point, but recommended. A simple user logout and login would suffice.

    To run OPCAT on a Mac OS X or Linux you may ignore opcat2.exe file and click on opcat2.jar or run java -jar opcat2.jar from your command shell instead.

    Be warn though that presently some paths inside .opz files are hard coded to point to a particular directory, say file://C:\Documents And Settings\... which would cause OPCAT to fail on a Mac with a java.lang.String.subString error when loading such .opz file. This isn’t a major issue since I’m able to manually edit an .opz file with a text editor and fix the erroneous file paths. I believe future version of OPCAT would resolve this problem.

    OPCAT 3.00 has taken OPM concept a step further, having improved in areas of teamwork modeling and simulation. While the previous version had an Academia look and feel, this latest update to Prof. Dov Dori’s OPM arsenal reflects a more professional commercial product.

    Also, OPCAT 3.00 look and feel blends seamlessly with Mac OS X. Cool!

    Cisco Router

    Quake in Taiwan cripples Internet. The title says it all.

    While many Internet Service Providers in South East Asia are affected by the crippled international link in Taiwan, the truth is that some ISPs are just plain incompetent. It just goes to show how much (or lack of) readiness the ISPs have to handle emergencies.

    For Streamyx, a leading ISP in Malaysia by government linked monopoly this is the time to put the blame on Taiwan’s international link. The truth is more sinister. They’re lazy and incompetent.

    A simple traceroute reveals poor network traffic route management. Take for example 72.14.207.191, one of Google’s node.

    • 10.100.0.1
    • 219.93.218.177 - Subang Jaya, Selangor, MY
    • 219.93.216.189 - Petaling Jaya, Selangor, MY
    • 210.187.142.1 - Kangar, Perlis, MY
    • 210.187.142.5 - Kangar, Perlis, MY
    • 219.94.12.138
    • 210.187.133.83 - Labuan, Sabah, MY
    • 58.27.124.54 - Kuala Lumpur, Federal Territory, MY
    • 219.94.9.25
    • 219.94.9.42
    • 195.66.224.125 - London, England, UK
    • 72.14.236.216
    • 72.14.236.213
    • 72.14.233.113
    • 66.249.94.92
    • 66.249.94.50
    • eh-in-f191.google.com [72.14.207.191]

    Now, if you’re familiar with Malaysia’s geography you can tell that this is stupid. The trace was done from Subang Jaya in Selangor state. It hits Perlis state in northern Malaysia, then to Sabah state just across the wide South China Sea, and then back to Kuala Lumpur, adjacent to Selangor before reaching the international gateway.

    Yes, I know how Internet works. I know how router works. A lot of people do. So, why would Streamyx try to weasel out by blaming it on the fastest available route? Only if they’re incompetent and they themselves don’t know how to manage network efficiently, that’s why.

    I tried the same trace 3 days later, and it gave me a similar result. This is not a packet routing issue. It’s just bad routing table entries.

    To confirm my suspicions, I manually routed my connections to a VPN port I left open in Tokyo, Japan. I have less network issues when I route it through there and I can easily hit international nodes that I should but can’t even see without starting VPN.

    Then I went to use Internet at an international brand hotel that uses MagiNet for broadband access, and found a more efficient route without VPN. It doesn’t look good for Streamyx, in fact, it’s beginning to smell like a dead woodchuck under the porch.

    Telekom Malaysia, the parent of Streamyx, like most Malaysian government linked companies is a Malay-centric organization that often don’t deliver the best but takes credit when something randomly goes right and makes junk-o-logic comparison with their Singapore counterpart when things goes wrong.

    Bad Internet is high on my whine list since I arrived here couple weeks ago.

    Next Page »