Exception raised after posting gl account data to bapi_incominginvoice_create1 - abap

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.

Related

How can I update BUT050 & BUT051 tables?

I have the following scenario:
I am using BAPI BAPI_BUPR_RELATIONSHIP_CHANGE to change validuntildate. (BUT050-DATE_TO / BUT051-DATE_TO).
But I also need to update field BUT051-PAFKT and a custom field in BUT050 (lets call it ZZFIELD).
I do this by updating BUT050 / BUT051 from internal tables.
At the end, if I write COMMIT WORK or call FM BAPI_TRANSACTION_COMMIT, only the fields from BAPI_BUPR_RELATIONSHIP_CHANGE will be updated. If I do not write anything at the end, only the field from UPDATE FROM TABLE will be updated.
How can I update all my fields?
Are there any BAPI that can allow me to modify BUT051-PAFKT and custom fields from BUT050 ?
Sample code for testing:
DATA: lt_return TYPE bapiret2_t,
lv_kunnr TYPE kunnr VALUE '111',
lv_partner TYPE bu_partner VALUE '222',
lv_rel_cat TYPE bu_reltyp VALUE 'BUR001',
lv_new_date TYPE sy-datum VALUE '20300101',
lt_but051 TYPE TABLE OF but051.
CALL FUNCTION 'BAPI_BUPR_RELATIONSHIP_CHANGE'
EXPORTING
businesspartner1 = lv_kunnr
businesspartner2 = lv_partner
relationshipcategory = lv_rel_cat
validfromdate = sy-datum
validuntildate = sy-datum
validuntildatenew = lv_new_date
datetox = abap_true
TABLES
RETURN = lt_return.
SELECT *
FROM but051
INTO TABLE lt_but051
WHERE partner1 = lv_kunnr
AND partner2 = lv_partner
AND reltyp = lv_rel_cat.
LOOP AT lt_but051 ASSIGNING FIELD-SYMBOL(<ls_but051>).
<ls_but051>-pafkt = '0003'.
ENDLOOP.
UPDATE but051 FROM TABLE lt_but051.
COMMIT WORK.
Try this (or its wrapper BAPI_BUPR_CONTP_CHANGE):
DATA: ls_person TYPE bapibus1006_central_person.
DATA: ls_person_x TYPE bapibus1006_central_person_x.
DATA: ls_central TYPE bapibus1006_central.
DATA: ls_central_x TYPE bapibus1006_central_x.
DATA: lt_return TYPE bapiret2_t.
is_data-function = '0001'. "<-- your PAFKT
is_data_x-function = abap_true.
* changes of the central data
CALL FUNCTION 'BUPR_CONTP_CHANGE'
EXPORTING
iv_partner = is_data-partner1
* IV_PARTNER_GUID =
iv_contactperson = is_data-partner2
* IV_CONTACTPERSON_GUID =
* IV_DATE_FROM =
* IV_DATE_TO =
* IV_DEFAULTRELATIONSHIP =
* IV_DEFAULTRELATIONSHIP_X =
is_data = is_data-data
is_data_x = is_data_x-central
* IV_TESTRUN = ' '
TABLES
et_return = lt_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = abap_true.
Also check my answer about updating relations and the corresponding note.
Regarding the custom field in BUT050, you can't just add a new field and update it, you need to change the BOL model.

How to display itab in ALV with dynamic layout variant?

