Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Create Delivery and PGI of this delivery using BAPI

former_member212148
Participant
0 Kudos
1,989

Hello Experts,

I want to create Delivery with reference of sales order and PGI of this Delivery.

As many suggestion by experts I am using BAPI to create delivery and for PGI.  Delivery is created but here is issue with Storage location. As i passed Storage location in parameters of BAPI but it not display in Delivery and PGI is not possible without Storage location.

My code is here:-

REPORT  ZBAPI_VL01N.

TABLES: VBAP, VBAK, LIKP, LIPS, T100.

DATA: BEGIN OF IT_SO OCCURS 0.

        INCLUDE STRUCTURE BAPIDLVREFTOSALESORDER.

DATA: END OF IT_SO.

*DATA: V_WERKS LIKE VBAP-WERKS.

DATA: DLV_NO LIKE LIPS-VBELN,

      GW_VBKOK TYPE STANDARD TABLE OF VBKOK WITH HEADER LINE,

      GW_VBELN LIKE LIKP-VBELN,

      GW_PROT TYPE STANDARD TABLE OF PROTT WITH HEADER LINE,

      GW_VBPOK TYPE STANDARD TABLE OF VBPOK WITH HEADER LINE,

      GW_VERKO    LIKE VERKO  OCCURS 0  WITH HEADER LINE,

      GW_VERPO    LIKE VERPO  OCCURS 0  WITH HEADER LINE,

      GW_VBSUPCON LIKE VBSUPCON OCCURS 0  WITH HEADER LINE,

      LV_ERR_ANYERR TYPE C,

      LV_ERR_ITMDEL TYPE C,

      LV_ERR_PODUPD TYPE C,

      LV_ERR_INTERF TYPE C,

      LV_ERR_GOODSI TYPE C,

      LV_ERR_FINALC TYPE C.

DATA: BEGIN OF IT_LIPS OCCURS 0,

      VBELN LIKE LIPS-VBELN,

      POSNR LIKE LIPS-POSNR,

      MATNR LIKE LIPS-MATNR,

      WERKS LIKE LIPS-WERKS,

      LGORT LIKE LIPS-LGORT,

      LFIMG LIKE LIPS-LFIMG,

      MEINS LIKE LIPS-MEINS,

      VGBEL LIKE LIPS-VGBEL,

      VGPOS LIKE LIPS-VGPOS,

      END OF IT_LIPS.

TYPES: BEGIN OF TYSALES,

      VBELN LIKE VBAP-VBELN,

      POSNR LIKE VBAP-POSNR,

      MATNR LIKE VBAP-MATNR,

      KWMENG LIKE VBAP-KWMENG,

      VRKME LIKE VBAP-VRKME,

      WERKS LIKE VBAP-WERKS,

    END OF TYSALES.

DATA: ITSALES TYPE STANDARD TABLE OF TYSALES WITH HEADER LINE,

      WASALES TYPE TYSALES.

DATA: BEGIN OF IT_SOTMP OCCURS 0,

      VBELN LIKE VBAP-VBELN,

      END OF IT_SOTMP.

SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_SO TYPE VBAK-VBELN.

            C_DATE TYPE VBAK-ERDAT DEFAULT SY-DATUM,

            V_WERKS TYPE VBAP-WERKS DEFAULT 'HEVE'.

SELECTION-SCREEN END OF BLOCK BK1.

START-OF-SELECTION.

  DATA: GL_DATE(10) TYPE C,

        I_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.

  CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

     EXPORTING

       DATE_INTERNAL                  = C_DATE

     IMPORTING

       DATE_EXTERNAL                  = GL_DATE

*     EXCEPTIONS

*       DATE_INTERNAL_IS_INVALID       = 1

*       OTHERS                         = 2

              .

  SELECT VBELN POSNR MATNR KWMENG VRKME WERKS FROM VBAP INTO TABLE ITSALES  VBELN =P_SO.

  SELECT VBELN FROM VBAP INTO CORRESPONDING FIELDS OF TABLE IT_SOTMP WHERE VBELN =P_SO.

  LOOP AT IT_SALES.

    IT_SO-REF_DOC = ITSALES-VBELN.

    IT_SO-REF_ITEM = ITSALES-POSNR.

    IT_SO-DLV_QTY = ITSALES-KWMWNG.

    IT_SO-SALES_UNIT = ITSALES-VRKME.

    APPEND IT_SO.

  ENDLOOP.

  LOOP AT IT_SOTMP.

    READ TABLE IT_SO WITH KEY REF_DOC = IT_SOTMP-VBELN.

    CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'

      EXPORTING

        SHIP_POINT        = V_WERKS

        DUE_DATE          = SY-DATUM

      TABLES

        SALES_ORDER_ITEMS = IT_SO

        RETURN            = I_RETURN.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

        WAIT = 'X'.

