[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 807
  • Last Modified:

Generalisation of a drop down datawindow in pb7

Follwoing is an exportable version of a dropdown datawindow namely 'dddw_user_id' created in pb7

$PBExportHeader$dddw_user_id.srd
$PBExportComments$security
release 7;
datawindow(units=0 timer_interval=0 color=16777215 processing=1 HTMLDW=no print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no grid.lines=0 )
header(height=92 color="536870912" )
summary(height=0 color="536870912" )
footer(height=0 color="536870912" )
detail(height=88 color="536870912" )
table(column=(type=char(6) update=yes updatewhereclause=yes key=yes name=user_id dbname="password.user_id" )
 column=(type=char(2) updatewhereclause=yes name=company_code dbname="password.company_code" )
 column=(type=char(10) updatewhereclause=yes name=apps_name dbname="password.apps_name" )
 retrieve="  SELECT password.user_id,  
         password.company_code,  
         password.apps_name  
    FROM password
where company_code = '02'
and apps_name = 'packing'  
" update="password" updatewhere=1 updatekeyinplace=no )
text(band=header alignment="2" text="User Id" border="0" color="0" x="9" y="8" height="76" width="416"  name=user_id_t  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="26845365" )
column(band=detail id=1 alignment="0" tabsequence=10 border="0" color="0" x="9" y="8" height="72" width="416" format="[general]"  name=user_id edit.limit=6 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" )
column(band=detail id=2 alignment="0" tabsequence=0 border="0" color="0" x="439" y="0" height="56" width="594"  name=company_code  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" )
text(band=header alignment="0" text="Company Code" border="0" color="0" x="434" y="4" height="76" width="599"  font.face="Arial" font.height="-12" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="16777215" )
column(band=detail id=3 alignment="0" tabsequence=0 border="0" color="0" x="1047" y="0" height="56" width="690"  name=apps_name  font.face="Arial" font.height="-8" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912" )
text(band=header alignment="0" text="Apps Name" border="0" color="0" x="1042" y="4" height="76" width="695"  font.face="Arial" font.height="-12" font.weight="400"  font.family="2" font.pitch="2" font.charset="0" background.mode="2" background.color="16777215" )
htmltable(border="1" )
htmlgen(clientevents="1" clientvalidation="1" clientcomputedfields="1" clientformatting="0" clientscriptable="0" generatejavascript="1" )


The sql select of the above dd is

SELECT password.user_id,  
         password.company_code,  
         password.apps_name  
    FROM password
where company_code = '02'
and apps_name = 'packing'  

This dd is associated in a window 'w_user_group'

I have never created dd at runtime and want to create now in the open event(or any right event suggested by dear experts) of the window.

I want to do so because I have enough apps_names and enough company_codes. At runtime my system knows the values of
company_code in global variable gs_company_code and apps_name in gs_apps_name and at runtime creation of dd
I want to  change the line
where company_code = '02'
and apps_name = 'packing'
with
where company_code = value of global variable gs_company_code
and apps_name = value of global vairable of gs_apps_name.

SECOND ASPECT/METHOD MAY BE:
If I write the sql this way
SELECT password.user_id,  
         password.company_code,  
         password.apps_name  
    FROM password
where company_code = :ra_company_code
and apps_name = :ra_apps_name

and control it through datawindow child then again I know this technique for one retrieval argument and I don't know
how to do this for two retrieval arguments.

Points will be awarded 500 each for both method.

Mateen:

There may be third aspect also and that is filtration line.
Thd dd may be retieved and then set filter with the values of gs_company_code and gs_apps_name.

0
Mateen
Asked:
Mateen
  • 4
  • 3
  • 2
2 Solutions
 
namasi_navaretnamCommented:
There are few ways...

You can try this in the constructor event of datawindow control.

Method 1:
string ls_sql
datawindowchild ldw_child
ls_sql = " SELECT password.user_id,    " + &
         " password.company_code,    " + &
         " password.apps_name " + &
         "  FROM password  "  + &
         " where company_code = '" +gs_company_code + "'" +  &
         " and apps_name = '" + gs_apps_name + "'"  

dw_1.GetChild('yourcolumnname', ldw_child)
ldw_child.SetSQLSelect(ls_sql)
ldw_child.SetTransObject(SQLCA)
ldw_child.Retrieve()

Method 2:
datawindowchild ldw_child
dw_1.GetChild('yourcolumnname', ldw_child)
ldw_child.SetTransObject(SQLCA)
ldw_child.Retrieve(gs_company_code , gs_apps_name )


Method 3:
You can also use SyntaxFromSQL, Create functions to create dw dynamically.

Pls let us know if you need further help...

regards-










0
 
namasi_navaretnamCommented:
If you need to see if dddw is associated with a column, you can try

string ls_desc, ls_dddwname
long ll_cc, ll_rc, ll_i

ll_cc = long(dw_1.Describe("Datawindow.column.count"))

for ll_i = 1 to ll_cc
    ls_desc = "#" + string(ll_i) + ".DDDW.Name"
    ls_dddwname = dw_1.Describe(ls_desc)


    if ls_dddwname = '?' then
       // column does not have dddw associated
    else
       // column has dddw associated
    end if    
next      
regards-
0
 
diasroshanCommented:
hi mateen,

u can define ur dddw at runtime as follows....
..write this code in the open event...

datawindowchild dwc

dw_2.object.<column name>.dddw.name ='dddw_user_id'
dw_2.object.<column name>.dddw.displaycolumn = '<ur displaycolumn name>'
dw_2.object.field_value.dddw.datacolumn = '<ur datacolumn name>'

dw_2.getchild("<column name>",dwc)
dwc.SetTransObject(sqlca);
if dwc.Retrieve(gs_company_code,gs_apps_name) = 0 Then dwc.InsertRow(0)  // if retrieve finds no rows retrieved then it insert a row so that at runtime argument window is not prompted


... u can pass as many retieval arguments u like in the datawindowchild provided u have declared those many in ur dddw creation (dddw_user_id)...

...this should solve ur problem...

Cheers,
Rosh
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MateenAuthor Commented:
Hi experts :
I was confusing in
dw_1.GetChild('yourcolumnname', ldw_child)
and was wrongly thinking how to replace 'yourcolumnname' with two columns/arguments.

The best and simplest is

Method 2:
datawindowchild ldw_child
dw_1.GetChild('yourcolumnname', ldw_child)
ldw_child.SetTransObject(SQLCA)
ldw_child.Retrieve(gs_company_code , gs_apps_name )

0
 
MateenAuthor Commented:
Hi Namasi:

as suggested I wrote in the open event.

datawindowchild dwc
dw_detail.GetChild('user_name', dwc)
dwc.SetTransObject(SQLCA)
IF dwc.Retrieve(gs_company_code , gs_apps_name ) = 0 THEN
      dwc.insertrow(0)
end if

and it worked.

But after saving one record it didn't work because after dw_detail.update() my system do dw_detail.reset()
So I wrote the same line in Extend Ancestor Script of ue_new (in my system for inserting new record). and it
worked.

But when I queried and retrieved and went to a particular record then again failed.
So I wrote the same line in the itemchanged event which worked with one defect and that is my dw_detail contains only one column 'user_id' and a copy of user_id renamed with 'user_name' and this name is  associated with dd.  When I enter in user_id and then click the arrow of dd it shows values but when I directly click the arrow key of dd it doesn't show any values (may be itemchanged event doesn't fire on mouse click)

Dear Namasi, I have written so lengthy just to make u understand what is my problem now and so far I have failed to find out any event of pb which may avoid these duplications.

Please suggest although the answer has been accepted.

Thanks in Advance:
Mateen:
0
 
diasroshanCommented:
hi mateen,

itemchanged only triggers when u make any change in the values...only clicking with the mouse on the arrow will not trigger itemchanged....

try writing the code in getfocus event or clicked event of the datawindow...

datawindowchild dwc
dw_detail.GetChild('user_name', dwc)
dwc.SetTransObject(SQLCA)
IF dwc.Retrieve(gs_company_code , gs_apps_name ) = 0 THEN
     dwc.insertrow(0)
end if

...if this doesn't work let me know...i'd help...

Cheers,
Rosh
0
 
MateenAuthor Commented:
Hi Rosh:

Thanks

I deleted the codes from every events and wrote in getfocus event of dw and it is working nicely.

Please given any cooment for
http://www.experts-exchange.com/Programming/Programming_Languages/PowerBuilder/Q_20963086.html
to be accepted at once.
0
 
namasi_navaretnamCommented:
> I deleted the codes from every events and wrote in getfocus event of dw and it is working nicely.
Do you have code to delete from dd in every other event? That is not a good thing. That may be reason why you get watson error you have posted.

To avoid dups try this:

datawindowchild ldw_child
dw_1.GetChild('yourcolumnname', ldw_child)
ldw_child.SetTransObject(SQLCA)
ldw_child.reset()
ldw_child.Retrieve(gs_company_code , gs_apps_name )

regards-
0
 
namasi_navaretnamCommented:
ignore my comment about watson error. That  is a different issue.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now