Friday, 9 December 2016

Manipulating Data on a Grid: Scroll Select




 

Sometimes you want to pull information from multiple records and display in a grid on a page.
you create a view to get data from one or more records and associate with grid as Primary record .
Consider that you want to populate the grid dynamically passing parameters to the view.
Since, static views cannot accept parameters , how do you handle this kind of situation.

 Lets say we have a Grid on a page and the main record on the grid is called IBT_CMAT_STDLST_VW . Well we would first want to define a Rowset object to manipulate. The code for this would look as follows:


   Local Rowset &Level0, &Att_Tmplt;
   Local Row &Level0_Row;


  &Level0 = GetLevel0();
   &Level0_Row = &Level0(1);
 
   &LC = IBT_CMAT_WRK.IBT_UPOU_LC.Value;
   &ACTION = IBT_CMAT_WRK.IBT_ACTION.Value;
 
   &APPR_STATUS = IBT_CMAT_WRK.IBT_APPROVL_STATUS.Value;
 
   &EMPLID = IBT_CMAT_WRK.EMPLID.Value;
 
   &APPL_DT = IBT_CMAT_WRK.ACTION_DT.Value;
 
   &NAME = IBT_CMAT_WRK.NAME.Value;
 
 
 
 
   &where = "  1=1";
   If All(&LC) Then
      &where = &where | "AND  IBT_UPOU_LC  = " | Quote(&LC);
    
   End-If;
   If All(&ACTION) Then
    
      &where = &where | "AND  IBT_ACTION  = " | Quote(&ACTION);
    
   End-If;


   If All(&APPL_DT) Then
    
      &where = &where | "AND  ACTION_DT  = " | Quote(&APPL_DT);
    
   End-If;


   If All(&APPR_STATUS) Then
      &where = &where | " AND IBT_APPROVL_STATUS = " | Quote(&APPR_STATUS);
   End-If;
 
   If All(&EMPLID) Then
      &where = &where | " AND EMPLID = " | Quote(&EMPLID);
   End-If;
 
   If All(&NAME) Then
      &where = &where | " AND NAME LIKE " | Quote(&NAME);
   End-If;
 
rem    MessageBox(0, "", 0, 0, "" | &where);
 
   


  

Next we will want to instantiate the object. Instantiate just means to represent by an instance. If you notice, I am not creating a new Rowset. I am getting the Rowset from the current grid called IBT_CMAT_STDLST_VW , using the GetRowSet function. And, I am defining the Grid object as a Rowset.
 
 
   &Att_Tmplt = &Level0_Row.GetRowset(Scroll.IBT_CMAT_STDLST_VW);



Once that is complete, I want to remove all rows of data from the Grid. To do that I simply use the Flush method.


   &Att_Tmplt.Flush();

Now lets fill the grid with new data that we really want.  


   &Att_Tmplt.Select(Record.IBT_CMAT_STDLST_VW, "WHERE " | &where | "");
 
 




 -----------------------------------------------------------------------------------------------------------------



    Local Rowset &Level0, &Att_Tmplt;
    Local Row &Level0_Row;
    Local Rowset &Level0, &Att_Tmplt;
   Local Row &Level0_Row;


  &Level0 = GetLevel0();
   &Level0_Row = &Level0(1);


   &LC = IBT_CMAT_WRK.IBT_UPOU_LC.Value;
   &ACTION = IBT_CMAT_WRK.IBT_ACTION.Value;
 
   &APPR_STATUS = IBT_CMAT_WRK.IBT_APPROVL_STATUS.Value;
 
   &EMPLID = IBT_CMAT_WRK.EMPLID.Value;
 
   &APPL_DT = IBT_CMAT_WRK.ACTION_DT.Value;
 
   &NAME = IBT_CMAT_WRK.NAME.Value;
 
 
 
 
   &where = "  1=1";
   If All(&LC) Then
      &where = &where | "AND  IBT_UPOU_LC  = " | Quote(&LC);
    
   End-If;
   If All(&ACTION) Then
    
      &where = &where | "AND  IBT_ACTION  = " | Quote(&ACTION);
    
   End-If;
   If All(&APPL_DT) Then
    
      &where = &where | "AND  ACTION_DT  = " | Quote(&APPL_DT);
    
   End-If;
   If All(&APPR_STATUS) Then
      &where = &where | " AND IBT_APPROVL_STATUS = " | Quote(&APPR_STATUS);
   End-If;
 
   If All(&EMPLID) Then
      &where = &where | " AND EMPLID = " | Quote(&EMPLID);
   End-If;
 
   If All(&NAME) Then
      &where = &where | " AND NAME LIKE " | Quote(&NAME);
   End-If;

 

 
 
 
   &Att_Tmplt = &Level0_Row.GetRowset(Scroll.IBT_CMAT_STDLST);
   &Att_Tmplt.Flush();
 
   &Att_Tmplt.Select(Record.IBT_CMAT_STDLST, "WHERE " | &where | "");
 
 






No comments:

Post a Comment