Change Payment Block programmatically in MIRO tcode? - abap

Is it possible to change the payment block via a BAPI, FM or code?

Use BAdi INVOICE_UPDATE for changing this, method CHANGE_BEFORE_UPDATE.
Implementation sample is here.
For changing payment block via BAPI use BAPI_ACC_PYMNTBLK_UPDATE_POST, here is how to call:
DATA: it_return TYPE STANDARD TABLE OF bapiret2,
wa_return LIKE LINE OF it_return .
DATA ld_referenceinv TYPE bapiacpmblk.
MOVE it_bkfp-awkey TO ld_referenceinv-obj_key.
MOVE it_bkfp-awtyp TO ld_referenceinv-obj_type.
MOVE it_bkfp-awsys TO ld_referenceinv-obj_sys.
MOVE it_bkfp-bukrs TO ld_referenceinv-comp_code.
CALL FUNCTION 'BAPI_ACC_PYMNTBLK_UPDATE_POST'
EXPORTING
referenceinv = ld_referenceinv
TABLES
return = it_return .
IF sy-subrc = 0.
" Everything OK
ENDIF.

I've always used FI_DOCUMENT_CHANGE. Check out this example.
Hope it helps.
" VARIABLES
DATA: LT_ACCCHG TYPE TABLE OF ACCCHG.
DATA: LS_ACCCHG TYPE ACCCHG.
DATA: LV_AWTYP TYPE AWTYP.
DATA: LV_AWSYS TYPE AWSYS.
DATA: LV_AWREF TYPE AWREF.
DATA: LV_AWORG TYPE AWORG.
DATA: LV_LIFNR TYPE LIFNR.
" Fill variables here
" Can be found in tables BKPF AND BSIK
" SET VALUES FOR NEW PAYMENT BLOCK
" P = Payment request, A = Blocked for payment
" Check T008 for more Payment Block values
LS_ACCCHG-FDNAME = 'ZLSPR'. "Payment Block
LS_ACCCHG-NEWVAL = 'P'.
APPEND LS_ACCCHG TO LT_ACCCHG.
" CHANGE PAYMENT BLOCK
CALL FUNCTION 'FI_DOCUMENT_CHANGE'
EXPORTING
I_AWTYP = LV_AWTYP
I_AWREF = LV_AWREF
I_AWORG = LV_AWORG
I_AWSYS = LV_AWSYS
I_LIFNR = LV_LIFNR
TABLES
T_ACCCHG = LT_ACCCHG.

Related

How to use CRM_STATUS_READ to get product status?

I want to know that How to use the Function Module CRM_STATUS_READ.
In table crmd_orderadm_h have a field GUID and I want to show status by passing the GUID to the FM CRM_STATUS_READ.
I don't know how to fill parameters in this FM.
FORM create_output USING i_t_crmd_orderadm_h TYPE g_tt_orderadm_h
CHANGING e_t_out TYPE g_tt_out.
DATA: l_r_crmd_orderadm_h TYPE g_ty_orderadm_h,
l_r_out TYPE g_ty_out.
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT i_t_crmd_orderadm_h INTO l_r_crmd_orderadm_h.
CALL FUNCTION 'CRM_STATUS_READ'
EXPORTING
* CLIENT = SY-MANDT
objnr =
* ONLY_ACTIVE = ' '
* IMPORTING
* OBTYP =
* STSMA =
* STONR =
* ET_JEST_BUF =
* TABLES
* STATUS =
ENDFORM.
Best Regards,
Huy Vu
To call this module you gotta know two things: GUID and fragment GUID. The latter can be taken from product attributes (table COMM_PCAT_REL).
Here is the sample:
DATA(lv_guid) = get_guid_by_id( '11111111111' ).
DATA: lv_frg_guid TYPE comm_pr_frg_rod-fragment_type VALUE '37D58F1B772D53A4E10000009B38FA0B',
rt_stat TYPE ttjstat.
DATA: lv_objnr TYPE comm_pr_frg_rod-status_object,
lt_status TYPE STANDARD TABLE OF jstat.
SELECT SINGLE status_object FROM comm_pr_frg_rod
INTO lv_objnr WHERE product_guid = lv_guid AND fragment_type = lv_frg_guid.
CHECK sy-subrc = 0.
CALL FUNCTION 'CRM_STATUS_READ'
EXPORTING
objnr = lv_objnr
TABLES
status = rt_status
EXCEPTIONS
object_not_found = 1.

