Many times you find useful to call a transaction from your program. Most common request when creating an ALV report for example is "...the user should click on the customer number field and XD03 should be called..." or something similar.
The first response from your side would be, "...sure this is piece of cake...". So in your code after fetching the customer number you would call transaction XD03.
CALL transaction 'XD03' AND skip first screen.
I am not sure how many of you know that with call transaction you bypass the standard authorization check for S_TCODE object. So it would be possible for someone to have access in a transaction that it is not intended to have . Only when you use LEAVE TO transaction the S_TCODE authorization check is called.
So it is necessary to do an authorization check for object S_TCODE prior using CALL TRANSACTION.
Another alternative ( and much better in my opinion) would be to use the FM ABAP4_CALL_TRANSACTION
This FM gives you the option to skip first screen, to pass parameters or even batch input data and of course you won't have to worry and implement authorization checks.
DATA lt_mem TYPE TABLE OF rfc_spagpa.
FIELD-SYMBOLS <lfs_mem> TYPE rfc_spagpa.
APPEND INITIAL LINE TO lt_mem ASSIGNING <lfs_mem>.
<lfs_mem>-parid = 'KUN'.
<lfs_mem>-parval = lv_kunnr.
APPEND INITIAL LINE TO lt_mem ASSIGNING <lfs_mem>.
<lfs_mem>-parid = 'BUK'.
<lfs_mem>-parval = lv_bukrs.
CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
EXPORTING
tcode = 'XD03'
skip_screen = 'X'
TABLES
spagpa_tab = lt_mem
EXCEPTIONS
OTHERS = 1.
ENDIF.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Don't shoot the abaper
Tuesday, September 4, 2012
Monday, December 19, 2011
Free SAP IDES Access
I believe many of you have searched for a low price IDES access in order to "get your hands dirty".
There is one company which offers free IDES or MiniSAP access. All you have to do is to register at the following address.
http://www.consolut.com/en/s/sap-ides-access.html
I have try it and it really works. This is a very good initiative from Consolut, which is the company offering this service.
Feel free to try it for yourselves.
There is one company which offers free IDES or MiniSAP access. All you have to do is to register at the following address.
http://www.consolut.com/en/s/sap-ides-access.html
I have try it and it really works. This is a very good initiative from Consolut, which is the company offering this service.
Feel free to try it for yourselves.
Thursday, November 17, 2011
Display return messages from BAPI and BI calls
You have the requirements, you plan the algorithm, you search for the correct BAPI that fulfills the requirements, you plan the UI and start writing some code.
Everything seems to be fine and as you proceed you have to face the boring part of displaying the return messages from the BAPI call.
How you should display the return messages? There is always the solution of writing the output as a list, but I don't think that anyone likes the old-school-fashioned list display. Moreover there is always the need to display messages from 2 or more recursive BAPI calls or from a combination between a BAPI and Batch Input call.
One good solution is to create a custom function module which will display the return messages in a popup using the application log functionality.
FUNCTION z_display_return_messages.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" BAPIRET2 TYPE BAPIRET2_T OPTIONAL
*" BI_MESSAGES TYPE ETTCD_MSG_TABTYPE OPTIONAL
*"----------------------------------------------------------------------
* Message log structures
DATA: ls_s_log TYPE bal_s_log,
ls_s_msg TYPE bal_s_msg,
ls_s_prof TYPE bal_s_prof,
lv_handle TYPE balloghndl.
DATA ls_return2 TYPE bapiret2.
DATA ls_messages TYPE bdcmsgcoll.
CLEAR: ls_s_log, ls_s_prof, lv_handle.
ls_s_log-aldate = sy-datum.
ls_s_log-altime = sy-uzeit.
ls_s_log-aluser = sy-uname.
ls_s_log-alprog = sy-repid.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_s_log
IMPORTING
e_log_handle = lv_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF LINES( bapiret2 ) > 0.
LOOP AT bapiret2 INTO ls_return2 .
CLEAR ls_s_msg.
ls_s_msg-msgid = ls_return2-id.
ls_s_msg-msgty = ls_return2-type.
ls_s_msg-msgno = ls_return2-number.
ls_s_msg-msgv1 = ls_return2-message_v1.
ls_s_msg-msgv2 = ls_return2-message_v2.
ls_s_msg-msgv3 = ls_return2-message_v3.
ls_s_msg-msgv4 = ls_return2-message_v4.
CASE ls_s_msg-msgty.
WHEN 'E'.
ls_s_msg-probclass = 1.
WHEN 'W'.
ls_s_msg-probclass = 2.
WHEN 'I'.
ls_s_msg-probclass = 3.
WHEN 'S'.
ls_s_msg-probclass = 4.
ENDCASE.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_handle
i_s_msg = ls_s_msg
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
ENDLOOP.
ENDIF.
IF LINES( bi_messages ) > 0.
LOOP AT bi_messages INTO ls_messages .
CLEAR ls_s_msg.
ls_s_msg-msgid = ls_messages-msgid.
ls_s_msg-msgty = ls_messages-msgtyp.
ls_s_msg-msgno = ls_messages-msgnr.
ls_s_msg-msgv1 = ls_messages-msgv1.
ls_s_msg-msgv2 = ls_messages-msgv2.
ls_s_msg-msgv3 = ls_messages-msgv3.
ls_s_msg-msgv4 = ls_messages-msgv4.
CASE ls_s_msg-msgty.
WHEN 'E'.
ls_s_msg-probclass = 1.
WHEN 'W'.
ls_s_msg-probclass = 2.
WHEN 'I'.
ls_s_msg-probclass = 3.
WHEN 'S'.
ls_s_msg-probclass = 4.
ENDCASE.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_handle
i_s_msg = ls_s_msg
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
ENDLOOP.
ENDIF.
IF sy-subrc = 0.
CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
IMPORTING
e_s_display_profile = ls_s_prof.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = ls_s_prof
EXCEPTIONS
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
OTHERS = 5.
ENDIF.
CALL FUNCTION 'BAL_LOG_REFRESH'
EXPORTING
i_log_handle = lv_handle
EXCEPTIONS
log_not_found = 1
OTHERS = 2.
ENDFUNCTION.
Everything seems to be fine and as you proceed you have to face the boring part of displaying the return messages from the BAPI call.
How you should display the return messages? There is always the solution of writing the output as a list, but I don't think that anyone likes the old-school-fashioned list display. Moreover there is always the need to display messages from 2 or more recursive BAPI calls or from a combination between a BAPI and Batch Input call.
One good solution is to create a custom function module which will display the return messages in a popup using the application log functionality.
FUNCTION z_display_return_messages.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" BAPIRET2 TYPE BAPIRET2_T OPTIONAL
*" BI_MESSAGES TYPE ETTCD_MSG_TABTYPE OPTIONAL
*"----------------------------------------------------------------------
* Message log structures
DATA: ls_s_log TYPE bal_s_log,
ls_s_msg TYPE bal_s_msg,
ls_s_prof TYPE bal_s_prof,
lv_handle TYPE balloghndl.
DATA ls_return2 TYPE bapiret2.
DATA ls_messages TYPE bdcmsgcoll.
CLEAR: ls_s_log, ls_s_prof, lv_handle.
ls_s_log-aldate = sy-datum.
ls_s_log-altime = sy-uzeit.
ls_s_log-aluser = sy-uname.
ls_s_log-alprog = sy-repid.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_s_log
IMPORTING
e_log_handle = lv_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF LINES( bapiret2 ) > 0.
LOOP AT bapiret2 INTO ls_return2 .
CLEAR ls_s_msg.
ls_s_msg-msgid = ls_return2-id.
ls_s_msg-msgty = ls_return2-type.
ls_s_msg-msgno = ls_return2-number.
ls_s_msg-msgv1 = ls_return2-message_v1.
ls_s_msg-msgv2 = ls_return2-message_v2.
ls_s_msg-msgv3 = ls_return2-message_v3.
ls_s_msg-msgv4 = ls_return2-message_v4.
CASE ls_s_msg-msgty.
WHEN 'E'.
ls_s_msg-probclass = 1.
WHEN 'W'.
ls_s_msg-probclass = 2.
WHEN 'I'.
ls_s_msg-probclass = 3.
WHEN 'S'.
ls_s_msg-probclass = 4.
ENDCASE.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_handle
i_s_msg = ls_s_msg
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
ENDLOOP.
ENDIF.
IF LINES( bi_messages ) > 0.
LOOP AT bi_messages INTO ls_messages .
CLEAR ls_s_msg.
ls_s_msg-msgid = ls_messages-msgid.
ls_s_msg-msgty = ls_messages-msgtyp.
ls_s_msg-msgno = ls_messages-msgnr.
ls_s_msg-msgv1 = ls_messages-msgv1.
ls_s_msg-msgv2 = ls_messages-msgv2.
ls_s_msg-msgv3 = ls_messages-msgv3.
ls_s_msg-msgv4 = ls_messages-msgv4.
CASE ls_s_msg-msgty.
WHEN 'E'.
ls_s_msg-probclass = 1.
WHEN 'W'.
ls_s_msg-probclass = 2.
WHEN 'I'.
ls_s_msg-probclass = 3.
WHEN 'S'.
ls_s_msg-probclass = 4.
ENDCASE.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_handle
i_s_msg = ls_s_msg
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
ENDLOOP.
ENDIF.
IF sy-subrc = 0.
CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
IMPORTING
e_s_display_profile = ls_s_prof.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = ls_s_prof
EXCEPTIONS
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
OTHERS = 5.
ENDIF.
CALL FUNCTION 'BAL_LOG_REFRESH'
EXPORTING
i_log_handle = lv_handle
EXCEPTIONS
log_not_found = 1
OTHERS = 2.
ENDFUNCTION.
Subscribe to:
Posts (Atom)