|
|
#1 |
|
Участник
|
в общем как правильно перетащить программный код из Отчета с несколькими датаитемами в функцию кодеюнита.
Пример: DataItem Item <Item> OnPreDataItem code_1 OnAfterGetrecord OnPostDataItem Integer BOMLoop OnPreDataItem code_2 OnAfterGetrecord code_3 OnPostDataItem Integer <Integer> OnPreDataItem OnAfterGetrecord code_4 OnPostDataItem code_5 Я так понимаю что должно быть так: Код: repeat code_1 repeat code_2 code_3 repeat code_4 code_5 until until until |
|
|
|
|
#2 |
|
Участник
|
REPORT.RUN(ReportID, FALSE, FALSE, Item);
|
|
|
|
|
#3 |
|
Участник
|
мне не надо его запускать
|
|
|
|
|
#4 |
|
Участник
|
Я подозреваю, что OnPreDataItem (то есть Code_1 и Code_2) должно быть перед соответствующим Repeat. Смотря что там делается.
|
|
|
|
|
#5 |
|
Участник
|
DataItem
Item <Item> OnPreDataItem code_1 OnAfterGetrecord OnPostDataItem Integer BOMLoop OnPreDataItem code_2 OnAfterGetrecord code_3 OnPostDataItem Integer <Integer> OnPreDataItem OnAfterGetrecord code_4 OnPostDataItem code_5 Код: Item - OnPreDataItem()
ItemFilter := Item.GETFILTERS;
SETFILTER("Production BOM No.",'<>%1','');
Item - OnAfterGetRecord()
Item - OnPostDataItem()Код: BOMLoop - OnPreDataItem()
Level := 1;
ProdBOM.GET(Item."Production BOM No.");
VersionCode[Level] := VersionMgt.GetBOMVersion(Item."Production BOM No.","Calc.Date",FALSE);
CLEAR(BomComponent);
BomComponent[Level]."Production BOM No." := Item."Production BOM No.";
BomComponent[Level].SETRANGE("Production BOM No.",Item."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
BomComponent[Level].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[Level].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
NoList[Level] := Item."No.";
Quantity[Level] :=
UOMMgt.GetQtyPerUnitOfMeasure(Item,Item."Base Unit of Measure") /
UOMMgt.GetQtyPerUnitOfMeasure(
Item,
VersionMgt.GetBOMUnitOfMeasure(
Item."Production BOM No.",VersionCode[Level]));
UpperLevelItem := Item;
BOMLoop - OnAfterGetRecord()
MESSAGE('1');
WHILE BomComponent[Level].NEXT = 0 DO BEGIN
Level := Level - 1;
IF Level < 1 THEN
CurrReport.BREAK;
IF NOT UpperLevelItem.GET(NoList[Level]) THEN
UpperLevelItem."Production BOM No." := NoList[Level];
BomComponent[Level].SETRANGE("Production BOM No.",UpperLevelItem."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
END;
NextLevel := Level;
CLEAR(CompItem);
QtyPerUnitOfMeasure := 1;
CASE BomComponent[Level].Type OF
BomComponent[Level].Type::Item:
BEGIN
CompItem.GET(BomComponent[Level]."No.");
IF CompItem."Production BOM No." <> '' THEN BEGIN
NextLevel := Level + 1;
CLEAR(BomComponent[NextLevel]);
NoList[NextLevel] := CompItem."No.";
VersionCode[NextLevel] :=
VersionMgt.GetBOMVersion(CompItem."Production BOM No.","Calc.Date",FALSE);
BomComponent[NextLevel].SETRANGE("Production BOM No.",CompItem."Production BOM No.");
BomComponent[NextLevel].SETRANGE("Version Code",VersionCode[NextLevel]);
BomComponent[NextLevel].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[NextLevel].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
QtyPerUnitOfMeasure :=
UOMMgt.GetQtyPerUnitOfMeasure(
Item,
Item."Base Unit of Measure") /
UOMMgt.GetQtyPerUnitOfMeasure(
CompItem,
VersionMgt.GetBOMUnitOfMeasure(
CompItem."Production BOM No.",VersionCode[NextLevel]));
END;
IF Level > 1 THEN BEGIN
IF BomItem.GET(BomComponent[Level - 1]."No.") THEN BEGIN
QtyPerUnitOfMeasure :=
UOMMgt.GetQtyPerUnitOfMeasure(BomItem,BomComponent[Level - 1]."Unit of Measure Code")
/
UOMMgt.GetQtyPerUnitOfMeasure(
BomItem,VersionMgt.GetBOMUnitOfMeasure(BomItem."Production BOM No.",VersionCode[Level]));
END;
END;
END;
BomComponent[Level].Type::"Production BOM":
BEGIN
ProdBOM.GET(BomComponent[Level]."No.");
NextLevel := Level + 1;
CLEAR(BomComponent[NextLevel]);
NoList[NextLevel] := ProdBOM."No.";
VersionCode[NextLevel] := VersionMgt.GetBOMVersion(ProdBOM."No.","Calc.Date",FALSE);
BomComponent[NextLevel].SETRANGE("Production BOM No.",NoList[NextLevel]);
BomComponent[NextLevel].SETRANGE("Version Code",VersionCode[NextLevel]);
BomComponent[NextLevel].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[NextLevel].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
END;
END;
IF NextLevel <> Level THEN
Quantity[NextLevel] := BomComponent[NextLevel - 1].Quantity * QtyPerUnitOfMeasure * Quantity[Level];
BOMLoop - OnPostDataItem()Код: Integer - OnPreDataItem() Integer - OnAfterGetRecord() BOMQty := Quantity[Level] * QtyPerUnitOfMeasure * BomComponent[Level].Quantity; Integer - OnPostDataItem() Level := NextLevel; IF CompItem."Production BOM No." <> '' THEN UpperLevelItem := CompItem; Код: ItemPresents.COPY(Rec);
REPEAT
ItemPresents.SETFILTER("Production BOM No.",'<>%1','');
REPEAT
Level := 1;
ProdBOM.GET(ItemPresents."Production BOM No.");
VersionCode[Level] := VersionMgt.GetBOMVersion(ItemPresents."Production BOM No.","Calc.Date",FALSE);
CLEAR(BomComponent);
BomComponent[Level]."Production BOM No." := ItemPresents."Production BOM No.";
BomComponent[Level].SETRANGE("Production BOM No.",ItemPresents."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
BomComponent[Level].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[Level].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
NoList[Level] := ItemPresents."No.";
Quantity[Level] :=
UOMMgt.GetQtyPerUnitOfMeasure(ItemPresents,ItemPresents."Base Unit of Measure") /
UOMMgt.GetQtyPerUnitOfMeasure(
ItemPresents,
VersionMgt.GetBOMUnitOfMeasure(
ItemPresents."Production BOM No.",VersionCode[Level]));
UpperLevelItem := ItemPresents;
WHILE BomComponent[Level].NEXT = 0 DO BEGIN
Level := Level - 1;
IF Level < 1 THEN
EXIT;
IF NOT UpperLevelItem.GET(NoList[Level]) THEN
UpperLevelItem."Production BOM No." := NoList[Level];
BomComponent[Level].SETRANGE("Production BOM No.",UpperLevelItem."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
END;
NextLevel := Level;
CLEAR(CompItem);
QtyPerUnitOfMeasure := 1;
CASE BomComponent[Level].Type OF
BomComponent[Level].Type::Item:
BEGIN
CompItem.GET(BomComponent[Level]."No.");
IF CompItem."Production BOM No." <> '' THEN BEGIN
NextLevel := Level + 1;
CLEAR(BomComponent[NextLevel]);
NoList[NextLevel] := CompItem."No.";
VersionCode[NextLevel] :=
VersionMgt.GetBOMVersion(CompItem."Production BOM No.","Calc.Date",FALSE);
BomComponent[NextLevel].SETRANGE("Production BOM No.",CompItem."Production BOM No.");
BomComponent[NextLevel].SETRANGE("Version Code",VersionCode[NextLevel]);
BomComponent[NextLevel].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[NextLevel].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
QtyPerUnitOfMeasure :=
UOMMgt.GetQtyPerUnitOfMeasure(
ItemPresents,
ItemPresents."Base Unit of Measure") /
UOMMgt.GetQtyPerUnitOfMeasure(
CompItem,
VersionMgt.GetBOMUnitOfMeasure(
CompItem."Production BOM No.",VersionCode[NextLevel]));
END;
IF Level > 1 THEN BEGIN
IF BomItem.GET(BomComponent[Level - 1]."No.") THEN BEGIN
QtyPerUnitOfMeasure :=
UOMMgt.GetQtyPerUnitOfMeasure(BomItem,BomComponent[Level - 1]."Unit of Measure Code")
/
UOMMgt.GetQtyPerUnitOfMeasure(
BomItem,VersionMgt.GetBOMUnitOfMeasure(BomItem."Production BOM No.",VersionCode[Level]));
END;
END;
END;
BomComponent[Level].Type::"Production BOM":
BEGIN
ProdBOM.GET(BomComponent[Level]."No.");
NextLevel := Level + 1;
CLEAR(BomComponent[NextLevel]);
NoList[NextLevel] := ProdBOM."No.";
VersionCode[NextLevel] := VersionMgt.GetBOMVersion(ProdBOM."No.","Calc.Date",FALSE);
BomComponent[NextLevel].SETRANGE("Production BOM No.",NoList[NextLevel]);
BomComponent[NextLevel].SETRANGE("Version Code",VersionCode[NextLevel]);
BomComponent[NextLevel].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[NextLevel].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
END;
END;
IF NextLevel <> Level THEN
Quantity[NextLevel] := BomComponent[NextLevel - 1].Quantity * QtyPerUnitOfMeasure * Quantity[Level];
REPEAT
BOMQty := Quantity[Level] * QtyPerUnitOfMeasure * BomComponent[Level].Quantity;
Level := NextLevel;
IF CompItem."Production BOM No." <> '' THEN
UpperLevelItem := CompItem;
UNTIL BomComponent[Level].NEXT =0;
UNTIL BomComponent[Level].NEXT =0;
UNTIL ItemPresents.NEXT =0; |
|
|
|
|
#6 |
|
Участник
|
не срабатывает второй repeat
|
|
|
|
|
#7 |
|
Участник
|
Вот как мне кажется должно все выглядеть:
Тезрают сомнение: 1) EXIT; а отчете он пишется как CurrReport.BREAK; Код: WHILE BomComponent[Level].NEXT = 0 DO BEGIN
Level := Level - 1;
IF Level < 1 THEN
EXIT;
IF NOT UpperLevelItem.GET(NoList[Level]) THEN
UpperLevelItem."Production BOM No." := NoList[Level];
BomComponent[Level].SETRANGE("Production BOM No.",UpperLevelItem."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
END;во втором и третьем датаитеме: IF BomComponent[Level].FIND('-') THEN REPEAT 3) Выдается ошибка: Индекс массива 0 за пределами допустимого интервала.... мне кажется что это BomComponent[Level] Код: ItemPresents.COPY(Rec);
IF ItemPresents.FIND('-') THEN REPEAT
ItemPresents.SETFILTER("Production BOM No.",'<>%1','');
Level := 1;
ProdBOM.GET(ItemPresents."Production BOM No.");
VersionCode[Level] := VersionMgt.GetBOMVersion(ItemPresents."Production BOM No.","Calc.Date",FALSE);
CLEAR(BomComponent);
BomComponent[Level]."Production BOM No." := ItemPresents."Production BOM No.";
BomComponent[Level].SETRANGE("Production BOM No.",ItemPresents."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
BomComponent[Level].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[Level].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
NoList[Level] := ItemPresents."No.";
Quantity[Level] :=
UOMMgt.GetQtyPerUnitOfMeasure(ItemPresents,ItemPresents."Base Unit of Measure") /
UOMMgt.GetQtyPerUnitOfMeasure(
ItemPresents,
VersionMgt.GetBOMUnitOfMeasure(
ItemPresents."Production BOM No.",VersionCode[Level]));
UpperLevelItem := ItemPresents;
IF BomComponent[Level].FIND('-') THEN REPEAT
WHILE BomComponent[Level].NEXT = 0 DO BEGIN
Level := Level - 1;
IF Level < 1 THEN
EXIT;
IF NOT UpperLevelItem.GET(NoList[Level]) THEN
UpperLevelItem."Production BOM No." := NoList[Level];
BomComponent[Level].SETRANGE("Production BOM No.",UpperLevelItem."Production BOM No.");
BomComponent[Level].SETRANGE("Version Code",VersionCode[Level]);
END;
NextLevel := Level;
CLEAR(CompItem);
QtyPerUnitOfMeasure := 1;
CASE BomComponent[Level].Type OF
BomComponent[Level].Type::Item:
BEGIN
CompItem.GET(BomComponent[Level]."No.");
IF CompItem."Production BOM No." <> '' THEN BEGIN
NextLevel := Level + 1;
CLEAR(BomComponent[NextLevel]);
NoList[NextLevel] := CompItem."No.";
VersionCode[NextLevel] :=
VersionMgt.GetBOMVersion(CompItem."Production BOM No.","Calc.Date",FALSE);
BomComponent[NextLevel].SETRANGE("Production BOM No.",CompItem."Production BOM No.");
BomComponent[NextLevel].SETRANGE("Version Code",VersionCode[NextLevel]);
BomComponent[NextLevel].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[NextLevel].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
QtyPerUnitOfMeasure :=
UOMMgt.GetQtyPerUnitOfMeasure(
ItemPresents,
ItemPresents."Base Unit of Measure") /
UOMMgt.GetQtyPerUnitOfMeasure(
CompItem,
VersionMgt.GetBOMUnitOfMeasure(
CompItem."Production BOM No.",VersionCode[NextLevel]));
END;
IF Level > 1 THEN BEGIN
IF BomItem.GET(BomComponent[Level - 1]."No.") THEN BEGIN
QtyPerUnitOfMeasure :=
UOMMgt.GetQtyPerUnitOfMeasure(BomItem,BomComponent[Level - 1]."Unit of Measure Code")
/
UOMMgt.GetQtyPerUnitOfMeasure(
BomItem,VersionMgt.GetBOMUnitOfMeasure(BomItem."Production BOM No.",VersionCode[Level]));
END;
END;
END;
BomComponent[Level].Type::"Production BOM":
BEGIN
ProdBOM.GET(BomComponent[Level]."No.");
NextLevel := Level + 1;
CLEAR(BomComponent[NextLevel]);
NoList[NextLevel] := ProdBOM."No.";
VersionCode[NextLevel] := VersionMgt.GetBOMVersion(ProdBOM."No.","Calc.Date",FALSE);
BomComponent[NextLevel].SETRANGE("Production BOM No.",NoList[NextLevel]);
BomComponent[NextLevel].SETRANGE("Version Code",VersionCode[NextLevel]);
BomComponent[NextLevel].SETFILTER("Starting Date",'%1|..%2',0D,"Calc.Date");
BomComponent[NextLevel].SETFILTER("Ending Date",'%1|%2..',0D,"Calc.Date");
END;
END;
IF NextLevel <> Level THEN
Quantity[NextLevel] := BomComponent[NextLevel - 1].Quantity * QtyPerUnitOfMeasure * Quantity[Level];
IF BomComponent[Level].FIND('-') THEN REPEAT
BOMQty := Quantity[Level] * QtyPerUnitOfMeasure * BomComponent[Level].Quantity;
UNTIL BomComponent[Level].NEXT =0;
Level := NextLevel;
IF CompItem."Production BOM No." <> '' THEN
UpperLevelItem := CompItem;
UNTIL BomComponent[Level].NEXT =0;
UNTIL ItemPresents.NEXT =0; |
|
|
|
|
#8 |
|
Участник
|
Так начну с нуля...
1) создаю форму с параметром SourceTable : Item 2) перетаскиваю глобальные переменные все 3) создаю TableBox:BomComponent[Level]."No." сохронаю, запускаю Индекс массива 0 за пределами допустимого интервала |
|
|
|
|
#9 |
|
Участник
|
Если сначала
Level := 1, а потом Level := Level - 1; то в результате Level=0, а это и есть недопустимый индекс массива. |
|
|