*  WAIT UP TO 1 SECONDS.

    SELECT VBELN POSNR MATNR WERKS LGORT LFIMG MEINS VGBEL VGPOS FROM LIPS

        INTO TABLE IT_LIPS WHERE VGBEL = IT_SOTMP-VBELN.

*  SORT IT_LIPS BY VBELN DESCENDING.

*  DELETE ADJACENT DUPLICATES FROM IT_LIPS COMPARING VGBEL.

    LOOP AT IT_LIPS.

*      READ TABLE IT_SO WITH KEY REF_DOC = IT_LIPS-VGBEL.

      GW_VBPOK-VBELN_VL = IT_LIPS-VBELN.

      GW_VBPOK-POSNR_VL = IT_LIPS-POSNR.

      GW_VBPOK-VBELN = IT_LIPS-VGBEL.

      GW_VBPOK-POSNN = IT_SO-REF_ITEM."IT_LIPS-POSNR.

      GW_VBPOK-MATNR = IT_LIPS-MATNR.

      GW_VBPOK-PIKMG = IT_LIPS-LFIMG.

      GW_VBPOK-NDIFM = IT_LIPS-LFIMG.

      GW_VBPOK-VRKME = IT_LIPS-MEINS.

      GW_VBPOK-KZVFDAT = 'X'.

      GW_VBPOK-KZHSDAT = 'X'.

*    READ TABLE IT_FINAL WITH KEY DLV_VBELN = IT_LIPS-VBELN.

      GW_VBPOK-WERKS = V_WERKS.

*    GW_VBPOK-LGORT = 'M10'.

      GW_VBPOK-LIANP = 1.

      GW_VBPOK-LFIMG = 1.

      APPEND GW_VBPOK.

      AT END OF VBELN.

        GW_VBELN = IT_LIPS-VBELN.

        DLV_NO = IT_LIPS-VBELN.

        GW_VBKOK-VBELN_VL = DLV_NO.

        GW_VBKOK-WABUC    = 'X'.

        GW_VBKOK-KODAT = SY-DATUM.

        GW_VBKOK-WADAT_IST = C_DATE.

        GW_VBKOK-WADAT = SY-DATUM.

        GW_VBKOK-WAUHR = SY-UZEIT.

        GW_VBKOK-LFDAT = SY-DATUM.

        GW_VBKOK-LFUHR = SY-UZEIT.

        GW_VBKOK-LDDAT = SY-DATUM.

        GW_VBKOK-LDUHR = SY-UZEIT.

        GW_VBKOK-TDDAT = SY-DATUM.

        GW_VBKOK-KZEBU = 1.

        APPEND GW_VBKOK.

        CALL FUNCTION 'WS_DELIVERY_UPDATE'

           EXPORTING

             VBKOK_WA                 = GW_VBKOK

*    SYNCHRON                 = 'X'

*    NO_MESSAGES_UPDATE       = ' '

             UPDATE_PICKING        = 'X'

     COMMIT                   = 'X'

             DELIVERY                 = GW_VBELN

*    NICHT_SPERREN            = 'X'

             IF_DATABASE_UPDATE       = '1'

             IF_ERROR_MESSAGES_SEND_0 = 'X'

           TABLES

             VBPOK_TAB                = GW_VBPOK

*        PROT                     = GW_PROT

*    VERKO_TAB                = GW_VERKO

*        VERPO_TAB                = GW_VERPO

*        VBSUPCON_TAB             = GW_VBSUPCON

             .

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            WAIT = 'X'.

        IF SY-SUBRC EQ 0.

          COMMIT WORK .

        ELSE.

          WRITE:/ 'Error Occured during PGI'.

        ENDIF.

      ENDAT.

    ENDLOOP.

  ENDLOOP.

One more issues I have passed in serial number of material also in delivery.

