Everyone who writes Reports in ABAP/4 for SAP R3 systems is confronted with several code chunks that tend to be required for almost any program so he creates a template program for himself which he then uploads and amends when a new program needs to be written. This as well helps to make sure that all required inline documentation has been supplied.
However, this particular code frame assists you with Reports only (as opposed to Dialog transactions) as those tend to be far more customized but the documentation headers can be taken for almost any kind of code.
All but the most trivial ABAP programs require some kind of error or warning handling. Unfortunately many ABAP programmers have a tendency to cut short the apropriate handling routines. The framework therefore includes three macros, ERROR, WARNING and INFO that can be used to signal information to the user. The information will be collected and published at the end of the report run. Multiple occurrences of the same message will be aggregated and then presented with a counter next to them.
Notice how the macros are used in the following code fragment..
SELECT * FROM YTABLE WHERE FNNN = 'XZZY'.
IF SY-SUBRC NE 0.
WARNING 'Could not find expected record in YTABLE'.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
ERROR 'SAP OFFICE send call failed'.
You might want to use WARNING whenever you encounter a situation that should be signaled to the user but could be fixed internally (say, by selecting a default value). ERROR should only be used when an irrecoverable error has occurred which lead you to abort processing.
Multiple occurrences of the same message will be aggregated and then presented with a counter next to them. This can be used to produce a fairly simple statistics counter:
SELECT * FROM BKPF WHERE ...
INFO 'Number of documents read'.
In order to produce the collected messages, please make sure the following line is executed once after processing is complete (say at the end of END-OF-SELECTION). This is already done in the framework so nothing to do there.
PERFORM ERROR USING 'L' SPACE SPACE. "Output of error messages
The framework also contains code needed to create and process Batch-Input sessions. It can handle sessions internally which need to be split up into multiple blocks of say 10000 Transactions if you require to handle large volumes of data.
Two simple forms provide the functionality to handle BDC sessions, BDCI and BDCA. BDCA fills an internal table with the required BDC data, BDCI passes it on for processing.
The process is quite similar to the one taught in many ABAP classes:
PERFORM BDCA USING : 'PROGRAM' 'DYNPRO' 'X', "A new DYNPRO
'FIELD1' 'CONTENT' ' ', "Data for a field
'FIELD2' 'CONTENT' ' ', "Another field
'FIELD3' 'CONTENT' ' '. "A third field
PERFORM BDCI USING 'MYSESSION' "Name of the BDC session
'FB00' "Transaction code
0 "Number of transactions 0=unlim
SPACE. "Test run flag
Notice the last parameter in the BDCI perform. If you link this to a checkbox that you have placed on the selection screen, the program will not actually perform any BDCI when checked. This is useful to allow the user to verify that all required data would have been selected and/or warnings and errors have been eliminated prior to the live run.