BAPI for getting material and order BOM? - abap

Is there a BAPI for getting material and order BOM?
Function modules won't help as those can't be called remotely.

You can use CSAP_MAT_BOM_READ module like this
DATA:
lt_stpo TYPE TABLE OF stpo_api02,
lt_stko TYPE TABLE OF stko_api02,
lt_dep_data TYPE TABLE OF csdep_dat,
lt_dep_descr TYPE TABLE OF csdep_desc,
lt_dep_order TYPE TABLE OF csdep_ord,
lt_dep_source TYPE TABLE OF csdep_sorc,
lt_dep_doc TYPE TABLE OF csdep_doc,
lt_doc_link TYPE TABLE OF csdoc_link,
lt_dmu_tmx TYPE TABLE OF csdmu_tmx,
lt_ltx_line TYPE TABLE OF csltx_line,
lt_stpu TYPE TABLE OF stpu_api01.
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
material = 'P-501'
plant = '1000'
bom_usage = '1'
TABLES
t_stpo = lt_stpo
t_stko = lt_stko
t_dep_data = lt_dep_data
t_dep_descr = lt_dep_descr
t_dep_order = lt_dep_order
t_dep_source = lt_dep_source
t_dep_doc = lt_dep_doc
t_doc_link = lt_doc_link
t_dmu_tmx = lt_dmu_tmx
t_ltx_line = lt_ltx_line
t_stpu = lt_stpu
EXCEPTIONS
error = 1
OTHERS = 2.
It is remote-enabled so can be perfectly called outside

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 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.

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.

Read material text for multiple languages at the same time with READ_TEXT FM

I have managed to make the READ_TEXT FM work only for one cID at a time on multiple calls of function read_text(for example I found out how to access it for cID = 'GRUN' cObject = 'MATERIAL'. Can anyone advise how to connect read_text function so that inspection text(cID = 'GRUN' cObject = 'MATERIAL') will be dispalyed in my alv grid on the same line with material details?
FORM READTEXT.
data: it_MVKE type standard table of MVKE initial size 0.
data: lMVKE like MVKE, lMAKT like MAKT, lT002 like T002 ,
lTDNAME like THEAD-TDNAME,"text header
it_TLINE type standard table of TLINE,
wa_TLINE type TLINE.
data: cObject(10) type c, cID(4) type c.
select MATNR from MARA into corresponding fields of table it_MVKE
where MATNR in Material order by MATNR.
cID = 'GRUN'. cObject = 'MATERIAL'. "Text date principale "
loop at it_MVKE into lMVKE.
lTDNAME = lMVKE-MATNR.
select spras from T002 into lT002.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = cID
LANGUAGE = lT002-SPRAS
NAME = lTDNAME
OBJECT = cObject
TABLES
LINES = it_TLINE
EXCEPTIONS
ID = 1
OTHERS = 8.
IF SY-SUBRC EQ 0.
select single * from MAKT into lMAKT where MATNR eq lMVKE-MATNR
and SPRAS eq lT002-SPRAS.
LOOP AT it_TLINE INTO wa_TLINE.
wa_join-TEXTPRI = wa_TLINE-TDLINE.
append wa_join to lt_join.
clear wa_join.
ENDLOOP.
ENDIF.
ENDSELECT.
ENDLOOP.
ENDFORM.
You cannot do like this. Function modules in SAP accept only single parameter at one time, unless this parameter is specified as a table type or in TABLES section.
However, here is workaround from my previous answer you can use to get rid of READ_TEXT at all.
As forgetaboutme said, put you cIDs into itab together with TDNAMEs:
wa_cids-cid = 'GRUN'.
wa_cids-cobject = 'MATERIAL'.
if cID = '0001'.
concatenate lMVKE-MATNR lMVKE-VKORG lMVKE-VTWEG into wa_cids-lTDNAME.
else.
lTDNAME = lMVKE-MATNR.
endif.
append wa_cids to it_cids.
Select texts from db table considering your itab.
SELECT l~tdname l~clustr l~clustd
INTO CORRESPONDING FIELDS OF TABLE t_stxl
FROM stxl AS l
JOIN stxh AS h
ON h~tdobject = l~tdobject
AND h~tdname = l~tdname
AND h~tdid = l~tdid
FOR ALL ENTRIES it_cids
WHERE l~relid = 'TX' "standard text
AND h~tdobject = it_cids-cobject
AND h~tdname = it_cids-lTDNAME
AND h~tdid = it_cids-cid
AND l~tdspras = sy-langu.
Convert them from raw form into readable form
CLEAR: t_stxl_raw[], t_tline[].
APPEND VALUE ty_stxl_raw( clustr = <stxl>-clustr clustd = <stxl>-clustd ) TO t_stxl_raw.
IMPORT tline = t_tline FROM INTERNAL TABLE t_stxl_raw.
Read them
LOOP AT t_tline ASSIGNING <tline>.
wa_Report-TEXT = <tline>-TDLINE.
append wa_Report to it_Report.
ENDLOOP.
You can create an internal table of cIDs & cObjects like this:
types: begin of cids,
cid(4) type c,
cobject(10) type c,
end of cids.
data: wa_cids type cids.
data: it_cids type standard table of cids.
Then you can simply append all the different types of cIDs/cObjects you have to your internal table:
wa_cids-cid = 'GRUN'.
wa_cids-cobject = 'MATERIAL'.
append wa_cids to it_cids.
Then loop over your internal table calling function 'READ_TEXT'
loop at it_cids into wa_cids.
call function 'READ_TEXT'
exporting
client = sy-mandt
id = wa_cids-cid
language = lt002-spras "p_SPRAS
name = ltdname
object = wa_cids-cobject
tables
lines = it_tline
exceptions
id = 1
others = 8.
* Do what you need to do with it_tline here.
endloop.
* Rest of code here

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.