Exception raised after posting gl account data to bapi_incominginvoice_create1

I get an exception raised after posting gl account data to bapi_incominginvoice_create1.
This is my gl account data:
DATA : it_glacnt TYPE STANDARD TABLE OF bapi_incinv_create_gl_account,
wa_glacnt TYPE bapi_incinv_create_gl_account.
wa_glacnt-invoice_doc_item = '000002'.
wa_glacnt-gl_account = '0000400100'.
wa_glacnt-item_amount = '100.0000'.
wa_glacnt-db_cr_ind = 'H'.
wa_glacnt-comp_code = '010'.
wa_glacnt-item_text = 'Test TEXT'.
* wa_glacnt-sdoc_item = '0'.
wa_glacnt-bus_area = 'TMKK'.
wa_glacnt-alloc_nmbr = v_scanid.
APPEND wa_glacnt TO it_glacnt .
CLEAR wa_glacnt.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE1'
EXPORTING
headerdata = wa_miro_header
IMPORTING
invoicedocnumber = v_invno
fiscalyear = v_miroyr
TABLES
itemdata = it_miro_item
taxdata = it_miro_tax
glaccountdata = it_glacnt
withtaxdata = it_withtax
return = it_ret.
IF NOT v_invno IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDIF.
I want to post this amount to gl account but when I execute, I get this exception:
It looks like records are not found in EKPO (purchasing document item) table. Generally, invoice posting needs PO records.

Movilizer for SAP - How to call the same movelet screen repeatedly?

I need to call the same screen (question) repeatedly in a Movelet for filling and send its fields to SAP.
The number of calls to the screen will be set dinamically depending on a variable value.
Is it possible to do that? How can I do it?
Thanks in advance.
it is possible. Create a method for generating a screen called (for instance) ADD_LOOP_SCR:
IV_SCREEN_KEY TYPE /MOVI/LZR_ANSWER_KEY Movilizer: Answer Key
IV_NEXT_SCR_KEY TYPE /MOVI/LZR_ANSWER_KEY Movilizer: Answer Key
CS_MOVELET TYPE /MOVI/MS_ST_BUSSTEP_STRUCTURE Movelet structure
implementation (Epsilon example)
DATA:
lr_screen TYPE REF TO /movi/ms_st_screen_epsilon,
lr_answer TYPE REF TO /movi/ms_st_answer.
APPEND INITIAL LINE TO cs_movelet-epsilon_screens REFERENCE INTO lr_screen.
lr_screen->key = iv_screen_key.
APPEND INITIAL LINE TO lr_screen->answers REFERENCE INTO lr_answer.
CONCATENATE 'AK_' iv_screen_key INTO lr_answer->key.
CONCATENATE 'CK_' iv_screen_key INTO lr_answer->client_key.
lr_answer->next_screen_key = iv_next_scr_key.
lr_answer->followup_action = /movi/dsd_if_const=>movilizer-followup_action_none.
add_XXXXXX_mel(
EXPORTING
...... if needed
CHANGING
ct_mel_expressions = lr_screen->mel_expressions
ct_validations = lr_screen->validations
ct_restrictions = lr_screen->restrictions ).
and then mainly in the GENERATE method:
es_movelet-first_screen_key = 'SK_LOOPSCREEN_001'.
DATA:
lv_i TYPE numc3,
lv_sk TYPE /movi/lzr_answer_key,
lv_next_sk TYPE /movi/lzr_answer_key.
DO 5 TIMES.
lv_i = sy-index.
CONCATENATE 'SK_LOOPSCREEN_' lv_i INTO lv_sk.
ADD 1 TO lv_i.
IF lv_i > 5.
lv_next_sk = /movi/lzr_if_constants=>movilizer_movelet_exit_key.
ELSE.
CONCATENATE 'SK_LOOPSCREEN_' lv_i INTO lv_next_sk.
ENDIF.
add_generate_printout_data_scr( EXPORTING iv_screen_key = lv_sk
iv_next_scr_key = lv_next_sk
CHANGING cs_movelet = es_movelet ).
ENDDO.
Good luck, cheers,
Aleq

