Skip to Content
Author's profile photo Former Member

Generating reports in SAP NetWeaver with FastReport (tutorial)- Part 2

Part 2: Output messages (print documents)

Task:

Build a print form of a purchase order and assign a document type “NB standard order” to it.

Example:

Preparation of a Data dictionary

For PO output data we will create structures in ABAP dictionary. These structures will be used in a report designer as a data source.

Run transaction SE11. Create and activate the following objects:

Structure ZZPO_ITEM_S

Table type ZZPO_ITEM_TT

Structure ZZPO_PARTNER_S

Structure ZZPO_DOC_S

Table type ZZPO_DOC_TT

Preparation of a template

Run transaction ZFR_RMAN.

Press on “New” button and add a new report “ZPO_FR” with parameters as presented in the screenshot below.

Save the report.

After that switch to edit mode (press “Edit” button) and then press on “Designer” button.

System will ask to enter a Data source table. Enter ZPO_DOC_TT.

 

After that Fast report designer will be open.

 

Configure bands.

Menu: Report->Configure bands.

  • Configure (add\remove) bands as presented in the screenshot below

Press on “Close” button.

  • Double click on 1st level “Data” band and select “ITEMS” as a data source.

  • Double click on 2d level “Data” band and select “SCHD” as a data source.

The place of the following report elements:

  • Stretch “Report Title” band, place “text elements” from the element toolbar and fill them with the static texts. Drag fields from “MYDATASET” data source table to the “Report Title”;
  • Format “Page header” band to display items header (add static text elements );
  • Format “Data: ITEMS” band. Place fields from “ITEMS” table;
  • Format “Data: SCHD” band. Place fields from “SHDL” table;
  • On “Footer” band place summary fields from “ITEMS” table ([ITEMS.MENGE] and [ITEMS.MEINS]).

A user and a developer manual for a designer can be found here: https://www.fast-report.com/en/product/fast-report-net/documentation/

The final template:

If you press “preview” button, the report will be empty because there will be no generated “test” data. Later we will study how to generate a temporary data and preview a report with some data.

Save the report template (press “SAP” standard button) and leave the designer.

Now press on “Save” button to save\update report settings.

 

Development of a print program and output customizing

We need to develop a program\subroutine to be able to call a printing form from a purchase order output function.

In ABAP Workbench create a new module pool ZZMM_FRPRINTING.

Add a subroutine “po_print_fr” with the following code:

*&---------------------------------------------------------------------*
*& Module Pool       ZZMM_FRPRINTING
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

PROGRAM zzmm_frprinting.
TABLES: nast.

*&---------------------------------------------------------------------*
*&      Form  po_print_fr
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->ENT_RETCO  text
*      -->ENT_SCREEN text
*----------------------------------------------------------------------*
FORM po_print_fr USING ent_retco ent_screen.

  DATA: lv_druvo LIKE t166k-druvo,
        ls_nast  LIKE nast,
        lv_from_memory,
        ls_doc   TYPE meein_purchase_doc_print,
        lt_ret TYPE bapiret2_t.

  DATA  lo_fr TYPE REF TO zcl_frbase_report.

  DATA: ls_order TYPE zzpo_doc_s,
        lt_order TYPE zzpo_doc_tt,
        ls_item  TYPE  zzpo_item_s,
        ls_schd  TYPE eket.

  FIELD-SYMBOLS: <fs1> TYPE ekpo,
                 <fs2> TYPE eket.

  CLEAR ent_retco.

  IF nast-aende EQ space.
    lv_druvo = '1'.
  ELSE.
    lv_druvo = '2'.
  ENDIF.

  CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'
    EXPORTING
      ix_nast        = nast
      ix_screen      = ent_screen
    IMPORTING
      ex_retco       = ent_retco
      ex_nast        = ls_nast
      doc            = ls_doc
    CHANGING
      cx_druvo       = lv_druvo
      cx_from_memory = lv_from_memory.

  CHECK ent_retco EQ 0.

  MOVE-CORRESPONDING ls_doc-xekko TO ls_order.

  SELECT SINGLE * INTO CORRESPONDING FIELDS OF ls_order-provdata
     FROM lfa1 WHERE lifnr = ls_order-lifnr.

  LOOP AT ls_doc-xekpo ASSIGNING <fs1>.

    CLEAR ls_item.
    MOVE-CORRESPONDING <fs1> TO ls_item.

    LOOP AT  ls_doc-xeket ASSIGNING <fs2>.
      CLEAR ls_schd.
      CHECK <fs2>-ebelp = ls_item-ebelp.
      MOVE-CORRESPONDING <fs2> TO ls_schd.
      APPEND ls_schd TO ls_item-schd.
    ENDLOOP.

    APPEND ls_item TO  ls_order-items.

  ENDLOOP.

  APPEND ls_order TO lt_order.

  CREATE OBJECT lo_fr
    EXPORTING
      iv_reportkey = 'ZPO_FR'.

  " use for production
   ent_retco =  lo_fr->build_report( lt_order ).

**********************************************************************
**use for debugging\template correction
"  DATA: lv_answer.

"  lo_fr->set_mode( zcl_frbase_report=>mc_edit ).
"  lo_fr->call_designer( lt_order ).
"  CALL FUNCTION 'POPUP_TO_CONFIRM'
"    EXPORTING
"      text_question = 'update report template in DB?'
"    IMPORTING
"      answer        = lv_answer.
"  if lv_answer eq '1'.
"    lo_fr->save_report( ).
"  ENDIF.
**********************************************************************


ENDFORM.                    "po_print_fr

 

In the code we call a function to retrieve PO information. Then we map the data to our structure and call the method ZCL_FRBASE_REPORT->BUILD_REPORT to generate a report. In case we need to debug a form with a data, comment a call of “BUILD_REPORT” method and uncomment a section below.

Customizing

Call the transaction NACE and create a new output type ZZFR for a purchase order. As a printing program select ZZMM_FRPRINTING and the routine PO_PRINT_FR. Choose the access sequence 0001.

Add a new output type to your output scheme (for example, RMBEF1).

Create a condition record for a condition type ZZFR and PO type NB.

 

Open the following settings path: SPRO->Material Management->Purchasing->Messages->Output control->Message types->Define message types for Purchase order-> Fine-Tuned Control: Purchase Order.

Add the following records for ZZFR:

 

Now you can open an already existing purchase order or create a new one and test a printing form using standard buttons in the transaction ME23N or use the transaction ME9F for printing.

 

 

Enjoy!

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.