Kundenfelder (Z-Felder) in der Kontraktposition ändern

Oft müssen auch Kundenfelder (Z-Felder) in einer Kontraktposition geändert werden, diese müssen in folgender Strukturen enthalten sein:
– BAPE_VBAP
– BAPE_VBAPX
– VBAPKOZ
– VBAPKOZX
Hierzu gibt es auch einer sehr gute Dokumentation im Funktionsbaustein BAPI_CUSTOMERCONTRACT_CHANGE

hier ein Beispiel bei dem die Konraktposition 10 geändert wurde:

REPORT zextensionin.

DATA:ls_header         TYPE bapisdh1,
     ls_headerx        TYPE bapisdh1x,
     lt_pos            TYPE TABLE OF bapisditm,
     ls_pos            TYPE bapisditm,
     lt_posx           TYPE TABLE OF bapisditmx,
     ls_posx           TYPE bapisditmx,
     lt_return         TYPE TABLE OF bapiret2,
     lt_contract_inx   TYPE TABLE OF bapictrx,
     ls_contract_inx   TYPE bapictrx,
     lt_contract       TYPE TABLE OF bapictr,
     ls_contract       TYPE bapictr,
     lt_extensionin    TYPE TABLE OF bapiparex WITH HEADER LINE,
     ls_extensionin    TYPE bapiparex,
     l_valuepart1(240) TYPE c,
     l_kreuzleiste     TYPE string.

  DO 15 TIMES.
    CONCATENATE l_kreuzleiste 'X' INTO l_kreuzleiste.
  ENDDO.

ls_contract_inx-itm_number = '000010'.
ls_contract_inx-con_st_dat = 'X'.
ls_contract_inx-con_en_dat = 'X'.
APPEND ls_contract_inx TO lt_contract_inx.

ls_contract-itm_number = '000010'.
ls_contract-con_st_dat = '20200101'.
ls_contract-con_en_dat = '99991231'.
APPEND ls_contract TO lt_contract.

CLEAR ls_headerx.
ls_headerx-updateflag = 'U'. "Mussfeld beim Updaten

CLEAR lt_pos.
CLEAR lt_posx.

ls_pos-itm_number = '000010'.
APPEND ls_pos TO lt_pos.

ls_posx-itm_number = '000010'.
ls_posx-updateflag = 'U'.
APPEND ls_posx TO lt_posx.

"Erweiterung für die VBAP auffüllen
ls_extensionin-structure    = 'BAPE_VBAP'.
CLEAR: l_valuepart1.

"Hier die Felder die in der Kontraktposition geändet werden sollen:
CONCATENATE
   '0430000667'              "Verkaufsbeleg CHAR10
   '000010'                  "Verkaufsbelegposition NUMC6
   '00000000000000000315'    "Identifikation der Entsorgungsanlage (IS-U-W) CHAR 20
    '    '                   "Nummer der Herkunft CHAR4
    '                    '   "Entsorgungsnachweisnummer CHAR20
    'E'                      "Vorgangsart CHAR1
    'RECHNUNG ANL.KONTR. '   "Entsorgungsanlagenauftragsart CHAR20
    '  '                     "(Z-Feld!)Zusatzfeld , Information - Gutschrift CHAR2
    '100'                    "Abrechnungsanteil NUMC1
    '1992998                       ' "(Z-Feld!)Standplatz des Behälters CHAR30
    '04'                     "Wiegedatenart CHAR2
    'DD'                     "Art der Behandlung des Abfalls CHAR1
    'DK0       '             "Lagertyp (XXX spezifisch) CHAR10
    '          '             "Lagerplatz (XXX spezifisch) CHAR10
    'AVV150199_00      '     "(Z-Feld!)Materialnummer CHAR18

INTO l_valuepart1 RESPECTING BLANKS.
ls_extensionin-l_valuepart1   = l_valuepart1.
"Unsere extensions
APPEND ls_extensionin TO lt_extensionin.

"Füllen der Ankreuzleiste für die Kundenerweiterung
    ls_extensionin-structure     = 'BAPE_VBAPX'.

