What Is Exact Difference Between BD87 and WE19
In BD87 you only deal with this failed IDoc, when you restart processing of a failed IDoc but
if you open an existing IDoc in WE19 and process it again you create a new IDoc.
In WE19 you can process only one idoc at a time, whereas in BD87 you can process any
number of idocs.
In WE19 a new idoc number gets generated every time you process on idoc but in BD87,
the same IDOC number is retained even after reprocessing.
We CANNOT process a SUCCESFUL Idoc in BD87 but we you CAN process a successful
idoc in WE19.
SPAU and SPDD difference
https://blogs.sap.com/2013/10/14/technical-upgrade-spdd-spau-phase/
BD87 : Process inbound IDocs
Using IDoc number and the transaction BD87, with the required message type you can
reprocess the IDoc. Match the error number with this transaction and execute the function for
the IDocs incorrectly processed.
WE19 : IDoc Test tool inbound
Use transaction WE19 to test inbound function module in debugging mode.
P.S: Please do not use we19 for reprocessing. It is only for testing and debugging
purposes.
TEST OUTBOUND IDOCS
WE19 is for testing for Inbound IDOC..
If you want to test Outbound IDOC ,you need to create delivery or change the delivery in
VL01N or VL02N Transaction.
Here you need to give correct output type like Delivery transaction output would be LD00 -> you
can find out Delivery Output type in NACE Transaction.
GO TO NACE -> select V2 Application -> Click on output type -> here you are able to see all
output types
if you don't find output type then contact Functional guy.
once you create delivery it will create IDOC ,you can IDOC Status in WE02 Transaction.
If you want to debug outbound IDOC then follow below Steps :
Go to delivery transaction -> when you create delivery ,please modify output type -> extras ->
header -> output type
here see the further data -> select peridocally scheduling
now come to RSNAST00 Program
enter delivery number as object number
Application -> V2
Output type -> enter delivery output type
Medium - A (ALE) ,6(EDI)
Now you are able to work on debugging
Also use WE05 to view the IDocs and their statuses.
IDOC Requirement: Transfer cost center master data and post (create)
Important T-codes in Idoc:
1. BD64 - Maintain the Distribution Model
After the distribution model is created, we can send any message to any receiver. No need
to create a new distribution model for each receiver and message type.
Distribution model acts as a bag to carry the list of receiver details from the sender for any
Message type and any receiver.
2. WE02/WE05 - Idoc List - to check idoc no, data records and status of idoc
Direction 1 - Outbound 2 - Inbound
3. SALE -> to define and link the logical system to the client
4. SM59 -> maintain RFC destination to sender
5. WE21 -> create a port to sender system
6. WE20 -> Maintain outbound partner profile
--> In Outbound partner profile, we maintain the below information:
1. Whom to send - partner (receiver)
2. What to send - Message Type + Idoc Type
3. Medium of data transfer - tRFC port
4. Mode of dispatch - .Immediate/.Collect
7. BD87 - Process inbound Idoc
8. WE19 - Idoc Test tool inbound
Note: We always Create Only One Profile for each receiving(Partner) and One Entry for each
Message type we transfer.
9. BD56 - Segment Filters in IDOCs
Explain about change pointer in SAP
We come across change pointer technique while dealing with master data distribution thru
ALE/IDOCs.
When we want to reflect changes made to master data (i.e. customer master, vendor master,
material master) visible to other clients listed in customer distribution model, we follow change
pointer technique. No Change Pointers Specific Settings are required for inbound idoc,
change pointers are only required for outbound interface.
Change Pointers related tables
CDHDR - Change Doc. Header
CDPOS - Change Doc. Items
BDCP - Change Pointer
BDCPS - Change Pointer Status
Change pointer specific configuration is done only in Outbound interface:
1.BD61 - Activate change pointers globally
2.BD50 - Enable change pointers for a message type
3.BD52 - Specify the fields for which change pointers are written
Status Code:
53 - Posted Successfully
03 - Dispatch OK
BD16 - Send Cost Center
ks01 - create cost center
bd17 - request cost center
2. Examples for Pooled, Clustered and transparent tables
Pool Table (match codes, look up tables)
Pool table is a logical table that must be assigned to a table pool when they are defined. The
pool table is used to store control data. Several pooled tables can be combined in a table pool.
The data of these pooled tables are then sorted in a common table in the database.
Table pool can contain 10 to 1000 small pool table which has 10 to 100 records.
A pooled table in R/3 has a many-to-one relationship with a table in the database. For one table
in the database, there are many tables in the R/3 Data Dictionary. The table in the database has
a different name than the tables in the DDIC, it has a different number of fields, and the fields
have different names as well. Pooled tables are an SAP proprietary construct.
Should be buffered (SE11->Display Table->technical settings)
Cluster Table (BSEG, KONV, BSEC)
Cluster tables are logical tables that must be assigned to a table cluster when they are defined.
Cluster tables can be used to store control data. They can also be used to store temporary data
or texts, such as documentation.
Cluster table can contain very big but few (1 to 10) cluster table.
A cluster table is similar to a pooled table. It has a many-to-one relationship with a table in the
database. Many cluster tables are stored in a single table in the database called a table cluster.
Cannot be buffered
A clustered and a pooled table cannot be read from outside SAP because certain data are
clustered and pooled in one field. All the pool table stored table in table pool does not need
to have any foreign key relationship but in the case of cluster table, it is must.
Pool and cluster table is basically used to store application data.
3. Difference between BADI and User Exits
During migration or upgrade for BADI we have patch but not for other enhancement
techniques
Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. They can
be inserted into the SAP System to accommodate user requirements too specific to be included
in the standard delivery. Since specific industries often require special functions, SAP allows
you to predefine these points in your software.
As with customer exits two different views are available:
In the definition view, an application programmer predefines exit points in a source that allow
specific industry sectors, partners, and customers to attach additional software to standard SAP
source code without having to modify the original object.
In the implementation view, the users of Business Add-Ins can customize the logic they need
or use a standard logic if one is available.
In contrast to customer exits, Business Add-Ins no longer assume a two-level infrastructure
(SAP and customer solutions), but instead allow for a multi-level system landscape (SAP,
partner, and customer solutions, as well as country versions, industry solutions, and the like).
Definitions and implementations of Business Add-Ins can be created at each level within such a
system infrastructure.
SAP guarantees the upward compatibility of all Business Add-In interfaces. Release upgrades
do not affect enhancement calls from within the standard software nor do they affect the validity
of call interfaces. You do not have to register Business Add-Ins in SSCR.
Difference between BADI and USER-EXIT.
1. BADI's can be used any number of times, whereas USER-EXITS can be used only one time.
Ex: - if your assigning a USER-EXIT to a project in (CMOD), then you cannot assign the
same to other project.
2. The Business Add-In enhancement technique differentiates between enhancements
that can only be implemented once and enhancements that can be used actively by any
number of customers at the same time. In addition, Business Add-Ins can be defined
according to filter values. This allows you to control add-in implementation and make it
dependent on specific criteria (on a specific Country value, for example).
3. BADI's are oops based.
In Function module SAP provides Two Standard Exception, give name
of that two exceptions.
In the function module two standard exceptions are
1.communication_failure
2.system_failure
What is the difference between RFC & normal Function module?
RFC is used to call the function module from the remote system, where as normal function
module is used within the system.
What are VTTK and VTTP table used for?
VTTK Shipment header
VTTP Shipment item
What are KNA1 and KNB1 table used for?
KNA1 - General data (one record for each customer)
KNB1 - Company code data (one record for each customer/company code combination)
KNC1 - Posting data (one record for each customer/company code/year combinations)
Events in Classical Reports
Below are the list and sequence of events available under classical reports, each event has its
own importance.
Load-of-program
This event is used to load program into memory for execution and this is the first event in
execution sequence.
Initialization
This event is used to initialize variables, screen default values and other default actions.
At Selection-Screen output
By using this event we can manipulate dynamic selection-screen changes.
At Selection-Screen on field
This event is used to validate a single selection-screen input parameter.
Syntax: AT SELECTION-SCREEN ON <parameter name>. "Validate an input parameter
At Selection-Screen on value request
This event is used to provide value help (field help) for a input field.
Syntax: AT SELECTION-SCREEN ON VALUE REQUEST FOR <parameter name>. "Input
search help for a input parameters
At Selection-Screen on help request
By using this event we can provide F1 help for a input field.
Syntax: AT SELECTION-SCREEN ON HELP REQUEST FOR <parameter name>. "Input (F1)
help for a input parameters
At Selection-Screen
This event is used to validate multiple input fields
Syntax: AT SELECTION-SCREEN . "used to validate multiple input fields
Start-of-Selection
This is default event which is used to write actual business logic.
Syntax: START-OF-SELECTION. "Default event
End-of-Selection
We can use this event just to state that start-of-selection is ended, this event is used with logical
databases, and logical databases are in HR ABAP only. In normal ABAP we don`t have much
importance.
Syntax: END-OF-SELECTION . "Start of selection is ended
Top-of-Page
This event prints constant heading for all pages.
Syntax: TOP-OF-PAGE."Page heading
End-of-Page
This event prints constant footer for all pages.
Before using this event, we need to reserve some lines for displaying footer.
Syntax: END-OF-PAGE. "Page footer
Example: REPORT ZPROGRAM LINE-COUNT 27(3). " Here we reserve 3 lines for footer
SD flow
1. INQUIRY
VA11 is the T-Code for inquiry and related tables are VBAK, VBAP. Once inquiry is done
customer requests quotation.
2. QUOTATION
T-code for quotation in VA21, tables are VBAK, VBAP. After quotation flow goes for purchase
order.
3. PURCHASE ORDER
Purchase order t-code is ME21N, related tables are EKKO, EKPO. Based on purchase order
sales order will be created.
4. SALES ORDER
Sales order t-code is VA01, related tables are VBAK, VBAP. Once sales order is created,
delivery will be done.
5. DELIVERY
T-Code for delivery order is VL01N, tables are LIKP, LIPS. Next the goods should be delivered
through shipping
6. SHIPPING
Shipping t-code is VT01, related tables are VTTK, VTTP. Once goods are shipped, go for billing.
7. BILLING
Billing t-code is VF01, tables are VBRK, VBRP. Every bill has invoice...next provide invoice.
8. INVOICE
Invoice t-code is VF21, related tables are VBRK, VBRP. Invoice end of sales flow.
SD includes
MV45AFZZ and MV45EFZ1
USER EXITS name-
SDVFX001 User exit header line in delivery to accounting
SDVFX002 User exit for A/R line in transfer to accounting
SDVFX003 User exit cash clearing in transfer to accounting
SDVFX004 User exit G/L line in transfer to accounting
SDVFX005 User exit reserves in transfer to accounting
SDVFX006 User exit tax line in transfer to accounting
SDVFX007 User exit: Billing plan during transfer to Accounting
SDVFX008 User exit: Processing of transfer structures SD-FI
SDVFX009 Billing doc. processing KIDONO (payment reference number)
SDVFX010 User exit item table for the customer lines
SDVFX011 Userexit for the komkcv- and kompcv-structures
USEREXIT_PRICING_PREPARE_TKOMK SAPLV60A RV60AFZZ This user exit
allows you to copy additional fields for pricing in the TKOMK communication
structure (header fields), which have not been provided in the standard SAP
system. These fields can also be used for pricing in the billing document. This
user exit is described in detail in the "New fields in pricing" section.
USEREXIT_PRICING_PREPARE_TKOMP SAPLV60A RV60AFZZ This user exit
allows you to copy additional fields for pricing in the TKOMP communication
structure (item fields), which have not been provided in the standard SAP
system. These fields can also be used for pricing. This user exit is described
in detail in the "New fields in pricing" section.
USEREXIT_FIELD_MODIFICATION SAPMV61A MV61AFZA You can use this user
exit to adjust the display of individual lines in the condition screen by
changing the display attributes of the screen fields. This does not include the
display of subtotals. This user exit is also used in order processing.
Link
https://www.stechies.com/sales-related-user-exits/
SAP HR Flow
https://www.guru99.com/sap-hcm.html
MM flow with transaction codes and tables in SAP
1. Purchase Requisition (ME51N)
Material requirement are identified either by the user, department or via material planning and
control. For example, a MRP Run in production planning or material falling short of reorder-point
can automatically generate Purchase Requisition. At the same time PR can be created
manually in the system.
2. Source Determination - RFQ (ME41)
Identify the possible source of supply based on the past order and existing long-term purchase
contract. Then create Request for Quotation, which can be then sent electronically to vendors.
3. Vendor Selection and Comparison of Quotation (ME49)
After receiving quotation system is capable to simulate pricing scenarios, allowing user to
compare number of quotations and sent rejection letter automatically.
4. Purchase Order (ME21N)
Data from Quotation or Purchase Requisition can be adopted to create Purchase Orders.
Purchase Order is then sent to Vendor to supply the goods.
5. Purchase Order Follow ups ME91, ME91F, ME92F
Reminder can be sent to vendors at predefined intervals.
6. Goods Receipts (MIGO, MB01)
Goods were received.
7. Invoice Verification (MIRO)
Along with the goods vendor also submits Invoice, system verifies then invoice against the
quantity received and PO data. The account payable clerk is notified.
Important Transactions in MM
MM01 Material Creation
Me51N Purchase Requisition
Me41 Request for Quotation
Me49 Comparison of Quotation
Me21N Purchase Order Creation
MIGO, MB01 Goods Receipt
MIRO Invoice Verification
MB1A Good Issue
Tables in MM
MARA Material General
MARC Material Plant Data
MAKT Material Description
MARD Material Storage Location Data
MAST Material BOM Link
MBEW Material Valuation
MKPF Material Document Header
MSEG Material Document Line Item
MVKE Material Sales Data
T023 Material Group
T024 Purchase Organization
EBAN Purchase Requisition
EBKN Account Assignment Purchase Requisition
EINA Purchasing Info Record - General Data
EINE Purchase Info Record - Purchase Organization Data
EKKO Purchase Order Header Data
EKPO Purchase Order Line Item Data
EKKN Account Assignment Purchase Order
EKBE History Purchase Order
EKET Scheduling Agreement Purchase Order
EKAB Release Documentation
FI Flow
Basically there are 5 major topics/areas in FI,
1. GL Accounting -
related tables are SKA1, SKB1 Master data
BSIS and BSAS are the Transaction Data
2. Account Receivables- related to Customer
All the SD related data when transfered to FI these are created.
Related Tables BSID and BSAD
3. Account Payables - related Vendor
All the MM related documents data when transfered to FI these are created
Related Tables BSIK and BSAK
All the above six tables data is present in BKPF and BSEG tables
You can link these tables with the hlp of BELNR and GJAHR and with Dates also.
4. Special Purpose Ledger.. which is rarely used.
5. Asset Managment
In CO there are
Profit center Accounting
Cost center Accounting will be there.
Cross-Application Components -> Financial.
http://help.sap.com/saphelp_470/helpdata/en/e1/8e51341a06084de10000009b38f83b/
frameset.htm
you will go through this link
http://www.sapgenie.com/sapfunc/fi.htm
Check this Link it out
http://www.sap-img.com/sap-download/sap-tables.zip
http://www.thespot4sap.com/IntroTo/SAP_FI_Module_Introduction.asp
http://www.thespot4sap.com/IntroTo/SAP_CO_Module_Introduction.asp
for tables check out link..
http://www.sapgenie.com/abap/tables_fi.htm
Take a look at this.
http://www.sap-img.com/sap-fi.htm
http://www.erpgenie.com/sapfunc/fi.htm
http://www.sap-img.com/index.htm
http://www.amazon.com/Configuring-SAP-Essential-Financial-Controlling/dp/0782125972
Difference between bapi commit and normal commit
Handle queueing in IDOCs
What is SAP LSMW?
LSMW is a tool that supports the transfer of data from non-SAP systems ("Legacy Systems") to
SAP R/3 systems. This can be a one-time transfer as well as a periodic one.
LSMW also supports conversion of data of the legacy system in a numerous way. The data can
then be imported into the SAP R/3 system via batch input, direct input, BAPIs or IDocs.
Furthermore, the LSM Workbench provides a recording function that allows generating a "data
migration object" to enable migration from any required transaction.
LSMW can be used for following 3 functions -
The main functions of the LSM Workbench are:
1. Import data (legacy data in spreadsheet tables and/or sequential files)
2. Convert data (from source format to target format)
3. Import data (into the database of the R/3 application)
To start the LSMW workbench use transaction code: LSMW
LSMW workbench shows the following information
Project: An ID with a maximum of 10 characters to name your data transfer project. If
you want to transfer data from several legacy systems, you may create a project e.g. for
every legacy system.
Subproject: An ID with a maximum of 10 characters that is used as a further structuring
attribute.
Object: An ID with a maximum of 10 characters to name the business object.
Enter Project ID, Subproject ID, Object ID. Click Execute The next screen gives the STEPS in
your LSMW data Migration
UPLOADING AND DOWNLOADING FILE FROM PRESENTATION
SERVER IN SAP
REPORT ztestr_file_handling.
PARAMETERS : p_path TYPE dxfields-longpath,
p_down TYPE dxfields-longpath.
TYPES : BEGIN OF ty_final,
field1(4) TYPE c,
field2(4) TYPE n,
END OF ty_final.
DATA : git_string TYPE STANDARD TABLE OF string INITIAL SIZE 1,
git_final TYPE STANDARD TABLE OF ty_final INITIAL SIZE 1.
*-- F4 help for the presentation layer
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
i_location_flag = 'P'
* i_server = space
* i_path = lv_i_path
* FILEMASK = '*.*'
* FILEOPERATION = 'R'
IMPORTING
* O_LOCATION_FLAG =
* O_SERVER =
o_path = p_path
* ABEND_FLAG =
EXCEPTIONS
rfc_error = 1
error_with_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*-- F4 help for the presentation layer
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_down.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
i_location_flag = 'P'
* i_server = space
* i_path = lv_i_path
* FILEMASK = '*.*'
* FILEOPERATION = 'R'
IMPORTING
* O_LOCATION_FLAG =
* O_SERVER =
o_path = p_down
* ABEND_FLAG =
EXCEPTIONS
rfc_error = 1
error_with_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
START-OF-SELECTION.
IF p_path IS NOT INITIAL.
*-- Validate whether path exists or not
PERFORM validate_path.
*-- Upload the file
PERFORM upload_file.
IF git_string[] IS NOT INITIAL.
*-- Populate the internal table for processing
PERFORM populate_itab .
IF git_final[] IS NOT INITIAL.
*-- Process the file
PERFORM process_file.
IF p_down IS NOT INITIAL.
PERFORM validate_path_d.
*-- Download the file
PERFORM download_file.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& Form VALIDATE_PATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM validate_path .
DATA: lv_result TYPE char1,
lv_file TYPE string.
lv_file = p_path.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_file
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF lv_result NE 'X'." if lv_result = 'X' then file exists
MESSAGE 'File does not exist' TYPE 'I'.
EXIT.
ENDIF.
ENDFORM. " VALIDATE_PATH
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_file .
DATA : lv_filename TYPE string.
lv_filename = p_path.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_filename
* filetype = 'ASC'
* has_field_separator = SPACE
* header_length = 0
* read_by_line = 'X'
* dat_mode = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* virus_scan_profile =
* IMPORTING
* filelength =
* header =
CHANGING
data_tab = git_string
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form POPULATE_ITAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_itab .
DATA : lwa_final TYPE ty_final.
FIELD-SYMBOLS : <fwa_string> TYPE string.
LOOP AT git_string ASSIGNING <fwa_string>.
SPLIT <fwa_string> AT '|' INTO lwa_final-field1
lwa_final-field2.
APPEND lwa_final TO git_final.
CLEAR lwa_final.
ENDLOOP.
ENDFORM. " POPULATE_ITAB
*&---------------------------------------------------------------------*
*& Form PROCESS_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process_file .
FIELD-SYMBOLS : <fwa_final> TYPE ty_final.
LOOP AT git_final ASSIGNING <fwa_final>.
<fwa_final>-field2 = <fwa_final>-field2 + 1.
CONDENSE <fwa_final>-field2.
ENDLOOP.
ENDFORM. " PROCESS_FILE
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_file .
DATA : lv_filename TYPE string,
lwa_string TYPE string,
lit_string TYPE STANDARD TABLE OF string INITIAL SIZE 1.
FIELD-SYMBOLS : <fwa_final> TYPE ty_final.
IF p_down IS NOT INITIAL.
lv_filename = p_down.
IF git_final[] IS NOT INITIAL.
LOOP AT git_final ASSIGNING <fwa_final>.
CONCATENATE <fwa_final>-field1 <fwa_final>-field2 INTO lwa_string
SEPARATED BY '|'.
APPEND lwa_string TO lit_string.
CLEAR lwa_string.
ENDLOOP.
ENDIF.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
* bin_filesize =
filename = lv_filename
* filetype = 'ASC'
* append = SPACE
* write_field_separator = SPACE
* header = '00'
* trunc_trailing_blanks = SPACE
* write_lf = 'X'
* col_select = SPACE
* col_select_mask = SPACE
* dat_mode = SPACE
* confirm_overwrite = SPACE
* no_auth_check = SPACE
* codepage = SPACE
* ignore_cerr = ABAP_TRUE
* replacement = '#'
* write_bom = SPACE
* trunc_trailing_blanks_eol = 'X'
* wk1_n_format = SPACE
* wk1_n_size = SPACE
* wk1_t_format = SPACE
* wk1_t_size = SPACE
* show_transfer_status = 'X'
* fieldnames =
* write_lf_after_last_line = 'X'
* virus_scan_profile = '/SCET/GUI_DOWNLOAD'
* IMPORTING
* filelength =
CHANGING
data_tab = lit_string
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*& Form VALIDATE_PATH_D
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM VALIDATE_PATH_D .
DATA: lv_result TYPE char1,
lv_file TYPE string.
lv_file = p_down.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_file
RECEIVING
result = lv_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF lv_result NE 'X'." if lv_result = 'X' then file exists
MESSAGE 'File does not exist' TYPE 'I'.
EXIT.
ENDIF.
ENDFORM. " VALIDATE_PATH_D
INPUT file contents
ABCD|1000
EFGH|2000
IJKL|3000
MNOP|4000
QRST|5000
OUTPUT FILE CONTENT :
ABCD|1001
EFGH|2001
IJKL|3001
MNOP|4001
QRST|5001
UPLOADING AND DOWNLOADING FILE FROM APPLICATION
SERVER IN SAP
REPORT ztestr_file_handling.
PARAMETERS : p_path TYPE dxfields-longpath,
p_down TYPE dxfields-longpath.
TYPES : BEGIN OF ty_final,
field1(4) TYPE c,
field2(4) TYPE n,
END OF ty_final.
DATA : git_string TYPE STANDARD TABLE OF string INITIAL SIZE 1,
git_final TYPE STANDARD TABLE OF ty_final INITIAL SIZE 1.
*-- F4 help for the presentation layer
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
i_location_flag = 'A'
* i_server = space
* i_path = lv_i_path
* FILEMASK = '*.*'
* FILEOPERATION = 'R'
IMPORTING
* O_LOCATION_FLAG =
* O_SERVER =
o_path = p_path
* ABEND_FLAG =
EXCEPTIONS
rfc_error = 1
error_with_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*-- F4 help for the presentation layer
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_down.
CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
EXPORTING
i_location_flag = 'A'
* i_server = space
* i_path = lv_i_path
* FILEMASK = '*.*'
* FILEOPERATION = 'R'
IMPORTING
* O_LOCATION_FLAG =
* O_SERVER =
o_path = p_down
* ABEND_FLAG =
EXCEPTIONS
rfc_error = 1
error_with_gui = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
START-OF-SELECTION.
IF p_path IS NOT INITIAL.
*-- Validate whether path exists or not
PERFORM validate_path.
*-- Upload the file
PERFORM upload_file.
IF git_final[] IS NOT INITIAL.
*-- Process the file
PERFORM process_file.
IF p_down IS NOT INITIAL.
*-- Validate whether path exists or not
PERFORM validate_path_d.
*-- Download the file
PERFORM download_file.
ENDIF.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& Form VALIDATE_PATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM validate_path .
DATA: lv_file TYPE tpfht-pffile,
lv_true TYPE char1.
CLEAR lv_file.
lv_file = p_path.
CALL FUNCTION 'PFL_CHECK_OS_FILE_EXISTENCE'
EXPORTING
fully_qualified_filename = lv_file
IMPORTING
file_exists = lv_true.
IF lv_true = space.
MESSAGE 'File does not exist' TYPE 'I'.
EXIT.
ENDIF.
ENDFORM. " VALIDATE_PATH
*&---------------------------------------------------------------------*
*& Form UPLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_file .
DATA : lv_filename TYPE string,
lwa_data TYPE string,
lwa_final TYPE ty_final.
lv_filename = p_path.
*-- Read data from Application Server
OPEN DATASET lv_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc IS INITIAL.
DO.
READ DATASET lv_filename INTO lwa_data.
IF sy-subrc EQ 0.
SPLIT lwa_data AT '|' INTO lwa_final-field1 lwa_final-field2.
APPEND lwa_final TO git_final.
CLEAR: lwa_final.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET lv_filename.
ELSE.
MESSAGE 'Path does not exist' TYPE 'I'.
EXIT.
ENDIF.
ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------*
*& Form PROCESS_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM process_file .
FIELD-SYMBOLS : <fwa_final> TYPE ty_final.
LOOP AT git_final ASSIGNING <fwa_final>.
<fwa_final>-field2 = <fwa_final>-field2 + 1.
CONDENSE <fwa_final>-field2.
ENDLOOP.
ENDFORM. " PROCESS_FILE
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM download_file .
DATA : lv_filename TYPE string,
lwa_string TYPE string,
lit_string TYPE STANDARD TABLE OF string INITIAL SIZE 1.
FIELD-SYMBOLS : <fwa_final> TYPE ty_final.
IF p_down IS NOT INITIAL.
lv_filename = p_down.
IF git_final[] IS NOT INITIAL.
LOOP AT git_final ASSIGNING <fwa_final>.
CONCATENATE <fwa_final>-field1 <fwa_final>-field2 INTO lwa_string
SEPARATED BY '|'.
APPEND lwa_string TO lit_string.
CLEAR lwa_string.
ENDLOOP.
ENDIF.
* // Upload error file to Application Layer
OPEN DATASET lv_filename FOR OUTPUT IN BINARY MODE.
IF sy-subrc IS INITIAL.
LOOP AT lit_string INTO lwa_string.
TRANSFER lwa_string TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.
ENDIF.
ENDIF.
ENDFORM. " DOWNLOAD_FILE
*&---------------------------------------------------------------------*
*& Form VALIDATE_PATH_D
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM validate_path_d .
DATA: lv_file TYPE tpfht-pffile,
lv_true TYPE char1.
CLEAR lv_file.
lv_file = p_down.
CALL FUNCTION 'PFL_CHECK_OS_FILE_EXISTENCE'
EXPORTING
fully_qualified_filename = lv_file
IMPORTING
file_exists = lv_true.
IF lv_true = space.
MESSAGE 'File does not exist' TYPE 'I'.
EXIT.
ENDIF.
ENDFORM. " VALIDATE_PATH_D
INPUT file contents
ABCD|1000
EFGH|2000
IJKL|3000
MNOP|4000
QRST|5000
OUTPUT FILE CONTENT :
ABCD|1001
EFGH|2001
IJKL|3001
MNOP|4001
QRST|5001
The addition IN TEXT MODE opens the file as a text file. Only the content of character-like data objects can be
passed to text files and read from text files.
The addition IN BINARY MODE opens the file as a binary file. When writing to a binary file, the binary content
of a data object is passed in unchanged form to the file. When reading from a binary file, the binary content of
the file is passed in unchanged form to a data object.
Singleton Class
Singleton pattern: is the one of the simplest design patterns which involves only one class
which instantiates itself to make sure that it creates one instance. Singleton ensues that it has
only one instance and provides global point of access to the object.
One example of a Singleton class is a Logger class which can be globally consumed within
multiple sub-systems for logging information and warning messages occurring during an end-to-
end process. As an application developer you don’t want to instantiate more than one instances
of Logger class because then either each sub-system will have their own loggers or they will not
have the correct instance of logger class to feed the messages.
Follow below steps to create singleton class in Object oriented ABAP
Step 1: Create a private class in Se24
Go to SE24, provide name as ZSAPN_CL_SINGLETON and click on create.
Provide description, select class as private and save.
Go to attributes tab, add a private attribute of type reference to same class.
Go to methods tab, add a static method INSTANTIATE and click on parameters button .
Add a returning parameter as below.
Go back to methods, double click on method INSTANTIATE and add below code.
METHOD INSTANTIATE.
IF LV_INST IS NOT BOUND.
CREATE OBJECT RO_INST.
LV_INST = RO_INST.
ELSE.
RO_INST = LV_INST.
ENDIF.
ENDMETHOD.
Save and activate the class, go to SE38, create a program ZSAPN_SINGLETON_GLOBAL.
Try to create instance directly.
REPORT ZSAPN_SINGLETON_GLOBAL.
DATA : LO_CLASS TYPE REF TO ZCL_SAPN_SINGLETON.
create OBJECT lo_class.
It will through an error.
Now create instance through static method.
REPORT ZSAPN_SINGLETON_GLOBAL.
DATA : LO_CLASS TYPE REF TO ZCL_SAPN_SINGLETON.
LO_CLASS = ZCL_SAPN_SINGLETON=>INSTANTIATE( ).
Now you can access all public instance components through the object.
Types of data classes:
APPL0 (master data): Data which is seldomly changed. ...
APPL1 (transaction data): Data that is frequently changed. ...
APPL2 (organizational data): Customizing data that is defined when the system is
installed and seldomly changed.
How to Debug a Completed SAP Background Job?
It is easy to debug an error job to find out the cause of the error. To debug the background job,
go to transaction code SM37 and display the jobs.
First, we need to keep a break-point in the program, so that the control stops at the break-point
when the debugger is switched on.
To find the name of the program, select the job that we want to debug and press step in the
application toolbar.
Display the program by using the Menu Goto –> Program.
Keep a break-point in the program and go back to Job overview screen.
Again select the job that we want to debug and enter JDBG in the command field and press
enter.
Once JDBG is entered in the command field the debugger will get switched on. Now press F8 to
reach the break-point in the program.
Now we can analyze the program for the cause of the error.
Validate data entered in table maintenance generator for Z table
Se11 -> Enter table ->Display( F7 ) -> Menu bar -> Utilities -> Table main. generator
Once you are on the table maintenance generator screen.
Menu Bar - Environment --> Modification --> Events
Here specify Event as '01' and the Subroutine name that will hold the data for the validation.
As you know we need to specify a function group.
Go to SE80 and Open your function group.
Now in the PBO of the screen write a subroutine for the validation before saving an entry in
the table.
Change pointers use in IDOC
Change documents are working based on change document technique which tracks
changes made to the key documents (Material Master, Customer Master, Vendor Master
etc.) in SAP.
Changes made to the key documents are recorded in the change document
Header table i.e. CDHDR and Item table CDPOS, Additional change pointers are written in
the BDCP and BDCPS tables.
Change pointers technique is used to initiate the outbound process automatically when
master data is created or changed.
A standard program RBDMIDOC is scheduled to run on periodic basis to evaluate the
change pointers for a message type and starts the ALE process for distributing the Master
data to the appropriate destination.
'Object' is collection of fields of different database tables. T-code for creating an object is
SCDO.
N.B: 1. BD61 Active change pointers generally
- Check the checkbox "Change pointers activated -generally"
- Save it
2. BD50 Active change pointers for Message Type
- Message Type Active
Why BADI
In contrast to the earlier enhancement techniques, BADI follows Object Oriented approach to
make them reusable. A BADI can be used any number of times where as standard
enhancement techniques can be used only once.
For example, if we assign an enhancement to one custom project, then that enhancement
cannot be assigned to any other custom projects. To overcome this drawback SAP has
provided a new enhancement technique called BADI.
Transaction code for BADI Definition: SE18
When you create a BAdI definition, a class interface will be automatically created, and you
can define your methods in the interface. The implementation of the methods can be
done in SE19 transaction.
When a BAdi is created following are automatically generated:
An interface with 'IF_EX_' inserted between the first and second characters of the BAdi name
An adapter class with 'CL_EX_' inserted between the first and second characters of the BAdi
name.
Transaction code to Implement BADI: SE19
Types of BADI's:
While creating a BADI using the T-code SE18, it provides the pop-up screen to select the type
of BADI to be used is as shown below.
There are two types of BADI's.
1) Multi use BADI:
With this option, any number of active implementations can be assigned to the same definition
BADI. By default, this option is checked.
If we want the BADI for multiple use
If you have multiple-use BADI definitions, the sequence must not play any role.
The drawback in Multiple use BADI is, it is not possible to know which BADI is active especially
in country specific version.
2) Filter dependent BADI:
Using this option we can define the BADI's according to the filter values to control the add-in implementation on specific criteria.
Ex: Specific country value.
How to Find BADI's in SAP system:
Method 1:
Steps to find BADI:
1. Go to SE 24 transaction, type CL_EXITHANDLER and then click on display.
2. Double click on GET_INSTANCE method.
3. Put a break-point on class method CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE.
4. Run any transaction on which we want find the BADI's say VA01.
5. Give the transaction name VA01 and press enter.
6. It will automatically take you to the break-point which we have set in the SE24 transaction. Each time if you press F8 a list BADI
names will be displayed.
7. You can find the BADI name in field EXIT_NAME and if you double click on it, we can get the corresponding BADI name before
hit the corresponding screen. Based on the requirement find the BADI name and accordingly implement your functionality using the
transaction se19.
Method 2:
Go to transaction SE84 and click on Enhancements. Then double click on Business Add-Ins.
For example, if you want to find the BADI's for the standard transaction ME22n, the procedure is as follows. This example shows,
finding the way of BADI names by providing the Package of ME22n.
1) Go to transaction ME22n. Select the System option from the menu and then click on Status. It displays the following information.
2) Double click on the program name i.e. SAPLMEGUI. It will take you into the program and click on Go to tab from the Menu.
There we can find the package name of the standard transaction ME22n.Copy and paste it in the package filed.
3) Now Press F8, a list of BADI names will be displayed as shown below. Select the appropriate BADI name and implement it based
on the business requirement using the transaction SE19.
Method 3:
Finding the BADI names using SE18 transaction
1) Go to transaction SE 18. Select F4 help for the definition name and click on Information System button as shown below.
2) A pop-up screen will be displayed and give the package name for any standard transaction say VA02. Finding the package is
explained above. Please refer above method to find the package name. The package name for VA02 transaction is 'VA.'
3) A list of BADI names will be displayed for the transaction VA02. Select the appropriate BADI name and implement it using T-
code SE19.
Example:
This Example explains how to implement BADI's. Here I am trying to show how to add custom screen to the ME23N Transactions using
BADI's.
The procedure is as explained below.
- Find the BADI using the method 1 as shown above.
The BADI name to add the custom screen to ME23n is 'ME_GUI_PO_CUST'.
- Go to T-code SE19 and create an implementation ZME_GUI_PO_CUST and then click on create button
- Give the Definition name "ME_GUI_PO_CUST" and continue, give short text, save
- Click on Interface Tab, you can find the implementation class name as ZCL_IM_ME_GUI_PO_CUST2.
- Click on ZCL_IM_ME_GUI_PO_CUST2, which will take you to SE24.
- Add "MMMFD" in the Type Group Section of properties tab.
- Go to Attributes section and declare the following attribute
- SUBSCREEN1 Constant Public Type MEPO_NAME Name of a View
'ITEMSCREEN1 '.
- Go to Methods section, you can find the BADI interface methods.
- Double click on the method "IF_EX_ME_GUI_PO_CUST~SUBSCRIBE", this method is having 3 parameters
Go to the code section of the method and add the following code there.
Code for IF_EX_ME_GUI_PO_CUST~SUBSCRIBE:
DATA: ls_subscriber LIKE LINE OF re_subscribers.
*--FIRST SCREEN POPULATION
*--we want to add a customer subscreen on the item detail tab
CHECK im_application = 'PO'.
CHECK im_element = 'ITEM'.
*--each line in re_subscribers generates a subscreen. We add one subscreen
*--in this example
CLEAR re_subscribers[].
*--the name is a unique identifier for the subscreen and defined in this
*--class definition
ls_subscriber-name = subscreen1.
*--the dynpro number to use
ls_subscriber-dynpro = '0002'.
*--the program where the dynpro can be found
ls_subscriber-program = 'ZME_GUI_PO_CUST_SCREEN'.
*--each subscreen needs itsown DDIC-Structure
ls_subscriber-struct_name = 'ZMARA'.
*--a label can be defined
ls_subscriber-label = 'Cust BADI'.
*--the position within the tabstrib can be defined
ls_subscriber-position = 7.
*--the height of the screen can be defined here. Currently we support two
*--screen sizes:
*--value <= 7 a sevel line subscreen
*--value > 7 a 16 line subscreen
ls_subscriber-height = 7.
APPEND ls_subscriber TO re_subscribers.
Save and check and back
Double click on method IF_EX_ME_GUI_PO_CUST~MAP_DYNPRO_FIELDS".
Add the following code in the method.
*given the field catalog of structure ZMARA we have to
*establish a mapping to metafields which are used for field selection
*purposes and error handling Standard definitions can be found in type
*pool MMMFD. It is important for customer fields to use integer
*constants above 90000000 for the metafield.
FIELD-SYMBOLS: <mapping> LIKE LINE OF ch_mapping.
LOOP AT ch_mapping ASSIGNING <mapping>.
CASE <mapping>-fieldname.
WHEN 'MATNR'. <mapping>-metafield = mmmfd_cust_08.
WHEN 'MTART'. <mapping>-metafield = mmmfd_cust_09.
WHEN 'MATKL'. <mapping>-metafield = mmmfd_cust_10.
ENDCASE.
ENDLOOP.
The metafield mapping important for field selection and error handling purpose.
Save, check and back
Activate the Implementation class.
Activate the BADI Implementation.
Now create a structure in SE11 with the name ZMARA.
Add the following fields in the structure.
Now Create a Program with the Name 'ZME_GUI_PO_CUST_SCREEN' and create a screen with sub screen type with the number
0002.
Add the fields on to screen from ZMARA program 'ZME_GUI_PO_CUST_SCREEN'.
**
De comment the PBO module in screen flow logic and create the module in above program.
Add the following code in program ZME_GUI_PO_CUST_SCREEN.
TABLES: ZMARA.
DATA: call_subscreen TYPE sy-dynnr,
call_prog TYPE sy-repid,
call_view TYPE REF TO cl_screen_view_mm,
call_view_stack TYPE REF TO cl_screen_view_mm OCCURS 0.
*---------------------------------------------------------------------*
* FORM SET_SUBSCREEN_AND_PROG *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> DYNNR *
* --> PROG *
* --> VIEW *
* --> TO *
* --> CL_SCREEN_VIEW_MM *
*---------------------------------------------------------------------*
FORM set_subscreen_and_prog USING dynnr TYPE sy-dynnr
prog TYPE sy-repid
view TYPE REF TO cl_screen_view_mm.
call_subscreen = dynnr.
call_prog = prog.
call_view = view.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module STATUS_0002 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0002 OUTPUT.
SELECT SINGLE * FROM MARA
INTO CORRESPONDING FIELDS OF ZMARA
WHERE MATNR = '100-100'.
ENDMODULE. " STATUS_0002 OUTPUT
The sub-routine "set_subscreen_and_prog" is must with the same signature.
This routine is called from BADI to call the sub screen.
Activate the screen & program.
Now Go to T-Code ME23N to test the application.
You can find a new tab is added in the item level with the name CUST BADI.
There are 5 types of RFCs
Synchrnous RFCs
Asynchronous RFCs
Transactional RFCs
Queue RFCs
Parallel RFCs
Synchronous RFC
The first version of RFC is synchronous RFC (sRFC). This type of RFC executes the function call
based on synchronous communication, which means that the systems involved must both be
available at the time the call is made.
Transactional RFC (tRFC)
Transactional RFC (tRFC, also originally known as asynchronous RFC) is an asynchronous
communication method that executes the called function module in the RFC server only once. The
remote system need not be available at the time when the RFC client program is executing a tRFC.
The tRFC component stores the called RFC function, together with the corresponding data, in the
SAP database under a unique transaction ID (TID).
If a call is sent, and the receiving system is down, the call remains in the local queue until a later
time. The calling dialog program can proceed without waiting to see whether or not the remote call
was successful. If the receiving system does not become active within a certain amount of time, the
call is scheduled to run in batch.
tRFC is always used if a function is executed as a Logical Unit of Work (LUW). Within a LUW, all
calls are
· executed in the order in which they are called
· executed in the same program context in the target system
· run as a single transaction: they are either committed or rolled back as a unit.
Implementation of tRFC is recommended if you want to guarantee that the transactional order of the
calls is preserved.
Disadvantages of tRFC
· tRFC processes all LUWs independent of one another. Due to the amount of activated tRFC
processes, this procedure can reduce performance significantly in both the send and the target
systems.
· In addition, the sequence of LUWs defined in the application cannot be kept. Therefore, there is no
guarantee that the transactions are executed in the sequence dictated by the application. The only
guarantee is that all LUWs are transferred sooner or later.
Queued RFC (qRFC)
To guarantee that multiple LUWs are processed in the order specified by the application, tRFC can
be serialized using queues (inbound and outbound queues). This type of RFC is called queued RFC
(qRFC).
qRFC is therefore an extension of tRFC. It transfers an LUW (transaction) only if it has no
predecessors (in reference to the sequence defined in different application programs) in the
participating queues.
Implementation of qRFC is recommended if you want to guarantee that several transactions are
processed in a predefined order.
The other RFC's are: Parallel RFC
Asynchronous RFC.
Business Add-ins - Filter BADI - Application
for displaying customer data based on filter
value - Country code
What is a Filter-BADI?
Business Add-Ins may be implemented based on a filter value. If an enhancement for country-
specific versions is provided for in the standard version, it is likely that different partners will
want to implement this enhancement. The individual countries can create and activate their own
+implementation.
How to define a Filter-BADI and then implement it
We encounter a business requirement where different country clients (customers) may have
different country specific applications. These applications can be integrated centrally in one
standard application by means of a 'Filter'.
Here we consider a scenario for three country specific application (say) for India (IN), USA (US)
and Germany (DE) respectively.
→ Note: Here the scenario will be dealt with a BADI created under customer name space for
easy understanding.
→ To enable a BADI to allow 'Filter' implementations, make the BADI filter dependent. In case
of a standard BADI it should be inbuilt 'Filter dependent'.
→ As usual create an interface method,
→ Create interface parameters. Here 'FLT_VAL' indicates the parameter which will act as a
filter,
→ Create an implementation for (say) filter value 'INDIA' that is 'IN'.
→ Navigate inside the method to write the code,
→ Observe the code for filter value 'INDIA',
method zif_ex_dave_badi_filter~zdave_method_country.
data:
begin of fs_kna1,
kunnr type kunnr,
land1 type land1,
name1 type name1,
ort01 type ort01,
pstlz type pstlz,
regio type regio,
stras type stras,
end of fs_kna1.
data:
t_kna1 like
standard table
of fs_kna1.
select kunnr
land1
name1
ort01
pstlz
regio
stras
from kna1
into table
t_kna1
where kunnr = customer
and land1 = flt_val.
if sy-subrc eq 0.
write:/2 'Customer'(001) color 1,
15 'India Ctry Key'(002) color 2,
35 'Name'(003) color 3,
65 'City'(004) color 4,
80 'PO code'(005) color 5,
95 'Region'(006) color 6,
110 'Street'(007) color 7.
skip.
loop at t_kna1 into fs_kna1.
write:/2 fs_kna1-kunnr color 1 inverse,
15 fs_kna1-land1 color 2 inverse,
35 fs_kna1-name1 color 3 inverse,
65 fs_kna1-ort01 color 4 inverse,
80 fs_kna1-pstlz color 5 inverse,
95 fs_kna1-regio color 6 inverse,
110 fs_kna1-stras color 7 inverse.
endloop.
endif.
endmethod.
→ Now, create a filter implementation for country code 'US' that is USA,
→ Navigate inside the filter method to code for the filter condition,
→ Observe the code for filter implementation 'USA',
method zif_ex_dave_badi_filter~zdave_method_country.
data:
begin of fs_kna1,
kunnr type kunnr,
land1 type land1,
name1 type name1,
sortl type sortl,
telf1 type telf1,
telfx type telfx,
adrnr type adrnr,
end of fs_kna1.
data:
t_kna1 like
standard table
of fs_kna1.
select kunnr
land1
name1
sortl
telf1
telfx
adrnr
from kna1
into table
t_kna1
where kunnr = customer
and land1 = flt_val.
write:/2 'Customer'(001) color 1,
15 'USA Ctry Key'(002) color 2,
35 'Name'(003) color 3,
65 'Sort Name'(004) color 4,
80 'Tel no'(005) color 5,
95 'Fax no'(006) color 6,
110 'Addr no'(007) color 7.
skip.
loop at t_kna1 into fs_kna1.
write:/2 fs_kna1-kunnr color 1 inverse,
15 fs_kna1-land1 color 2 inverse,
35 fs_kna1-name1 color 3 inverse,
65 fs_kna1-sortl color 4 inverse,
80 fs_kna1-telf1 color 5 inverse,
95 fs_kna1-telfx color 6 inverse,
110 fs_kna1-adrnr color 7 inverse.
endloop.
endmethod.
→ Create an implementation for (say) filter value 'GERMANY' that is 'DE'.
→ Navigate inside the method to write the code,
→ Observe the code for filter implementation 'DE',
method zif_ex_dave_badi_filter~zdave_method_country.
data:
begin of fs_kna1,
kunnr type kunnr,
land1 type land1,
name1 type name1,
anred type anred,
erdat type erdat,
ktokd type ktokd,
lifnr type lifnr,
end of fs_kna1.
data:
t_kna1 like
standard table
of fs_kna1.
select kunnr
land1
name1
anred
erdat
ktokd
lifnr
from kna1
into table
t_kna1
where kunnr = customer
and land1 = flt_val.
write:/2 'Customer'(001) color 1,
15 'DE Ctry Key'(002) color 2,
35 'Name'(003) color 3,
65 'Title'(004) color 4,
80 'Created on'(005) color 5,
95 'Acct grp'(006) color 6,
110 'Vendor'(007) color 7.
skip.
loop at t_kna1 into fs_kna1.
write:/2 fs_kna1-kunnr color 1 inverse,
15 fs_kna1-land1 color 2 inverse,
35 fs_kna1-name1 color 3 inverse,
65 fs_kna1-anred color 4 inverse,
80 fs_kna1-erdat color 5 inverse,
95 fs_kna1-ktokd color 6 inverse,
110 fs_kna1-lifnr color 7 inverse.
endloop.
endmethod.
→ Now it’s time to call the enhancements in the customer application,
→ Now, execute the application (here report) and test the customer enhancement,
→ Test case I - Country code 'INDIA' (IN),
→ Execute the test data and observe the functionality,
→ Test case II - Country code 'USA' (US),
→ Execute the test data and observe the functionality,
→ Test case III - Country code 'Germany' (DE)
→ Execute the test data and observe the functionality,
Adapter class
In order to enhance a SAP application program, the BADI must first be defined. The developer will
create an interface for the BADI. An adapter class is created from this that will implement the
interface. Developers will then create an instance of the adapter class in the SAP application
program and create method calls as required.
Adapter class performs these tasks
1. Control ( the class calls all active implementations)
2. Filtering (If the Add-in has to be executed under certain conditions, the class ensures that
only certain implementations are executed)
What is the use of distribution model in Idoc:
Distribution Model Acts as a BAG to Carry the List of Receiver Details for any Message Type
and any receiver from the SENDOR.
Use of filtering in Idoc:
There are two filtering in IDoc.
Segment Filtering:
Segment filtering can be achieved using T/Code BD56. Here you can suppress a whole
segment irrespective of data inside it. You have to give Message Type / Sender Partner /
Receiver Partner.
Data Filtering:
Data filtering can be done in distribution model (BD64) where you can restrict whole IDOCS or
partials IDOCS to be send based on data in fields inside IDOC depending on whether the
segment in which you filter is at the highest level or at a lower level. For example, in MATMAS if
you put a filter of E1MARCM for a particular plant, only data for this plant will go and other
plants will be ignored.
FM’s used in sapscript:
Open_form
Start_form
Write_form
End_form
Close_form
Various Types of Enhancements
There are these new enhancement concepts:
Enhancement spots
Introduced as part of the enhancement concept from SAP NetWeaver 7.0,
Enhancement spots are used for handling explicit enhancement options. These include
both the explicit enhancement sections and explicit enhancement points. An
enhancement spot can handle several explicit enhancement options of an object in
repository. An enhancement option can also have several enhancement spots assigned
to it. Enhancement spots, like most enhancement framework components, are reusable and
can be used in different objects as and when needed using the spot element definition.
Enhancement spots can also be created by SAP users.
T-code – se18
Explicit Enhancements – Explicit enhancements are similarly provided by SAP at various point
of the code. They are provided with ENHANCEMENT-POINT and ENHANCEMENT-SECTION.
ENHANCEMENT-POINT is the empty placeholder for the code whereas ENHANCEMENT-
SECTION is the placeholder with default code.
Implicit Enhancements – Implicit enhancements are not delivered by SAP in the code, but
SAP has given flexibility to implement them at various locations
Beginning of the Subroutine/Method/FM/Include
End of the subroutine/Method/FM/Include
Class Enhancements – Pre/Post/Overwrite method
FM Enhancements – Additional Parameters
Best enhancement link: http://zevolving.com/2014/03/abap-enhancement-implementations-
introduction/
Adding Explicit Enhancement to custom program
Enhancement Framework is the new paradigm to bring all enhancement techniques under one roof. It
can also be switched using Switch Framework. The following are different enhancement technologies
available under this framework.
• Source Code Enhancement
• Function Group Enhancement
• Class Enhancement
• Kernel-BADI Enhancement
Source Code enhancement
Whenever enhancement needs to be incorporated directly into the ABAP source code, this technology
shall be provided. Implementing this technology is also called as Source Code Plug-In. There are two
types of Source Code enhancements possible.
• Implicit enhancement option
• Explicit enhancement option
Explicit enhancement option
As implicit enhancements are predefined enhancements provided by SAP in the source code, the explicit
enhancements can be implemented by the customers or partners.
There are two types of Explicit Enhancement options available. For this, we now have two new ABAP
statements, viz.
1. Enhancement point (Syntax - ENHANCEMENT-POINT)
2. Enhancement section (Syntax - ENHANCEMENT-SECTION)
Enhancement section is used to replace a set of code or statements with the customer (custom code). In
this technique the original source code does not get executed but, the customer implementation (custom
code) gets executed.
Note - Explicit enhancements though can be placed anywhere in the source code but, not just anywhere
except some areas where SAP would allow (program allows).
STEP 1: Create a package in transaction SE80 (Object navigator) Name YDEV
STEP 2: Navigate to 'Enhancements' folder of your package. Package (YDEV) Enhancement.
Right click the 'Enhancements' 'Create' 'Enhancement Spot'.
Fill in the details in the 'Create Enhancement Spot' dialog.
And save it into created package. Observe the enhancement spot created under the 'Enhancement
Spots' folder.
STEP 3: 'Right Click' the spot created and 'Implement' it (Create an Implementation).
Fill in all the details in the 'Create Enhancement Implementation' dialog.
STEP 4: Now, we need to 'Activate' the enhancement spot. In addition with the Enhancement spot the
'Enhancement Implementation' will get activated.
STEP 5: Here we are applying enhancements to a CUSTOM program not a standard program to
demonstrate the functionality. So we create a simple program 'YDEV_CODE' (say) it is retrieving records
from the database table 'VBAK' (Sales Document Header) and displaying a few records.
Now, if the customer wants to replace the set of logic with his own logic (say) like retrieving records from
database table 'VBAP' (Sales Document Item) and then display a few records, he/she will create an
enhancement section which goes like,
Create a program YDEV_CODE.
OUTPUT
STEP 6: Right click the area which is appropriate to apply the enhancement
Note - Explicit enhancements though can be placed anywhere in the source code but, not just anywhere
except some areas where SAP would allow (program allows).
Now, in the 'Create Enhancement Option' fill in the details, here fill the name under 'Enhancement-
section' only. Then fill in the Enhancement Spot Implementation Name which we created earlier.
Now we are able to see program lines have Enhancement-Section…End Enhancement-Section.
Note - Make sure that the code which has to be replaced is within the 'ENHANCEMENT-SECTION...' and
'END-ENHANCEMENT-SECTION'.
STEP 7: Now to include the custom code in the program which will replace the original code, enable the
'Enhancement Mode' by clicking on the 'Spiral' button.
Place the cursor on the 'Enhancement-section' and navigate to 'Edit' 'Enhancement
Operations' 'Create Implementation'.
Fill in the details for the 'Create Enhancement Implementation' dialog. Click on 'Create' button for the
'Select or Create Enhancement Implementation' dialog.
STEP 8: Now, write the code within the 'ENHANCEMENT' and 'ENDENHANCEMENT' statements as the
replacement code.
STEP 9: Don't forget to 'Activate' the enhancement Switch the 'Enhancement' mode OFF and
'Activate' the entire program.
STEP 10: Execute the transaction/program to find out the difference.
Before Enhancement:
After Enhancement:
Summary:
1. Here we deals with the enhancement of a 'Z' program it is possible to 'CREATE' an
'ENHANCEMENT-SECTION'. But, in case of a 'STANDARD SAP' program there are certain
places (provided by SAP) like 'ENHANCEMENT-POINT...' and 'ENHANCEMENT-SECTION...'
where we can create implementations based on customer’s business functionality.
2. There can be only one and only one 'ACTIVE' implementation for an 'ENHANCEMENT-
SECTION'.
Source Code:
*&---------------------------------------------------------------------*
*& Report YDEV_CODE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT YDEV_CODE.
TABLES : VBAK, VBAP.
DATA : IT_VBAK TYPE STANDARD TABLE OF VBAK INITIAL SIZE 0,
WA_VBAK TYPE VBAK,
IT_VBAP TYPE STANDARD TABLE OF VBAP INITIAL SIZE 0,
WA_VBAP TYPE VBAP.
INITIALIZATION.
REFRESH : IT_VBAK,
IT_VBAP.
CLEAR : WA_VBAK,
WA_VBAP.
START-OF-SELECTION.
ENHANCEMENT-SECTION YDEV_ENHANCE_SECTION SPOTS YDEV_IMPLEMENT_SPOT .
SELECT *
FROM VBAP
INTO TABLE IT_VBAP[]
UP TO 15 ROWS.
WRITE: /02 'Sales Document',
20 'Date',
40 'Time',
65 'Name of Person'.
ULINE .
IF IT_VBAP[] IS NOT INITIAL.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE: /02 WA_VBAP-VBELN,
20 WA_VBAP-POSNR,
40 WA_VBAP-MATNR,
65 WA_VBAP-MATWA.
ENDLOOP.
ENDIF.
END-ENHANCEMENT-SECTION.
*$*$-Start: YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*
ENHANCEMENT 1 YDEV_IMPLEMENT_ENHC_SECTION. "active version
SELECT *
FROM VBAP
INTO TABLE IT_VBAP[]
UP TO 10 ROWS.
WRITE: /02 'Sales Document',
20 'Sales Item',
40 'Material Number',
65 'Material entered'.
ULINE .
IF IT_VBAP[] IS NOT INITIAL.
LOOP AT IT_VBAP INTO WA_VBAP.
WRITE: /02 WA_VBAP-VBELN,
20 WA_VBAP-POSNR,
40 WA_VBAP-MATNR,
65 WA_VBAP-MATWA.
ENDLOOP.
ENDIF.
ENDENHANCEMENT.
*$*$-End: YDEV_ENHANCE_SECTION----------------------------------------------------------------$*$*
Types of ABAP reports in SAP
ABAP report types are of 7 types. ABAP report types are available in reports attributes screen.
Executable program
Function group (containing function modules)
Include
Interface pool
Class pool
Module pool
Subroutine pool
FREQUENTLY USED BAPI’S
MM
BAPI_MATERIAL_SAVEDATA
BAPI_GOODSMVT_CREATE
BAPI_INCOMINGINVOICE_CREATE
BAPI_OBJCL_GETDETAIL
PO Creation: BAPI_PO_CREATE
SD
Sales order Creation: BAPI_SALESORDER_CREATEFROMDAT2
Sales order change: BAPI_SALESORDER_CHANGE
Delivery: BAPI_OUTB_DELIVERY_CONFIRM_DEC
Cancel Billing: BAPI_BILLINGDOC_CANCEL1
Create Billing: BAPI_BILLINGDOC_CREATE
PP
Production order Creation: BAPI_PRODORDCONF_CREATE_ACT
BAPI
It stands for Business API(Application Program Interface).
A BAPI is remotely enabled function module i.e. it can be invoked from remote programs like
standalone JAVA programs, web interface etc..
You can make your function module remotely enabled in attributes of Function module but
A BAPI are standard SAP function modules provided by SAP for remote access. Also they are
part of Businees Objest Repository(BOR).
BAPI are RFC enabled function modules.
Difference between RFC and BAPI are business objects.
You create business objects and those are then registered in your BOR (Business Object
Repository) which can be accessed outside the SAP system by using some other applications
(Non-SAP) such as VB or JAVA. In this case u only specify the business object and its method
from external system in BAPI there is no direct system call. While RFC are direct system call
Some BAPIs provide basic functions and can be used for most SAP business object types.
These BAPIs should be implemented the same for all business object types. Standardized
BAPIs are easier to use and prevent users having to deal with a number of different BAPIs.
Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.
CONSTRUCTOR AND STATIC CONSTRUCTOR
Two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are
automatically called when you create an object (CONSTRUCTOR) or when you first
access the components of a class (CLASS_ CONSTRUCTOR).
Constructor: This method is executed automatically whenever object is created; this is used to
set default values with respect to instance/object. The name of the constructor method
is CONSTRUCTOR.
These methods can only have importing parameters; there will not be any exporting parameters.
Static Constructor: This method is executed automatically whenever you first access the
components (static or instance) of a class; this is used to set default values globally irrespective
of instances/objects. The name of the static constructor is CLASS_CONSTRUCTOR.
These methods will not have any importing and exporting parameters. These methods will be
executed only once.
What is the difference between abstract class and interface?
Abstract class is a class which contains at least one abstract method (Method without
implementation), Abstract class contains methods with implementation and without
implementation and we cannot create instance for the abstract class.
Abstract class is mainly for inheritance.
Interface contains methods without implementation.
What is alias name in OOABAP?
Alias is an alias name for the interface method implemented in the class.
Can we raise events in interface?
No, you cannot raise events in interface, because there is no Implementation for the methods.
We can create events in interfaces.
What is the difference in attributes defined in the public versus
private section of a class?
Public attributes can be accessed by class, subclasses and other classes whereas Private
attributes can be accessed by class itself only.
What is the difference between Singleton and Static Class in SAP
ABAP?
Before going to static classes, you should understand static components.
Static Components: Static components (static attributes, static events and static methods)
exists globally, no need to create object/instance of the class to access them, we can access
them by using static component selector => .
Static Class: A class that only contains static components and no instance components is
referred to as a static class.
Singleton Class: It is a class which does not allow you to create multiple instances.
Can we make methods of interface as abstract and final in OOABAP?
No we cannot make interface methods as abstract or final in Object Oriented ABAP
Can we declare events in interface in OOABAP?
Yes, we can declare events in interface in Object Oriented ABAP but we cannot raise an event
in interface
What is an Event in OOABAP?
Event is a mechanism by which method of one class can raise method of another class, without
the hazard of instantiating that class.
How to declare and raise events in OOABAP?
We need to follow below steps when working with events in Object Oriented ABAP
Define an event
Define a method
Link event and method and convert the method into event-handler method
Create a triggering method which will raise the event
Use set handler and register event handler method to a particular instance in the program
What is Abstract method in OOABAP ?
Abstract methods are method which doesn't contain any implementation.
What is an Abstract class in OOABAP
It is a class which contains methods with implementation as well as methods without
implementation .
(or)
Abstract class is a class which contains at least one abstract method.
Can we instantiate Abstract class in OOABAP ?
We cannot create an object to the abstract class instead create an object to the child class and
call the methods .
Abstract class are mainly used for creating inheritance.
What is the use of 'DEFINATION DEFERRED' keyword in OOABAP ?
It is the keyword which indicates the class definition is delayed or postponed or Defined at some
place in program.
Syntax: CLASSÂ Â DEFINITION DEFERED.
What are the Advantages of OO ALV?
Some of the main advantages of Object Oriented ALV
We have no of events available in the classes when compared to ALV with function modules
which gives flexibility for the programmer to develop ALV for various scenarios.
We can display more than one ALV grid data on a single screen.
The ALV grid data is displayed in the form of custom container with which we can control the
size of ALV grid whereas we cannot control the size of the ALV with function Modules.
We can also place different UI elements like checkbox, radio button on the same screen in
addition ALV grid data.
What is a Polymorphism in OOABAP?
Polymorphism is a concept by which the same method names will behave differently in different
classes i.e. each method will have its own implementation in different classes but with the same
name.
Can we defined a class without a constructor in OO ABAP ?
Yes, class can be created without any constructor. Default constructor will be created when we
define a class without constructor.
Call Function module IN BACKGROUND TASK - Execute abap code in
separate background process
The IN-BACKGROUND TASK statement allows you to execute remote
enabled function modules in a background task asynchronously. Be careful
thought as it might not quite work as it appears too i.e. If you debug the
ABAP program logic it will step over the FM onto the next line of code, not
waiting for this function module to finish it processing. But this doesn't
mean it has gone off to start the processing at this point as it has not!! It
has simply created the background task ready for processing and will
not actually be executed until a commit work is reached in the current
logical unit of work.
So basically, if you want it to go off and perform this background
processing straight away you need to add a commit work after the call
function… in background task command.
AS SEPARATE UNIT
The "as separate unit” addition is used if you are calling the same FM
multiple times or FM's within the same function group. It basically ensures
each call is processed within its own context and is not affected by global
data changes from other function calls.
DESTINATION
This simply allows you to specify a different RFC destination
Example ABAP code to Execute FM in background task
CALL FUNCTION 'Z_FMODULE' IN BACKGROUND TASK
EXPORTING
P_UNAME = sy-uname.
*IN BACKGROUND TASK additional options
CALL FUNCTION 'Z_FMODULE' IN BACKGROUND TASK
AS SEPARATE UNIT
DESTINATION 'NONE'
EXPORTING
P_UNAME = sy-uname.
break-point. "does not wait and continues with next line of ABAP code
Commit Work.
Background task is only triggered at this point.
Function module STARTING NEW TASK statement - Execute abap
code in separate work process
The STARTING NEW TASK statement allows you to call a function module but it will be executed in a
separate processing task asynchronously, so the ABAP program logic does not wait for this FM to finish
its processing but continues with the next line of abap code. The clever thing about this statement is
that once the FM has finished processing it will then execute the specified FORM within the original
program to continue processing.
This small example is actually the basis for reports which auto-refresh themselves. i.e. the program calls
a function module in a new task which then waits a few seconds (WAIT 10 seconds). Once it returns to
the program and performs the return form it basically re-runs the whole report again. This especially
creates an endless loop so report keeps updating itself until it is cancelled by the user.
Execute FM in update task within separate unit of work
CALL FUNCTION 'Z_FMODULE'
starting new task 'UPDATE'
destination 'NONE'
performing processing_done on end of task
EXPORTING
P_UNAME = sy-uname.
"program does not wait for FM to finish processing and continues with next line of ABAP code
break-point.
"...perform display_report.
FORM processing_done.
* In the mean time once processing of FM Z_FMODULE is complete this abap FORM is then executed.
Within here you can perform any processing you like, including re-displaying a report
"...perform display_report.
ENDFORM.
Function module IN UPDATE TASK statement - Execute abap code in
seperate unit of work
The IN UPDATE TASK statement allows you to call a function module but it will not be executed until an
update task is initiated by the 'COMMIT WORK' statement. This means that the program logic after
calling the FM will immediately continue with the next line of ABAP code and the FM will sit and wait for
the commit work. This also allows you to execute several sections of code asynchronously by calling the
ABAP function module with the IN UPDATE TASK statement then performing the commit work
command. See example below!
If you are thinking of using this functionality please consider if it is actually an update task you want
rather than a background task.
The 'IN BACKGROUND TASK' works in exactly the same but performs the final processing in
background rather than using one of the update processes available on your SAP system.
Example ABAP code to execute FM in update task within separate unit of work
CALL FUNCTION 'Z_FMODULE' IN UPDATE TASK
EXPORTING
P_UNAME = sy-uname.
commit work. "Commits all work to database and also starts all FM's running in update task
"loop at it_ekko. "program continues with next line of ABAP without waiting for update and FM to finish
"...
"endloop.
Persistence class
ABAP Program stays in the local ABAP memory for the session only till the runtime of that
program. This data lives only as long as its context – that is, as long as its associated procedure
(for local procedure data); its object (for attributes of classes); or its program (for global program
data). This means that the data and state is preserved only till the context of the program is
active.
This data is known as transient. Data that can be preserved beyond the runtime of the
program is known as persistent. When working with persistent data, system loads
data in transient state and stores it back to persistent state after use.
Uses of Persistent Class
Persistent classes are used extensively for workflow programming. The main advantage
of persistence class is that you need not to fetch the data from the database Every time, as
the data is already fetched using SELECT.
Use of Persistent classes would be good when we are dealing with only one object like
Wrapper Module pool program for creating a document where you have only one header
and certain line items
Example of persistent class: https://mysapnuts.blogspot.com/2017/04/persistence-class.html
Abstract and Final Methods and Classes
Abstract and final methods or classes can be defined using the
additions ABSTRACT and FINAL of the statements METHODS and CLASS.
Abstract methods are declared in abstract classes and cannot be implemented in the same
class.
They must first be implemented in a subclass of the inheritance tree.
Abstract classes cannot, therefore, be instantiated.
A non-abstract method is a concrete method. With the exception of the instance constructor,
concrete instance methods of a class can also call their abstract methods.
Final methods can no longer be redefined in subclasses.
They cannot have any additional subclasses and close an inheritance tree definitively.
Notes
In classes that are both abstract and final, only the static components can be used. Although
instance components can be declared, they cannot be used.
Specifying ABSTRACT and FINAL together therefore is useful only for static classes.
Private methods cannot be redefined and can therefore not be abstract.
Local class with event and event handler method in SAP OO ABAP
The below example explains of using events with local classes using SAP ABAP programming.
Define a Class
Define a local class CL_EVENTS and follow the below steps.
Step 1:Define an event .
Step 2:Define a method and make it as event handler.
Step 4:Create a triggering method which will raise the event.
Step 5:Use set handler and register event handler method to a particular instance in the
program.
1. Define an event inside the local class definition under public section.
EVENTS : NO_MATERIAL. "event
2. Define a method and makt it as Event handler method
METHODS : EVENT_HANDLER FOR EVENT NO_MATERIAL OF CL_EVENTS. "event
handler method
3. Create one more method for this example.
METHODS : GET_MATERIAL_DETAILS
IMPORTING IM_MATNR TYPE MARA-MATNR
EXPORTING EX_MARA TYPE MARA.
4.Create a triggering point with keyword RAISE.
CLASS CL_EVENTS IMPLEMENTATION.
METHOD GET_MATERIAL_DETAILS.
SELECT SINGLE * FROM MARA
INTO EX_MARA
WHERE MATNR = IM_MATNR.
IF SY-SUBRC NE 0.
RAISE EVENT NO_MATERIAL. "triggering point
ENDIF.
ENDMETHOD.
METHOD EVENT_HANDLER.
WRITE :/ 'No material found'.
ENDMETHOD.
ENDCLASS. "CL_EVENTS
5. Register event using SET HANDLER and use it in our program
Define class, create object and register the event with the object using SET HANDLER
keyword.
DATA LO_EVENT TYPE REF TO CL_EVENTS.
DATA : WA_MARA TYPE MARA.
CREATE OBJECT LO_EVENT.
SET HANDLER LO_EVENT->EVENT_HANDLER FOR LO_EVENT.
CALL METHOD LO_EVENT->GET_MATERIAL_DETAILS
EXPORTING
IM_MATNR = P_MATNR
IMPORTING
EX_MARA = WA_MARA.
Final Program code will be
REPORT ZSAPN_LOCAL_CLASS_EVENTS.
CLASS CL_EVENTS DEFINITION DEFERRED.
DATA LO_EVENT TYPE REF TO CL_EVENTS. "declare class
DATA : WA_MARA TYPE MARA. "declare work area
PARAMETERS P_MATNR TYPE MARA-MATNR. "Material no input
CLASS CL_EVENTS DEFINITION. "class definition
PUBLIC SECTION.
EVENTS : NO_MATERIAL. "event
METHODS : GET_MATERIAL_DETAILS
IMPORTING IM_MATNR TYPE MARA-MATNR
EXPORTING EX_MARA TYPE MARA.
METHODS : EVENT_HANDLER FOR EVENT NO_MATERIAL OF CL_EVENTS. "event
handler method
ENDCLASS.
START-OF-SELECTION.
CREATE OBJECT LO_EVENT. "create object
SET HANDLER LO_EVENT->EVENT_HANDLER FOR LO_EVENT. "register event handler
method for the object
CALL METHOD LO_EVENT->GET_MATERIAL_DETAILS "call method to get material details
EXPORTING
IM_MATNR = P_MATNR
IMPORTING
EX_MARA = WA_MARA.
WRITE :/ WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MEINS, WA_MARA-MATKL.
CLASS CL_EVENTS IMPLEMENTATION. "class implementation
METHOD GET_MATERIAL_DETAILS.
SELECT SINGLE * FROM MARA
INTO EX_MARA
WHERE MATNR = IM_MATNR.
IF SY-SUBRC NE 0.
RAISE EVENT NO_MATERIAL. "trigger the event
ENDIF.
ENDMETHOD.
METHOD EVENT_HANDLER.
WRITE :/ 'No material found'. "event handler method implementation
ENDMETHOD.
ENDCLASS. "CL_EVENTS
Now test the program with invalid material number (material that is not available in MARA ), it
will raise the event.
Use of port in idoc
How to add the functionality of transport req. when we save the data
in table
Go to Transaction SE10.
Give the userid and click on Display.
Click on the Create button and select the second radio button 'Transportable
Change Request', which will create a new request.
Now place the cursor on the task and click on the button 'Display object list',
which is next to the Delete button.
Click on the Change button and then the Add button.
Give PgmId as R3TR
Obj as TABU
Objectname as Table to be transported
as shown below, and then double click on the table name, in this case SKA1.
Double click on the Key field.
Fill in the details.
These are the key fields of that table which will transport the particular record.
Now click on back button then add(Plus button) to add more entries to be
transported.
Again click on the Back button and add more tables and follow the same
procedure for each table.
Finally, save the task, which is ready to be transported.
what is t-rfc in idoc
Difference between kernel and classic badi
The old classic-BADI’s are implemented purely at the ABAP Workbench level; that is, both the
definition and implementation are realized as workbench repository objects (global classes and
interfaces). The Kernel BADI takes it to the ABAP language level with new commands ‘GET
BADI’ and ‘CALL BADI’.
Apart from Classic BADI’s which are been called by Proxy class cl_exithandler, Kernel BADI’s
are called directly with the reference to the BADI definition via GET BADI and CALL BADI
statements. That is one of the reasons why Kernel BADI is faster than classic BADI. Also
in Classic BADI, while we call it via cl_exithandler, we use the reference to the interface
rather than BADI definition.
Parallel Processing in SAP
Parallel Processing means Asynchronous Type of function module.
Generally when we call a function module, it will stop the current program, execute another
program and then returns control to original program and again original program starts
execution.
With asynchronous function module control will start parallelly without stopping the current
program from which you called the function module.
We use parallel processing when we have to process large amount of data.
In parallel processing, a job step is started as usual in a background processing work process.
A program that runs in a job step can be programmed to use a special variant of asynchronous
RFC to have portions of the data to be processed run in parallel in other work processes. You
can recognize such a program by its use of the CALL FUNCTION STARTING NEW TASK
DESTINATION IN GROUP instruction to start the function modules that process the data.
While the job itself runs in a background process, the parallel processing tasks that it
starts run in dialog work processes. Such dialog work processes may be located on any
SAP server.
Parallel processing has been implemented in some SAP applications that have long-
running reports. The parallel processing interface is also available directly to customers.
Pre-requisites to use parallel processing
The function module that you call must be marked as externally callable. This attribute is
specified in the Remote function call supported field in the function module definition
(transaction SE37).
The called function module may not include a function call to the destination "BACK."
The calling program should not change to a new internal session after making an
asynchronous RFC call. That is, you should not use SUBMIT or CALL TRANSACTION in such
a report after using CALL FUNCTION STARTING NEW TASK.
You cannot use the CALL FUNCTION STARTING NEW TASK DESTINATION IN GROUP
keyword to start external programs.
In calls between systems, both systems must be of Release 3.0A or higher.
Every ABAPer would have definitely encountered issues regarding performance tuning. So we
generally attack the select queries and optimize the performance.
In this article, we would be covering the topic for parallel processing in ABAP with respect to
asynchronous RFC Function Modules.
The idea behind this would be an Asynchronous call of a remote-capable function module using
the RFC interface.
To understand the concept we would take a simple example where we would
use ‘BAPI_MATERIAL_GET_DETAIL’ to fetch the Material Description from the Material
Number and then we will try to optimize the performance using parallel processing.
So the Program without any parallel processing would look like.
REPORT ZMATERIAL_NO_PARALLEL.
TABLES: MARA.
DATA : BAPIMATDOA TYPE BAPIMATDOA,
BAPIRETURN TYPE BAPIRETURN.
SELECT-OPTIONS S_MATNR FOR MARA–MATNR.
LOOP AT S_MATNR.
CALL FUNCTION ‘BAPI_MATERIAL_GET_DETAIL’
EXPORTING
MATERIAL = S_MATNR–LOW
IMPORTING
MATERIAL_GENERAL_DATA = BAPIMATDOA.
write : BAPIMATDOA–MATL_DESC.
ENDLOOP.
So every time the during loop execution the control would wait for the Function Module to return
its value only then the loop will continue with the next record.
In this case only One Work Process is busy executing your program it does not consider other
work processes even they are ideal
REPORT ZMATERIAL_DISPLAY_PARALLEL.
TABLES : MARA.
DATA : BAPIMATDOA TYPE BAPIMATDOA,
BAPIRETURN TYPE BAPIRETURN.
DATA : SYSTEM TYPE RZLLI_APCL,
taskname(8) type c,
index(3) type c,
snd_jobs TYPE i,
rcv_jobs TYPE i,
exc_flag TYPE i,
mess TYPE c LENGTH 80.
TYPES : BEGIN OF type_material,
desc TYPE maktx,
END OF type_material.
DATA : Material type table of type_material with header line.
data: functioncall1(1) type c.
constants: done(1) type c value ‘X’.
SELECT-OPTIONS S_MATNR FOR MARA–MATNR.
system = ‘parallel_generators’. ” RFC Server Group
LOOP AT S_MATNR.
index = sy–tabix.
CONCATENATE ‘Task’ index into taskname. ” Generate Unique Task Name
CALL FUNCTION ‘BAPI_MATERIAL_GET_DETAIL’ STARTING NEW TASK taskname
DESTINATION IN GROUP system
performing set_function1_done on end of task
EXPORTING
MATERIAL = S_MATNR–LOW
EXCEPTIONS
system_failure = 1 MESSAGE mess
communication_failure = 2 MESSAGE mess
resource_failure = 3.
CASE sy–subrc.
WHEN 0.
snd_jobs = snd_jobs + 1.
WHEN 1 OR 2.
MESSAGE mess TYPE ‘I’.
WHEN 3.
IF snd_jobs >= 1 AND
exc_flag = 0.
exc_flag = 1.
WAIT UNTIL rcv_jobs >= snd_jobs
UP TO 5 SECONDS.
ENDIF.
IF sy–subrc = 0.
exc_flag = 0.
ELSE.
MESSAGE ‘Resource failure’ TYPE ‘I’.
ENDIF.
WHEN OTHERS.
MESSAGE ‘Other error’ TYPE ‘I’.
ENDCASE.
ENDLOOP.
WAIT UNTIL rcv_jobs >= snd_jobs.
loop at material.
write : material–desc.
endloop.
form set_function1_done using taskname.
rcv_jobs = rcv_jobs + 1.
receive results from function ‘BAPI_MATERIAL_GET_DETAIL’
IMPORTING
MATERIAL_GENERAL_DATA = BAPIMATDOA.
BAPIRETURN = BAPIRETURN.
functioncall1 = done.
APPEND bapimatdoa–matl_desc TO material.
ENDFORM.
Things to keep in mind , before we start coding.
RFC server group
For group, you must specify a data object of the type RZLLI_APCL from the ABAP Dictionary.
This is usually one of the RFC server group created in transaction RZ12. In our case it is
“parallel_generators”.
For each asynchronous RFC where the group is specified, the most suitable application server
is determined automatically, and the called function module is executed on this.
CALL FUNCTION func STARTING NEW TASK task
DESTINATION {dest|{IN GROUP {group|DEFAULT}}}]
Parameter list
[{PERFORMING subr}|{CALLING meth} ON END OF TASK].
With this statement, you are instructing the SAP system to process function module calls in
parallel. Typically, you’ll place this keyword in a loop in which will divide up the data that is to be
processed into work packets.
Calling program is continued using the statement CALL FUNCTION, as soon as the remotely
called function has been started in the target system, without having to wait for its processing to
be finished
It creates Different task name TASK in a separate work process. Each such task
executes “formset_function1_done” in a separate work process.
Result : The runtime analysis of both the program is given as below.
Both the Program were executed for 200 materials as input.
With parallel Processing
Without Parallel Processing
Clearly the program with parallel processing is near 50% more effective than the normal
program.
A method meth as the callback routine, which is executed after terminating the asynchronously
called function module. For subr, you must directly specify a subroutine of the same program.
For meth, you can enter the same specifications as for the general method call.
Normal ALV Table Display
DATA: o_alv TYPE REF TO cl_salv_table.
* exception class
DATA: lx_msg TYPE REF TO cx_salv_msg.
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = t_vbak ).
CATCH cx_salv_msg INTO lx_msg.
ENDTRY.
* Displaying the ALV
* Here we will call the DISPLAY method to get the output on the scre
en
o_alv->display( ).
Adding Default PF STATUS in ALV
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
*
lo_functions = co_alv->get_functions( ).
lo_functions->set_default( abap_true ).
Adding Custom PF STATUS in ALV
It is very tedious to add all the ALV buttons in our PF status manually. So here is the easy way:
We will copy the PF-Status using of any standard SALV_DEMO report using the transaction
SE41: Menu Painter. After Copying the PF-Status we can add our own buttons. I have used the
pfstaus SALV_STANDARD of the Report SALV_DEMO_TABLE_SELECTIONS.
* Calling method to set the PF-Status
co_alv->set_screen_status(
pfstatus = 'SALV_STANDARD'
report = 'SALV_DEMO_TABLE_SELECTIONS'
set_functions = co_alv->c_functions_all ).
FREE Keyword
Basically, the free statement will clear the whole internal table and not the work area(header).
so memory is still allocated to the table and that after this statement the Internal table can still
be accessed.
EXCEPTION HANDLING
An exception is a problem that arises during the execution of a program. When an exception
occurs the normal flow of the program is disrupted and the program application terminates
abnormally, which is not recommended, therefore these exceptions are to be handled.
Exceptions provide a way to transfer control from one part of a program to another. ABAP
exception handling is built upon three keywords − RAISE, TRY, CATCH and CLEANUP.
Assuming a block will raise an exception, a method catches an exception using a combination
of the TRY and CATCH keywords. A TRY - CATCH block is placed around the code that might
generate an exception. Following is the syntax for using TRY – CATCH −
TRY.
Try Block <Code that raises an exception>
CATCH
Catch Block <exception handler M>
. . .
. . .
. . .
CATCH
Catch Block <exception handler R>
CLEANUP.
Cleanup block <to restore consistent state>
ENDTRY.
RAISE − Exceptions are raised to indicate that some exceptional situation has occurred.
Usually, an exception handler tries to repair the error or find an alternative solution.
TRY − The TRY block contains the application coding whose exceptions are to be handled. This
statement block is processed sequentially. It can contain further control structures and calls of
procedures or other ABAP programs. It is followed by one or more catch blocks.
CATCH − A program catches an exception with an exception handler at the place in a program
where you want to handle the problem. The CATCH keyword indicates the catching of an
exception.
CLEANUP − The statements of the CLEANUP block are executed whenever an exception
occurs in a TRY block that is not caught by the handler of the same TRY - ENDTRY construct.
Within the CLEANUP clause, the system can restore an object to a consistent state or release
external resources. That is, cleanup work can be executed for the context of the TRY block.
Detail: http://saptechnical.com/Tutorials/ABAP/RETRY/CLEANUP.htm
Raising Exceptions
Exceptions can be raised at any point in a method, a function module, a subroutine, and so on.
There are two ways an exception can be raised −
Exceptions raised by ABAP runtime system.
For instance Y = 1 / 0. This will result in a run time error of type CX_SY_ZERODIVIDE.
Exceptions raised by programmer.
Raise and create an exception object simultaneously. Raise an exception with an exception
object that already exists in the first scenario. The syntax is: RAISE EXCEPTION exep.
Catching Exceptions
Handlers are used to catch exceptions.
Let’s take a look at a code snippet −
DATA: result TYPE P LENGTH 8 DECIMALS 2,
exref TYPE REF TO CX_ROOT,
msgtxt TYPE STRING.
PARAMETERS: Num1 TYPE I, Num2 TYPE I.
TRY.
result = Num1 / Num2.
CATCH CX_SY_ZERODIVIDE INTO exref.
msgtxt = exref→GET_TEXT( ).
CATCH CX_SY_CONVERSION_NO_NUMBER INTO exref.
msgtxt = exref→GET_TEXT( ).
In the above code snippet, we are trying to divide Num1 by Num2 to get the result in a float type
variable.
Two types of exceptions could be generated.
Number conversion error.
Divide by zero exception. Handlers catch CX_SY_CONVERSION_NO_NUMBER exception
and also the CX_SY_ZERODIVIDE exception. Here the GET_TEXT( ) method of the
exception class is used to get the description of the exception.
Attributes of Exceptions
Here are the five attributes and methods of exceptions −
S.No Attribute & Description
.
1
Textid
Used to define different texts for exceptions and also affects the result of
the method get_text.
2
Previous
This attribute can store the original exception that allows you to build a
chain of exceptions.
3
get_text
This returns the textual representation as a string as per the system
language of the exception.
4
get_longtext
This returns the long variant of the textual representation of the
exception as a string.
5
get_source_position
Gives the program name and line number reached where the exception
was raised.
Example
REPORT ZExceptionsDemo.
PARAMETERS Num_1 TYPE I.
DATA res_1 TYPE P DECIMALS 2.
DATA orf_1 TYPE REF TO CX_ROOT.
DATA txt_1 TYPE STRING.
start-of-selection.
Write: / 'Square Root and Division with:', Num_1.
write: /.
TRY.
IF ABS( Num_1 ) > 150.
RAISE EXCEPTION TYPE CX_DEMO_ABS_TOO_LARGE.
ENDIF.
TRY.
res_1 = SQRT( Num_1 ).
Write: / 'Result of square root:', res_1.
res_1 = 1 / Num_1.
Write: / 'Result of division:', res_1.
CATCH CX_SY_ZERODIVIDE INTO orf_1.
txt_1 = orf_1→GET_TEXT( ).
CLEANUP.
CLEAR res_1.
ENDTRY.
CATCH CX_SY_ARITHMETIC_ERROR INTO orf_1.
txt_1 = orf_1→GET_TEXT( ).
CATCH CX_ROOT INTO orf_1.
txt_1 = orf_1→GET_TEXT( ).
ENDTRY.
IF NOT txt_1 IS INITIAL.
Write / txt_1.
ENDIF.
Write: / 'Final Result is:', res_1.
In this example, if the number is greater than 150, the exception
CX_DEMO_ABS_TOO_LARGE is raised. The above code produces the following output for the
number 160.
Square Root and Division with: 160
The absolute value of number is too high
Final Result is: 0.00
V1 and V2 update
The V1 modules are processed consecutively in a single update work
process on the same application server. This means that they belong to
the same database LUW and can be reversed. Furthermore, V1 updates
are carried out under the SAP locks of the transaction that creates the
update. This ensures that the data remains consistent; simultaneous changes
to the objects to be updated are not possible.
All V2 updates are carried out in a separate LUW and not under the
locks of the transaction that creates them. If your SAP System contains a
work process for V2 updates, these are only carried out in this work process. If
this is not the case, the V2 components are processed by a V1 update process.
All V1 modules of an update must be processed before the V2 modules.
1. Update with Start immediate
Set this option for high priority ("V1") functions that run in a shared (SAP LUW).
These functions can be restarted by the update task in case of errors.
2. Update with immediate start start, No Restart
Set this option for high priority ("V1") functions that run in a shared (SAP LUW).
These functions may not be restarted by the update task.
3. Update with Start Delayed
Set this option for low priority ("V2") functions that run in their own update
transactions. These functions can be restarted by the update task in case of
errors.
4. coll. run
- For internal use only -
A number of similar function modules that previously used to run individually in
the V2 update process can be grouped together and run collectively.
ABAP Objects Design Patterns – Composite Class
Composite allows clients to access individual object and composition objects in uniform way.
Sometimes we have to deal with Hierarchical or Tree type of data. The data which are related
with each other and form a type of hierarchy. We can write the recursive logic to process related
entries. But, the problem with the approach is : client has to distinguish between the type of
objects, weather it is a end node or collection of nodes. It would become more complex as, we
need to do this distinction all the time when we work with those objects. So, composite design
pattern shows how to use recursive composition so that client doesn’t have to distinguish
between the objects.
Design Time Consideration:
We should follow these steps to achieve Composite Design Pattern.
Create an Abstract Class
Inherit an individual class with certain behavior
Inherit a composite class which would store the Kids objects. Operation of Composite
objects * should actually perform the operations of each child.
Client should use Component Abstract class to interact with composite objects.
TCODE for checking the performance are
ST05 :- Performance Trace
SE30 / SAT :- ABAP Objects Runtime Analysis
SLIN :- ABAP: Extended Program Check
SCI :- ABAP Code Inspector
T-Code - SAT
NAST is the table which stores Conditions for Output control.
You can assign Output types to Condition records through transaction NACE.
How to create a bar code in smartform
https://wiki.scn.sap.com/wiki/display/Snippets/Step-by-
step+New+Barcode+Technology+for+Smart+Forms
Language translation in smart forms
Here are the steps...
1. Go to transaction 'SE63'.
2. Click on 'Translation' -> 'ABAP objects' -> 'Other long texts'.
3. Click on 'FS forms and Styles' and select 'SSF SAP Smart form'.
4. Then enter the smart form name in the object name text field.
5. Select the source language as English and the target language as the language u want to convert. (In our ex. Portuguese)
6. Click edit.
7. It will open the smart form in two frames.
8. Now add the translated content to the target text window and click 'Save Active'.
How to find FM name from message type from idoc
How to debug a RFC
What is pass by value and pass by reference in RFC
BAPI's are generally RFC (Remote Function Calls) enabled function modules. In this type of FM's,
we can not pass a parameter by reference. So, U see only Pass by Value option selected in both
import and export parameters.
Read exception:
CX_SY_ITAB_LINE_NOT_FOUND
Fallback class in BADI
One of the key feature in SAP R/3 ecc 6.0 onwards is that the BADI can be assecced without implementation.
Steps:
1.) Go to SE18 ( create an enhancement spot )
give short description and continue
Step 2.) Create BADI by giving BADI name and short description
step 3.) Save your BADI definition and Enhancement Spot. Click on Interface
step 4.) Give interface as Z_BADI_INTERFACE and save it.
step 5.) Double click on the Interface and create a method like GET_FLIGHT_DATA and activate the interface.
step 6.) In the main screen of SE18 where we had created BADI, define a Fall Back Class and give a z_class name and
press enter ..
The class will automatically inherit the methods of the interface defined. ( ie Z_BADI_INTERFACE ).
Step 7.) Double click on the method and write the code.
Step 8.) Save and Activate the Enhancement Spot and the BADI.
Step 9.) In the Application use ABAP statements GET BADI, CALL BADI to Access Badi Objects . Following is the code to
access the BADI
Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT yh1328_badi_flight_test.
*&---------------------------------------------------------------------
*& Parameters declaration
*&---------------------------------------------------------------------
PARAMETERS:
p_carrid TYPE scarr-carrid, " Airline code
p_connid TYPE sflight-connid, " Connection number
p_fldate TYPE sflight-fldate. " Flight date
*&---------------------------------------------------------------------
*& Internal table declaration
*&---------------------------------------------------------------------
DATA:
lt_flight TYPE STANDARD TABLE OF sflight.
*&---------------------------------------------------------------------
*& Field string declaration
*&---------------------------------------------------------------------
DATA:
fs_flight LIKE LINE OF lt_flight.
*&---------------------------------------------------------------------
*& Create instance for BADI
*&---------------------------------------------------------------------
DATA:
w_flight TYPE REF TO z_badi_test.
*&---------------------------------------------------------------------
*& START-OF-SELECTION EVENT
*&---------------------------------------------------------------------
START-OF-SELECTION.
GET BADI w_flight. " Access badi objects
*& Call BADI
CALL BADI w_flight->get_flight_data
EXPORTING
carrid = p_carrid
connid = p_connid
fldate = p_fldate
RECEIVING
t_flight = lt_flight.
LOOP AT lt_flight INTO fs_flight.
WRITE:
/ fs_flight-carrid,
fs_flight-connid,
fs_flight-fldate,
fs_flight-price,
fs_flight-seatsmax,
fs_flight-seatsocc.
ENDLOOP. " LOOP AT lt_flight INTO fs_flight
It is mandatory to have exactly one active implementation for a single-use BAdI. The program dumps if there is no
active implementation. You can handle this error by catching the respective exception cx_badi_not_implemented or
by creating a FALLBACK Class.
As soon as there is an active BAdI implementation, the fallback class is no longer used at runtime.
Significant Advantages of Using a fallback class :
● The program runs with a single-use BAdI without throwing an exception (cx_badi_not_implemented) and
ensures no dump.
● It is guaranteed that the fallback class is not used any more as soon as a BAdI implementation is supplied.
ABAP Factory Method Design Pattern
Summary: in this tutorial, you will learn what is ABAP factory method design pattern and
how to implement factory method in ABAP.
Problems
You want to abstract the process of creating objects so the type of object created can be
specified at run-time.
Intent
Provides an interface for create new objects, but let subclasses decide what kind of
object to create. Factory Method allows a class to defer instantiation to subclasses.
CREATE OBJECT is consider harmful.
ABAP Factory Method UML Diagram
The following UML diagram illustrates factory method. There are four classes:
Creator. The Creator class is an abstract base class for all ConcreteCreator classes
which will truly create new objects. In the diagram, this class can be replaced by an
interface that contains the factory method signature. In this case, all subclassess will
implement this interface.
ConcreteCreator. This is subclass that inherits all functionalities of the Creator base
class. You can implement the logic for creating actual objects here. In the diagram,
the ConcreteCreator class is in charge of creating object of ConcreateProduct class.
Product. The Product is an abstract class. This class is a base class for all object
types which the factory class creator can create therefore it is a return type of the
factory method. You can replace this abstract class by an interface if no common
functionality is to be inherited by its subclasses.
ConcreteProduct. You can define multiple subclasses of
the Product as ConcreateProduct that contains specific functionality. Objects
of ConcreateProduct classes are created by the factory method.
Factory Method
Design Pattern UML
ABAP Factory Method Implementation
We are going to implement ABAP factory method pattern as the following UML diagram:
ABAP Factory
Method Design Pattern UML Diagram
On the left side of the diagram, we have class LCL_SALE_DOCUMENT that is a super
class for all sale documents. The quotation and order classes inherit all functionalities of the
sale document class. For demonstration, we use only write() method to output a message
for quotation and order. The class LCL_SALE_DOCUMENT is equivalent to the
class Product in the above UML diagram. The class LCL_QUOTATION and class
LCL_ORDER are equivalent to the class ConcreateProduct.
On the right side of the diagram, we have an
interface LIF_SALE_DOCUMENT_FACTORY that has a factor method create() that
creates LCL_SALE_DOCUMENT instances. The
class LCL_SALE_DOCUMENT_FACTORYimplements the
interface LIF_SALE_DOCUMENT_FACTORY and contains actual logic for
creating LCL_SALE_DOCUMENT objects.
The following ABAP code illustrates the ABAP Factory Method UML diagram above:
1 *&---------------------------------------------------------------------*
2 *& Report ZDP_FACTORY_METHOD
3 *&
4 *&---------------------------------------------------------------------*
5 *& Description : This program demonstrates ABAP Factory Method
6 *& Design Pattern
7 *& Program Author : ABAPTutorial.com
8 *&---------------------------------------------------------------------*
10 REPORT zdp_factory_method.
11
12 *----------------------------------------------------------------------*
13 * CLASS lcl_sale_document DEFINITION
14 *----------------------------------------------------------------------*
15 * Sale document
16 *----------------------------------------------------------------------*
17 CLASS lcl_sale_document DEFINITION ABSTRACT.
18 PUBLIC SECTION.
19 METHODS: write ABSTRACT.
20 ENDCLASS. "lcl_sale_document DEFINITION
21
22 *----------------------------------------------------------------------*
23 * CLASS lcl_quotation DEFINITIO
24 *----------------------------------------------------------------------*
25 * Quotation
26 *----------------------------------------------------------------------*
27 CLASS lcl_quotation DEFINITION
28 INHERITING FROM lcl_sale_document.
29 PUBLIC SECTION.
30 METHODS: write REDEFINITION.
31 ENDCLASS. "lcl_quotation DEFINITIO
32
33 *----------------------------------------------------------------------*
34 * CLASS lcl_quotation IMPLEMENTATION
35 *----------------------------------------------------------------------*
36 * Quotation implementation
37 *----------------------------------------------------------------------*
38 CLASS lcl_quotation IMPLEMENTATION.
39 METHOD write.
40 WRITE: 'Quotation'.
41 ENDMETHOD. "write
42 ENDCLASS. "lcl_quotation IMPLEMENTATION
43
44 *----------------------------------------------------------------------*
45 * CLASS lcl_order DEFINITIO
46 *----------------------------------------------------------------------*
47 * Sale order
48 *----------------------------------------------------------------------*
49 CLASS lcl_order DEFINITION
50 INHERITING FROM lcl_sale_document.
51 PUBLIC SECTION.
52 METHODS: write REDEFINITION.
53 ENDCLASS. "lcl_order DEFINITIO
54
55 *----------------------------------------------------------------------*
56 * CLASS lcl_order IMPLEMENTATION
57 *----------------------------------------------------------------------*
58 * Sale Order implementation
59 *----------------------------------------------------------------------*
60 CLASS lcl_order IMPLEMENTATION.
61 METHOD write.
62 WRITE: 'Order'.
63 ENDMETHOD. "write
64 ENDCLASS. "lcl_order IMPLEMENTATION
65
66 *----------------------------------------------------------------------*
67 * INTERFACE lif_sale_document_factory IMPLEMENTATION
68 *----------------------------------------------------------------------*
69 * Sale document factor interface
70 *----------------------------------------------------------------------*
71 INTERFACE lif_sale_document_factory.
72 METHODS:
73 create IMPORTING im_docty TYPE vbtyp
74 RETURNING value(re_doc) TYPE REF TO lcl_sale_document.
75 ENDINTERFACE. "lif_sale_document_factory IMPLEMENTATION
76
77 *----------------------------------------------------------------------*
78 * CLASS lcl_sale_document_factory DEFINITION
79 *----------------------------------------------------------------------*
80 * Sale document factory
81 *----------------------------------------------------------------------*
82 CLASS lcl_sale_document_factory DEFINITION.
83 PUBLIC SECTION.
84 INTERFACES:
85 lif_sale_document_factory.
86 ALIASES: create FOR lif_sale_document_factory~create.
87 ENDCLASS. "lcl_sale_document_factory DEFINITION
88
89 *----------------------------------------------------------------------*
90 * CLASS lcl_sale_document_factory IMPLEMENTATION
91 *----------------------------------------------------------------------*
92 * Sale document factory implementation
93 *----------------------------------------------------------------------*
94 CLASS lcl_sale_document_factory IMPLEMENTATION.
95 METHOD create.
96 DATA: lo_doc TYPE REF TO lcl_sale_document.
97 CASE im_docty.
98 WHEN 'B'.
99 CREATE OBJECT lo_doc TYPE lcl_quotation.
10 WHEN 'C'.
0
CREATE OBJECT lo_doc TYPE lcl_order.
10
1 WHEN OTHERS.
10 " default, create order
2
CREATE OBJECT lo_doc TYPE lcl_order.
10
ENDCASE.
3
re_doc = lo_doc.
10
4 ENDMETHOD. "create
10 ENDCLASS. "lcl_sale_document_factory IMPLEMENTATION
5
10
6 DATA:
10 go_doc TYPE REF TO lcl_sale_document,
7
go_sale_document_factory TYPE REF TO lif_sale_document_factory.
10
8
PARAMETERS:
10
9 pa_docty TYPE vbtyp. " B quotation, C order
11
0
START-OF-SELECTION.
11
1 " create factory
11 CREATE OBJECT go_sale_document_factory
2
TYPE lcl_sale_document_factory.
11
3
11 " create sale document at runtime.
4
go_doc = go_sale_document_factory->create( pa_docty ).
11
5
11
6
11
7
11
8
11
9
12 go_doc->write( ).
0
12
1
12
2
12
3
12
4
Factory-Pattern in ABAP OO
When you work with ABAP Objects you always need to create instances of classes. Even if you use
“CREATE OBJECT” to create those instances, you probably faced with the problem, that it is not so
comfortable as if you have a function for creating objects in the same way. Or, you have a complex
logic to create each instance.
Background
For those cases, there is a design-pattern for creating instances. This pattern is called “Factory”-
pattern. There is also a pattern called “factory-method”, which is different, because it combines the
creation and relationship of objects. Thanks to Naimesh Patel, who advise me of this point.
The factory-pattern is one of the most used design pattern. It creates object instances without
exposing the concrete instantiation logic. The instantiated objects will be accessable through an
interface, which encapsulate the concrete implementation to the users.
In the classical GoF-Pattern, the factory-pattern looks like this:
A client needs a product (a.k.a. “class”) and asks a factory for a concrete instance by passing the
neccessary parameters to it. The factory creates a class of a specific interface ( “Product” ) and
gives the instance back to the client. The specific interface should also be an abstract class, but by
using an interface you will have a much better support for the separations-of-concerns principle.
The ABAP-way of the factory pattern
Sure, it should be very simple, to transfer the underlying UML to a ABAP class structure. But, you
have much more than just a OO-language: The SAP Netweaver AS gives you some nice featues –
customizing with a maintenance dialog is one of them.
So, here is my approach for the ABAP OO-Factory:
As you can see, the factory use informations out of a customizing table and holds all created
instances in a internal table. The rest ( Interface, Concrete Classes) are simple ABAP OO Elements.
By the way: If you can be sure, that the instances should not be buffered so far, you do not need an
internal table with all created instances.
At least, the “create” Method is not so complex:
The customizing table should look like this:
For your internal table in the factory, you should define a DDIC-Structure and Tabletype which
includes the customizing information and a reference to the created instance.
One hint: Create a view on SEOCLASSTX and SEOMETAREL with the used interface as constant
for “REFCLSNAME”, use it as foreign-key and you get a DDIC-based check, if the used class
implements the correct interface.
And last, but not least: you need a maintenance view, created by the maintenance view generator.
Why should you use a factory-pattern?
With the factory pattern you centralize the create of objects within your application. By using this
approach, you can manage the instantiation of objects ( “Products” ) and separate the usage of the
concrete implementation logic.
Through interfaces you introduce the design principle “separation of concerns” and you give a
contract for all users of your classes. By accepting this contract the users of your interface count on
the correct implementation of the contract.
Additional, you get an overview about who implements your interface and where is it used – just look
in the ABAP Workbench and expand the implementation tree of your interface:
Adding new aspects to your software
Another important thing, which I have not mentioned so far: You can build your factory in a way, that
you can very easy introduce proxy-classes (another design pattern) which covers new aspects – for
example: logging or authentication – without changing the underlying classes.
By using this, your user does not affect, that there is another implementation – the interface, and its
underlying contract is stil fulfilled.
Conclusion
The factory-pattern is an important pattern for creating object instances within your own code. With
this pattern, you can get a more manageable, extensible and customizable software.
Abstract Class and Interface – both has there own usages. Lets explore when to use which
in ABAP while developing an application in SAP.
Basics
Before jumping to the differences, lets check out the basics of both – Abstract Class and
Interface.
What is an Abstract Class?
Abstract Class is a special kind of class which can’t be instantiated. We can only instantiate
the subclasses of the Abstract class if they are not abstract. Abstract class should at least
contain one abstract method. Abstract methods are methods without any implementation –
only a declaration. We can certainly define the variables referencing to Abstract class and
instantiate with specific subclass at runtime.
Simple Abstract Class
*
CLASS zcl_base_functions DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS: set_my_name ABSTRACT IMPORTING iv_text TYPE STRING .
METHODS: write_name.
PRIVATE SECTION.
DATA: my_name TYPE STRING.
ENDCLASS. "zcl_base_functions DEFINITION
*
CLASS zcl_base_functions IMPLEMENTATION.
METHOD write_name.
ENDMETHOD. "write_name
ENDCLASS. "zcl_base_functions IMPLEMENTATION
What is an Interface?
An interface is not a class.
It is an entity which can’t have implementation.
An interface can only contain empty method declaration and components.
Interface components are always public. We can later change the visibility of the
components within the implementing class using the ALIASES.
Simple Interface
INTERFACE zif_order.
METHODS: set_order_data IMPORTING iv_order_Data TYPE STRING.
METHODS: create_order.
ENDINTERFACE.
*
CLASS zcl_sales_order DEFINITION.
PUBLIC SECTION.
INTERFACES: zif_order.
ENDCLASS.
Differences
Since both abstract class and interface are different entity, they have few differences:
Multiple Inheritance:We can achieve multiple inheritance using Interfaces. Since
ABAP doesn’t support more than one Super class, we can have only one abstract
class as Super class.
New Functionality:If we add a new method in the Interface, all the implementing
classes have to implement this method. If we don’t implement the method, it would
result into Run-time error. For Abstract class, if we add a non-abstract method, its
not required to redefine that in each and every inherited class.
Default Behavior:We can have a default behavior of a non-abstract method in
abstract class. We can’t have any implementation in Interface as it only contains the
empty stub.
Visibility:All interface components are PUBLIC by default. For Abstract class, we
can set the visibility of each component.
Enhancement Point and Enhancement Section
New for syntax replacing loop
4 * Original
** Loop through and save Plant and Name only
*LOOP AT lt_plant INTO ls_plant WHERE regio EQ lv_regio.
* ls_plant_name-plant = ls_plant-werks.
* ls_plant_name-name = ls_plant-name1.
* APPEND ls_plant_name TO lt_plant_name.
*ENDLOOP.
5 * New
6 * Loop through and save Plant and Name only
7 DATA(lt_plant_name) = VALUE ltt_plant_name( FOR ls_plant IN lt_plant
8 WHERE ( regio EQ lv_regio )
9 ( plant = ls_plant-werks name = ls_plant-name1 )
1 ).
0
1
1
1
2
1
3
1
4
1
5
SAP SCRIPT – SE71
Command statement in Smartforms
BTE
https://blogs.sap.com/2013/01/07/btes-business-transaction-events/
#targetText=A%20BTE%20has%20a%20predefined,to%20function
%20OPEN_FI_PERFORM_%20or%20OUTBOUND_CALL_.
There are four types of windows in Smartform:
1. Main window
2. Secondary window
3. Copies window
4. Final window
Main Window
It is used for the continues output such as table output.
Secondary Window
It is used for output with a fixed length.
Final Window
It is a kind of special secondary window used for details which are needed to
be processed only at the end of processing form.
Copies Window
It is also a kind of special secondary window which is used for making pages
as copy or original.
Deadline monitoring in workflow
Parallel workflow
Can we create a smartform without main window?
Yes, you can create a Smartform without a Main Window. But there is no
need to do anything of such sort. Whenever you create a Smartform, a main
window is created by default.
OO ALV using CL_GUI_ALV_GRID
DATA : o_cust TYPE REF TO cl_gui_custom_container,
o_alv TYPE REF TO cl_gui_alv_grid,
it_spfli TYPE TABLE OF spfli,
wa_spfli TYPE spfli,
ok_code TYPE sy-ucomm.
SELECT-OPTIONS : p_carr FOR wa_spfli-carrid.
START-OF-SELECTION.
PERFORM data_fetch.
CALL SCREEN 100.
FORM data_fetch .
SELECT * FROM spfli INTO TABLE it_spfli WHERE carrid IN p_carr.
ENDFORM. ” DATA_FETCH
MODULE status_0100 OUTPUT.
SET PF-STATUS ‘STATUS’.
SET TITLEBAR ‘TITLE’.
ENDMODULE. ” STATUS_0100 OUTPUT
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN ‘BACK’ OR ‘EXIT’ OR ‘CANCEL’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. ” USER_COMMAND_0100 INPUT
Advertisement
Privacy Settings
MODULE display_alv OUTPUT.
CREATE OBJECT o_cust
EXPORTING
container_name = ‘CUSTOM’.
CREATE OBJECT o_alv
EXPORTING
i_parent = O_CUST.
CALL METHOD o_alv->set_table_for_first_display
EXPORTING
i_structure_name = ‘SPFLI’
CHANGING
it_outtab = IT_SPFLI.
ENDMODULE. ” DISPLAY_ALV OUTPUT
SCREEN FLOW LOGIC
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE DISPLAY_ALV.
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
Adobe forms – T-code – SFP
The following five steps show how to place an SE78
graphic on an Adobe Form.
In this example, we will add an existing color logo named Z_LOGO to an
existing Adobe form,
ZRUOTC_SERVSTAR_PDF. First, make sure the logo exists in SE78 as a
bitmap image and that
the Adobe form and interface exist as well.
(1) Go to transaction SE78 and ascertain Z_LOGO exists by
following this path:
Form Graphics->Stored on Document Server->GRAPHICS
General Graphics->BMAP Bitmap Images.
Do a print preview to see the graphic.
(2) Go to transaction SFP. Select the Interface radio
button and click the Change icon.
Under the Global Definitions folder double click into Global
Data and add these fields.
Variable name Type Assignment Type
Name Default Value
V_FIELD TYPE XSTRING
V_BTYPE TYPE
TDBTYPE 'BCOL'
V_ID TYPE
TDIDGR 'BMAP'
V_OBJECT TYPE
TDOBJECTGR 'GRAPHICS'
V_NAME TYPE STXBITMAPS-
TDNAME 'Z_LOGO'
G_LOGO TYPE XSTRING
Do a syntax check.
(3) Under the Initialization folder, double click into the
Code Initialization area.
Create the following logic.
* Call method get_bds_graphic_as_bmp to retrieve z_logo.
Note that v_field and g_logo
* MUST be typed as XSTRING NOT string or the conversion
of the form from SE78 will
* not work and the logo will NOT display on the Adobe
form. On the layout tab of the
* Adobe form, bind z_logo to the graphics node created
here in the Interface, NOT
* directly to g_logo. Adobe sees g_logo as a text field.
CALL METHOD
cl_ssf_xsf_utilities=>get_bds_graphic_as_bmp
EXPORTING
p_object = v_object " 'GRAPHICS'
p_name = v_name " Name of the SE78 logo
inside Quotes
p_id = v_id " 'BMAP'
p_btype = v_btype " 'BCOL' for color, 'BMON' for
Black & White
RECEIVING
p_bmp = v_field " v_field and g_logo must be
typed xstring
EXCEPTIONS
not_found =1
internal_error = 2
OTHERS = 3.
g_logo = v_field. " g_logo and v_field must be
typed xstring
Do a syntax check, save, and back out of the Interface.
(4) Select the Adobe Form radio button and click the
Change Icon.
Go to the Context tab.
Expand the Global Data folder. You should see the 6 fields
created in the Interface.
Under the Context bar on the upper right window, right
click on the top folder.
Choose Create, Graphic and give it a name.
Under the Global Data folder on the upper left window
locate the G_LOGO field.
Drag and drop G_LOGO on top of your new Graphics Node.
Under Properties at the bottom right window, change the
Graphic Type Value.
It defaults to 'Graphic Reference'. Change it to 'Graphic
Content'.
Enter G_LOGO as the Graphic Content field.
Enter 'IMAGE/BMP' with the quotes as the MIME Type.
(5) Go to the Layout Tab of the Adobe form.
Expand the standard palette object library and choose an
Image Field.
Drag and drop the Image field to the location on the form
where you want the logo displayed.
Under the Field tab make sure the URL field is blank
because this is not a static logo.
Check the Embed Image Data box. However, it seems to
work checked or unchecked.
Choose Scale Image Proportionately.
Under the Binding Tab, bind the image field to the Graphic
Node, not to the G_LOGO field.
Do a syntax check on the interface and form. Save and
activate.
ADOBE FORMS TUTORIALS-
https://sapyard.com/sap-adobe-interactive-form-tutorial-part-i-first-adobe-
form/
Difference between Adobe forms and smart forms
Adobe forms have version management
Adobe forms are interactive, they have push button
You could monitor all the Idocs in Queue through
SMQ1.Activate the log and select your criteria for viewing
the log.
Debug the background job then you have to create infinite loop in
your program.
Goto SM50
Select the work processor executing this processor.
Select Program/Mode -> Program -> Debugging. Now the execution of
the program would be opened in debug mode.
Change the value of the variable, causing the program executing in
endless loop and click F8. Now the program execution would
successfully be completed