DavidFeldhoff / al-codeactions

MIT License
17 stars 8 forks source link

Extract to Procedure: Not all variables needed are handed over as parameter #77

Closed DavidFeldhoff closed 4 years ago

DavidFeldhoff commented 4 years ago

If the selection which should be extracted is inside a begin..end Block, then variables which are assigned before this block aren't passed to the extracted procedure as parameter. Instead they are just normal variables. Example:

    local procedure MyProcedure()
    var
        MyInt: Integer;
        SalesLine: Record "Sales Line";
    begin
        MyInt := 5;
        if true then begin
            SalesLine.SetRange("Document Type", "Sales Document Type"::Order);
            if SalesLine.FindSet(true) then begin
                SalesLine.Quantity := MyInt;
                SalesLine.Modify();
            end;
        end;
    end;

results in

    local procedure MyProcedure()
    var
        MyInt: Integer;
        SalesLine: Record "Sales Line";
    begin
        MyInt := 5;
        if true then begin
            ExtractedProcedure();
        end;
    end;

    local procedure ExtractedProcedure()
    var
        MyInt: Integer;
        SalesLine: Record "Sales Line";
    begin
        SalesLine.SetRange("Document Type", "Sales Document Type"::Order);
        if SalesLine.FindSet(true) then begin
            SalesLine.Quantity := MyInt;
            SalesLine.Modify();
        end;
    end;