Inserting Effective-Dated Data Example

You can rename a collection in a Component Interface. For example, suppose you had the same record at level zero and at level one. You may want to rename the level one data collection to reflect this. The data in a data collection is associated with the primary database record of a scroll, not with the name you supply.

Here is an example of using a Component Interface that has the same record at level zero and level one. The Component Interface is based on the CURRENCY_CD_TBL component.

This example illustrates the fields and controls on the Example of CI with same record at level zero and level one. You can find definitions for the fields and controls later on this page.

Example of CI with same record at level zero and level one

The following code example is based on this Component Interface and does the following:

  1. Gets an existing Component Interface.

  2. Finds the current effective-dated item index.

  3. Inserts a new row before the current effective-dated item using the InsertItem method.

    Local ApiObject &Session;
    Local ApiObject &CURRENCY_CD;
    Local ApiObject &CURRENCY_CD_TBLCol;
    Local ApiObject &CURRENCY_CD_TBLItm;
    Local ApiObject &PSMessages;
    Local string &ErrorText, &ErrorType;
    Local number &ErrorCount;
    Local Boolean &Error;
    
    Function CheckErrorCodes()
    
       &PSMessages = &Session.PSMessages;
       &ErrorCount = &PSMessages.Count;
       For &i = 1 To &ErrorCount
          &ErrorText = &PSMessages.Item(&i).Text;
          &ErrorType = &PSMessages.Item(&i).Type;
       End-For;
    
    End-Function;
    
    /* Initialize Flags */
    &Error = False;
    
    &Session = %Session;
    
    If &Session <> Null Then
    
       CheckErrorCodes();
       /* Application Specific Error Processing */
    
    Else
    
       &CURRENCY_CD = &Session.GetCompIntfc(CompIntfc.CURRENCY_CD);
    
       If &CURRENCY_CD = Null Then
    
          CheckErrorCodes();
          /* Application Specific Error Processing */
    
       Else
    
          /* Set Component Interface Get Keys */
          &CURRENCY_CD.CURRENCY_CD = "USD";
    
          If Not &CURRENCY_CD.Get() Then
    
             CheckErrorCodes();
             /* Application Specific Error Processing */
             &Error = True;
    
          End-If;
    
          If Not &Error Then
    
             &CURRENCY_CD_TBLCol = &CURRENCY_CD.CURRENCY_CD_TBL;
             &CURRENCY_CD_TBLItm = &CURRENCY_CD_TBLCol.InsertItem(&CURRENCY_CD_⇒
    TBLCol.CurrentItemNum());
             &CURRENCY_CD_TBLItm.EFFDT = %Date;
             &CURRENCY_CD_TBLItm.EFF_STATUS = "A";
             &CURRENCY_CD_TBLItm.DESCR = "NewCurrencyCode";
             &CURRENCY_CD_TBLItm.DESCRSHORT = "New";
             &CURRENCY_CD_TBLItm.COUNTRY = "USA";
             &CURRENCY_CD_TBLItm.CUR_SYMBOL = "?";
             &CURRENCY_CD_TBLItm.DECIMAL_POSITIONS = 4;
             &CURRENCY_CD_TBLItm.SCALE_POSITIONS = 0;
    
             /* Save Instance of Component Interface */
             If Not &CURRENCY_CD.Save() Then
    
                CheckErrorCodes();
                /* Application Specific Error Processing */
    
             End-If;
    
          End-If;
          /* End: Set Component Interface Properties */
    
          /* Cancel Instance of Component Interface */
          &CURRENCY_CD.Cancel();
    
       End-If;
End-If;