Kindly help me.

Thanks,

Ranjit.

6 REPLIES 6

former_member662097
Active Participant
0 Kudos
662

Hi Ranjit,

Refer this link : http://scn.sap.com/message/3326612#3326612

You can go with BDC for the same issue. Check link for BDC http://scn.sap.com/thread/1360296

Hope it is helpful for you.

Regards,

Shatrughan

0 Kudos
662

Hi Shatrughan,

I have already go through these threads. But Storage Location is not saved in delivery.

Without storage location i cant PGI of this delivery.

Former Member
0 Kudos
662

Hi Ranjit,

First Create the Delivery without Storage location , then write one BDC Code who update the Storage location with Respective Delivery... Check below Sample Code ..

Note :

Part I :

           is Delivery Create without Storage location Using SAP Standard BAPI       

          "BAPI_OUTB_DELIVERY_CREATE_SLS"

Part II :  Using BDC Program Update the Storage Location with Respective output of above BAPI.

         

Regard's

Smruti

0 Kudos
662

Hi Smurti,

I am going this way but still I am not able to do PGI.

Code is following.

REPORT  ZBAPI_VL01N.

TABLES: VBAP, VBAK, LIKP, LIPS, T100.

DATA: BEGIN OF IT_SO OCCURS 0.

        INCLUDE STRUCTURE BAPIDLVREFTOSALESORDER.

DATA: END OF IT_SO.

*DATA: V_WERKS LIKE VBAP-WERKS.

DATA: DLV_NO LIKE LIPS-VBELN,

      GW_VBKOK TYPE STANDARD TABLE OF VBKOK WITH HEADER LINE,

      GW_VBELN LIKE LIKP-VBELN,

      GW_PROT TYPE STANDARD TABLE OF PROTT WITH HEADER LINE,

      GW_VBPOK TYPE STANDARD TABLE OF VBPOK WITH HEADER LINE,

      GW_VERKO    LIKE VERKO  OCCURS 0  WITH HEADER LINE,

      GW_VERPO    LIKE VERPO  OCCURS 0  WITH HEADER LINE,

      GW_VBSUPCON LIKE VBSUPCON OCCURS 0  WITH HEADER LINE,

      LV_ERR_ANYERR TYPE C,

      LV_ERR_ITMDEL TYPE C,

      LV_ERR_PODUPD TYPE C,

      LV_ERR_INTERF TYPE C,

      LV_ERR_GOODSI TYPE C,

      LV_ERR_FINALC TYPE C.

DATA: BEGIN OF IT_LIPS OCCURS 0,

      VBELN LIKE LIPS-VBELN,

      POSNR LIKE LIPS-POSNR,

      MATNR LIKE LIPS-MATNR,

      WERKS LIKE LIPS-WERKS,

      LGORT LIKE LIPS-LGORT,

      LFIMG LIKE LIPS-LFIMG,

      MEINS LIKE LIPS-MEINS,

      VGBEL LIKE LIPS-VGBEL,

      VGPOS LIKE LIPS-VGPOS,

      END OF IT_LIPS.

*PARAMETERS: P_SO TYPE VBAK-VBELN.

TYPES: BEGIN OF TY_PGI,

      VBELN(10) TYPE C,

      BLDAT(10) TYPE C,

      KODAT(10) TYPE C,

      KOUHR(8) TYPE C,

      LIPS_SELKZ(1) TYPE C,

      MATNR(18) TYPE C,

      POSNR(6) TYPE C,

      LGORT(4) TYPE C,

      LFIMG(13) TYPE C,

      SELKZ(1) TYPE C,

      SERNR(18) TYPE C,

      END OF TY_PGI.

TYPES: BEGIN OF TY_FINAL,

      SO_VBELN(10) TYPE C,

      SO_POSNR(6) TYPE C,

      MATNR(18) TYPE C,

      LGORT(3) TYPE C,

      LFIMG(13) TYPE C,

      VRKME(3) TYPE C,

      SERNR(18) TYPE C,

      WERKS(4) TYPE C,

      DLV_VBELN(10) TYPE C,

      DLV_POSNR(6) TYPE C,

      END OF TY_FINAL.

