Advertising:
Additional writable customer fields in COOIS output: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{#description2:The aim of this enhancement is to be able to save any text, e.g. a comment for a particular entry, by means of an additional button in a newly added field.}} | |||
The aim of this enhancement is to be able to save any text, e.g. a comment for a particular entry, by means of an additional button in a newly added field. | The aim of this enhancement is to be able to save any text, e.g. a comment for a particular entry, by means of an additional button in a newly added field. | ||
Revision as of 12:38, 31 December 2024
The aim of this enhancement is to be able to save any text, e.g. a comment for a particular entry, by means of an additional button in a newly added field.
A BAdI and a Z program are used for this. No SAP standard code is modified. The text entry is only displayed once it has been called up again after the selection.
This is shown using an example for the "Component" list. An entry for components can be clearly identified with the order no., item no. and material number (component).
Extend table "IOOPCOMP" with append structure
Create a table in customer namespace to save a text
Implementation storage text
Create program in customer namespace to save the text in created table (see step 2)
Example code with popups and locking object
REPORT zpp_coois_comp_add_comment.
TABLES zpp_coois_comp_c.
PARAMETERS: p_aufnr TYPE aufnr MEMORY ID anr,
p_posnr TYPE aposn MEMORY ID pos,
p_matnr TYPE matnr MEMORY ID mat.
DATA: lt_fields TYPE TABLE OF sval,
lv_popup_title TYPE string,
lv_conf_popup_title TYPE string,
lv_rc TYPE char01,
ls_zpp_coois_comp_c TYPE zpp_coois_comp_c,
lv_answer TYPE char01,
lv_text_q TYPE char57,
lv_garg TYPE seqg3-garg,
lv_subrc TYPE sy-subrc,
lt_enq TYPE TABLE OF seqg3,
lv_eng_msg TYPE string.
lv_garg = |{ p_aufnr ALPHA = IN }| && |{ p_posnr ALPHA = IN }| && |{ p_matnr ALPHA = OUT }| .
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
gclient = sy-mandt
gname = 'ZPP_COOIS_COMP_C'
garg = lv_garg
guname = '*'
IMPORTING
subrc = lv_subrc
TABLES
enq = lt_enq.
IF sy-subrc = 0.
IF lt_enq IS INITIAL.
"do nothing
ELSEIF lt_enq IS NOT INITIAL. "Sperreintrag vorhanden
READ TABLE lt_enq INTO DATA(ls_enq) INDEX 1.
lv_eng_msg = text-008.
REPLACE FIRST OCCURRENCE OF '&1' IN lv_eng_msg WITH ls_enq-guname.
MESSAGE lv_eng_msg TYPE 'I'.
EXIT.
ENDIF.
ENDIF.
CALL FUNCTION 'ENQUEUE_EZPPCOOIS_COMP_C'
EXPORTING
mode_zpp_coois_comp_c = 'E'
aufnr = p_aufnr
posnr = p_posnr
matnr = p_matnr
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
lt_fields = VALUE #( ( tabname = 'ZPP_COOIS_COMP_C'
fieldname = 'COMMENTS'
fieldtext = 'Comment'(000) )
).
lv_popup_title = TEXT-001.
REPLACE FIRST OCCURRENCE OF '&1' IN lv_popup_title WITH |{ p_aufnr ALPHA = OUT }|.
REPLACE FIRST OCCURRENCE OF '&2' IN lv_popup_title WITH |{ p_posnr ALPHA = OUT }|.
REPLACE FIRST OCCURRENCE OF '&3' IN lv_popup_title WITH |{ p_matnr ALPHA = OUT }|.
DATA(lv_aufnr_in) = |{ p_aufnr ALPHA = IN }|.
DATA(lv_posnr_in) = |{ p_posnr ALPHA = IN }|.
DATA(lv_matnr_in) = |{ p_matnr ALPHA = IN }|.
CALL FUNCTION 'POPUP_GET_VALUES'
EXPORTING
popup_title = lv_popup_title
IMPORTING
returncode = lv_rc
TABLES
fields = lt_fields
EXCEPTIONS
error_in_fields = 1
OTHERS = 2.
IF lv_rc = 'A'.
ELSE.
READ TABLE lt_fields INTO DATA(ls_comment) INDEX 1.
IF ls_comment-value IS NOT INITIAL.
CLEAR ls_zpp_coois_comp_c.
SELECT SINGLE * FROM zpp_coois_comp_c INTO @ls_zpp_coois_comp_c
WHERE aufnr = @lv_aufnr_in
AND posnr = @lv_posnr_in
AND matnr = @lv_matnr_in.
IF sy-subrc <> 0.
ls_zpp_coois_comp_c-aufnr = lv_aufnr_in.
ls_zpp_coois_comp_c-posnr = lv_posnr_in.
ls_zpp_coois_comp_c-matnr = lv_matnr_in.
ls_zpp_coois_comp_c-comments = ls_comment-value.
INSERT zpp_coois_comp_c FROM ls_zpp_coois_comp_c.
IF sy-subrc = 0.
MESSAGE TEXT-002 TYPE 'S'.
ELSE.
MESSAGE TEXT-004 TYPE 'I'.
ENDIF.
ELSE.
lv_conf_popup_title = TEXT-007.
IF strlen( ls_zpp_coois_comp_c-comments ) <= 43.
REPLACE FIRST OCCURRENCE OF '&1' IN lv_conf_popup_title WITH ls_zpp_coois_comp_c-comments(43). "old comment
ELSEIF strlen( ls_zpp_coois_comp_c-comments ) > 43.
REPLACE FIRST OCCURRENCE OF '&1' IN lv_conf_popup_title WITH ls_zpp_coois_comp_c-comments(40).
lv_conf_popup_title = lv_conf_popup_title && '...'.
ENDIF.
lv_text_q = TEXT-005.
IF strlen( ls_comment-value ) <= 25.
REPLACE FIRST OCCURRENCE OF '&1' IN lv_text_q WITH ls_comment-value(25). "new comment"
ELSEIF strlen( ls_zpp_coois_comp_c-comments ) > 25.
DATA(lv_short_new_comment) = ls_comment-value(22) && '...'.
REPLACE FIRST OCCURRENCE OF '&1' IN lv_text_q WITH lv_short_new_comment. "new comment"
ENDIF.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = lv_conf_popup_title
text_question = lv_text_q
IMPORTING
answer = lv_answer.
IF lv_answer = '1'.
UPDATE zpp_coois_comp_c SET comments = ls_comment-value
WHERE aufnr = ls_zpp_coois_comp_c-aufnr
AND posnr = ls_zpp_coois_comp_c-posnr
AND matnr = ls_zpp_coois_comp_c-matnr.
IF sy-subrc = 0.
MESSAGE TEXT-003 TYPE 'S'.
ELSE.
MESSAGE TEXT-004 TYPE 'I'.
ENDIF.
ELSE.
MESSAGE TEXT-006 TYPE 'S'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
CALL FUNCTION 'DEQUEUE_EZPPCOOIS_COMP_C'
EXPORTING
mode_zpp_coois_comp_c = 'E'
aufnr = p_aufnr
posnr = p_posnr
matnr = p_matnr.
Create transaction code for created program
Use BADI "WORKORDER_INFOSYSTEM" to read text
Create BAdI implementation in customer namespace or extend existing one
To do this, call up SE18 and a implementation in customer namespsace is created on the "Implementation" tab under "Create". The BAdI can be used multiple times. Therefore, more than one implementation can be created and activated here.
Programming the "TABLES_MODIFY_LAY" interface method
METHOD if_ex_workorder_infosystem~tables_modify_lay.
LOOP AT ct_ioopcomp ASSIGNING FIELD-SYMBOL(<add_fields>).
SELECT SINGLE comments FROM zpp_coois_comp_c INTO <add_fields>-zzcomment
WHERE aufnr = aufnr_in
AND posnr = posnr_in
AND matnr = matnr_in.
ENDLOOP.
ENDMETHOD.