CONCATENATE
'0430014144' '000010' "Beleg / Pos.

l_kreuzleiste "15 Kreuze für die Updates

INTO l_valuepart1 RESPECTING BLANKS.

ls_extensionin-l_valuepart1 = l_valuepart1.

APPEND ls_extensionin TO lt_extensionin.

CALL FUNCTION 'BAPI_CUSTOMERCONTRACT_CHANGE'
  EXPORTING
    salesdocument       = '0430014144'
    contract_header_in  = ls_header
    contract_header_inx = ls_headerx
*   SIMULATION          =
*   BEHAVE_WHEN_ERROR   = ' '
*   INT_NUMBER_ASSIGNMENT       = ' '
*   LOGIC_SWITCH        =
*   NO_STATUS_BUF_INIT  = ' '
  TABLES
    return              = lt_return
    contract_item_in    = lt_pos
    contract_item_inx   = lt_posx
*   PARTNERS            =
*   PARTNERCHANGES      =
*   PARTNERADDRESSES    =
*   CONDITIONS_IN       =
*   CONDITIONS_INX      =
*   CONTRACT_CFGS_REF   =
*   CONTRACT_CFGS_INST  =
*   CONTRACT_CFGS_PART_OF  =
*   CONTRACT_CFGS_VALUE =
*   CONTRACT_CFGS_BLOB  =
*   CONTRACT_CFGS_VK    =
*   CONTRACT_CFGS_REFINST  =
*   CONTRACT_TEXT       =
    CONTRACT_DATA_IN    = lt_contract
    CONTRACT_DATA_INX   = lt_contract_inx
*   CONTRACT_KEYS       =
    extensionin         = lt_extensionin.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
  .

Kontraktposition ändern

Beispielcoding um ein Kontrakt auf Positionsebene zu ändern. In diesem Beispiel wurde das Vertragsbeginn- Vertragsendedatum auf Positionsebene geändert.

ls_contract_inx-itm_number = ‚000010‘.
ls_contract_inx-con_st_dat = ‚X‘.
ls_contract_inx-con_en_dat = ‚X‘.

APPEND ls_contract_inx TO lt_contract_inx.

ls_contract-itm_number = ‚000010‘.
ls_contract-con_st_dat = ‚20200101‘.
ls_contract-con_en_dat = ‚99991231‘.

APPEND ls_contract TO lt_contract.

Über die Itm-Number = ‚000000‘ ändern Sie den Vertragskopf.

ls_contract_inx-itm_number = ‚000000‘.
ls_contract_inx-con_st_dat = ‚X‘.
ls_contract_inx-con_en_dat = ‚X‘.
APPEND ls_contract_inx TO lt_contract_inx.

ls_contract-itm_number = ‚000000‘.
ls_contract-con_st_dat = gv_vbegdat.
ls_contract-con_en_dat = gv_venddat.
APPEND ls_contract TO lt_contract.

*---------------------------------------------------------------------*
* Report ZTEST_CUSTOMERCONTRACT_CHANGE
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
REPORT ZTEST_CUSTOMERCONTRACT_CHANGE.

DATA:ls_header       TYPE bapisdh1,
     ls_headerx      TYPE bapisdh1x,
     lt_pos          TYPE TABLE OF bapisditm,
     ls_pos          TYPE bapisditm,
     lt_posx         TYPE TABLE OF bapisditmx,
     ls_posx         TYPE bapisditmx,
     lt_return       TYPE TABLE OF bapiret2,
     lt_contract_inx TYPE TABLE OF bapictrx,
     ls_contract_inx TYPE bapictrx,
     lt_contract     TYPE TABLE OF bapictr,
     ls_contract     TYPE bapictr.

ls_contract_inx-itm_number = '000010'.
ls_contract_inx-con_st_dat = 'X'.
ls_contract_inx-con_en_dat = 'X'.
APPEND ls_contract_inx TO lt_contract_inx.

ls_contract-itm_number = '000010'.
ls_contract-con_st_dat = '20200101'.
ls_contract-con_en_dat = '99991231'.
APPEND ls_contract TO lt_contract.