TYPES: BEGIN OF TY_MAT,

      DLV_VBELN(10) TYPE C,

      DLV_POSNR(6) TYPE C,

      MATNR(18) TYPE C,

      WERKS(4) TYPE C,

      LGORT(3) TYPE C,

      LFIMG(13) TYPE C,

      END OF TY_MAT.

TYPES: BEGIN OF TY_SRN,

      DLV_VBELN(10) TYPE C,

      DLV_POSNR(6) TYPE C,

      MATNR(18) TYPE C,

      LGORT(3) TYPE C,

      LFIMG(13) TYPE C,

      SERNR(18) TYPE C,

      END OF TY_SRN.

TYPES: BEGIN OF TYSALES,

      VBELN LIKE VBAP-VBELN,

      POSNR LIKE VBAP-POSNR,

      MATNR LIKE VBAP-MATNR,

      KWMENG LIKE VBAP-KWMENG,

      VRKME LIKE VBAP-VRKME,

      WERKS LIKE VBAP-WERKS,

    END OF TYSALES.

TYPES: BEGIN OF TY_ERROR,

        MSGORDTYP(200) TYPE C,

        MSGSALES(200) TYPE C,

        MSGMAT(200) TYPE C,

        MSGCUSTSALES(200) TYPE C,

        MSGDLVPLANT(200) TYPE C,

        MSGPRCTR(200) TYPE C,

        MSGAC(200) TYPE C,

        MSGVCLASS(200) TYPE C,

        V_CNT TYPE INT2,

      END OF TY_ERROR.

DATA: W_ERROR TYPE TY_ERROR,

      IT_ERROR TYPE STANDARD TABLE OF TY_ERROR WITH HEADER LINE.

DATA: IT_MAT TYPE STANDARD TABLE OF TY_MAT WITH HEADER LINE,

      WA_MAT TYPE TY_MAT.

DATA: IT_PGI TYPE STANDARD TABLE OF TY_PGI WITH HEADER LINE,

      WA_PGI TYPE TY_PGI,

      IT_FINAL TYPE STANDARD TABLE OF TY_FINAL WITH HEADER LINE,

      WA_FINAL TYPE TY_FINAL,

      ITSALES TYPE STANDARD TABLE OF TYSALES WITH HEADER LINE,

      WASALES TYPE TYSALES.

DATA: BDCDATA TYPE STANDARD TABLE OF BDCDATA WITH HEADER LINE ,

      MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,

      I_ERROR LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,

      WA_ERROR TYPE BDCMSGCOLL.

DATA: IT_SRN TYPE STANDARD TABLE OF TY_SRN WITH HEADER LINE,

      WA_SRN TYPE TY_SRN.

DATA: BEGIN OF IT_SOTMP OCCURS 0,

      VBELN LIKE VBAP-VBELN,

      END OF IT_SOTMP.

DATA: V_MSG(200) TYPE C,

     V_LINE TYPE INT2,

     V_MATLINE TYPE INT2,

     V_MATIDX(4) TYPE C.

SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_FILE LIKE RLGRAP-FILENAME OBLIGATORY DEFAULT 'C:\Documents and Settings\ItServ\Desktop\PGI DELIVERY.txt',

            C_DATE TYPE VBAK-ERDAT DEFAULT SY-DATUM,

            V_WERKS TYPE VBAP-WERKS DEFAULT 'HEVE'.

SELECTION-SCREEN END OF BLOCK BK1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  PERFORM GET_F4VALUES CHANGING P_FILE.

START-OF-SELECTION.

  PERFORM UPLOAD_DATA.

  DATA: GL_DATE(10) TYPE C,

        I_RETURN TYPE TABLE OF BAPIRET2 WITH HEADER LINE.

  CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

     EXPORTING

       DATE_INTERNAL                  = C_DATE

     IMPORTING

       DATE_EXTERNAL                  = GL_DATE

*     EXCEPTIONS

*       DATE_INTERNAL_IS_INVALID       = 1

*       OTHERS                         = 2

              .

  SELECT VBELN POSNR MATNR KWMENG VRKME WERKS FROM VBAP INTO TABLE ITSALES FOR ALL ENTRIES IN IT_FINAL WHERE VBELN = IT_FINAL-SO_VBELN.

  SELECT VBELN FROM VBAP INTO CORRESPONDING FIELDS OF TABLE IT_SOTMP FOR ALL ENTRIES IN IT_FINAL WHERE VBELN = IT_FINAL-SO_VBELN.

  LOOP AT IT_FINAL WHERE SO_POSNR <> ' '.

    IT_SO-REF_DOC = IT_FINAL-SO_VBELN.

    IT_SO-REF_ITEM = IT_FINAL-SO_POSNR.

    IT_SO-DLV_QTY = IT_FINAL-LFIMG.

    IT_SO-SALES_UNIT = IT_FINAL-VRKME.

    APPEND IT_SO.

  ENDLOOP.

  LOOP AT IT_SOTMP.

    READ TABLE IT_SO WITH KEY REF_DOC = IT_SOTMP-VBELN.

    CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'

      EXPORTING

        SHIP_POINT        = V_WERKS

        DUE_DATE          = SY-DATUM

      TABLES

        SALES_ORDER_ITEMS = IT_SO

        RETURN            = I_RETURN.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

        WAIT = 'X'.

*  WAIT UP TO 1 SECONDS.

    SELECT VBELN POSNR MATNR WERKS LGORT LFIMG MEINS VGBEL VGPOS FROM LIPS

        INTO TABLE IT_LIPS WHERE VGBEL = IT_SOTMP-VBELN.

*  SORT IT_LIPS BY VBELN DESCENDING.

*  DELETE ADJACENT DUPLICATES FROM IT_LIPS COMPARING VGBEL.

    LOOP AT IT_LIPS.

*      READ TABLE IT_SO WITH KEY REF_DOC = IT_LIPS-VGBEL.

      GW_VBPOK-VBELN_VL = IT_LIPS-VBELN.

      GW_VBPOK-POSNR_VL = IT_LIPS-POSNR.

      GW_VBPOK-VBELN = IT_LIPS-VGBEL.

      GW_VBPOK-POSNN = IT_SO-REF_ITEM."IT_LIPS-POSNR.

      GW_VBPOK-MATNR = IT_LIPS-MATNR.

      GW_VBPOK-PIKMG = IT_LIPS-LFIMG.

      GW_VBPOK-NDIFM = IT_LIPS-LFIMG.

      GW_VBPOK-VRKME = IT_LIPS-MEINS.

      GW_VBPOK-KZVFDAT = 'X'.

      GW_VBPOK-KZHSDAT = 'X'.

*    READ TABLE IT_FINAL WITH KEY DLV_VBELN = IT_LIPS-VBELN.

      GW_VBPOK-WERKS = V_WERKS.

*    GW_VBPOK-LGORT = 'M10'.

      GW_VBPOK-LIANP = 1.

      GW_VBPOK-LFIMG = 1.

      APPEND GW_VBPOK.

      AT END OF VBELN.

        GW_VBELN = IT_LIPS-VBELN.

        DLV_NO = IT_LIPS-VBELN.

        GW_VBKOK-VBELN_VL = DLV_NO.

        GW_VBKOK-WABUC    = 'X'.

        GW_VBKOK-KODAT = SY-DATUM.

        GW_VBKOK-WADAT_IST = C_DATE.

        GW_VBKOK-WADAT = SY-DATUM.

        GW_VBKOK-WAUHR = SY-UZEIT.

        GW_VBKOK-LFDAT = SY-DATUM.

        GW_VBKOK-LFUHR = SY-UZEIT.

        GW_VBKOK-LDDAT = SY-DATUM.

        GW_VBKOK-LDUHR = SY-UZEIT.

        GW_VBKOK-TDDAT = SY-DATUM.

        GW_VBKOK-KZEBU = 1.

        APPEND GW_VBKOK.

        CALL FUNCTION 'WS_DELIVERY_UPDATE'

           EXPORTING

             VBKOK_WA                 = GW_VBKOK

                 SYNCHRON                 = 'X'

*    NO_MESSAGES_UPDATE       = ' '

             UPDATE_PICKING        = 'X'

             COMMIT                   = 'X'

             DELIVERY                 = GW_VBELN

             NICHT_SPERREN            = 'X'

             IF_DATABASE_UPDATE       = '1'

             IF_ERROR_MESSAGES_SEND_0 = 'X'

           TABLES

             VBPOK_TAB                = GW_VBPOK

*        PROT                     = GW_PROT

*    VERKO_TAB                = GW_VERKO

*        VERPO_TAB                = GW_VERPO

*        VBSUPCON_TAB             = GW_VBSUPCON

             .

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            WAIT = 'X'.

        IF SY-SUBRC EQ 0.

          COMMIT WORK .

        ELSE.

          WRITE:/ 'Error Occured during PGI'.

        ENDIF.

      ENDAT.

    ENDLOOP.

    PERFORM DO_PGI.

  ENDLOOP.

*&---------------------------------------------------------------------*

*&      Form  DO_PGI

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM DO_PGI.

  LOOP AT IT_FINAL.

  READ TABLE IT_LIPS WITH KEY VGBEL = IT_FINAL-SO_VBELN POSNR = IT_FINAL-SO_POSNR.

    READ TABLE IT_SO WITH KEY REF_DOC = IT_FINAL-SO_VBELN.

    IT_FINAL-DLV_VBELN = IT_LIPS-VBELN.

    IT_FINAL-DLV_POSNR = IT_LIPS-POSNR.

    MODIFY IT_FINAL TRANSPORTING DLV_VBELN DLV_POSNR.

  ENDLOOP.

  LOOP AT IT_FINAL WHERE LFIMG <> ' '.

    IT_MAT-DLV_VBELN = IT_FINAL-DLV_VBELN.

    IT_MAT-DLV_POSNR = IT_FINAL-DLV_POSNR.

    IT_MAT-MATNR = IT_FINAL-MATNR.

    IT_MAT-WERKS = V_WERKS.

    IT_MAT-LGORT = IT_FINAL-LGORT.

    IT_MAT-LFIMG = IT_FINAL-LFIMG.

    APPEND IT_MAT.

    ENDLOOP.

  LOOP AT IT_FINAL.

    IT_SRN-DLV_VBELN = IT_FINAL-DLV_VBELN.

    IT_SRN-DLV_POSNR = IT_FINAL-DLV_POSNR.

    IT_SRN-MATNR = IT_FINAL-MATNR.

    IT_SRN-LGORT = IT_FINAL-LGORT.

    IT_SRN-LFIMG = IT_FINAL-LFIMG.

    IT_SRN-SERNR = IT_FINAL-SERNR.

    APPEND IT_SRN.

  ENDLOOP.

  LOOP AT IT_FINAL INTO WA_FINAL.

    WA_PGI-VBELN = WA_FINAL-DLV_VBELN.

    WA_PGI-BLDAT = SY-DATUM.

    WA_PGI-LGORT = WA_FINAL-LGORT.

    WA_PGI-SERNR = WA_FINAL-SERNR.

    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

      EXPORTING

        DATE_INTERNAL = SY-DATUM

      IMPORTING

        DATE_EXTERNAL = WA_PGI-BLDAT.

    WA_PGI-KODAT = SY-DATUM.

    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

      EXPORTING

        DATE_INTERNAL = SY-DATUM

      IMPORTING

        DATE_EXTERNAL = WA_PGI-KODAT.

    APPEND WA_PGI TO IT_PGI.

  ENDLOOP.

  SORT IT_PGI BY VBELN.

  DELETE ADJACENT DUPLICATES FROM IT_PGI.

  DATA:V_LINE TYPE INT2,

       V_MATLINE TYPE INT2,

       V_MATIDX(4) TYPE C,

       FNAM(30) TYPE C,

       FNAM1(30) TYPE C,

       FNAM2(30) TYPE C,

       FNAM3(30) TYPE C,

       IDX(3) TYPE C,

       V_IDX(2) TYPE C.

  LOOP AT IT_PGI INTO WA_PGI.

    REFRESH BDCDATA.

    PERFORM BDC_DYNPRO      USING 'SAPMV50A' '4004'.

    PERFORM BDC_FIELD       USING 'BDC_CURSOR'

                                  'LIKP-VBELN'.

    PERFORM BDC_FIELD       USING 'BDC_OKCODE'

                                  '/00'.

    PERFORM BDC_FIELD       USING 'LIKP-VBELN'

                                  WA_PGI-VBELN.

    PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.

    PERFORM BDC_FIELD       USING 'LIKP-BLDAT'

                                  WA_PGI-BLDAT.

    PERFORM BDC_FIELD       USING 'LIKP-KODAT'

                                  WA_PGI-KODAT.

    PERFORM BDC_FIELD       USING 'LIKP-KOUHR'

                                  SY-UZEIT."WA_PGI-KOUHR.

    PERFORM BDC_FIELD       USING 'BDC_CURSOR'

                                  'LIPS-LGORT'.

    PERFORM BDC_FIELD       USING 'LIPS-LGORT'

                                  WA_PGI-LGORT.

    PERFORM BDC_FIELD       USING 'RV50A-LIPS_SELKZ'

                                    'X'.

    PERFORM BDC_DYNPRO      USING 'SAPLIPW1' '0200'.

    PERFORM BDC_FIELD       USING 'BDC_CURSOR'

                                  'RIPW0-SERNR'.

    PERFORM BDC_FIELD       USING 'BDC_OKCODE'

                                  '=RWS'.

    PERFORM BDC_FIELD       USING 'RIPW0-SERNR'

                                  WA_PGI-SERNR.

    PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.

    PERFORM BDC_FIELD       USING 'BDC_OKCODE'

                                  '=WABU_T'.

    PERFORM BDC_FIELD       USING 'LIKP-BLDAT'

                                  WA_PGI-BLDAT.

    PERFORM BDC_FIELD       USING 'BDC_CURSOR'

                                  'LIPS-POSNR'.

    PERFORM BDC_FIELD       USING 'LIKP-KODAT'

                                  WA_PGI-KODAT.

    PERFORM BDC_FIELD       USING 'LIKP-KOUHR'

                                  SY-UZEIT."WA_PGI-KOUHR.

    PERFORM BDC_TRANSACTION USING 'VL02N'.

  ENDLOOP.

