0% found this document useful (0 votes)
21 views4 pages

PO Automation Via ABAP & Adobe

The document contains ABAP code for a class-based implementation of a purchasing document management system. It defines a class 'zcl_mm_po_document' with methods to retrieve purchase order data, generate an Adobe form, and display output using ALV. The report 'ZMM_PO_PRINT' utilizes this class to process user input for purchasing document numbers and company codes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

PO Automation Via ABAP & Adobe

The document contains ABAP code for a class-based implementation of a purchasing document management system. It defines a class 'zcl_mm_po_document' with methods to retrieve purchase order data, generate an Adobe form, and display output using ALV. The report 'ZMM_PO_PRINT' utilizes this class to process user input for purchasing document numbers and company codes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ABAP Code - Class Based

Implementation
ABAP CODE IN CLASSES

CLASS zcl_mm_po_document DEFINITION


PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.

DATA lt_po_output_data TYPE ztt_po_output_data .


DATA lt_po_items TYPE ztt_po_item .
DATA ls_po_address TYPE zst_po_address .
DATA po_obj TYPE REF TO cl_salv_table .
DATA ls_po_header TYPE zst_po_header .
DATA ls_outputparms TYPE sfpoutputparams .
DATA ls_funcname TYPE funcname .
DATA ls_result TYPE sfpjoboutput .
DATA f_name TYPE fpname VALUE 'Z_MM_PO_ADOBE_FORM' ##NO_TEXT.
DATA ls_dest TYPE string VALUE 'LP01' ##NO_TEXT.

METHODS get_po_data
IMPORTING
!ls_ebeln TYPE ebeln
!ls_bukrs TYPE bukrs OPTIONAL .
METHODS get_po_output .
METHODS get_adobe_form
IMPORTING
!ls_ebeln TYPE ebeln
!ls_bukrs TYPE bukrs OPTIONAL .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS ZCL_MM_PO_DOCUMENT IMPLEMENTATION.

* -------------------------------------------------------------------------------------
* | Instance Public Method ZCL_MM_PO_DOCUMENT->GET_ADOBE_FORM
* +------------------------------------------------------------------------------------
* | [--->] LS_EBELN TYPE EBELN
* | [--->] LS_BUKRS TYPE BUKRS(optional)
* +------------------------------------------------------------------------------------
METHOD get_adobe_form.
CLEAR ls_outputparms.
ls_outputparms = VALUE sfpoutputparams(
nodialog = abap_true
preview = abap_true
dest = ls_dest " Optional printer destination
).
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = ls_outputparms " Form Processing Output Param
EXCEPTIONS
cancel = 1 " Canceled by user
usage_error = 2
system_error = 3 " System Error
internal_error = 4 " Internal Error
OTHERS = 5.

CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'


EXPORTING
i_name = f_name
IMPORTING
e_funcname = ls_funcname
* E_INTERFACE_TYPE =
* EV_FUNCNAME_INBOUND =
.

CALL FUNCTION ls_funcname


EXPORTING
* /1BCDWB/DOCPARAMS =
lv_ebeln = ls_ebeln
lv_bukrs = ls_bukrs
gs_po_header = ls_po_header
gt_po_items = lt_po_items
gs_po_address = ls_po_address
* IMPORTING
* /1BCDWB/FORMOUTPUT =
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.

CALL FUNCTION 'FP_JOB_CLOSE'


IMPORTING
e_result = ls_result
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

ENDMETHOD.

* -------------------------------------------------------------------------------------
* | Instance Public Method ZCL_MM_PO_DOCUMENT->GET_PO_OUTPUT
* +------------------------------------------------------------------------------------
* +------------------------------------------------------------------------------------
METHOD get_po_output.

TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = po_obj " Basis Class Simple ALV Tables
CHANGING
t_table = lt_po_output_data
).
CATCH cx_salv_msg. " ALV: General Error Class with Message
ENDTRY.

po_obj->display( ).

