How to import data when text length is max?

Hi Sir,

I want import into Customer Table. I can write import Data Port. But some data is max customer table field length. So i wann to move that data to other field.

Eg.

“S007”,“Sino Holdings Pte Ltd-Mte Fund for Leonie Hill Residence”,"",“No.1 Jalan Berseh”,""#03-03",“New World Centre”",“Singapore”,“Singapore 209037”,“SG”,"","","","","","",“SGD”,"",“LOCAL”,“LOCAL”,“LOCAL”,“30 DAYS”

"Sino Holdings Pte Ltd-Mte Fund for Leonie Hill Residence" is length is over 50.

So i wann to save “name” field into 50 char. Another char save in “name2”.

I use “customer”

Please Help to me.

Best Regards

Hi

You can check the length of this name field using STRLEN function.

if length is more than 50 then you have to cut the first 50 character in to name field & remianing in other new field.

Therefore you need to define a global variable of the type text with a size big enough to store the complete name (more than 50 characters.)

Then you assign this variable to the dataport fields and create code in the “OnAfterImportRecord” trigger which checks the sizes and assigns to the correct fields:

IF STRLEN(NameVar) > MAXSTRLEN(Name) THEN BEGIN
Name := COPYSTR(NameVar,1, MAXSTRLEN(Name));
"Name 2" := COPYSTR(NameVar,MAXSTRLEN(Name) + 1);
END ELSE
Name := NameVar;

Hi

Just copy this code & crete a simpel dataport i have taken 2 fields.

create a csv file with only 2 values like

12345 TestingTestingTestingTestingTestingTestingTestingTestingTestingTesting

Now try to import this csv file using dataport below it will copy first 50 character in name & other in name 2 field

OBJECT Dataport 50001 Cust
{
OBJECT-PROPERTIES
{
Date=16/03/09;
Time=16:24:36;
Modified=Yes;
Version List=;
}
PROPERTIES
{
}
DATAITEMS
{
{ PROPERTIES
{
DataItemTable=Table18;
OnAfterImportRecord=BEGIN
custrec.INSERT;
custrec.“No.”:=custno;
custrec.Name:=COPYSTR(custname,1,30);
custrec.“Name 2”:=COPYSTR(custname,31,60);
custrec.INSERT;
END;

}
FIELDS
{
{ ; ;custno }
{ ; ;custname }
}
}
}
REQUESTFORM
{
PROPERTIES
{
Width=9020;
Height=3410;
}
CONTROLS
{
}
}
CODE
{
VAR
custno@1000000000 : Code[20];
custname@1000000001 : Text[100];
custrec@1000000002 : Record 18;

BEGIN
END.
}
}

Ashish, please try your code before posting it here. This dataport will not work because:

  1. You should not do a manual INSERT in code before setting the “AutoSave” property of the dataitem to false - your code fails on the first line imported;
  2. You should not call the INSERT statement twice - your code fails on the second line imported.

Additionally there are a few (smaller) issues with your code:

Since recent versions the length of the name fields in the customer table (and others as well) are changed from 30 to 50. Your code would not cater for that. Rather consider using the MAXSTRLEN function instead.
You should (before assigning any field to the new customer) call an INIT on the customer table to make sure that all fields are cleared/initialized propertly, according to the InitValue of the fields.

Hi Sir,

Thx for your reply. I wrote your way point. I declare global variable. Then i put that variable in “Dataport Fields”. But it is not work. It sho show error message like that " Sino Holdings Pte Ltd-Mte Fund for Leonie Hill Residence is max length."

I put your code at  "OnAfterImportRecord".

IF STRLEN(NameVar) > MAXSTRLEN(Name) THEN BEGIN
  Name := COPYSTR(NameVar,1, MAXSTRLEN(Name));
  "Name 2" := COPYSTR(NameVar,MAXSTRLEN(Name) + 1);
END ELSE
  Name := NameVar;

I don’t clear . How to get data in “NameVar”? It source is “NameVar” at “Dataport”. It length is show zero when i wrote message.

Please help & teach me

My Object Here:

OBJECT Dataport 50005 T - Customer - Export/Import
{
OBJECT-PROPERTIES
{
Date=03/17/09;
Time=[ 3:38:56 PM];
Modified=Yes;
Version List=;
}
PROPERTIES
{
FieldStartDelimiter=;
FieldEndDelimiter=;
}
DATAITEMS
{
{ PROPERTIES
{
DataItemTable=Table50001;
DataItemTableView=SORTING(No.)
ORDER(Ascending)
WHERE(No.=FILTER(<>’’));
ReqFilterFields=No.,Name;
OnAfterImportRecord=BEGIN
IF STRLEN(NameVar) > MAXSTRLEN(Name) THEN BEGIN
Name := COPYSTR(NameVar,1, MAXSTRLEN(Name));
“Name 2” := COPYSTR(NameVar,MAXSTRLEN(Name) + 1);
END ELSE
Name := NameVar;
END;

}
FIELDS
{
{ ; ;“No.” }
{ ; ;Name }
{ ; ;“Name 2” }
{ ; ;Address }
{ ; ;“Address 2” }
{ ; ;City }
{ ; ;“Post Code” }
{ ; ;County }
{ ; ;Contact }
{ ; ;“Phone No.” }
{ ; ;“Fax No.” }
{ ; ;“E-Mail” }
{ ; ;“Home Page” }
{ ; ;“Salesperson Code” }
{ ; ;“Currency Code” }
{ ; ;“Customer Posting Group” }
{ ; ;“Gen. Bus. Posting Group” }
{ ; ;“VAT Bus. Posting Group” }
{ ; ;“Payment Terms Code” }
{ ; ;“Payment Method Code” }
{ ; ;“Location Code” }
{ ; ;“Shipment Method Code” }
{ ; ;“VAT Registration No.” }
{ ; ;NameVar ;Enabled=No }
}
}
}
REQUESTFORM
{
PROPERTIES
{
Width=9020;
Height=3410;
}
CONTROLS
{
}
}
CODE
{
VAR
NameVar@1000000000 : Text[1024];

BEGIN
END.
}
}

Data is here:

S007,Sino Holdings Pte Ltd-Mte Fund for Leonie Hill Residence,No.1 Jalan Berseh,#03-03New World Centre,Singapore,Singapore 209037,SG,SGD,LOCAL,LOCAL,LOCAL,30 DAYS

Regards

You should use NameVar as second line in the dataport fields (instead of Name).

Additionally the size of this text variable must be big enough to store the complete content of the text. So I suggest to use a Text with a length of 100.

Hi Sir,

Thx, I get it.

Regards,