Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Hi Friends,

The below sample code gives you an idea on applying batch split in an outbound delivery. The program apply batch split to quantity of a material of a line item of an outbound delivery based on the delivery number and HU ID.

Main Program Code: YTEST_BATCHSPLIT_1

*&---------------------------------------------------------------------*
*& Report  YTEST_BATCHSPLIT_1
*&
*&---------------------------------------------------------------------

REPORT  YTEST_BATCHSPLIT_1.

data : ws_c_delivery type likp-vbeln.

TYPES : BEGIN OF ty_batchsplit,
        vbeln TYPE lips-vbeln,
        posnr TYPE lips-posnr,
        charg TYPE vepo-charg,
        vemng TYPE vepo-vemng,
        END OF ty_batchsplit.

DATA : i_batchsplit TYPE STANDARD TABLE OF ty_batchsplit,
       wa_batchsplit TYPE ty_batchsplit.

DATA : ws_c_lfimg(16TYPE c,
       ws_flag TYPE c,
       ws_c_lines1(3type c.

DATA : i_bdcdata TYPE STANDARD TABLE OF bdcdata,
       wa_bdcdata TYPE bdcdata,
       i_messtab TYPE STANDARD TABLE OF bdcmsgcoll,
       WA_MESSTAB TYPE bdcmsgcoll,
       ws_temp_vbeln TYPE likp-vbeln,         
       ws_temp_posnr TYPE lips-posnr.

DATA : ws_c_lv_datfm_key TYPE usr01-DCPFM.

data : i_lips type STANDARD TABLE OF lips,
       wa_lips TYPE lips,
       i_vepo TYPE STANDARD TABLE OF vepo,
       wa_vepo type vepo,
       i_vekp TYPE STANDARD TABLE OF vekp.

data : text type string.

text = 'Error in applying Batch split'.

PARAMETERS : Delivery like likp-vbeln,
             HU-ID LIKE vekp-exidv.

CLEAR : i_lips.

    SELECT vbeln posnr matnr lfimg vgbel vgpos sobkz
        FROM lips
        INTO CORRESPONDING FIELDS OF TABLE i_lips
        WHERE vbeln = Delivery.

CLEAR : i_vekp.

  SELECT venum exidv brgew exidv2 vpobj status
      FROM vekp
      INTO CORRESPONDING FIELDS OF TABLE i_vekp
      WHERE venum NE space
      AND exidv2 = hu-id.

  CLEAR : i_vepo,ws_c_lines1.
  DESCRIBE TABLE i_vekp LINES ws_c_lines1.
  IF ws_c_lines1 GE 1.
    SELECT venum vepos vbeln posnr matnr vemng charg werks lgort sobkz sonum
    FROM  vepo
     INTO CORRESPONDING FIELDS OF TABLE i_vepo
     FOR ALL ENTRIES IN i_vekp
     WHERE venum = i_vekp-venum.
ENDIF.

REFRESH : i_bdcdata, i_batchsplit.
  LOOP AT i_lips INTO wa_lips.
    LOOP AT i_vepo INTO wa_vepo.                             

      IF ( wa_vepo-vemng GE wa_lips-lfimg ).

        ws_c_lfimg = wa_lips-lfimg.                  " Delivery Qty.
        wa_batchsplit-vbeln = wa_lips-vbeln.         " Delivery number.
        wa_batchsplit-posnr = wa_lips-posnr.
        wa_batchsplit-vemng = wa_lips-lfimg.
        wa_batchsplit-charg = wa_vepo-charg.

        IF wa_lips-lfimg IS INITIAL.
          wa_batchsplit-vemng = wa_vepo-vemng.
        ENDIF.

        APPEND wa_batchsplit TO i_batchsplit.
        " Latest Batch qty = Old batch qty - delivery qty.
        wa_vepo-vemng = wa_vepo-vemng - wa_lips-lfimg.
        MODIFY i_vepo FROM wa_vepo.
        EXIT.

      ELSEIF wa_vepo-vemng = 0.
        EXIT.

      ELSEIF ( wa_vepo-vemng < wa_lips-lfimg ).
        wa_batchsplit-vbeln = wa_lips-vbeln.         " Delivery number.
        wa_batchsplit-posnr = wa_lips-posnr.
        wa_batchsplit-vemng = wa_vepo-vemng.
        wa_batchsplit-charg = wa_vepo-charg.

        APPEND wa_batchsplit TO i_batchsplit.
        wa_lips-lfimg = wa_lips-lfimg - wa_vepo-vemng.
        MODIFY i_lips FROM wa_lips.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

CLEAR : wa_batchsplit.
  READ TABLE i_batchsplit INTO wa_batchsplit INDEX 1.
  ws_temp_vbeln = wa_batchsplit-vbeln.
  ws_temp_posnr = wa_batchsplit-posnr.

CLEAR : ws_c_lv_datfm_key.
  SELECT SINGLE DCPFM
INTO CORRESPONDING FIELDS OF (ws_c_lv_datfm_key)
FROM usr01
WHERE bname = sy-uname.

LOOP AT i_batchsplit INTO wa_batchsplit.

    AT NEW vbeln.
      CLEAR : ws_c_delivery.
      ws_c_delivery = wa_batchsplit-vbeln.

      PERFORM : f0016_bdc_dynpro      USING 'SAPMV50A'
                                           '4004',
               f0017_bdc_field       USING 'BDC_CURSOR'
                                           'LIKP-VBELN',
               f0017_bdc_field       USING 'BDC_OKCODE'
                                           '/00',
               f0017_bdc_field       USING 'LIKP-VBELN'
                                           ws_c_delivery,      " Delivery Number
               f0016_bdc_dynpro      USING 'SAPMV50A'
                                           '1000',
               f0017_bdc_field       USING 'BDC_OKCODE'        " Select all Button
                                           '=MKAL_T',
               f0016_bdc_dynpro      USING 'SAPMV50A'
                                           '1000',
               f0017_bdc_field       USING 'BDC_OKCODE'        " Batch Split Button
                                           '=CHSP_T'.
    ENDAT.
    ws_c_lfimg = wa_batchsplit-vemng.
    SHIFT ws_c_lfimg LEFT DELETING LEADING '0'.

    IF ws_temp_posnr = wa_batchsplit-posnr.

      IF ws_flag <> 'X'.

        PERFORM f0016_bdc_dynpro
       USING 'SAPMV50A'
             '3000'.       " Batch split screen.

        PERFORM f0017_bdc_field
          USING 'BDC_OKCODE'
                '/00'.

        PERFORM f0017_bdc_field
          USING 'LIPS-CHARG(01)'
                 wa_batchsplit-charg.

        IF ws_c_lv_datfm_key EQ space.
          REPLACE '.' WITH ',' INTO ws_c_lfimg.
        ENDIF.

        PERFORM f0017_bdc_field
          USING 'LIPS-LFIMG(01)'
                 ws_c_lfimg.

        ws_flag = 'X'.
      ELSE.

        PERFORM f0017_bdc_field
          USING 'LIPS-CHARG(02)'
                wa_batchsplit-charg.

        PERFORM f0017_bdc_field
          USING 'LIPS-LFIMG(02)'
                ws_c_lfimg.
        PERFORM f0017_bdc_field
      USING 'BDC_OKCODE'
            '=POAN_T'.          " PLUS BUTTON
      ENDIF.
    ELSE.
      CLEAR ws_flag.
      PERFORM f0016_bdc_dynpro
        USING 'SAPMV50A'
              '3000'.
      PERFORM f0017_bdc_field
        USING 'BDC_OKCODE'                 " Next Line Item button
               '=NITE_T'.

      IF ws_flag <> 'X'.

        PERFORM f0016_bdc_dynpro
          USING 'SAPMV50A'
                '3000'.       " Batch split screen.

        PERFORM f0017_bdc_field
          USING 'BDC_OKCODE'
                '/00'.

        PERFORM f0017_bdc_field
          USING 'LIPS-CHARG(01)'
                 wa_batchsplit-charg.

        PERFORM f0017_bdc_field
          USING 'LIPS-LFIMG(01)'
                 ws_c_lfimg.
        ws_flag = 'X'.
      ELSE.

        PERFORM f0017_bdc_field
          USING 'LIPS-CHARG(02)'
                wa_batchsplit-charg.

        PERFORM f0017_bdc_field
          USING 'LIPS-LFIMG(02)'
                ws_c_lfimg.

        PERFORM f0017_bdc_field
      USING 'BDC_OKCODE'
            '=POAN_T'.          " PLUS BUTTON

      ENDIF.

    ENDIF.

    AT END OF vbeln.
      PERFORM f0017_bdc_field       USING 'BDC_OKCODE'
                                    '=SICH_T'.                   " Save button

      CALL FUNCTION 'FMCT_WAIT_FOR_UPDATE'
        EXPORTING
          i_sec = 1.

      CALL TRANSACTION 'VL02N' USING i_bdcdata MODE 'N' UPDATE 'S' MESSAGES INTO i_messtab.
      REFRESH i_bdcdata.
    ENDAT.

    SORT i_messtab BY msgtyp.        "#CCE
    CLEAR : wa_messtab.
    READ TABLE i_messtab
          INTO wa_messtab
          WITH KEY msgtyp = 'E'
          BINARY SEARCH.

    IF sy-subrc EQ 0.
      MESSAGE text TYPE 'E'.

    ENDIF.

    ws_temp_vbeln = wa_batchsplit-vbeln.
    ws_temp_posnr = wa_batchsplit-posnr.
  ENDLOOP.
  IF i_batchsplit is INITIAL.
      MESSAGE text TYPE 'E'.

    ENDIF.

*&---------------------------------------------------------------------*
*&      Form  f0016_bdc_dynpro
*&---------------------------------------------------------------------
FORM f0016_bdc_dynpro USING program TYPE any
        dynpro  TYPE any.
  CLEAR wa_bdcdata.
  wa_bdcdata-program  = program.
  wa_bdcdata-dynpro   = dynpro.
  wa_bdcdata-dynbegin = 'X'.
  APPEND wa_bdcdata TO i_bdcdata.

ENDFORM.                    " f0016_bdc_dynpro
*&---------------------------------------------------------------------*
*&      Form  f0017_bdc_field
*&---------------------------------------------------------------------
FORM f0017_bdc_field  USING fnam TYPE any
        fval TYPE any.
  CLEAR wa_bdcdata.
  wa_bdcdata-fnam = fnam.
  wa_bdcdata-fval = fval.
  APPEND wa_bdcdata TO i_bdcdata.

ENDFORM.                    " f0017_bdc_field

 
 

*Text elements

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

* 000 Error occurred while applying batch split

 

  • No labels

1 Comment

  1. Former Member

    Very helpful!