*Vertragskopf
CLEAR ls_headerx.
ls_headerx-updateflag = 'U'. "Mussfeld beim Updaten

*Vertragsposition
CLEAR lt_pos.
*  REFRESH lt_pos.
CLEAR lt_posx.
*  REFRESH lt_posx.
CLEAR ls_pos.
CLEAR ls_posx.

ls_pos-itm_number = '000010'.
APPEND ls_pos TO lt_pos.

ls_posx-itm_number = '000010'.
ls_posx-updateflag = 'U'.
APPEND ls_posx TO lt_posx.


CALL FUNCTION 'BAPI_CUSTOMERCONTRACT_CHANGE'
  EXPORTING
    salesdocument       = '0430014144'
    contract_header_in  = ls_header
    contract_header_inx = ls_headerx
*   SIMULATION          =
*   BEHAVE_WHEN_ERROR   = ' '
*   INT_NUMBER_ASSIGNMENT       = ' '
*   LOGIC_SWITCH        =
*   NO_STATUS_BUF_INIT  = ' '
  TABLES
    return              = lt_return
    contract_item_in    = lt_pos
    contract_item_inx   = lt_posx
*   PARTNERS            =
*   PARTNERCHANGES      =
*   PARTNERADDRESSES    =
*   CONDITIONS_IN       =
*   CONDITIONS_INX      =
*   CONTRACT_CFGS_REF   =
*   CONTRACT_CFGS_INST  =
*   CONTRACT_CFGS_PART_OF  =
*   CONTRACT_CFGS_VALUE =
*   CONTRACT_CFGS_BLOB  =
*   CONTRACT_CFGS_VK    =
*   CONTRACT_CFGS_REFINST  =
*   CONTRACT_TEXT       =
    CONTRACT_DATA_IN    = lt_contract
    CONTRACT_DATA_INX   = lt_contract_inx
*   CONTRACT_KEYS       =
*   extensionin         =
  .


CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
  .

Behälterservice, Intervall, Tag ermitteln

Mit dem unten aufgeführten Sql-Statement können alle wichtigen Servicedaten zu einem Behälter selektiert werden wie z.B. der Service, Status-Service, Intervall, Wochentag, Ab, Bis. Es wird lediglich ein Objektnummer für den Input benötigt.

 SELECT * INTO TABLE lt_ewaobjh
          FROM ewaobjh
          WHERE objnr = lt_behle-objnr
          AND  ( ( ab >= SY-DATUM AND day_flag EQ 'X' )
                  OR ( bis >= SY-DATUM AND ( day_flag NE 'X'  ) )
               ) .
      IF lt_ewaobjh IS NOT INITIAL.

        READ TABLE lt_ewaobjh ASSIGNING <fs_ewaobjh> INDEX 1.
        lt_behle-weekley      = <fs_ewaobjh>-weekly.
        lt_behle-ab           = <fs_ewaobjh>-ab.
        lt_behle-bis          = <fs_ewaobjh>-bis.
        lt_behle-service_type = <fs_ewaobjh>-service_type.
        lt_behle-status_serv  = <fs_ewaobjh>-status_serv.
*   Wochentag umwandeln
        IF <fs_ewaobjh>-eweekday     = 1.
          lt_behle-wochentag  = 'Mo'.
        ELSEIF <fs_ewaobjh>-eweekday = 2.
          lt_behle-wochentag  = 'Di'.
        ELSEIF <fs_ewaobjh>-eweekday = 3.
          lt_behle-wochentag  = 'Mi'.
        ELSEIF <fs_ewaobjh>-eweekday = 4.
          lt_behle-wochentag  = 'Do'.
        ELSEIF <fs_ewaobjh>-eweekday = 5.
          lt_behle-wochentag  = 'Fr'.
        ELSEIF <fs_ewaobjh>-eweekday = 6.
          lt_behle-wochentag  = 'Sa'.
        ELSEIF <fs_ewaobjh>-eweekday = 7.
          lt_behle-wochentag  = 'So'.
        ENDIF.
      ENDIF.