I am using the class CL_GUI_ALV_GRID and a dynpro screen to display an internal table via the ALV tool.
In my selection screen I have a dropdown list where the user can choose a layout variant for the displayed internal table. The layout variants are stored in the table LTDX.
Now, back to my question, how can I display the variants depending on the selection of the user?
You supply in the initial set_table_for_first_display method the is_variant parameter:
DATA: ls_variant TYPE disvariant.
CLEAR: ls_variant.
ls_variant-report = sy-repid.
ls_variant-variant = pa_varid. "<<< this is the name of the variant
CALL METHOD gro_alv100->set_table_for_first_display
EXPORTING
is_variant = ls_variant
...
EDIT: okay you did not accept the simple answer, so I will add the manual alternative:
FORM set_variant USING ps_variant TYPE disvariant.
DATA: lf_user_specific TYPE char1,
ls_stable TYPE lvc_s_stbl VALUE 'XX'.
CHECK ps_variant-variant IS NOT INITIAL.
lf_user_specific = boolc( ps_variant-variant(1) <> '/' ).
CALL FUNCTION 'LVC_VARIANT_SELECT'
EXPORTING
i_dialog = space
i_user_specific = lf_user_specific
i_default = space
it_default_fieldcat = gt_fcat
IMPORTING
et_fieldcat = gt_fcat
et_sort = gt_sort
et_filter = gt_filter
TABLES
it_data = gt_outtab
CHANGING
cs_variant = ps_variant
EXCEPTIONS
wrong_input = 1
fc_not_complete = 2
not_found = 3
program_error = 4
data_missing = 5
OTHERS = 6.
IF sy-subrc <> 0.
ENDIF.
gro_alv100->set_variant( EXPORTING is_variant = ps_variant ).
gro_alv100->set_frontend_fieldcatalog( EXPORTING it_fieldcatalog = gt_fcat ).
gro_alv100->set_sort_criteria( EXPORTING it_sort = gt_sort ).
gro_alv100->set_filter_criteria( EXPORTING it_filter = gt_filter ).
gro_alv100->refresh_table_display( EXPORTING is_stable = ls_stable i_soft_refresh = abap_false ).
ENDFORM.

Add table rows to a TR programmatically?

I have a problem with adding rows of table to the transport request in programming way.
When i wrote down the transport request number i get the error:
You cannot use request EAMK913244
the code I use is
data lt_variable_changed type table of ztable_task2.
data: l_request type trkorr,
lt_e071 type tr_objects,
lt_e071k type tr_keys,
lv_tabkey type trobj_name,
ls_e071 type e071,
ls_e071k type e071k.
ls_e071-pgmid = 'R3TR'.
ls_e071-object = 'TABU'. "for table
ls_e071-obj_name = 'ZTABLE_TASK2'.
ls_e071-objfunc = 'K'.
append ls_e071 to lt_e071.
loop at lt_variable_changed into ls_variable.
lv_tabkey = ls_variable-num.
ls_e071k-pgmid = 'R3TR'.
ls_e071k-object = 'TABU'.
ls_e071k-objname = 'ZTABLE_TASK2'.
ls_e071k-mastertype = 'TABU'.
ls_e071k-mastername = 'ZTABLE_TASK2'.
ls_e071k-tabkey = lv_tabkey.
append ls_e071k to lt_e071k.
endloop.
call function 'TR_REQUEST_CHOICE'
exporting
iv_suppress_dialog = 'X'
iv_request = var_query
it_e071 = lt_e071
it_e071k = lt_e071k.
message 'Ok' type 'I'.
Screen from se01:
Thanks for help and good luck!
three function modules shall be used to transport changes
call function 'TR_ORDER_CHOICE_CORRECTION'
exporting
iv_category = 'CUST'
importing
ev_order = ev_request
ev_task = ev_task
exceptions
invalid_category = 1
no_correction_selected = 2
others = 3.
call function 'TR_OBJECTS_CHECK'
exporting
iv_no_show_option = abap_true
tables
wt_ko200 = lt_ko200_customizing
wt_e071k = lt_e071k_customizing
exceptions
cancel_edit_other_error = 1
show_only_other_error = 2
others = 3.
call function 'TR_OBJECTS_INSERT'
exporting
wi_order = lv_request
iv_no_show_option = abap_true
tables
wt_ko200 = lt_ko200_customizing
wt_e071k = lt_e071k_customizing
exceptions
cancel_edit_other_error = 1
show_only_other_error = 2
others = 3.
You can also use object-oriented approach for transporting tables.
This piece creates a customizing request and puts contents of a table in it:
DATA(instance) = cl_adt_cts_management=>create_instance( ).
TRY.
instance->insert_objects_in_wb_request( EXPORTING pgmid = 'R3TR'
object = 'TABU'
obj_name = CONV trobj_name( 'Z_TABLE' )
CHANGING trkorr = l_trkorr ).
CATCH cx_adt_cts_insert_error.
RETURN.
ENDTRY.
This piece uses ADT CTS classes and is very flexible. Despite the name wb_request this method is adaptive and will create workbench or customizing request depending on the objects passed.