ENDMETHOD.
* -------------------------------------------------------------------------------------
* | Instance Public Method ZCL_MM_PO_DOCUMENT->GET_PO_DATA
* +------------------------------------------------------------------------------------
* | [--->] LS_EBELN TYPE EBELN
* | [--->] LS_BUKRS TYPE BUKRS(optional)
* +------------------------------------------------------------------------------------
METHOD get_po_data.
SELECT ekko~ebeln, ekpo~ebelp,ekko~bedat,ekko~bukrs,ekko~lifnr,ekpo~txz01,ekpo~mat
ekpo~meins,ekpo~netwr,ekpo~afnam,ekpo~banfn,ekpo~peinh,t001w~adrnr,lfa1~lan
lfa1~stras,lfa1~adrnr AS ven_adrs,lfa1~mcod3,adrc~name1,adrc~city1,adrc~str
adrc~fax_number,adr6~addrnumber,adr6~smtp_addr
FROM ekko
INNER JOIN ekpo
ON ekko~ebeln = ekpo~ebeln
INNER JOIN t001w
ON ekpo~werks = t001w~werks
INNER JOIN lfa1
ON ekko~lifnr = lfa1~lifnr
INNER JOIN adrc
ON lfa1~adrnr = adrc~addrnumber
INNER JOIN adr6
ON adrc~addrnumber = adr6~addrnumber
WHERE ekko~ebeln = @ls_ebeln
AND ekko~bukrs = @ls_bukrs
ORDER BY ekko~ebeln ,ekpo~ebelp
INTO TABLE @lt_po_output_data.
IF lt_po_output_data IS NOT INITIAL.
DATA(lt_po_data) = lt_po_output_data.
SORT lt_po_data BY matnr .
DELETE ADJACENT DUPLICATES FROM lt_po_data COMPARING matnr .
ENDIF.

DATA(ls_first_line) = VALUE #( lt_po_output_data[ 1 ] OPTIONAL ).


IF ls_first_line IS NOT INITIAL.
me->lt_po_items = VALUE #(
FOR ls_output IN lt_po_output_data
( ebelp = ls_output-ebelp
txz01 = ls_output-txz01
matnr = ls_output-matnr
werks = ls_output-werks
menge = ls_output-menge
meins = ls_output-meins
netwr = ls_output-netwr
peinh = ls_output-peinh
)
).
me->ls_po_header = VALUE #( ebeln = lt_po_output_data[ 1 ]-ebeln
bedat = lt_po_output_data[ 1 ]-bedat
bukrs = lt_po_output_data[ 1 ]-bukrs
lifnr = lt_po_output_data[ 1 ]-lifnr ) .

me->ls_po_address = VALUE #( land1 = lt_po_output_data[ 1 ]-land1


pstlz = lt_po_output_data[ 1 ]-pstlz
regio = lt_po_output_data[ 1 ]-regio
stras = lt_po_output_data[ 1 ]-stras
ven_adrs = lt_po_output_data[ 1 ]-ven_adrs
mcod3 = lt_po_output_data[ 1 ]-mcod3
name1 = lt_po_output_data[ 1 ]-name1
city1 = lt_po_output_data[ 1 ]-city1
street = lt_po_output_data[ 1 ]-street
tel_number = lt_po_output_data[ 1 ]-tel_number
fax_number = lt_po_output_data[ 1 ]-fax_number
addrnumber = lt_po_output_data[ 1 ]-addrnumber
smtp_addr = lt_po_output_data[ 1 ]-smtp_addr
plant_adrs = lt_po_output_data[ 1 ]-plant_adrs
afnam = lt_po_output_data[ 1 ]-afnam
banfn = lt_po_output_data[ 1 ]-banfn ).
ENDIF.
ENDMETHOD.
ENDCLASS.

REPORT ABAP CODE.


*&---------------------------------------------------------------------*
*& Report ZMM_PO_PRINT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmm_po_print.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.


PARAMETERS: p_ebeln TYPE ebeln OBLIGATORY,
p_bukrs TYPE bukrs.
SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.
DATA(obj) = NEW zcl_mm_po_document( ).
obj->get_po_data(
ls_ebeln = p_ebeln " Purchasing Document Number
ls_bukrs = p_bukrs " Company Code
).
obj->get_adobe_form(
ls_ebeln = p_ebeln " Purchasing Document Number
ls_bukrs = p_bukrs " Company Code
).
obj->get_po_output( ).

You might also like