ABAP check delivery header - abap

Is there a way to check document changes in the header of a delivery?
I tried it with the CHANGEDOCUMENT_READ_HEADERS.
Like this:
CALL FUNCTION 'CHANGEDOCUMENT_READ_HEADERS'
EXPORTING
objectclass = 'LIEFERUNG'
objectid = l_cdobjid
date_of_change = p_datfr
time_of_change = p_timfr
date_until = p_datto
time_until = p_timto
username = ''
TABLES
i_cdhdr = lt_cdhdr
EXCEPTIONS
OTHERS = 4.
Greetings

Related

How to remove batch number on delivery?

I need to remove the batch number (LIPS-CHARG) on the delivery item and tried with BAPI_OUTB_DELIVERY_CHANGE without success.
I can change the delivery quantity (LIPS-LFIMG) correctly with this BAPI and change the picking number (LIPS-PKIMG) with WS_DELIVERY_UPDATE_2, but can't remove the batch number.
Does someone already remove the batch number? Don't need to use this BAPI, can be another one. I just need to remove the batch in any way.
The following code works to change the delivery quantity and picking quantity. At a certain moment, I change picking quantity to zero and at this moment I need to remove the batch number.
"&**** Begin structures BAPI_OUTB_DELIVERY_CHANGE *******
ls_header_data-deliv_numb = p_vbeln.
ls_header_control-deliv_numb = p_vbeln.
APPEND INITIAL LINE TO lt_item_data ASSIGNING FIELD-SYMBOL(<ls_item_data>).
<ls_item_data>-deliv_numb = p_vbeln.
<ls_item_data>-deliv_item = lv_posnn.
<ls_item_data>-material = <ls_alv>-matnr.
<ls_item_data>-batch = <ls_alv>-charg.
<ls_item_data>-hieraritem = <ls_lips>-posnr.
<ls_item_data>-usehieritm = '1'.
<ls_item_data>-dlv_qty = lv_delivery_qtd. "my delivery quantity
<ls_item_data>-dlv_qty_imunit = lv_delivery_qtd. "my delivery quantity
<ls_item_data>-fact_unit_nom = <ls_lips>-umvkz.
<ls_item_data>-fact_unit_denom = <ls_lips>-umvkn.
<ls_item_data>-sales_unit = <ls_lips>-vrkme.
APPEND INITIAL LINE TO lt_item_control ASSIGNING FIELD-SYMBOL(<ls_item_control>).
<ls_item_control>-deliv_numb = p_vbeln.
<ls_item_control>-deliv_item = lv_posnn.
<ls_item_control>-chg_delqty = 'X'.
"&**** End structures BAPI_OUTB_DELIVERY_CHANGE *******
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
header_data = ls_header_data
header_control = ls_header_control
delivery = p_vbeln
TABLES
item_data = lt_item_data
item_control = lt_item_control
return = lt_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
"&**** Begin structures WS_DELIVERY_UPDATE_2 *******
APPEND INITIAL LINE TO lt_vbpok ASSIGNING FIELD-SYMBOL(<ls_vbpok>).
<ls_vbpok>-vbeln_vl = <ls_lips>-vbeln.
<ls_vbpok>-posnr_vl = <ls_lips>-posnr.
<ls_vbpok>-vbeln = <ls_lips>-vgbel.
<ls_vbpok>-posnn = <ls_lips>-vgpos.
<ls_vbpok>-matnr = <ls_lips>-matnr.
<ls_vbpok>-werks = <ls_lips>-werks.
<ls_vbpok>-umvkz = <ls_lips>-umvkz.
<ls_vbpok>-umvkn = <ls_lips>-umvkn.
<ls_vbpok>-gewei = <ls_lips>-gewei.
<ls_vbpok>-charg = <ls_alv>-charg.
<ls_vbpok>-pikmg = lv_picking_qtd. "my picking quantity
ls_vbkok-vbeln_vl = <ls_lips>-vbeln.
ls_vbkok-vbtyp_vl = 'J'.
ls_vbkok-komue = 'X'.
ls_vbkok-gewei = <ls_lips>-gewei.
ls_vbkok-anzpk = lv_anzpk.
ls_vbkok-kzapk = 'X'.
"&**** End structures WS_DELIVERY_UPDATE_2 *******
CALL FUNCTION 'WS_DELIVERY_UPDATE_2'
EXPORTING
vbkok_wa = ls_vbkok
delivery = p_vbeln
synchron = abap_true
update_picking = abap_true
nicht_sperren_1 = abap_true
commit = abap_false
if_error_messages_send = abap_false
IMPORTING
ef_error_any = ls_error-any
ef_error_in_item_deletion = ls_error-in_item_deletion
ef_error_in_pod_update = ls_error-in_pod_update
ef_error_in_interface = ls_error-in_interface
ef_error_in_goods_issue = ls_error-in_goods_issue
ef_error_in_final_check = ls_error-in_final_check
ef_error_partner_update = ls_error-partner_update
ef_error_sernr_update = ls_error-sernr_update
TABLES
vbpok_tab = lt_vbpok.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
I found my error!
When we need to remove the batch number, we don't need to send value on ITEM_DATA-DELIV_ITEM.
In my code, I was sending '90000001' on ITEM_DATA-DELIV_ITEM and '00010' on ITEM_DATA-USEHIERITM, but to work I just send ITEM_DATA-USEHIERITM and the batch number was removed correctly.
Thanks all!

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.

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.

