Browse data print

Hello All,

In my program, I am using the standard browse.
I m having the browse name only.

with the help of that browse name, i want to print the content of that browse..without viewing the data.........

Thanks in advance.
 

GregTomkins

Active Member
I can't think of a quick and simple way to do this (other than Alt-PrtSc...)

You'd have to find the source of the browse's data, eg. the underlying table or temp-table, and write something that queries it and generates a print file or whatever.

The details of printing vary hugely depending on whether you are Windows or Unix, WebClient or AppServer, etc. In general they are all a hassle though.
 

rusguy

Member
You need to scroll thru every widget in your window to get the handle of the browse. After that you can get the query that was used to fill the data and only then you can print data. You need to have a code similar to this example:
Code:
run getBrowseData ("MyBrowseName"). 
procedure getBrowseData:
  define input parameter cBrowseName as character no-undo.
  def var hBrowse as handle no-undo.
  def var hQuery as handle no-undo.
  def var hBuffer as handle no-undo.
  def var i as integer no-undo.
  def var hColumn as handle no-undo.
  def var hField as handle no-undo.
 
  /*scroll thru every object in current window*/
  run scrollAndFindObject (cBrowseName, current-window, output hBrowse).
 
  if not valid-handle(hBrowse) then
  do:
    message "Target Browse was not found" view-as alert-box.
    return.
  end.
  /*get the query*/
  hQuery = hBrowse:query.
  /*now you are ready to dynamically access data*/
  /*i am using just the first buffer as the example, 
  you would need to do something different most likely*/
  hBuffer = hQuery:get-buffer-handle(1).
 
  hQuery:get-first().
  do while not hQuery:query-off-end:
    /*scroll thru every column and message its data*/
    do i = 1 to hBrowse:num-columns:
      hColumn = hBrowse:get-browse-column(i).
      hField = hColumn:buffer-field.
      if valid-handle(hField) then
      do:
        message hField:buffer-value
          view-as alert-box.
      end.
    end.
    hQuery:get-next().
  end.
end procedure.
procedure scrollAndFindObject:
  define input parameter cTargetName as character no-undo.
  define input parameter hScrollObject as handle no-undo.
  define output parameter hTargetHandle as handle no-undo.
  def var h as handle no-undo.
  if hScrollObject:type = "window" or 
     hScrollObject:type = "frame" or 
     hScrollObject:type = "field-group" then
  do:
    h = hScrollObject:first-child.
    do while valid-handle(h):
      if h:name = cTargetName then
      do:
        hTargetHandle = h.
        return.
      end.
      run scrollAndFindObject(cTargetName, h, output hTargetHandle).
      if valid-handle(hTargetHandle) then
        return.
      h = h:next-sibling.
    end.
  end.
end procedure.

Also, i remember there was a program written by someone that already had all this functionality and it allowed you to export the contents of the browse to different outputs - printer, csv, etc.
 

Cecil

19+ years progress programming and still learning.
Using the above code I have extended it to output to PDF.

I loved the idea so much that I think that I implement this into our own application.

Please find a proof-of-concept with following code. NOTE: It uses PDF include which if you don't already have it download it.

Code:
{pdf_inc.i}

&GLOBAL-DEFINE PDFSTREAM 'browsePrint'

DEFINE INPUT PARAMETER pchBrowseName AS CHARACTER NO-UNDO.

DEFINE VARIABLE cPDFDocumentFilename AS CHARACTER   NO-UNDO.
DEFINE VARIABLE inColumnPos AS INTEGER     NO-UNDO.

ASSIGN
  cPDFDocumentFilename = SUBSTITUTE('/tmp/&1-&2.pdf',
                                    pchBrowseName,
                                    MTIME ( NOW )
                                    ).

RUN pdf_reset_stream (INPUT {&PDFSTREAM}).

/* Create New PDF Document */
RUN pdf_New (INPUT {&PDFSTREAM}, 
             INPUT cPDFDocumentFilename).

RUN pdf_set_info({&PDFSTREAM},"Author",USERID('DICTDB') ).
RUN pdf_set_info({&PDFSTREAM},"Subject",pchBrowseName).
RUN pdf_set_info({&PDFSTREAM},"Title",pchBrowseName).
RUN pdf_set_info({&PDFSTREAM},"Keywords","").
RUN pdf_set_info({&PDFSTREAM},"Creator","PDFinclude").
RUN pdf_set_info({&PDFSTREAM},"Producer",PROGRAM-NAME(1)).
  
/*  Always compress the document...*/
RUN pdf_set_parameter({&PDFSTREAM},"Compress","TRUE"). 

