To build print form of purchase order and generate it for document type “NB standard order”.
Example:
For PO output data we need to create structures in ABAP dictionary. These structures will be used in the report designer as data source.
Run transaction SE11. Create and activate the follow objects:
Structure ZZPO_ITEM_S
Table type ZZPO_ITEM_TT
Structure ZZPO_PARTNER_S
Structure ZZPO_DOC_S
Table type ZZPO_DOC_TT
Run transaction ZFR_RMAN.
Press on “New” button and add a new report “ZPO_FR” with parameters as presented on the screenshot
Save the report.
After saving switch into edit mode (press “Edit” button) and then press “Designer” button.
System will ask to enter Data source table. Enter ZPO_DOC_TT.
After confirmation Fast report designer will be opened.
Menu: Report->Configure bands.
Press on “Close” button.
User and Developer manual for designer can be found here: https://www.fast-report.com/en/product/fast-report-net/documentation/
Final template:
If to press “preview” button - report will be empty because still no “test” data has been generated. Later we will see how generate temporary data and preview report with the data.
Save report template (press SAP standard button) and leave designer.
Now press “Save” to save\update report settings.
We need to develop program\routine to be able to call printing form from purchase order output function.
In ABAP Workbench create new module pool ZZMM_FRPRINTING.
Add subroutine “po_print_fr” with the follow code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
*&---------------------------------------------------------------------* *& 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 function to retrieve PO information, then map the data to our structure and call method ZCL_FRBASE_REPORT->BUILD_REPORT for report generation. In case we need to debug form with test data - comment call of “BUILD_REPORT” method and uncomment section below.
Customizing.
Call transaction NACE and create new output type ZZFR for Purchase order. As printing program select ZZMM_FRPRINTING and routine PO_PRINT_FR. Choose access sequence 0001.
Add new output type to your output schema (for example RMBEF1)
Create condition record for condition type ZZFR and PO type NB.
Open follow settings path: SPRO->Material Management->Purchasing->Messages->Output control->Message types->Define message types for Purchase order-> Fine-Tuned Control: Purchase Order.
Add records for ZZFR
Now you can open existing purchase order or create a new one and test printing form using standard buttons in the transaction ME23N. Otherwise use transaction ME9F for printing.