Formatting repair
This commit is contained in:
parent
89ac40c868
commit
26452d5f7c
20 changed files with 134 additions and 179 deletions
|
|
@ -4,7 +4,7 @@ weight = 220
|
|||
+++
|
||||
# Argument table pattern
|
||||
|
||||
_By Nikola Kukrika and Waldo_
|
||||
_Originally By Nikola Kukrika and Waldo_
|
||||
|
||||
# Abstract
|
||||
|
||||
|
|
@ -27,36 +27,37 @@ Few examples of the bad implementations are as illustrated here:
|
|||
## Bad example 1
|
||||
|
||||
|
||||
**PROCEDURE FillInVATReturnData@1200001(VAR DeclarationID@1200000 : Code\[20\];VAR LineID@1200001 :**
|
||||
**Code\[20\];VAR PeerID@1200002 : Code\[20\]; VAR DocumentNo@1200003 : Code\[20\]; VAR NumberOfCopies@1200007 :**
|
||||
**Integer; VAR Uploaded@1200004 : Boolean; VAR Correction@1200005 : Boolean; VAR HasValidationErr@1200006 :**
|
||||
**Boolean);**
|
||||
```AL
|
||||
PROCEDURE FillInVATReturnData@1200001(VAR DeclarationID@1200000 : Code [20];VAR LineID@1200001 : Code [20];VAR PeerID@1200002 : Code [20]; VAR DocumentNo@1200003: Code[20]; VAR NumberOfCopies@1200007: Integer; VAR Uploaded@1200004 : Boolean; VAR Correction@1200005 : Boolean; VAR HasValidationErr@1200006 : Boolean);
|
||||
```
|
||||
|
||||
Call
|
||||
**Call**
|
||||
|
||||
**FillInVATReturnData(NoSeries, NextLineID, CustomerID, DocumentNo, SingleCopy, ???, ??, ...., ...)**
|
||||
|
||||
```AL
|
||||
FillInVATReturnData(NoSeries, NextLineID, CustomerID, DocumentNo, SingleCopy, ???, ??, ...., ...)
|
||||
```
|
||||
|
||||
In this example the code is hard to read and understand. Adding an additional argument will require refactoring of the existing function. Each time a new argument is added a new function will be created.
|
||||
|
||||
## Bad example 2
|
||||
|
||||
**LOCAL PROCEDURE GetTableSyncSetupW1@3(**
|
||||
**OldTableId@1002 : Integer;**
|
||||
**VAR UpgradeTableId@1001 : Integer;**
|
||||
**VAR TableUpgradeMode@1000 : 'Check, Copy, Move, Force') : Boolean;**
|
||||
```AL
|
||||
LOCAL PROCEDURE GetTableSyncSetupW1@3(OldTableId@1002 : Integer; VAR UpgradeTableId@1001 : Integer; VAR TableUpgradeMode@1000 : 'Check, Copy, Move, Force') : Boolean;
|
||||
BEGIN
|
||||
CASE OldTableId OF
|
||||
DATABASE::"Sales Header":
|
||||
SetTableSyncSetup(0,TableUpgradeMode::Check,UpgradeTableId,TableUpgradeMode);
|
||||
DATABASE::"Posting Exch. Column Def":
|
||||
SetTableSyncSetup(104025,TableUpgradeMode::Copy,UpgradeTableId,TableUpgradeMode);
|
||||
DATABASE::"Payment Export Data":
|
||||
SetTableSyncSetup(0,TableUpgradeMode::Force,UpgradeTableId,TableUpgradeMode);
|
||||
ELSE
|
||||
EXIT(FALSE);
|
||||
END;
|
||||
EXIT(TRUE);
|
||||
CASE OldTableId OF
|
||||
DATABASE::"Sales Header":
|
||||
SetTableSyncSetup(0,TableUpgradeMode::Check,UpgradeTableId,TableUpgradeMode);
|
||||
DATABASE::"Posting Exch. Column Def":
|
||||
SetTableSyncSetup(104025,TableUpgradeMode::Copy,UpgradeTableId,TableUpgradeMode);
|
||||
DATABASE::"Payment Export Data":
|
||||
SetTableSyncSetup(0,TableUpgradeMode::Force,UpgradeTableId,TableUpgradeMode);
|
||||
ELSE
|
||||
EXIT(FALSE);
|
||||
END;
|
||||
EXIT(TRUE);
|
||||
END;
|
||||
```
|
||||
|
||||
In this example each time a new argument is added all function calls will have to be updated. Option is duplicated in the signature, which will cause issues if a new option is defined or the existing options are renamed.
|
||||
|
||||
|
|
@ -75,28 +76,33 @@ The examples of usages addressing problems shown above are:
|
|||
## Good example 1
|
||||
|
||||
New table
|
||||
```AL
|
||||
TAB 50003 VAT Return Data
|
||||
**PROCEDURE FillInVATReturnData@1200001(VAR VATReturnData@1200000 : Record 50003);**
|
||||
PROCEDURE FillInVATReturnData@1200001(VAR VATReturnData@1200000 : Record 50003);
|
||||
```
|
||||
|
||||
****
|
||||
|
||||
```AL
|
||||
VATReturnData.INIT;
|
||||
VATReturnData.NumberOfCopies := GetDefaultNumberOfCopies;
|
||||
VATReturnData.Uploaded := FALSE;
|
||||
|
||||
FillInVATReturnData(VATReturnData);
|
||||
```
|
||||
|
||||
By introducing an argument table, code is much more readable since there is a single argument for a function. It is easy to see which arguments are passed in and which are modified in a function.
|
||||
|
||||
## Good example 2
|
||||
|
||||
Good example
|
||||
**PROCEDURE GetTableSyncSetupW1@3(VAR TableSynchSetup@1000 : Record 2000000135);**
|
||||
```AL
|
||||
PROCEDURE GetTableSyncSetupW1@3(VAR TableSynchSetup@1000 : Record 2000000135);
|
||||
BEGIN
|
||||
SetTableSyncSetup(DATABASE::"Sales Header",0,TableSynchSetup.Mode::Check);
|
||||
SetTableSyncSetup(DATABASE::"Posting Exch. Column Def",104025,TableSynchSetup.Mode::Copy);
|
||||
SetTableSyncSetup(DATABASE::"Payment Export Data",0,TableSynchSetup.Mode::Force);
|
||||
SetTableSyncSetup(DATABASE::"Sales Header",0,TableSynchSetup.Mode::Check);
|
||||
SetTableSyncSetup(DATABASE::"Posting Exch. Column Def",104025,TableSynchSetup.Mode::Copy);
|
||||
SetTableSyncSetup(DATABASE::"Payment Export Data",0,TableSynchSetup.Mode::Force);
|
||||
END;
|
||||
```
|
||||
|
||||
Option definition is not encapsulated within the table. Arguments are grouped and we can add additional arguments without the need to change the signature.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue