Mar 28, 2012

How to use ternary operator?


static void intro_ternaryOperator(Args _args)
{
    Boolean         a = true;
    ;
    info(a?"Customer name":"Coustomer account");

}

How to get dataAreaId ?


static void DataDic_ChangeCompany(Args _args)
{
    DataArea dataArea;
    CustTable custTable;
    ;
    while select dataArea
    {
        if (!dataArea.isVirtual)
        {
        info(strfmt("Company: %1", dataArea.Id));
            changeCompany(dataArea.id)
            {
            custTable = null;
                while select custTable
                {
                info(strfmt("%1, %2", custTable.dataAreaId, custTable.accountNum));
                }
            }
        }
    }
}

How to display the field values separating by comma?

This simple job displays all the itemnames horizontally separated by comma  of  PO (000386)  lines


static void myTest(Args _args)
{

    PurchLine               PurchLine;
    Str                         itemName;
    boolean                 multipleTrans = false;
    ;
    while select PurchLine
        where PurchLine.purchId  == '000386'
    {
            if (multipleTrans == true)
            {
                itemName += " ,  ";
            }
             itemName += PurchLine.Name;
             multipleTrans = true;
    }
     info(itemName);
}

 O/P :    High End Speaker - ash/14 inches ,  Projection Television Model 01

How to get the current month and day of the year ?


The below job gives the current month of the year

static void mthOfYrExample(Args _arg)
{
    int i;
    ;
    i = mthOfYr(today());
    info( "The number of the month in today's date is " + int2Str(i));

}

The below job gives the current day of the year


static void dayOfYrExample(Args _arg)
{
    date d = today();
    int i;
    ;
    i = dayOfYr(d);
    info( "Today's day of the year is " + int2Str(i));
 
}

     Just try this job
----------------------

static void dateExample(Args _arg)
{
    date d = today();
    str s;
    ;
    info(strfmt("%1,%2,%3",dayOfmth(d),mthofyr(d),year(d)));

}




How to validate the alphabets?


The below simple job checks that the given string contains only alphabets or not ...

static void TextBuffer_regularExpression(Args _args)
{
    TextBuffer txt = new TextBuffer();
    str msg = "ABCDEFGS";
    ;

    txt.setText(msg);
    txt.regularExpressions(true);   // activate regular expr in search


     // Regular expression to validate only alphabets
    if (txt.find("^[A-Z]+$"))
    {
        info("String contains only Alphabets");
    }
    else
    {
        info("String contains others characters");
    }

}