SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Алгоритм заполнения инфоструктуры S066



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
Рустам
Специалист
Специалист



Joined: 26 Dec 2007
Posts: 73

PostPosted: Wed Aug 20, 2008 10:35 am    Post subject: Алгоритм заполнения инфоструктуры S066 Reply with quote

Здравствуйте,
стоит задача разобраться, почему в таблицу S066 (Open orders: credit management) попала отрицательная сумма. Кто-нибудь знает, как заполняется эта таблица?
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Wed Aug 20, 2008 11:06 am    Post subject: Reply with quote

Для получения суммы открытых заказов по покупателю в саповских транзакциях часто используется ФМ 'SD_CREDIT_EXPOSURE', как раз использующая инфоструктуры s066, s067.

Когда стояла задача расчета сумм в другой валюте, отличной от валюты в этих инфосистемах, пришлось расчитывать суммы руками:

Code:
*&---------------------------------------------------------------------*
*&      Form  SD_CREDIT_EXPOSURE2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->p_kkber LIKE T014-KKBER
*      -->p_knkli LIKE KNKK-KNKLI
*      <--p_open_delivery LIKE  S067-OLIKW
*      <--p_open_invoice LIKE  S067-OFAKW
*      <--p_open_order LIKE  S066-OEIKW
*----------------------------------------------------------------------*
FORM SD_CREDIT_EXPOSURE2 USING p_kkber LIKE T014-KKBER
              p_knkli LIKE KNKK-KNKLI
              CHANGING
              p_open_delivery LIKE S067-OLIKW
              p_open_invoice LIKE S067-OFAKW
              p_open_order LIKE S066-OEIKW.

TABLES:  VBCOM, FACOM, LICOM, vbco7, TVBST, RV60A.

DATA: BEGIN OF POSTAB OCCURS 50,
        VBELN LIKE VBUP-VBELN,
        POSNR LIKE VBUP-POSNR,
      END OF POSTAB.

DATA:    BEGIN OF SELTAB OCCURS 6.
        INCLUDE STRUCTURE RKASK.
DATA:    END   OF SELTAB.

DATA:   BEGIN OF VBPOSTAB OCCURS 200.
        INCLUDE STRUCTURE VBMTV.       " Listanzeigen-Struktur
DATA:   END   OF VBPOSTAB.

DATA:   BEGIN OF FAPOSTAB OCCURS 200.
        INCLUDE STRUCTURE FAMTV.
DATA:      SPART LIKE TVTA-SPART,
        END  OF FAPOSTAB.

DATA:    BEGIN OF LLIMTV OCCURS 200.
           INCLUDE STRUCTURE LIMTV.
DATA:    END   OF LLIMTV.

CLEAR:
              p_open_delivery,
              p_open_invoice,
              p_open_order.

* get open orders
  VBCOM-MANDT = sy-mandt.
  VBCOM-VKORG = P_KKBER.
  VBCOM-KUNDE = P_KNKLI.
  VBCOM-AUDAT_BIS = SY-DATUM.
  VBCOM-VBOFF = 'X'.
  VBCOM-trvog = '0'.
  VBCOM-PARVW = 'AG'.
  VBCOM-STAT_DAZU = 'X'.
  VBCOM-NAME_DAZU = 'X'.

REFRESH VBPOSTAB.
CALL FUNCTION 'RV_SALES_DOCUMENT_VIEW_3'
  EXPORTING
    VBCOM                           = VBCOM
*   I_CONTRACT_WITH_REFSTATUS       =
*   I_NEW_VALIND_SELECT             =
*   KONV_FLAG                       =
*   BSTKD_FLAG                      =
*   EURO_FLAG                       = ' '
* IMPORTING
*   TIME                            =
  TABLES
    LVBMTV                          = VBPOSTAB
*   LSELTAB                         =
          .
    CALL FUNCTION 'SD_VEDA_PROCESS_SELECT'
         EXPORTING
              I_VBCOM            = VBCOM
         TABLES
              POSTAB             = VBPOSTAB
         EXCEPTIONS
              NO_DATA_TO_PROCESS = 01.

    CASE SY-SUBRC.
      WHEN 1.
    ENDCASE.

  LOOP AT VBPOSTAB.
    IF NOT VBPOSTAB-BMENG IS INITIAL. "only confirmed
      p_open_order = p_open_order + VBpostab-NETWR.
    ENDIF.
  ENDLOOP.

* get open invoices

  FACOM-MANDT = sy-mandt.
  FACOM-VKORG = P_KKBER.
  FACOM-KUNDE = P_KNKLI.
  FACOM-FKDAT_BIS = SY-DATUM.
  FACOM-ZUART = 'A'.
  FACOM-VBOFF = 'X'.

  FACOM-PARVW = 'RG'.
  FACOM-STAT_DAZU = 'X'.
  FACOM-NAME_DAZU = 'X'.
  FACOM-LESGU = 'X'.
  FACOM-LESST = 'X'.
  FACOM-LESLA = 'X'.
  FACOM-LESRE = 'X'.
  FACOM-LESIV = 'X'.

refresh FApostab.
CALL FUNCTION 'RV_INVOICE_VIEW_2'
       EXPORTING FACOM   = FACOM
       TABLES    LFAMTV  = FAPOSTAB
                 LSELTAB = SELTAB.

  LOOP AT FAPOSTAB.
    p_open_invoice = p_open_invoice + FApostab-NETWR.
  ENDLOOP.

* get open delivery

DATA: BEGIN OF LVBUK OCCURS 0001.
INCLUDE STRUCTURE VBUK .
DATA: END OF LVBUK .

DATA: BEGIN OF LVLKPA OCCURS 0001.
INCLUDE STRUCTURE VLKPA .
DATA: END OF LVLKPA .

DATA: BEGIN OF LLIKP OCCURS 0001.
INCLUDE STRUCTURE LIKP .
DATA: END OF LLIKP .

DATA: BEGIN OF LLIPS OCCURS 0001.
INCLUDE STRUCTURE LIPS .
DATA: END OF LLIPS .

DATA: POSTAB_TFILL LIKE SY-TABIX.
DATA: ACTIV LIKE LIMTV-ACTIV VALUE '0'.               "Listverarbeitung
DATA: B_ZAEHLER LIKE SY-TABIX.
DATA: LV LIKE SY-TABIX.
DATA: LV2 LIKE SY-TABIX.
DATA: LV3 LIKE SY-TABIX.
DATA: LV4 LIKE SY-TABIX.
DATA: LIPS_TABIX LIKE SY-TABIX.
DATA: LIMTV_TABIX LIKE SY-TABIX.

DATA: BEGIN OF LIKP_KEY,
   MANDT LIKE LIKP-MANDT,
   VBELN LIKE LIKP-VBELN,
END OF LIKP_KEY.

DATA: BEGIN OF LIPS_KEY,
   MANDT LIKE LIPS-MANDT,
   VBELN LIKE LIPS-VBELN,
   POSNR LIKE LIPS-POSNR,