Uploading a DMS document via a web service

Can somebody please explain how to upload DMS files via a rest service. I'm using BAPI_DOCUMENT_CREATE2 like some guides suggest, but I don't see how to get the file on the server.
If you look at the guide I link below, he passes the filename, but not the content. Can anybody please explain how he gets the content?
Btw, I can't use the Gateway so I'm just using a SICF service.
https://blogs.sap.com/2016/08/22/upload-document-into-dms-server-using-net-weaver-gateway/
"Variables
DATA: LS_DOCDATA TYPE BAPI_DOC_DRAW2.
DATA: LS_OBJECTLINK TYPE BAPI_DOC_DRAD.
DATA: LT_OBJECTLINKS TYPE TABLE OF BAPI_DOC_DRAD.
DATA: LS_OBJECTDESCR TYPE BAPI_DOC_DRAT.
DATA: LT_OBJECTDESCR TYPE TABLE OF BAPI_DOC_DRAT.
DATA: LS_OBJECTFILE TYPE BAPI_DOC_FILES2.
DATA: LT_OBJECTFILES TYPE TABLE OF BAPI_DOC_FILES2.
DATA: LV_DOCTYPE TYPE DOKAR.
DATA: LV_DOCNUMBER TYPE DOKNR.
DATA: LV_DOCPART TYPE DOKTL_D.
DATA: LV_DOCVERSION TYPE DOKVR.
" SET VALUES
LS_DOCDATA-DOCUMENTTYPE = 'DRW'.
LS_DOCDATA-DOCUMENTVERSION = '00'.
LS_DOCDATA-DOCUMENTPART = '000'.
LS_DOCDATA-LABORATORY = '001'.
LS_OBJECTDESCR-DESCRIPTION = 'test dms doc'.
LS_OBJECTDESCR-LANGUAGE = 'E'.
LS_OBJECTDESCR-LANGUAGE_ISO = 'EN'.
APPEND LS_OBJECTDESCR TO LT_OBJECTDESCR.
LS_OBJECTFILE-ORIGINALTYPE = '1'.
LS_OBJECTFILE-SOURCEDATACARRIER = 'SAP-SYSTEM'.
LS_OBJECTFILE-CREATED_BY = SY-UNAME
LS_OBJECTFILE-DOCFILE = 'test'.
LS_OBJECTFILE-WSAPPLICATION = 'JPG'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
LS_OBJECTLINK-OBJECTTYPE = 'EQUI'.
LS_OBJECTLINK-OBJECTKEY = '000000000210100004'.
APPEND LS_OBJECTLINK TO LT_OBJECTLINKS.
" CREATE ATTACHMENT
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
DOCUMENTDATA = LS_DOCDATA
HOSTNAME = SY-HOST
PF_FTP_DEST = 'SAPFTPA'
PF_HTTP_DEST = 'SAPHTTP'
IMPORTING
DOCUMENTTYPE = LV_DOCTYPE
DOCUMENTNUMBER = LV_DOCNUMBER
DOCUMENTPART = LV_DOCPART
DOCUMENTVERSION = LV_DOCVERSION
RETURN = LT_RETURN
TABLES
DOCUMENTDESCRIPTIONS = LT_OBJECTDESCR
OBJECTLINKS = LT_OBJECTLINKS
DOCUMENTFILES = LT_OBJECTFILES.
IF SY-SUBRC <> 0.
MESSAGE 'Error uploading attachment' TYPE 'E'.
ENDIF.
" COMMIT
COMMIT WORK.
I actually used this piece of code to solve it. I found it here: Solution
DATA LV_OUTPUT_LENGTH TYPE I.
DATA LS_SOLIX TYPE SOLIX-LINE.
DATA LT_SOLIX_TAB TYPE TABLE OF SOLIX-LINE.
DATA LV_FILENAME TYPE STRING.
DATA LV_DOCNUM TYPE DOKNR.
CONCATENATE '/usr/sap/' SY-SYSID SY-UNAME SY-DATUM INTO LV_FILENAME.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LV_FILESOURCE " this is the XSTRING of the file u want to upload
IMPORTING
OUTPUT_LENGTH = LV_OUTPUT_LENGTH
TABLES
BINARY_TAB = LT_SOLIX_TAB.
IF NOT LT_SOLIX_TAB IS INITIAL.
OPEN DATASET LV_FILENAME FOR OUTPUT IN BINARY MODE.
LOOP AT LT_SOLIX_TAB INTO LS_SOLIX.
TRANSFER LS_SOLIX TO LV_FILENAME.
ENDLOOP.
CLOSE DATASET LV_FILENAME.
ENDIF.
So I combined my earlier code with the above snippet and it seems to work.
"Variables
DATA: LS_DOCDATA TYPE BAPI_DOC_DRAW2.
DATA: LS_OBJECTLINK TYPE BAPI_DOC_DRAD.
DATA: LT_OBJECTLINKS TYPE TABLE OF BAPI_DOC_DRAD.
DATA: LS_OBJECTDESCR TYPE BAPI_DOC_DRAT.
DATA: LT_OBJECTDESCR TYPE TABLE OF BAPI_DOC_DRAT.
DATA: LS_OBJECTFILE TYPE BAPI_DOC_FILES2.
DATA: LT_OBJECTFILES TYPE TABLE OF BAPI_DOC_FILES2.
DATA: LV_DOCTYPE TYPE DOKAR.
DATA: LV_DOCNUMBER TYPE DOKNR.
DATA: LV_DOCPART TYPE DOKTL_D.
DATA: LV_DOCVERSION TYPE DOKVR.
" SET VALUES
LS_DOCDATA-DOCUMENTTYPE = 'DRW'.
LS_DOCDATA-DOCUMENTVERSION = '00'.
LS_DOCDATA-DOCUMENTPART = '000'.
LS_DOCDATA-LABORATORY = '001'.
LS_OBJECTDESCR-DESCRIPTION = 'test dms doc'.
LS_OBJECTDESCR-LANGUAGE = 'E'.
LS_OBJECTDESCR-LANGUAGE_ISO = 'EN'.
APPEND LS_OBJECTDESCR TO LT_OBJECTDESCR.
LS_OBJECTFILE-ORIGINALTYPE = '1'.
LS_OBJECTFILE-SOURCEDATACARRIER = 'SAP-SYSTEM'.
LS_OBJECTFILE-CREATED_BY = SY-UNAME.
LS_OBJECTFILE-DOCFILE = LV_FILENAME.
LS_OBJECTFILE-WSAPPLICATION = 'TXT'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.
LS_OBJECTLINK-OBJECTTYPE = 'EQUI'.
LS_OBJECTLINK-OBJECTKEY = '000000000210100004'.
APPEND LS_OBJECTLINK TO LT_OBJECTLINKS.
" CREATE ATTACHMENT
CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
EXPORTING
DOCUMENTDATA = LS_DOCDATA
PF_FTP_DEST = 'SAPFTPA'
PF_HTTP_DEST = 'SAPHTTP'
IMPORTING
DOCUMENTTYPE = LV_DOCTYPE
DOCUMENTNUMBER = LV_DOCNUMBER
DOCUMENTPART = LV_DOCPART
DOCUMENTVERSION = LV_DOCVERSION
RETURN = LT_RETURN
TABLES
DOCUMENTDESCRIPTIONS = LT_OBJECTDESCR
OBJECTLINKS = LT_OBJECTLINKS
DOCUMENTFILES = LT_OBJECTFILES.
IF SY-SUBRC <> 0.
MESSAGE 'Error uploading attachment' TYPE 'E'.
ENDIF.
" COMMIT
COMMIT WORK.
You should give file path and storage category. This should solve the problem.
LS_OBJECTFILE-ORIGINALTYPE = '001'. "**
LS_OBJECTFILE-storagecategory = 'DMS_C1_ST'.. "**
LS_OBJECTFILE-CREATED_BY = SY-UNAME
LS_OBJECTFILE-DOCFILE = IV_SLUG. "path that comes from the OData service.
LS_OBJECTFILE-WSAPPLICATION = 'JPG'.
APPEND LS_OBJECTFILE TO LT_OBJECTFILES.

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.