Update BSEG-ZUONR with Function Module

I successfully change BKPF-BKTXT with FM CHANGE_DOCUMENT but why can't I change BSEG-ZUONR with FM CHANGE_DOCUMENT too?
Here's the FM CHANGE_DOCUMENT:
CALL FUNCTION 'CHANGE_DOCUMENT'
TABLES
T_BKDF = t_bkdf
T_BKPF = t_bkpf
T_BSEC = t_bsec
T_BSED = t_bsed
T_BSEG = t_bseg
T_BSET = t_bset
* T_BSEG_ADD =
.
Here's the code to change BKPF-BKTXT (succeeded):
wa_t_bkpf-mandt = sy-mandt.
wa_t_bkpf-bukrs = '1000'.
wa_t_bkpf-gjahr = gjahr_import.
wa_t_bkpf-belnr = belnr_import.
wa_t_bkpf-bktxt = zuonr_import.
APPEND wa_t_bkpf TO t_bkpf.
Here's the code to change BSEG-ZUONR (failed):
wa_t_bseg-mandt = sy-mandt.
wa_t_bseg-bukrs = '1000'.
wa_t_bseg-gjahr = gjahr_import.
wa_t_bseg-belnr = belnr_import.
wa_t_bseg-buzei = '1'.
wa_t_bseg-zuonr = zuonr_import.
APPEND wa_t_bseg TO t_bseg.
As author has no time to confirm, I can do this for him as I just tested this case.
If we pass to FM all parameters from its signature the update runs smoothly. For example, like this:
DATA: lt_bkdf TYPE TABLE OF bkdf,
lt_bkpf TYPE TABLE OF bkpf,
wa_bkpf TYPE bkpf,
lt_bsec TYPE TABLE OF bsec,
wa_bseg TYPE bseg,
lt_bsed TYPE TABLE OF bsed,
lt_bseg TYPE TABLE OF bseg,
lt_bset TYPE TABLE OF bset.
wa_bkpf-mandt = sy-mandt.
wa_bkpf-bukrs = '5900'.
wa_bkpf-gjahr = gjahr_import.
wa_bkpf-belnr = belnr_import.
wa_bkpf-bktxt = 'Batch'.
APPEND wa_bkpf TO lt_bkpf.
wa_bseg-mandt = sy-mandt.
wa_bseg-bukrs = '5900'.
wa_bseg-gjahr = gjahr_import.
wa_bseg-belnr = belnr_import.
wa_bseg-buzei = '1'.
wa_bseg-zuonr = '20151131'.
APPEND wa_bseg TO lt_bseg.
CALL FUNCTION 'CHANGE_DOCUMENT'
TABLES
t_bkdf = lt_bkdf
t_bkpf = lt_bkpf
t_bsec = lt_bsec
t_bsed = lt_bsed
t_bseg = lt_bseg
t_bset = lt_bset
.
COMMIT WORK.
All FM table parameters except the last one are mandatory.
Do not use this FM
CALL FUNCTION 'CHANGE_DOCUMENT'
This FM is changing all other fields to initial if not provided.
CALL FUNCTION 'FI_DOCUMENT_CHANGE'
It seems that this FM cannot be used to change line item which has account type (BSEG-KOART) - 'S' (GL Account).
Try this FM:
'FI_ITEMS_MASS_CHANGE'
The field zuonr references to an object it belongs to.
For example a purchase order.
Lets asume you pay a position of a purchase order.
A document in bkpf/bseg is created (and more).
Bseg-Zuonr contains the number of this purchase order position.
If you were allowed to change this field, you would destroy the referential integrity of the data. It would point to a purchase order position it was not created from or one that doesn't exist at all.
So from a business standpoint it makes no sense to ever change this field after it is created, therefore SAP will never allow to change it.

