Add table rows to a TR programmatically? - abap

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.

Related

Update SD condition records using FM/BAPI

I am trying to update DATBI field of A* pricing condition tables using the data coming from excel file.I have tried below approaches but unable to update the entry as DATBI is key field. It creates new record instead of updating the existing one. Approaches:
FM: RV_CONDITION_COPY(with mai tain_ mode as B)
FM: RV_CONDITION_MAINTENANCE(using maintain_mode as B)
BAPI_PRICES_CONDITIONS(It changes KONH table but not A* table.Also, as per note#1135984,we shouldn't be using it)
FM:RV_KONDITION_SICHERN_V13A in update mode(This gives sy-subrc 4 in this FM post update A* from table__ syntax as the datbi is new coming from my excel file)
Idoc COND_A04(This also creates new entry instead of updating existing one)
BDC is the only approach that I can think of but looking at VK12 screen, it has been observed that based on key combination and its underlying A* tables, it should be dynamic.
Can you please help in this regard?Is there any dynamic BDC for VK12?
Undoubtedly we shouldn't use BAPI_PRICES_CONDITIONS, and note 94443 describes the problems it can cause when you push incorrect conditions into system, but sometime there is no way to avoid it. I tried this FM and it definitely worked on my system.
Here is the code for updating A009 table:
* header table
APPEND INITIAL LINE TO lt_head ASSIGNING <fs_head>.
<fs_head>-operation = '009'.
<fs_head>-cond_usage = 'A'.
<fs_head>-table_no = '007'.
<fs_head>-applicatio = 'V'.
<fs_head>-cond_type = 'ZP15'.
<fs_head>-valid_from = '20210103'.
<fs_head>-valid_to = '99991231'.
<fs_head>-cond_no = '$000000001'.
<fs_head>-varkey = 'BE110101001000635199993112'.
** items
APPEND INITIAL LINE TO lt_konh ASSIGNING <fs_konh>.
<fs_konh>-operation = '009'.
<fs_konh>-cond_no = '$000000001'.
<fs_konh>-cond_usage = 'A'.
<fs_konh>-table_no = '007'.
<fs_konh>-applicatio = 'V'.
<fs_konh>-cond_type = 'ZP15'.
<fs_konh>-valid_from = '20210103'.
<fs_konh>-valid_to = '99991231'.
<fs_konh>-created_by = sy-uname.
<fs_konh>-creat_date = sy-datum.
APPEND INITIAL LINE TO lt_konp ASSIGNING <fs_konp>.
<fs_konp>-operation = '009'.
<fs_konp>-cond_no = '$000000001'.
<fs_konp>-cond_count = '01'.
<fs_konp>-applicatio = 'V'.
<fs_konp>-cond_type = 'ZP15'.
<fs_konp>-scaletype = 'A'.
<fs_konp>-scalebasin = space.
<fs_konp>-scale_qty = '0'.
<fs_konp>-cond_p_unt = '1'.
<fs_konp>-cond_unit = 'ΠΆ'.
<fs_konp>-calctypcon = 'C'.
<fs_konp>-cond_value = '160'.
<fs_konp>-condcurr = 'EUR'.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
pi_initialmode = abap_true
TABLES
ti_bapicondct = lt_head
ti_bapicondhd = lt_konh
ti_bapicondit = lt_konp
ti_bapicondqs = lt_konm
ti_bapicondvs = lt_konw
to_bapiret2 = lt_return
to_bapiknumhs = lt_knumh
to_mem_initial = lt_buffer
EXCEPTIONS
update_error = 1
OTHERS = 2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = abap_true.
I tried the above code and record with the specified key was properly updated with new valid to field (DATAB). Updating DATBI is a bit more complicated since it is included in the primary key and cannot be updated in one step. You must delete the record with the old DATBI and the create the new one. In this blog you can read more about how to use this BAPI:
https://blogs.sap.com/2019/07/22/how-to-use-bapi_prices_conditions-to-mass-upload-price-conditions/

Add business objects to contacts

I've successfully created a contact in the SAP IS-U (Release 618) system using the function: BCONTACT_CREATE
EDIT:
Since this question was voted "close" for being "too broad" - here's some very specific code:
DATA:
ls_contact TYPE bpc01_bcontact_auto,
ls_contact_properties TYPE bcont,
lv_contact_text TYPE string,
lv_bp TYPE bu_partner,
lv_bpcontact_id TYPE ct_contact,
lv_no_dialog TYPE flag VALUE abap_true,
lv_repid TYPE syst-repid.
* Main logic
lv_contact_text = 'Test'.
lv_bp = '0010000062'.
ls_contact_properties-cclass = '0003'.
ls_contact_properties-activity = '0001'.
ls_contact_properties-f_coming = '3'.
* Mapping
*--------------------------------------------------------------------*
ls_contact-notice-line = lv_contact_text.
ls_contact-bcontd = ls_contact_properties.
* set flag to use auto data
ls_contact-bcontd_use = abap_true.
lv_repid = sy-repid.
CALL FUNCTION 'BCONTACT_CREATE'
EXPORTING
x_no_dialog = lv_no_dialog
x_auto = ls_contact
x_prgcontext = lv_repid
x_partner = lv_bp
IMPORTING
y_new_bpcontact = lv_bpcontact_id
EXCEPTIONS
existing = 1
foreign_lock = 2
number_error = 3
general_fault = 4
input_error = 5
not_authorized = 6
OTHERS = 7.
When I open the created contact in the BCT2 transaction I see the nothing under Business-Objects:
How can I programmatically add a business object to a contact, so that it is displayed here like this?
I found it a solution!
First create variables (a table and a structure for filling the table) for your business objects that you want to add (I saw some code that had a limit of 5 so I just set that too to be safe):
lt_business_objs TYPE TABLE OF bpc_obj INITIAL SIZE 5,
ls_business_obj TYPE bpc_obj,
Next append your object, in this example I'm just appending one:
* Append business objects
*--------------------------------------------------------------------*
ls_business_obj-objkey = 'The value here may be your business object input value'.
ls_business_obj-objrole = 'DEFAULT'. "Don't know what this is for...
ls_business_obj-objtype = 'OBJECT_NAME'. "Name of your business object - seen in table TOJTB
APPEND ls_business_obj TO lt_business_objs.
And lastly put the object list into the contact structure:
ls_contact-iobjects = lt_business_objs.

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.

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.

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.