ENDFORM.                    "DO_PGI

*&---------------------------------------------------------------------*

*&      Form  BDC_TRANSACTION

FORM BDC_TRANSACTION USING TCODE.

  DATA: L_MSTRING(480).

  DATA: L_SUBRC LIKE SY-SUBRC,

        LS_CTU_PARAMS TYPE CTU_PARAMS.

  LS_CTU_PARAMS-DEFSIZE = 20.

  REFRESH MESSTAB.

  DATA: V_OPTION LIKE CTU_PARAMS.

  V_OPTION-DISMODE  = 'A'.

  V_OPTION-UPDMODE  = 'S'."p_udmode.

  V_OPTION-CATTMODE  = ' '.

  V_OPTION-DEFSIZE  = 'X'.

  V_OPTION-RACOMMIT = ' '.

  V_OPTION-NOBINPT  = 'X'.

  V_OPTION-NOBIEND  = ' '.

  CALL TRANSACTION TCODE

            USING BDCDATA

            MESSAGES INTO MESSTAB

            OPTIONS FROM V_OPTION.

  L_SUBRC = SY-SUBRC.

  WRITE: / 'CALL_TRANSACTION',

           TCODE,

           'RETURNCODE:'(I05),

           L_SUBRC,

           'WA_PGI-:',

           SY-INDEX.

  LOOP AT MESSTAB.

    SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA

    AND ARBGB = MESSTAB-MSGID

    AND MSGNR = MESSTAB-MSGNR.

    IF SY-SUBRC = 0.

      L_MSTRING = T100-TEXT.

      IF L_MSTRING CS '&1'.

        REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.

        REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.

        REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.

        REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.

      ELSE.

        REPLACE '&' WITH MESSTAB-MSGV1 INTO L_MSTRING.

        REPLACE '&' WITH MESSTAB-MSGV2 INTO L_MSTRING.

        REPLACE '&' WITH MESSTAB-MSGV3 INTO L_MSTRING.

        REPLACE '&' WITH MESSTAB-MSGV4 INTO L_MSTRING.

      ENDIF.

      CONDENSE L_MSTRING.

      WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).

    ELSE.

      WRITE: / MESSTAB.

    ENDIF.

    I_ERROR-MSGTYP = MESSTAB-MSGTYP.

    I_ERROR-MSGV1 = L_MSTRING.

    APPEND I_ERROR.

    CLEAR I_ERROR.

  ENDLOOP.

  SKIP.

  REFRESH BDCDATA.

ENDFORM. " BDC_TRANSACTION

*&---------------------------------------------------------------------*

*&      Form  BDC_DYNPRO