How to display list of attachments from Generic Object Services

I have a report that should display an attachment list from an object.
For instance, in transaction FI02 (maintenance of banks), the GOS toolbar has the menu Attachment List:
I want to display this list. What is the best way to display it?
REPORT zay_gos_demo.
DATA ls_appl_object TYPE gos_s_obj.
DATA lo_gos_api TYPE REF TO cl_gos_api.
DATA lt_attachment_list TYPE gos_t_atta.
DATA lt_role_filter TYPE gos_t_rol.
DATA ls_attachment TYPE gos_s_atta.
DATA ls_attachm_cont TYPE gos_s_attcont.
DATA ls_atta_key TYPE gos_s_attkey.
ls_appl_object-typeid = 'KNA1'.
ls_appl_object-instid = '0000000001'.
ls_appl_object-catid = 'BO'. "BO - BOR Object
"CL - Persistent Class
START-OF-SELECTION.
* create instance of GOS API providing unique application object
TRY.
lo_gos_api = cl_gos_api=>create_instance( ls_appl_object ).
* get attachment list for this object (if needed restrict selection
* by adding certain roles to filter table; initial table means: get
* attachments in all roles)
APPEND cl_gos_api=>c_attachment TO lt_role_filter.
APPEND cl_gos_api=>c_annotation TO lt_role_filter.
APPEND cl_gos_api=>c_website TO lt_role_filter.
lt_attachment_list = lo_gos_api->get_atta_list( lt_role_filter ).
CATCH cx_gos_api.
* error handling
ENDTRY.
I found other example and I want to test it:
REPORT zay_attachment_list_display.
DATA: go_attachments TYPE REF TO cl_gos_attachments,
g_att_container TYPE REF TO cl_gui_custom_container,
ls_object TYPE borident,
lo_bitem TYPE REF TO cl_sobl_bor_item.
ls_object-objtype = 'KNA1'.
ls_object-objkey = '0000000001'.
IF NOT go_attachments IS INITIAL.
CLEAR go_attachments.
ENDIF.
CREATE OBJECT g_att_container
EXPORTING
container_name = 'ATTS'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
* ADD your handling
ENDIF.
CREATE OBJECT lo_bitem
EXPORTING
is_bor = ls_object.
IF go_attachments IS INITIAL.
CREATE OBJECT go_attachments
EXPORTING
io_object = lo_bitem
ip_check_arl = 'X'
ip_check_bds = 'X'
io_container = g_att_container
* is_layout = ls_layout
* ip_mode = wf_mode
ip_notes = 'X'
ip_attachments = 'X'
ip_urls = 'X'.
ELSE.
go_attachments->set_container( g_att_container ).
ENDIF.
go_attachments->display( ).
I created a custom control in dynpro 0100 and I named it ATTS. I still can't get the attachment list of GOS. Did I miss something?
After weeks of searching and asking. it was really simple. just call the function GOS_ATTACHMENT_LIST_POPUP.
Example:
DATA: ls_object TYPE sibflporb,
save_request TYPE sgs_flag.
ls_object-instid = 'FR 1234567890'.
ls_object-typeid = 'BUS1011'.
ls_object-catid = 'BO'.
CALL FUNCTION 'GOS_ATTACHMENT_LIST_POPUP'
EXPORTING
is_object = ls_object
ip_mode = 'E' " Edit mode
IMPORTING
ep_save_request = save_request.
IF save_request = 'X'.
COMMIT WORK.
ENDIF.