Code: Alles auswählen.
"Definition
gt_stpo TYPE TABLE OF stpo,
gs_stpo LIKE LINE OF gt_stpo,
ev_stlnr TYPE stnum VALUE '00087523',
ev_matnr TYPE CSAP_MBOM-MATNR VALUE '1101011115F01',
ev_werks TYPE CSAP_MBOM-WERKS VALUE '0510',
ev_stlan TYPE stlan VALUE '1'.
"
"
"
METHOD create_testDouble_partslist.
INSERT INTO MAST
VALUES @( VALUE #(
matnr = ev_matnr "1101011115F01
werks = ev_werks "0510
stlan = ev_stlan "1
stlnr = ev_stlnr "00087523
stlal = 1
andat = 01012020
annam = 'XXX'
) ).
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
"STZU:
INSERT INTO STZU
VALUES @( VALUE #(
stlty = 'M'
stlnr = ev_stlnr
stlan = ev_stlan
wrkan = ev_werks
stldt = sy-datum
) ).
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
INSERT INTO STKO
VALUES @( VALUE #(
stlty = 'M' "MatStückliste
stlnr = ev_stlnr
stlal = 1
stkoz = 1
datuv = sy-datum
wrkan = ev_werks
stlst = 01
) ).
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
"Fill itab with STPO Entries
gt_stpo = VALUE #( BASE gt_stpo ( stlty = 'M' stlnr = ev_stlnr stlkn = 1 stpoz = 5 datuv = sy-datum idnrk = '180447103501440' meins = 'ST' menge = 3 postp = 'L' ) ).
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
gt_stpo = VALUE #( BASE gt_stpo ( stlty = 'M' stlnr = ev_stlnr stlkn = 2 stpoz = 8 datuv = sy-datum idnrk = 'QM9999' meins = 'ST' menge = 1 postp = 'L' ) ).
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
gt_stpo = VALUE #( BASE gt_stpo ( stlty = 'M' stlnr = ev_stlnr stlkn = 3 stpoz = 12 datuv = sy-datum idnrk = '985219' meins = 'ST' menge = 8 postp = 'L' ) ).
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
"Insert created STPOs
INSERT stpo FROM TABLE gt_stpo.
if sy-subrc <> 0.
RAISE EXCEPTION TYPE lcx_local_exception.
endif.
ENDMETHOD.
METHOD read_bmo_with_test_data.
"when
TRY.
lo_cut->read_bmo( ie_matnr = ev_matnr ie_plant = ev_werks ie_usage = '1'
ie_valid_from = '29.11.2020').
CATCH lcx_local_exception INTO gx_oref.
cl_abap_unit_assert=>fail( msg = 'Parts List cannot be displayed' ).
ENDTRY.
"then
cl_abap_unit_assert=>assert_equals(
act = lo_cut->mt_tstp
exp = gt_stpo
msg = 'STPO: Table Content differs' ).
ENDMETHOD.
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report YCS_BOM_UPLOAD *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ycs_bom_upload_seg .
DATA gt_exclude TYPE STANDARD TABLE OF syucomm.
DATA rc TYPE i.
* Data Filenames: MATNR.txt
* BMK(SORTF);MENGE;MATNR;CATEG;SHKZ
*e.g.
* -SH14;5,00;271252832;L;X
* -*;6,00;271252838;L;
* -A10;7,00;271252844;L;X
* -1U1;2,00;271259006;D;
* POPUP Selection def
TYPES:
BEGIN OF ty_sel,
component TYPE stpo_api02-component,
change_no TYPE stpo_api02-change_no,
bom_text TYPE stko_api01-bom_text,
checkbox(1),
END OF ty_sel.
DATA g_exit.
DATA:
* Data displayed
gt_seldat TYPE TABLE OF ty_sel.
* Datenfile
DATA: BEGIN OF it_bom OCCURS 0,
sortstring TYPE sortp,
comp_qty TYPE i,
component TYPE matnr,
item_categ TYPE postp,
item_no TYPE sposn,
item_text2 TYPE potx2,
bulk_mat TYPE schgt,
END OF it_bom.
TYPES: BEGIN OF t_files,
fname TYPE file_table-filename,
component TYPE matnr,
* aennr TYPE csap_mbom-aennr,
END OF t_files.
FIELD-SYMBOLS <p> TYPE t_files.
* File Table
DATA: it_files TYPE TABLE OF t_files.
DATA: ls_files TYPE t_files.
DATA: i TYPE i,
gv_heute TYPE csap_mbom-datuv.
* Datei
DATA f_name TYPE string.
START-OF-SELECTION.
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-p00.
PARAMETERS: p_werk TYPE marc-werks OBLIGATORY.
PARAMETERS: p_stlan TYPE mast-stlan DEFAULT '3' OBLIGATORY.
PARAMETERS: p_date TYPE d DEFAULT sy-datum.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN SKIP 4.
*** Drucktaste 1
SELECTION-SCREEN PUSHBUTTON /22(40) text-pb1 USER-COMMAND pb1.
INITIALIZATION.
p_werk = '1207'.
* siehe RSSYSTDB Gui Status %_00
*** "Ausführen" verbieten
APPEND 'ONLI' TO gt_exclude.
*** "Ausführen + Drucken" verbieten
APPEND 'PRIN' TO gt_exclude.
*** "Im Hintergrund ausführen" verbieten
APPEND 'SJOB' TO gt_exclude.
*** Variante sichern verbieten
APPEND 'SPOS' TO gt_exclude.
*** Variante löschen verbieten
APPEND 'VDEL' TO gt_exclude.
*** Variante holen
APPEND 'GET' TO gt_exclude.
*** Variante anzeigen verbieten
APPEND 'VSHO' TO gt_exclude.
* ZURÜCK unterdrücken
* APPEND 'E' TO gt_exclude.
* BEENDEN unterdrücken
APPEND 'ENDE' TO gt_exclude.
* ABBRECHEN unterdrücken
APPEND 'ECAN' TO gt_exclude.
*** Aktuellen Status setzen und obige Funktionen verbieten
CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = sy-pfkey
TABLES
p_exclude = gt_exclude.
* Datumsformat = DD.MM.JJJJ
WRITE p_date TO gv_heute.
*** Selektionsbild (PAI)
AT SELECTION-SCREEN.
CASE sy-ucomm.
*** Drucktasten abfragen
WHEN 'PB1'.
FREE it_bom.
rc = 0.
PERFORM file_select.
IF rc NE 0.
EXIT.
ENDIF.
* Read the selected files into it_files
PERFORM update_filetab.
IF g_exit IS INITIAL.
LOOP AT it_files ASSIGNING <p>.
rc = 0.
PERFORM file_upload.
IF rc NE 0.
EXIT.
ENDIF.
PERFORM renew_bom.
IF rc = 1 OR rc = 2.
EXIT.
ENDIF.
rc = 0.
PERFORM maint_bom.
ENDLOOP.
ENDIF.
* IF rc NE 0.
* Ausgabe des Protokolls
CALL FUNCTION 'Y_BAL_LOG'
EXPORTING
i_display = 'X'
i_refresh = 'X'
i_repid = sy-repid
EXCEPTIONS
error_create = 1
error_add_message = 2
error_refresh = 3
error_display_profile = 4
error_display = 5
OTHERS = 6.
* LEAVE PROGRAM.
* EXIT.
* ENDIF.
* MESSAGE s030(29) WITH <p>-component .
WHEN OTHERS.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form file_select
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM file_select.
DATA file_table TYPE filetable WITH HEADER LINE.
DATA lv_title TYPE string.
DATA lv_filter TYPE string.
lv_title = 'Open BOM file'(014).
lv_filter = 'BOM-file(*.TXT)|*.txt'.
REFRESH: it_files,file_table.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = lv_title
initial_directory = 'C:\temp'
file_filter = lv_filter
multiselection = 'X'
CHANGING
file_table = file_table[]
rc = rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0 OR rc < 1.
rc = 1.
ELSE.
LOOP AT file_table INTO f_name.
ls_files-fname = f_name.
APPEND ls_files TO it_files.
ENDLOOP.
rc = 0.
ENDIF.
ENDFORM. "file_select
*&---------------------------------------------------------------------*
*& Form file_upload
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM file_upload.
DATA it_data TYPE TABLE OF tab512.
DATA ls_data TYPE tab512.
DATA lv_fname TYPE string.
DATA lt_split TYPE TABLE OF tab512.
DATA ls_split TYPE sychar512.
DATA k TYPE i.
DATA lv_index TYPE i.
lv_fname = <p>-fname.
REFRESH it_bom.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_fname
filetype = 'ASC'
has_field_separator = 'X'
CHANGING
data_tab = it_data
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0 .
rc = 1.
EXIT.
ENDIF.
LOOP AT it_data INTO ls_data.
lv_index = sy-tabix * 10.
CLEAR it_bom.
SPLIT ls_data AT ';' INTO TABLE lt_split.
k = lines( lt_split ).
IF k > 0.
* GET BMK
READ TABLE lt_split INDEX 1 INTO ls_split.
IF sy-subrc = 0.
CONDENSE ls_split NO-GAPS.
it_bom-sortstring = ls_split.
ELSE.
CLEAR it_bom-sortstring.
ENDIF.
* GET Quantity
READ TABLE lt_split INDEX 2 INTO ls_split.
IF sy-subrc = 0.
CONDENSE ls_split NO-GAPS.
REPLACE ',' IN ls_split WITH '.' IN CHARACTER MODE.
it_bom-comp_qty = ls_split.
ELSE.
CLEAR it_bom-comp_qty.
ENDIF.
* GET Component
READ TABLE lt_split INDEX 3 INTO ls_split.
IF sy-subrc = 0.
CONDENSE ls_split NO-GAPS.
TRANSLATE ls_split TO UPPER CASE.
* Matnr mapping
CASE ls_split(1).
WHEN 'A'.
CONCATENATE '5011' ls_split+1 INTO it_bom-component.
WHEN 'B'.
CONCATENATE '5012' ls_split+1 INTO it_bom-component.
WHEN '3'.
CONCATENATE '5013' ls_split+1 INTO it_bom-component.
WHEN OTHERS.
it_bom-component = ls_split.
ENDCASE.
ELSE.
CLEAR it_bom-component.
ENDIF.
* GET Item Category
READ TABLE lt_split INDEX 4 INTO ls_split.
IF sy-subrc = 0.
CONDENSE ls_split NO-GAPS.
it_bom-item_categ = ls_split.
ELSE.
CLEAR it_bom-item_categ.
ENDIF.
* GET additional Document info text
IF it_bom-item_categ = 'D'.
READ TABLE lt_split INDEX 5 INTO ls_split.
IF sy-subrc = 0.
CONDENSE ls_split NO-GAPS.
it_bom-item_text2 = ls_split.
ELSE.
CLEAR it_bom-item_text2.
ENDIF.
ELSE.
CLEAR it_bom-item_text2.
ENDIF.
* GET Bulk Mat hook
READ TABLE lt_split INDEX 6 INTO ls_split.
IF sy-subrc = 0 .
CONDENSE ls_split NO-GAPS.
IF ls_split IS INITIAL.
CLEAR it_bom-bulk_mat.
ELSE.
it_bom-bulk_mat = 'X'.
ENDIF.
ELSE.
CLEAR it_bom-bulk_mat.
ENDIF.
* GET Posnr
it_bom-item_no = lv_index.
APPEND it_bom.
ENDIF." k>0
ENDLOOP.
*rc = 1.
ENDFORM. "file_upload
*&---------------------------------------------------------------------*
*& Form renew_bom
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM renew_bom.
CONSTANTS: lc_base_quan TYPE basmn_bi VALUE '1'. "Ticket#4293878 insert
* DATA lv_ans(1).
* DATA lv_matnr TYPE matnr.
* DATA lv_aennr TYPE aennr.
DATA lv_tstko TYPE stko_api01.
* DATA ls_stko TYPE stko_api02.
* DATA lt_stko TYPE TABLE OF stko_api02.
* DATA ls_stpo TYPE stpo_api02.
* DATA lt_stpo TYPE TABLE OF stpo_api02.
** Teste ob Materialstückliste schon existiert
* SELECT COUNT(*) FROM mast WHERE
* matnr = <p>-component AND
* werks = p_werk AND
* stlan = p_stlan.
* Check BOM exisitence (incl. ChangeNo)
* CALL FUNCTION 'CSAP_MAT_BOM_READ'
* EXPORTING
* material = <p>-component
* plant = p_werk
* bom_usage = p_stlan
* TABLES
* t_stpo = lt_stpo
* t_stko = lt_stko
* EXCEPTIONS
* error = 1
* OTHERS = 2.
*
* IF sy-subrc = 0.
* READ TABLE lt_stko INDEX 1 INTO ls_stko.
*
* LOOP AT lt_stpo INTO ls_stpo WHERE change_no NE ' '.
* EXIT.
* ENDLOOP.
*
** check for HEAD change number and POS change number
* IF ls_stpo-change_no IS INITIAL AND ls_stko-chg_no IS INITIAL.
* ELSE.
* PERFORM write_log USING <p>-component 'discarded - Change numbers'(016).
* CLEAR <p>-component.
* EXIT.
* ENDIF.
*
* ENDIF."sy-subrc
* IF NOT lt_stko[] IS INITIAL.
* für BOM_OPEN
** DATA: BEGIN OF tstpo2 OCCURS 0.
** INCLUDE STRUCTURE stpo_api02.
** DATA: END OF tstpo2.
** DATA ls_tstpo2 TYPE stpo_api02.
**
** REFRESH tstpo2.
** CALL FUNCTION 'CSAP_MAT_BOM_OPEN'
** EXPORTING
** material = <p>-component
** plant = p_werk
** bom_usage = p_stlan
** valid_from = ls_stko-valid_from
*** change_no = lv_aennr
** fl_no_change_doc = 'X'
** TABLES
** t_stpo = tstpo2
** EXCEPTIONS
** error = 1
** OTHERS = 2.
**
** IF sy-subrc = 0.
** LOOP AT tstpo2 INTO ls_tstpo2.
**
** ls_tstpo2-fldelete = 'X'.
**
** CALL FUNCTION 'CSAP_BOM_ITEM_MAINTAIN'
** EXPORTING
** i_stpo = ls_tstpo2
** EXCEPTIONS
** error = 1
** OTHERS = 2.
**
** ENDLOOP.
**
** ENDIF.
**
**
** CALL FUNCTION 'CSAP_MAT_BOM_CLOSE'
** EXCEPTIONS
** error = 1
** OTHERS = 2.
**
** IF sy-subrc <> 0.
** ENDIF.
rc = 0.
CALL FUNCTION 'CSAP_MAT_BOM_DELETE'
EXPORTING
material = <p>-component
plant = p_werk
bom_usage = p_stlan
* valid_from = ls_stko-valid_from
* change_no = lv_aennr
fl_commit_and_wait = 'X'
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID 'SY' TYPE 'E' NUMBER '002' WITH
* 'Error while trying to delete BOM.'(011).
ENDIF.
*- Materialstückliste anlegen (nur Kopfdaten)
*- Kopfdaten füllen
* lv_tstko-base_quan = '1.000'. " Ticket#4293878 delete
lv_tstko-base_quan = lc_base_quan. " Ticket#4293878 insert
lv_tstko-bom_text = 'Bill of Material from file'(012).
CALL FUNCTION 'CSAP_MAT_BOM_CREATE'
EXPORTING
material = <p>-component
plant = p_werk
bom_usage = p_stlan
valid_from = gv_heute
* change_no = <p>-aennr
i_stko = lv_tstko
EXCEPTIONS
error = 1.
IF sy-subrc EQ 1.
MESSAGE ID 'SY' TYPE 'E' NUMBER '002' WITH
'Error trying to create BOM.'(013).
ENDIF.
* ELSE.
* existiert nicht - neu anlegen
*- Materialstückliste anlegen (nur Kopfdaten)
*- Kopfdaten füllen
* lv_tstko-base_quan = '1.000'.
* lv_tstko-bom_text = 'Bill of Material from file'(012).
*
* CALL FUNCTION 'CSAP_MAT_BOM_CREATE'
* EXPORTING
* material = <p>-component
* plant = p_werk
* bom_usage = p_stlan
* valid_from = gv_heute
** change_no = <p>-aennr
* i_stko = lv_tstko
* EXCEPTIONS
* error = 1.
*
* IF sy-subrc EQ 1.
* MESSAGE ID 'SY' TYPE 'E' NUMBER '002' WITH
* 'Error trying to create BOM.'(013).
* ENDIF.
*
* ENDIF."bom exist
ENDFORM. "renew_bom
*&---------------------------------------------------------------------*
*& Form maint_bom
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM maint_bom.
* für BOM_OPEN
DATA: BEGIN OF tstpo2 OCCURS 0.
INCLUDE STRUCTURE stpo_api02.
DATA: END OF tstpo2.
DATA ls_tstpo2 TYPE stpo_api02.
DATA lv_matnr TYPE matnr.
DATA lv_ptext(80).
DATA lv_txt(6).
DATA lv_cnt TYPE i.
CHECK NOT <p>-component IS INITIAL.
* Böse Falle !
DO 100 TIMES.
WAIT UP TO 1 SECONDS.
CALL FUNCTION 'CSAP_MAT_BOM_OPEN'
EXPORTING
material = <p>-component
plant = p_werk
bom_usage = p_stlan
valid_from = gv_heute
* change_no = <p>-aennr
fl_no_change_doc = 'X'
TABLES
t_stpo = tstpo2
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc = 0. " Test(ohne wait) erreicht 4-5 durchläufe !
EXIT.
ENDIF.
ENDDO.
IF sy-subrc = 0.
i = lines( it_bom ).
LOOP AT it_bom.
lv_cnt = sy-tabix.
CLEAR ls_tstpo2.
MOVE-CORRESPONDING it_bom TO ls_tstpo2.
* ls_tstpo2-item_categ = 'L'. "Mußeingabe
IF ls_tstpo2-bulk_mat = 'X' AND ls_tstpo2-item_categ = 'L'.
ls_tstpo2-rel_cost = space.
ls_tstpo2-rel_engin = space.
ls_tstpo2-rel_pmaint = space.
ls_tstpo2-rel_sales = space.
ls_tstpo2-rel_prod = 'X'.
ENDIF.
* CLEAR ls_tstpo2-BULK_MAT.
IF ls_tstpo2-item_categ = 'D'.
ls_tstpo2-document = ls_tstpo2-component.
CLEAR ls_tstpo2-component.
CLEAR ls_tstpo2-bulk_mat.
ls_tstpo2-doc_type = 'SEG'.
ENDIF.
CALL FUNCTION 'CSAP_BOM_ITEM_MAINTAIN'
EXPORTING
i_stpo = ls_tstpo2
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
IF ls_tstpo2-component IS INITIAL.
PERFORM write_log USING ls_tstpo2-document 'could not be saved'(009).
ELSE.
PERFORM write_log USING ls_tstpo2-component 'could not be saved'(009).
ENDIF.
rc = 1.
ENDIF.
* Fortschrittsanzeige
lv_ptext = 'bearbeite Material'.
CONCATENATE lv_ptext ls_tstpo2-component INTO lv_ptext
SEPARATED BY space.
WRITE lv_cnt TO lv_txt.
CONDENSE lv_txt NO-GAPS.
CONCATENATE lv_ptext '-' lv_txt 'von' INTO lv_ptext
SEPARATED BY space.
WRITE i TO lv_txt.
CONDENSE lv_txt NO-GAPS.
CONCATENATE lv_ptext lv_txt INTO lv_ptext
SEPARATED BY space.
CALL FUNCTION 'PROGRESS_INDICATOR'
EXPORTING
i_text = lv_ptext
i_processed = lv_cnt
i_total = i
i_output_immediately = 'X'.
ENDLOOP.
CALL FUNCTION 'CSAP_MAT_BOM_CLOSE'
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
break guenther.
ENDIF.
ELSE.
PERFORM write_log USING <p>-component 'could not be Opened'.
ENDIF.
ENDFORM. "maint_bom
*&---------------------------------------------------------------------*
*& Form write_log
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->MATNR text
* -->TEXT text
*----------------------------------------------------------------------*
FORM write_log USING matnr TYPE c text TYPE c.
CALL FUNCTION 'Y_BAL_LOG'
EXPORTING
i_msgty = 'E'
i_msgid = '0U'
i_msgno = '533'
i_msgv1 = matnr
i_msgv2 = text
i_msgv3 = ' '
i_repid = sy-repid
EXCEPTIONS
error_create = 1
error_add_message = 2
error_refresh = 3
error_display_profile = 4
error_display = 5
OTHERS = 6.
ENDFORM. "write_log
*&---------------------------------------------------------------------*
*& Form update_filetab
*&---------------------------------------------------------------------*
* Extract BomNo and ChangeNo from filename
*----------------------------------------------------------------------*
FORM update_filetab.
DATA lt_split TYPE TABLE OF tab512.
DATA ls_split TYPE sychar512.
DATA k TYPE i.
LOOP AT it_files ASSIGNING <p>.
SPLIT <p>-fname AT '\' INTO TABLE lt_split.
k = lines( lt_split ).
IF k > 0.
READ TABLE lt_split INDEX k INTO ls_split.
SPLIT ls_split AT '.' INTO TABLE lt_split.
k = lines( lt_split ).
IF k > 1.
READ TABLE lt_split INDEX 1 INTO ls_split.
SPLIT ls_split AT '_' INTO TABLE lt_split.
k = lines( lt_split ).
IF k = 1.
READ TABLE lt_split INDEX 1 INTO <p>-component.
* check if material exist
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = <p>-component
IMPORTING
output = <p>-component.
SELECT COUNT(*) FROM mara WHERE matnr = <p>-component.
IF sy-subrc NE 0.
PERFORM write_log USING <p>-component 'Material doesn´t exist.'(015).
CLEAR <p>-component.
ENDIF.
ENDIF."k = 1.
ENDIF."k > 1.
ENDIF."k > 0.
ENDLOOP.
DELETE it_files WHERE component = space.
PERFORM f_display_data.
ENDFORM. "update_filetab
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
DATA:
ls_private TYPE slis_data_caller_exit,
ls_seldat TYPE ty_sel,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
REFRESH gt_seldat.
* Copy entries for selection
LOOP AT it_files ASSIGNING <p>.
CLEAR ls_seldat.
ls_seldat-component = <p>-component.
SELECT SINGLE maktx FROM makt INTO ls_seldat-bom_text WHERE
matnr = <p>-component AND spras = sy-langu.
PERFORM check_bom_change_num CHANGING <p>-component.
IF <p>-component IS INITIAL.
ls_seldat-checkbox = ' '.
ls_seldat-change_no = 'X'.
ELSE.
ls_seldat-checkbox = 'X'.
ls_seldat-change_no = ' '.
ENDIF.
APPEND ls_seldat TO gt_seldat.
ENDLOOP.
* Build the field catalog chg_kz
m_fieldcat 'COMPONENT' 'STPO_API02'.
m_fieldcat 'CHANGE_NO' 'STPO_API02'.
m_fieldcat 'BOM_TEXT' 'STKO_API01'.
* Optimize column width
ls_private-columnopt = 'X'.
* Display data in a POPUP
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_title = 'Please select items'
i_selection = 'X'
i_zebra = 'X'
it_fieldcat = lt_fieldcat
i_tabname = 'GT_SELDAT'
i_checkbox_fieldname = 'CHECKBOX'
is_private = ls_private
IMPORTING
e_exit = g_exit
TABLES
t_outtab = gt_seldat.
* Terminate
IF g_exit NE space.
PERFORM write_log USING '' 'Terminate by user'(017).
EXIT.
ENDIF.
LOOP AT it_files ASSIGNING <p> WHERE component NE ' '.
READ TABLE gt_seldat WITH KEY component = <p>-component checkbox = 'X' INTO ls_seldat.
IF sy-subrc NE 0.
CLEAR <p>-component.
ENDIF.
ENDLOOP.
DELETE it_files WHERE component = space.
ENDFORM. " F_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form check_bom_change_num
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->I_BOM text
*----------------------------------------------------------------------*
FORM check_bom_change_num CHANGING i_bom TYPE csap_mbom-matnr.
DATA lv_tstko TYPE stko_api01.
DATA ls_stko TYPE stko_api02.
DATA lt_stko TYPE TABLE OF stko_api02.
DATA ls_stpo TYPE stpo_api02.
DATA lt_stpo TYPE TABLE OF stpo_api02.
* Check BOM exisitence (incl. ChangeNo)
CALL FUNCTION 'CSAP_MAT_BOM_READ'
EXPORTING
material = i_bom
plant = p_werk
bom_usage = p_stlan
TABLES
t_stpo = lt_stpo
t_stko = lt_stko
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc = 0.
READ TABLE lt_stko INDEX 1 INTO ls_stko.
LOOP AT lt_stpo INTO ls_stpo WHERE change_no NE ' '.
EXIT.
ENDLOOP.
* check for HEAD change number and POS change number
IF ls_stpo-change_no IS INITIAL AND ls_stko-chg_no IS INITIAL.
ELSE.
PERFORM write_log USING i_bom 'discarded - Change numbers'(016).
CLEAR i_bom.
EXIT.
ENDIF.
ENDIF."sy-subrc
ENDFORM. "check_bom_change_num
Hey, danke für die schnelle Antwort,
Beherzige Trons Antwort. Man schreibt nicht direkt in SAP-Tabellen wenn man nicht 100%ig weiß was man tut und sich der Auswirkungen bewusst ist.der_neuling hat geschrieben: ↑01.12.2020 12:57Hey, danke für die schnelle Antwort,
ich erstelle ja nur Test Daten um einen FuBa auf Funktion zu testen, im teardown wird dann selbstverständlich ein ROLLBACK WORK gemacht.
So ist es natürlich der beste Fall, in meinem Beispiel wollte ich eben einen global gültigen Datensatz meinem Unit Testing mitgeben damit dieser auf all unseren Systemen gleiche Daten testen kann.
für ein eigenes Programm nutze ich den FuBA 'CSAP_MAT_BOM_READ', welcher eine Liste aller in einer Stückliste vorhandenen Materialien anzeigt.
kann man denn mit CSAP_MAT_BOM_READ überhaupt Daten aus der DB lesen, die nicht verbucht sind?5 von mir geschriebene INSERT INTO Statements in 3 von mir selbstgewählte Tabellen dessen Veränderungen ich dann selbständig mit einem ROLLBACK WORK zurücknehme
Das ist wirklich ein Dilemma. Eigentlich muss man für Unit Tests auf Stammdaten zugreifen, aber diese können sich ändern und sind im Entwicklungssystem gar nicht vorhanden. Das ganze auf Datenbankebene, um einen SELECT zu "unittesten". Um fake-Daten zu bekommen, kann man TEST-SEAMS verwenden, die aber auch nicht unumstritten sind.der_neuling hat geschrieben: ↑02.12.2020 08:19Was ist denn nun besser für eine Testumgebung? 5 von mir geschriebene INSERT INTO Statements in 3 von mir selbstgewählte Tabellen dessen Veränderungen ich dann selbständig mit einem ROLLBACK WORK zurücknehme und die DB LUW beende oder ein großer Fuba der mir dann auch noch meine Testdaten mittels COMMIT WORK ins System pflanzt?
Der OP schreibt doch, dass das Ganze auch im Produktivsystem laufen soll....ewx hat geschrieben: ↑02.12.2020 13:18Aber auch wenn deine Inserts in Standardtabellen erst mal ein mulmiges Gefühl hervorrufen (eben weil "man das nicht macht"), ist es ja keine produktive Anwendung. Es wird ja nur im Dev-System ausgeführt und da im Grunde noch so "elegant", dass die Daten gar nicht wirklich in der Datenbank landen. Und da Unit Tests auch keinen Programmabbruch verursachen können, besteht auch nicht die Gefahr, dass die Daten doch durch Zufall stehen bleiben.
Dann sind Unit Tests eh raus.black_adept hat geschrieben: ↑02.12.2020 17:06Der OP schreibt doch, dass das Ganze auch im Produktivsystem laufen soll....