*&---------------------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

  CLEAR BDCDATA.

  BDCDATA-PROGRAM = PROGRAM.

  BDCDATA-DYNPRO = DYNPRO.

  BDCDATA-DYNBEGIN = 'X'.

  APPEND BDCDATA.

ENDFORM. "bdc_dynpro

*----------------------------------------------------------------------*

* Insert field *

*----------------------------------------------------------------------*

FORM BDC_FIELD USING FNAM FVAL.

  CLEAR BDCDATA.

  BDCDATA-FNAM = FNAM.

  BDCDATA-FVAL = FVAL.

  APPEND BDCDATA.

ENDFORM. "bdc_field

*&---------------------------------------------------------------------*

*&      Form  GET_F4VALUES

FORM GET_F4VALUES CHANGING P_WP_FLNM.

  CALL FUNCTION 'F4_FILENAME'

    EXPORTING

      PROGRAM_NAME  = SYST-CPROG

      DYNPRO_NUMBER = SYST-DYNNR

    IMPORTING

      FILE_NAME     = P_WP_FLNM.

ENDFORM. " get_f4values

*&---------------------------------------------------------------------*

*& Form upload_data

*&---------------------------------------------------------------------*

FORM UPLOAD_DATA .

  DATA : W_FILE TYPE STRING.

  W_FILE = P_FILE.

  CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

      FILENAME            = W_FILE

      FILETYPE            = 'ASC'

      HAS_FIELD_SEPARATOR = '#'

    TABLES

      DATA_TAB            = IT_FINAL.

  IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

ENDFORM.                    "UPLOAD_DATA

Flat file is as follows:

<        

SalesOrderItemMaterialStorage LocQtyU-O-MSerial No
144000013510400016M101NOSHV09200A400016

Any one help me please.

Thanks,

Ranjit.

0 Kudos
662

Hi Ranjit ,

I don't Know your actual requirement , Can you tell me is above code only for Create delivery or Create delivery with PGI , if it is Create delivery with PGI but where you write for PGI Code .

Simple Logic ..

1st Use "BAPI_OUTB_DELIVERY_CREATE_SLS"  Create Delivery without Storage Location ,

      and Capture Delivery Number .

2nd Call BDC Code for T-code "VL02N"  and Update the above Delivery Number

      (i.e. Output of above BAPI )with Storage Location .

3rd Write Code for PGI (if your requirement PGI also required in same program )

    Or Using "VT01N"  for PGI .

Note :  Same type of requirement i am already work approx 2 years back SD automation .

Regard's

Smruti

hossain_rajib55
Explorer
0 Kudos
89

@smrutiCould you please help me to complete the process.

SAP STO to delivery order created through API. After creation of delivery similar way need to re update the  LGORT and PIKMG through API using BAPI.

I create a custom BAPI where BDC recorded for vl02n. Its take 15 entries after that its give a error.

Field LIPS-LGORT (16) does not exist in dynpro SAPMV50A
Field LIPSD-G_LFIMG (16) does not exist in dynpro SAPMV50A
Field LIPSD-PIKMG (16) does not exist in dynpro SAPMV50A
Field LIPS-LGORT (17) does not exist in dynpro SAPMV50A
Field LIPSD-G_LFIMG (17) does not exist in dynpro SAPMV50A
Field LIPSD-PIKMG (17) does not exist in dynpro SAPMV50A
Field LIPS-LGORT (18) does not exist in dynpro SAPMV50A
Field LIPSD-G_LFIMG (18) does not exist in dynpro SAPMV50A
Field LIPSD-PIKMG (18) does not exist in dynpro SAPMV50A
Field LIPS-LGORT (19) does not exist in dynpro SAPMV50A
Field LIPSD-G_LFIMG (19) does not exist in dynpro SAPMV50A
Field LIPSD-PIKMG (19) does not exist in dynpro SAPMV50A
Field LIPS-LGORT (20) does not exist in dynpro SAPMV50A
Field LIPSD-G_LFIMG (20) does not exist in dynpro SAPMV50A
Field LIPSD-PIKMG (20) does not exist in dynpro SAPMV50A
Field LIPS-LGORT (21) does not exist in dynpro SAPMV50A
Field LIPSD-G_LFIMG (21) does not exist in dynpro SAPMV50A
Field LIPSD-PIKMG (21) does not exist in dynpro SAPMV50A.

How I will cover come from it. Please guided me.