END OF LIPS_KEY.
  DATA: OK(1) TYPE C.

  LICOM-MANDT = sy-mandt.
  LICOM-VKORG = P_KKBER.
  LICOM-KUNDE = P_KNKLI.
  LICOM-LFDAT_BIS = SY-DATUM.
  LICOM-ZUART = 'A'.
  LICOM-VBOFF = 'X'.

  LICOM-PARVW = 'WE'.
  LICOM-STAT_DAZU = 'X'.
  LICOM-NAME_DAZU = 'X'.

  REFRESH: POSTAB.
  SELECT *
    INTO TABLE LVLKPA
    FROM VLKPA
    WHERE ( PARVW = LICOM-PARVW )
    AND   ( VKORG = LICOM-VKORG )
    AND   ( KUNAG = LICOM-KUNDE )
    ORDER BY VBELN.

  B_ZAEHLER = 0. LV = 0.
  DESCRIBE TABLE LVLKPA LINES POSTAB_TFILL.

  IF POSTAB_TFILL > 0.
    LOOP AT LVLKPA.
          POSTAB-VBELN = LVLKPA-VBELN.
          APPEND POSTAB.
          MOVE LVLKPA-KUNNR TO LLIMTV-KUNNR .
          MOVE LVLKPA-LFART TO LLIMTV-LFART .
          MOVE LVLKPA-VBELN TO LLIMTV-VBELN .
          MOVE LVLKPA-VKORG TO LLIMTV-VKORG .
          LLIMTV-ACTIV = ACTIV.
          APPEND LLIMTV.
    ENDLOOP.

    SELECT * FROM VBUK INTO TABLE LVBUK FOR ALL ENTRIES IN POSTAB
                       WHERE    VBELN = POSTAB-VBELN
                       ORDER BY PRIMARY KEY.

    LOOP AT LLIMTV.
      DATA: FELDNAME(10) TYPE C.

      CLEAR OK.
      VBUK_KEY-MANDT = SY-MANDT.
      VBUK_KEY-VBELN = LLIMTV-VBELN.
      READ TABLE LVBUK WITH KEY VBUK_KEY BINARY SEARCH.
      CHECK SY-SUBRC = 0.

      IF LICOM-VBOFF = ' ' OR
           LVBUK-WBSTK = 'A' OR LVBUK-WBSTK = 'B'.
        LLIMTV-STATUS = LVBUK-WBSTK.
        FELDNAME = 'WBSTA'.

        OK = 'X'.
        IF LICOM-STAT_DAZU = 'X'.
          TVBST-SPRAS = SY-LANGU.
          TVBST-TBNAM = 'VBUK'.
          TVBST-FDNAM = FELDNAME.
          TVBST-STATU = LLIMTV-STATUS.

          CALL FUNCTION 'RV_DOCUMENT_STATUS_TEXTS'
           EXPORTING
                TVBST_WA = TVBST
           IMPORTING
*         RETURNCODE = I01
                TEXT = LLIMTV-STATUS_BEZ.
        ENDIF.
      ENDIF.

      IF OK = ' '.
        DELETE LLIMTV.
        READ TABLE POSTAB WITH KEY VBELN = LLIMTV-VBELN
                                         BINARY SEARCH.
        IF SY-SUBRC = 0.
          DELETE POSTAB INDEX SY-TABIX.
        ENDIF.
      ELSE.
        MODIFY LLIMTV.
      ENDIF.
    ENDLOOP.

    DESCRIBE TABLE LLIMTV LINES SY-TFILL.
    IF SY-TFILL > 0.
* je nach Zugriffsart werden Auftragsk_pfe eingelesen
      IF LICOM-ZUART CA 'AC'.
        SELECT * FROM LIKP INTO TABLE LLIKP FOR ALL ENTRIES IN POSTAB
                       WHERE    VBELN = POSTAB-VBELN
                       ORDER BY PRIMARY KEY.
      ENDIF.

      IF LICOM-ZUART CA 'AB'.
        SELECT * FROM LIPS INTO TABLE LLIPS FOR ALL ENTRIES IN POSTAB
             WHERE  VBELN = POSTAB-VBELN
             AND    MATNR NE SPACE
             ORDER BY PRIMARY KEY.
      ENDIF.

      DESCRIBE TABLE LLIMTV LINES LV3.
      LV4 = 0.
      DO.
        LV4 = LV4 + 1.
        LIMTV_TABIX = LV4.
        IF LV4 > LV3. EXIT. ENDIF.
        READ TABLE LLIMTV INDEX LV4.
        IF SY-SUBRC NE 0. EXIT. ENDIF.

*     es wurden also nur Kopfindices gelesen
        IF LICOM-ZUART CA 'AC'.
*       K_pfe sollen gelesen werden
          LIKP_KEY-MANDT = SY-MANDT.
          LIKP_KEY-VBELN = LLIMTV-VBELN.
          READ TABLE LLIKP WITH KEY LIKP_KEY BINARY SEARCH.
          IF SY-SUBRC = 0.
            IF LICOM-ZUART = 'C'.
              DELETE LLIKP INDEX SY-TABIX.
            ENDIF.
            MOVE LLIKP-KUNNR TO LLIMTV-KUNNR .
            MOVE LLIKP-LFART TO LLIMTV-LFART .
            LLIMTV-ACTIV = ACTIV.
            MODIFY LLIMTV INDEX LV4.
          ELSE.
            DELETE LLIMTV INDEX LV4. LV4 = LV4 - 1.
            CHECK 1 = 2.
          ENDIF.
        ENDIF.
        IF LICOM-ZUART CA 'AB'.
