Erweiterung COOIS um beschreibares Feld: Unterschied zwischen den Versionen

Aus SAP Wiki ツ
Zeile 19: Zeile 19:
  <div class="mw-collapsible-content">
  <div class="mw-collapsible-content">
<syntaxhighlight lang="abap" line start="1">
<syntaxhighlight lang="abap" line start="1">
  REPORT zpp_coois_comp_add_comment.
REPORT zpp_coois_comp_add_comment.


TABLES zpp_coois_comp_c.
TABLES zpp_coois_comp_c.
Zeile 46: Zeile 46:
     garg    = lv_garg
     garg    = lv_garg
     guname  = '*'
     guname  = '*'
*  LOCAL  = ' '
*  FAST    = ' '
*  GARGNOWC                    = ' '
   IMPORTING
   IMPORTING
*  NUMBER  =
     subrc  = lv_subrc
     subrc  = lv_subrc
   TABLES
   TABLES
Zeile 63: Zeile 59:
     MESSAGE lv_eng_msg TYPE 'I'.
     MESSAGE lv_eng_msg TYPE 'I'.
     EXIT.
     EXIT.
  endif.
   ENDIF.
   ENDIF.
ENDIF.


CALL FUNCTION 'ENQUEUE_EZPPCOOIS_COMP_C'
CALL FUNCTION 'ENQUEUE_EZPPCOOIS_COMP_C'

Version vom 29. Oktober 2021, 08:30 Uhr

Das Ziel dieser Erweiterung ist, dass man durch ein zusätzlichen Button in einem neu hinzugefügtem Feld beliebigen Text z.B. ein Kommentar für einen jeweiligen Eintrag speichern kann. Dafür wird ein BAdI genutzt. Es wird kein SAP Standard Code modifiziert.

Dies wird anhand eines Beispiels für die Liste "Komponente" gezeigt. Ein Eintrag bei Komponenten kann eindeutig mit der Auftragsnr., Positionsnr. und Materialnr. (Komponente) identifiziert werden.

Tabelle "IOOPCOMP" um Append Struktur erweitern

Tabelle IOOPCOMP Append Struktur

Z-Tabelle zur Speicherung eines Textes erstellen

Z-Tabelle für COOIS Erweiterungsfeld

Umsetzung Speicherung Text

Z-Programm zur Speicherung des Textes in Z-Tabelle (s. Schritt 2) erstellen

Beispielcode mit PopUps und Sperrobjekt

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.

Transaktionscode für Z-Programm anlegen

Button für Transaktionsaufruf in COOIS bei Navigationsprofil hinzufügen

Navigationsprofil um Transaktionsaufruf erweitern

BADI "WORKORDER_INFOSYSTEM" verwenden um Text nachzulesen

BAdI Z Implementierung anlegen oder bestehenden erweitern

Interface-Methode "TABLES_MODIFY_LAY" ausprogrammieren