Skip to Content
0

attach one or multiple document to BOM using CSAP_MAT_BOM_MAINTAIN

Apr 14, 2017 at 07:10 PM

252

avatar image
Former Member

Hi Gurus,

I am trying to attach document as item category 'D' to existing BOM

But it is not giving any error or not working.

PFA , code . it is not giving any errors and documents are created successfully but it is not getting attached to BOM

FORM attaching_draw TABLES p_itab TYPE STANDARD TABLE
 USING p_mast_matnr TYPE matnr_d
 p_mast_werks TYPE werks_d.
**..... Document data
 DATA: ls_doc LIKE bapi_doc_draw2,
 lv_n TYPE sy-tabix,
 lv_len TYPE sy-tabix,
**..... Bapi-Returnstruktur
 ls_return LIKE bapiret2.
**.... Key feilds of the document
 DATA: BEGIN OF lt_doc OCCURS 0,
 documenttype TYPE dokar,
 documentnumber TYPE doknr,
 documentversion TYPE dokvr,
 documentpart TYPE doktl_d,
 description TYPE dktxt,
 END OF lt_doc.
**.... Originals that are checked in simultaneously
 DATA: lt_files LIKE bapi_doc_files2 OCCURS 0 WITH HEADER LINE,
**.... Short texts
 lt_drat LIKE bapi_doc_drat OCCURS 0 WITH HEADER LINE,
**.... Object links
 lt_drad LIKE bapi_doc_drad OCCURS 0 WITH HEADER LINE.
*---- Feldleiste Stücklistenkopfdaten
 DATA: BEGIN OF lt_tstk1.
 INCLUDE STRUCTURE stko_api01.
 DATA: END OF lt_tstk1.
 DATA: BEGIN OF lt_tstk2.
 INCLUDE STRUCTURE stko_api02.
 DATA: END OF lt_tstk2.
*---- Tabelle Stücklistenpositionen
 DATA: BEGIN OF lt_tstp2 OCCURS 0.
 INCLUDE STRUCTURE stpo_api03.
 DATA: END OF lt_tstp2.
*---- Tabellen für Beziehungswissen:
* Basisdaten
 DATA: BEGIN OF lt_tdep2_data OCCURS 0.
 INCLUDE STRUCTURE dep_data.
 DATA: END OF lt_tdep2_data.
* Beschreibung
 DATA: BEGIN OF lt_tdep2_descr OCCURS 0.
 INCLUDE STRUCTURE dep_descr.
 DATA: END OF lt_tdep2_descr.
* Source
 DATA: BEGIN OF lt_tdep2_source OCCURS 0.
 INCLUDE STRUCTURE dep_source.
 DATA: END OF lt_tdep2_source.
* Reihenfolge
 DATA: BEGIN OF lt_tdep2_order OCCURS 0.
 INCLUDE STRUCTURE dep_order.
 DATA: END OF lt_tdep2_order.
* Dokumentation
 DATA: BEGIN OF lt_tdep2_doc OCCURS 0.
 INCLUDE STRUCTURE dep_doc.
 DATA: END OF lt_tdep2_doc.
 DATA: lv_matnr TYPE matnr_d,
 lv_stlnr TYPE stnum,
 lv_aennr TYPE aennr,
 lv_datuv TYPE datuv,
 lv_f_date TYPE datuv_bi.
 DATA: lv_flg_warning LIKE capiflag-flwarning.
 FIELD-SYMBOLS: <fs_wa> TYPE zspm_filedetails.
***validate BOM combination.
 SELECT SINGLE matnr stlnr FROM mast INTO ( lv_matnr , lv_stlnr ) WHERE matnr = p_mast_matnr AND
 werks = p_mast_werks AND
 stlan = '4'.
 IF sy-subrc <> 0.
 MESSAGE 'No valid BOM exists' TYPE 'E' DISPLAY LIKE 'S'.
 ELSE.
 SELECT SINGLE datuv aennr FROM stko INTO ( lv_datuv , lv_aennr ) WHERE stlty = 'M' AND
 stlnr = lv_stlnr .
 ENDIF.
***validate file existance
 IF p_itab[] IS INITIAL.
 MESSAGE 'File cannot be Empty , please attach atleast one' TYPE 'E' DISPLAY LIKE 'S'.
 ELSE .
 LOOP AT p_itab ASSIGNING <fs_wa>.
 IF <fs_wa>-filename IS INITIAL.
 DELETE p_itab INDEX sy-tabix.
 ENDIF.
 ENDLOOP.
 IF p_itab[] IS INITIAL.
 MESSAGE 'File cannot be Empty , please attach atleast one' TYPE 'E' DISPLAY LIKE 'S'.
 ELSE.
 LOOP AT p_itab ASSIGNING <fs_wa>.
** Allcoate document data
 ls_doc-documenttype = 'Z02'.
 ls_doc-documentversion = '00'.
 ls_doc-documentpart = '000'.
** Check in original 1 simultaneously in the SAP Database
 REFRESH lt_files.
 CLEAR lt_files.
 BREAK x52193.
 CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
 EXPORTING
 full_name = <fs_wa>-filename
 IMPORTING
* STRIPPED_NAME =
 file_path = lt_files-docpath
 EXCEPTIONS
 x_error = 1
 OTHERS = 2.
 IF sy-subrc <> 0.
