ABAP: check if a function module exists programmatically
If you need to check if a function module within your program try running the following function: RH_FUNCTION_EXIST.
ABAP cancelling an SD Billing Document
If you have access to a billing document number try executing the following function:
DATA: l_rtrn TYPE bapireturn1 OCCURS 0.
DATA: l_succ TYPE bapivbrksuccess OCCURS 0.
CALL FUNCTION 'BAPI_BILLINGDOC_CANCEL1'
EXPORTING
billingdocument =
* testrun =
* no_commit =
billingdate = sy-datum
TABLES
return = l_rtrn
success = l_succ.
This should create a cancellation document.
ABAP: execute OS level command
There are many things that one can do to execute a command in an Operating System from an ABAP report. I’ll explain one method that one can take to accomplish this.
- Using transactions SM49 and SM69 set up and test a new OS command that you wish to execute. For the purposes of this post I’ve set up an executable command ZSAPCAR32.
- When I was setting up the new command I’ve selected the option to add additional parameters to the command.
- Once tested and satisfied you can add a new function module [SXPG_COMMAND_EXECUTE] to your report that will call preset executable command.
data: g_rlog TYPE btcxpm OCCURS 0.
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'ZSAPCAR32'
additional_parameters = <additional parameters>
operatingsystem = <system you specified in SM69>
TABLES
exec_protocol = g_rlog
EXCEPTIONS
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
wrong_asynchronous_parameters = 12
cant_enq_tbtco_entry = 13
jobcount_generation_error = 14
OTHERS = 15.
if sy-subrc eq 0.
LOOP AT g_rlog INTO g_warlog.
* display command output
write g_warlog.
ENDLOOP.
endif.
The above code will execute your OS command and display the results.
ABAP: load file using pop-up window
When writing a program the simplest way to load a file from your client PC in to the server SAP syste is through a use of a regular text box. But if you want to get a little fancier try using the following function:
data: l_select TYPE sapb-sappfad.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = l_select
def_path = ' '
mask = ',*.*,*.*.'
mode = 'O'
title = 'Select filename to OPEN'(f05)
IMPORTING
filename = l_select
EXCEPTIONS
selection_cancel = 1
selection_error = 2
OTHERS = 3.
This function will open up a pop-up window [standard to windows] allowing the user to select a file somewhere on their local comptuer.