/* Setting need to be set by datastore records...*/
RUN pdf_set_Orientation({&PDFSTREAM}, 'Landscape').
RUN pdf_set_PaperType({&PDFSTREAM}, 'A4').
RUN pdf_set_TopMargin ({&PDFSTREAM}, 20).
RUN pdf_set_BottomMargin ({&PDFSTREAM}, 20).
RUN pdf_set_LeftMargin ({&PDFSTREAM}, 20).

/*  Everything is set, so let's go....*/
RUN pdf_new_page(INPUT {&PDFSTREAM}).

RUN getBrowseData (INPUT pchBrowseName). 

/* Close the PDF Document Stream... */
RUN pdf_Close({&PDFSTREAM}).

procedure getBrowseData:
  define input parameter cBrowseName as character no-undo.
  def var hBrowse as handle no-undo.
  def var hQuery as handle no-undo.
  def var hBuffer as handle no-undo.
  def var i as integer no-undo.
  def var hColumn as handle no-undo.
  def var hField as handle no-undo.
 
  /*scroll thru every object in current window*/
  RUN scrollAndFindObject (cBrowseName, 
                           CURRENT-WINDOW, 
                           OUTPUT hBrowse).
 
  RUN pdf_set_font ({&PDFSTREAM},
                    "Courier-Bold",
                    8).

  IF NOT VALID-HANDLE(hBrowse) THEN
  DO:
    RUN pdf_text({&PDFSTREAM},
                 SUBSTITUTE("Target Browse was not found. &1",cBrowseName )
                 ).
    RETURN.
  END.
  
  /*get the query*/
  hQuery = hBrowse:query.
  /*now you are ready to dynamically access data*/
  /*i am using just the first buffer as the example, 
  you would need to do something different most likely*/
  hBuffer = hQuery:GET-BUFFER-HANDLE(1).
  
  RUN pdf_text({&PDFSTREAM},
               SUBSTITUTE("&1 - &2",
                          STRING(TODAY, '99/99/9999'),
                          STRING(TIME, 'HH:MM:SS')
                          )
               ).

  RUN pdf_text_center ({&PDFSTREAM},
                       hBrowse:TITLE,
                       (pdf_pageWidth({&PDFSTREAM}) / 2),
                       pdf_textY({&PDFSTREAM})
                       ).
  
  RUN pdf_set_font ({&PDFSTREAM},
                    "Courier",
                    8).

  RUN pdf_skip({&PDFSTREAM}).
  RUN pdf_skip({&PDFSTREAM}).


  
  ASSIGN
    inColumnPos = 1.

  DO i = 1 to hBrowse:NUM-COLUMNS:

    ASSIGN
      hColumn = hBrowse:GET-BROWSE-COLUMN(i).
    
    IF VALID-HANDLE(hColumn) THEN
    DO:
      
      RUN pdf_text_at (INPUT {&PDFSTREAM},
                       INPUT hColumn:LABEL,
                       INPUT inColumnPos).

      ASSIGN
        inColumnPos = inColumnPos + hColumn:WIDTH-CHAR + 1.
          
    END.
  END.

  RUN pdf_skip({&PDFSTREAM}).

  hQuery:GET-FIRST().
  DO WHILE NOT hQuery:QUERY-OFF-END:
    /*scroll thru every column and message its data*/

    ASSIGN
      inColumnPos = 1.

    DO i = 1 to hBrowse:NUM-COLUMNS:
      
      ASSIGN
        hColumn = hBrowse:GET-BROWSE-COLUMN(i)
        hField = hColumn:BUFFER-FIELD.

      IF Valid-handle(hField) THEN
      DO:
        
        RUN pdf_text_at (INPUT {&PDFSTREAM},
                         INPUT hField:BUFFER-VALUE,
                         INPUT inColumnPos).

        ASSIGN
          inColumnPos = inColumnPos + hColumn:WIDTH-CHAR + 1.

      END.
    END.

    RUN pdf_skip({&PDFSTREAM}).
    
    hQuery:GET-NEXT().
  END.
END PROCEDURE.

procedure scrollAndFindObject:
  define input parameter cTargetName as character no-undo.
  define input parameter hScrollObject as handle no-undo.
  define output parameter hTargetHandle as handle no-undo.
  def var h as handle no-undo.
  if hScrollObject:type = "window" or 
     hScrollObject:type = "frame" or 
     hScrollObject:type = "field-group" then
  do:
    h = hScrollObject:first-child.
    do while valid-handle(h):
      if h:name = cTargetName then
      do:
        hTargetHandle = h.
        return.
      end.
      run scrollAndFindObject(cTargetName, h, output hTargetHandle).
      if valid-handle(hTargetHandle) then
        return.
      h = h:next-sibling.
    end.
  end.
end procedure.
 
Top