*         Positionen sollen gelesen werden
          LV = 0.
          DO.
            IF LV = 0.
              LIKP_KEY-MANDT = SY-MANDT.
              LIKP_KEY-VBELN = LLIMTV-VBELN.
              READ TABLE LLIPS WITH KEY LIKP_KEY BINARY SEARCH.
              IF SY-SUBRC NE 0. LV2 = 0. EXIT. ENDIF.
              LIPS_TABIX = SY-TABIX.
              LV = LV + 1.
              MOVE LLIPS-POSNR TO LLIMTV-POSNR .
              MOVE LLIPS-VBELN TO LLIMTV-VBELN .
              LLIMTV-ACTIV = ACTIV.
              MODIFY LLIMTV INDEX LV4.
            ELSE.
              LIPS_TABIX = LIPS_TABIX + 1.
              READ TABLE LLIPS INDEX LIPS_TABIX.
              IF SY-SUBRC NE 0 OR
                 LLIPS-VBELN NE LLIMTV-VBELN.
                EXIT.
              ENDIF.
              LV = LV + 1.
              MOVE LLIPS-POSNR TO LLIMTV-POSNR .
              MOVE LLIPS-VBELN TO LLIMTV-VBELN .
              LLIMTV-ACTIV = ACTIV.
              APPEND LLIMTV.
              LIMTV_TABIX = SY-TABIX.
            ENDIF.
          ENDDO.
        ENDIF.
      ENDDO.
    ENDIF.

    DATA l_netwr LIKE VBAP-NETWR.
    LOOP AT LLIPS.
      CLEAR l_netwr.
      SELECT SINGLE netwr INTO l_netwr FROM VBAP
        WHERE vbeln = LLIPS-vgbel AND posnr = LLIPS-vgpos.
      IF SY-SUBRC IS INITIAL.
        p_open_delivery = p_open_delivery + l_netwr.
      ENDIF.
    ENDLOOP.
  ENDIF.
* addition open delivery
  RANGES : s_kunnr   FOR  vbco7-kunnr.
  RANGES : s_lland   FOR  vbco7-lland.
  RANGES : s_fkart   FOR  vbco7-fkart.
  RANGES : S_VBELN   FOR  VBCO7-VBELN.
  RANGES : s_sortkri FOR  vbco7-sortkri.
  RANGES : s_vtweg FOR vbco7-vtweg.
  RANGES : s_spart FOR vbco7-spart.
  RANGES : s_vstel FOR vbco7-vstel.

  DATA   : it_fvkdfi LIKE vkdfif OCCURS 50 WITH HEADER LINE.

  vbco7-vkorg     = P_KKBER.
  vbco7-kunnr     = P_KNKLI.
  vbco7-fkdat_bis = SY-DATUM.
  vbco7-name_dazu = 'X'.
  vbco7-ALLEL     = 'X'.
  CLEAR rv60a.
  s_kunnr-option = 'EQ'.
  s_kunnr-sign   = 'I'.
  s_kunnr-low   = P_KNKLI.
  append s_kunnr.

  PERFORM vkdfs_data_collect(SDBILLDL)
                TABLES
                  it_fvkdfi
                  s_kunnr
                  s_vbeln
                  s_lland
                  s_fkart
                  s_sortkri
                  s_vtweg
                  s_spart
                  s_vstel
                USING vbco7 rv60a.

    DATA l_vgbel LIKE LIPS-vgbel.

    LOOP AT it_fvkdfi.

      SELECT SINGLE vgbel FROM lips INTO l_vgbel
        WHERE vbeln = it_fvkdfi-vbeln.
      CHECK SY-SUBRC IS INITIAL.

      SELECT SINGLE netwr FROM vbak INTO l_netwr
        WHERE vbeln = l_vgbel.

      CHECK SY-SUBRC IS INITIAL.
      p_open_delivery = p_open_delivery + l_netwr.
    ENDLOOP.

ENDFORM.                    " SD_CREDIT_EXPOSURE2
Back to top
View user's profile Send private message Blog Visit poster's website
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Thu Aug 28, 2008 2:02 pm    Post subject: Reply with quote

FYI
Program: RVKRED07
SD: Reorganization of Credit Values after Update Errors
Back to top
View user's profile Send private message Blog Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.