mardi 26 juillet 2011

How to insert Data into AssetTable using Number Sequence for AssetId

here is the job:


// Changed on 22 Jui 2011 at 17:28:00 by ibs

static void Import_Immob(Args _args)
{
    AssetTable              assetTable;
    NumberSeq               assetIdNumberSeq;
    AssetId                 assetIdAllocated;
    container               c;
    TextIo                  io;
    String50                filename;
    AssetBook               AssetBook, AssetBook_Update;
    String30                grp, name;
    integer                 qty;
    AssetId                 assetId;
    Numberseq               num;
    String30                stop;
    AssetBookId             assetBookId;
    AssetAcquisitionDate    AcquisitionDate;
    String30                stringdate;

    ;
    ttsbegin;
    delete_from assetTable where assetTable.createdBy =='ibs';
    delete_from assetBook  where assetBook.createdBy  =='ibs';

    fileName = @"C:\\IMMOB\IMMOB.csv";
    io = SysLicenseCodeReadFile::openFile(fileName,'r');
    if (!io)
        throw error(strfmt("@SYS18678",fileName));
    io.inFieldDelimiter(";");
     c = io.read();
    while (io.status() == IO_Status::Ok)
    {
        c = io.read();

        if (io.status() != IO_Status::Ok)
          break;

        grp                = conpeek(c,1);
        name               = conpeek(c,3);
        qty                = str2int(conpeek(c,4));
        stringdate         = conpeek(c,6);
        AcquisitionDate    = str2date(stringdate,123);
        assetBookId        = conpeek(c,5);

        while (qty > 0)
        {
            assetTable.assetGroup           = grp;
            assetTable.Name                 = name;
            assetTable.NameAlias            = name;
            assetId                         = assetTable.initAssetNumberSeq(grp).num();
            AssetTable.AssetId              = assetId;
            assetTable.initAssetNumberSeq(grp).used();

            assetTable.insert();


            print qty;

            qty = qty - 1;

        }

    }
    info("finished");
    info(strfmt(assetId));
    ttscommit;

}

and in AssetBook 

static void Update_AssetBook(Args _args)
{
    AssetTable              assetTable;
    NumberSeq               assetIdNumberSeq;
    AssetId                 assetIdAllocated;
    container               c;
    TextIo                  io;
    AssetId                 assetId;
    String50                filename;
    AssetBook               AssetBook, AssetBook_Update;
    String30                grp, name;
    integer                 qty;
    Numberseq               num;
    String30                stop;
    AssetBookId             assetBookId;
    AssetAcquisitionDate    AcquisitionDate;
    String30                stringdate;
    Integer                 IncrementNum;
    String30                StrSub0, StrSub;
    String30                assetIdStr, Nums;
    Integer                 size;
    AssetAcquisitionDate    assetAcquisitionDate;

    ;

    ttsbegin;
    delete_from assetBook ;


    fileName = @"C:\\IMMOB\Immob_Rectif.csv";
    io = SysLicenseCodeReadFile::openFile(fileName,'r');
    if (!io)
        throw error(strfmt("@SYS18678",fileName));
    io.inFieldDelimiter(";");
     c = io.read();
    while (io.status() == IO_Status::Ok)
    {
        c = io.read();

        if (io.status() != IO_Status::Ok)
          break;

        assetBookId                 = conpeek(c,1);
        assetId                     = conpeek(c,2);
        qty                         = str2int(conpeek(c,3));
        StrSub0                     = substr(assetId,1,4);
        StrSub                      = substr(assetId,5,4);
        IncrementNum                = str2num(StrSub);
        assetAcquisitionDate        = str2date(conpeek(c,4),123);


        while (qty > 0)
        {
            size                = strlen(int2str(IncrementNum));
            Nums              = int2str(IncrementNum);
            while (size < 4 )
            {
                Nums          =  '0' + Nums;
                size = size + 1;
            }

            assetIdStr   = StrSub0 + Nums;
            if ( assetBook::Find(assetIdStr, assetBookId).RecId == 0)
            {
                assetBook.BookId            = assetBookId;
                assetBook.PostingProfile    = "IMMOB";
                assetBook.AcquisitionDate   = assetAcquisitionDate;
                assetBook.AssetId           = assetIdStr;
                assetBook.insert();
            }
            IncrementNum =  IncrementNum + 1;
            print IncrementNum;

            qty = qty -1 ;
        }
    }

    info("finished");
    info(strfmt(assetId));
    ttscommit;

}

Aucun commentaire:

Enregistrer un commentaire