LINQ - query Where method error

I have the following code that I cannot make it work.
I am new using Linq and Entity framework.
I attach the code sample, and also, and image with the error.
What I am trying to do, is a piece of code where I can add "Where"s dynamically.
Imports System.Linq
Private cntx As New attmanager_bdEntities()
Dim query = (From persona In cntx.tblperson
Select
ATT_TYPE = persona.att_type,
ATT_RECOG = persona.att_recog,
APELLIDO = persona.surname,
NOMBRE = persona.name,
PERSONA_ID = persona.id,
DNI = persona.identification,
DIRECCION = persona.address,
PIN = persona.att_pin,
TIPOASISTENCIA = persona.att_type,
EMAIL = persona.email,
EXTRA = persona.extra,
TELEFONO = persona.phone,
FECHANACIMIENTO = persona.birth,
SEXO = persona.sex,
DELETED = persona.deleted,
AREA_ID = persona.tblarea.id,
AREA = persona.tblarea.name,
CIUDAD = persona.tblcity.name,
CIUDAD_ID = persona.tblcity_id,
PROVINCIA = persona.tblcity.tblstate.name,
PAIS = persona.tblcity.tblstate.tblcountry.name
Where (DELETED = 0))
query = query.Where(Function(a) a.AREA_ID = 1)
'Here I should put another "Where"s
dbgrid_listado.DataSource = query.ToList()
Error translation:
Unexpected exception trying to load "personas"
Details:
Could not invoke the method because could not call a 'Public Function Where ..........
......
......
......
...... with those arguments.
The parameter 'predicate' of the argument could not be converted to VB$AnonymousDelegate_0(Of Object,Object)' into 'String'
Why not this?
Dim query = (From persona In cntx.tblperson
Where persona.DELETED = 0
Select persona)
Now your type is "persona" instead of an anonymous type of 21 random properties.
query = query.Where(Function(a) a.AREA_ID = 1)
Working with anonymous types is always tricky. Also, I always put the select last...
You could always list out the properties in an anonymous type like this:
Dim query = (From persona In cntx.tblperson
Where persona.DELETED = 0
Select New With {
ATT_TYPE = persona.att_type,
ATT_RECOG = persona.att_recog,
APELLIDO = persona.surname,
NOMBRE = persona.name,
PERSONA_ID = persona.id,
DNI = persona.identification,
DIRECCION = persona.address,
PIN = persona.att_pin,
TIPOASISTENCIA = persona.att_type,
EMAIL = persona.email,
EXTRA = persona.extra,
TELEFONO = persona.phone,
FECHANACIMIENTO = persona.birth,
SEXO = persona.sex,
DELETED = persona.deleted,
AREA_ID = persona.tblarea.id,
AREA = persona.tblarea.name,
CIUDAD = persona.tblcity.name,
CIUDAD_ID = persona.tblcity_id,
PROVINCIA = persona.tblcity.tblstate.name,
PAIS = persona.tblcity.tblstate.tblcountry.name
})
Maybe the where clause using the anon type is messing it up and using persona.DELETED = 0 would help?
I got it ....
I created a new project
I migrate all the resources (images for example) from the old project to this new one.
Opened the NuGet package manager, and installed EF6
Also installed MySQL.Data and MySQL EF6 provider.
I imported the forms, from the original project to the new one.
Now I can do what you guys suggested.
The Problem ??? .... The version on .Net framework, and the EF I was using.
I had t update everything.

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.