* Implement suitable error handling here
 ENDIF.
 lt_files-docfile = <fs_wa>-filename.
 DATA: lv_string TYPE string.
 lv_string = <fs_wa>-filename.
 IF lv_string CA '.'.
 lv_len = sy-fdpos + 1.
 lt_files-wsapplication = <fs_wa>-filename+lv_len(3).
 TRANSLATE lt_files-wsapplication TO UPPER CASE.
 ENDIF.
 lt_files-checkedin = abap_false.
 lt_files-active_version = abap_true.
 lt_files-originaltype = 1.
 CONDENSE lt_files-originaltype.
 APPEND lt_files.
** Object link to material master
 CLEAR lt_drad.
 REFRESH lt_drad.
** English short text
 IF <fs_wa>-filedesc IS NOT INITIAL.
 lt_drat-language = sy-langu.
 lt_drat-description = <fs_wa>-filedesc.
 APPEND lt_drat.
 ELSE.
 lt_drat-language = sy-langu.
 lt_drat-description = <fs_wa>-filename.
 APPEND lt_drat.
 ENDIF.
* ---------------------------------------------------------------------
* Create document
* ---------------------------------------------------------------------
 CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
 EXPORTING
 documentdata = ls_doc
 IMPORTING
 documenttype = lt_doc-documenttype
 documentnumber = lt_doc-documentnumber
 documentpart = lt_doc-documentpart
 documentversion = lt_doc-documentversion
 return = ls_return
 TABLES
 documentdescriptions = lt_drat
 objectlinks = lt_drad
 documentfiles = lt_files.
 IF ls_return-type CA 'EA'.
 ROLLBACK WORK.
 MESSAGE ID '26' TYPE 'I' NUMBER '000'
 WITH ls_return-message.
 ELSE.
 COMMIT WORK AND WAIT.
 APPEND lt_doc.
 ENDIF.
 ENDLOOP.
 ENDIF.
*- Datenbankprotokoll eröffnen
 CALL FUNCTION 'CALO_INIT_API'
 EXCEPTIONS
 log_object_not_found = 1
 log_sub_object_not_found = 2
 other_error = 3
 OTHERS = 4.
 WRITE lv_datuv TO lv_f_date.
*- Eröffnen der Stückliste für Änderungen
 CALL FUNCTION 'CSAP_MAT_BOM_OPEN'
 EXPORTING
 material = p_mast_matnr
 plant = p_mast_werks
 bom_usage = '4'
 valid_from = lv_f_date
 change_no = lv_aennr
 IMPORTING
 o_stko = lt_tstk2
 fl_warning = lv_flg_warning
 TABLES
 t_stpo = lt_tstp2
 EXCEPTIONS
 error = 1.
 IF sy-subrc = 0.
 DESCRIBE TABLE lt_tstp2 LINES lv_n.
 READ TABLE lt_tstp2 INDEX lv_n.
 IF sy-subrc = 0.
 LOOP AT lt_doc.
 lt_tstp2-item_categ = 'D'.
 lt_tstp2-item_no = lt_tstp2-item_no + 10.
 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
 EXPORTING
 input = lt_tstp2-item_no
 IMPORTING
 output = lt_tstp2-item_no.
 lt_tstp2-document = lt_doc-documentnumber.
 lt_tstp2-doc_type = lt_doc-documenttype.
 lt_tstp2-doc_part = lt_doc-documentpart.
 lt_tstp2-doc_vers = lt_doc-documentversion.
 lt_tstp2-rel_prod = 'X'.
 lt_tstp2-comp_qty = 1.
 APPEND lt_tstp2.
 ENDLOOP.
 MOVE-CORRESPONDING lt_tstk2 TO lt_tstk1.
 CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
 EXPORTING
 material = p_mast_matnr
 plant = p_mast_werks
 bom_usage = '4'
 alternative = '1'
 valid_from = lv_f_date
 change_no = lv_aennr
 i_stko = lt_tstk1
 fl_new_item = 'X'
 IMPORTING
 fl_warning = lv_flg_warning
 o_stko = lt_tstk2
 TABLES
 t_stpo = lt_tstp2
 EXCEPTIONS
 OTHERS = 1.
 IF sy-subrc = 0.
 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 EXPORTING
 wait = abap_true.ENDIFENDFORM.
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Apr 17, 2017 at 01:49 PM
0

Hi Evgeny Gubenko,

i am not creating any bom, i am just maintaining BOM.

i solved this by my own.

Instead of below

 lt_tstp2-document = lt_doc-documentnumber.
 lt_tstp2-doc_type = lt_doc-documenttype.
 lt_tstp2-doc_part = lt_doc-documentpart.
 lt_tstp2-doc_vers = lt_doc-documentversion.

i used the other 4 fields which is there in the same structure and it worked.

Regards

S.Janagar

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 17, 2017 at 05:02 AM
0

Hi Friends

Any updates on this

Regards

S.Janagar

Share
10 |10000 characters needed characters left characters exceeded
Evgeny Gubenko Apr 17, 2017 at 07:41 AM
0

Hi!

Try to use low-level FMs in the following sequence (below are FMs for creation of BOM):

CP_CC_S_LOAD_COMPLEX_BY_BOM

CS_CL_S_MAT_BOM_CREATE

CS_CL_S_ITM_CREATE

CP_CC_S_SAVE

BAPI_TRANSACTION_COMMIT

You can follow the logic of the class /PLMI/CL_UNITTEST_MBOM as example.

E. Gubenko

Share
10 |10000 characters needed characters left characters exceeded