Skip to Content
avatar image
Former Member

a sample program for save_text

hi,

i need a sample program for save_text function module

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 06, 2006 at 05:29 AM
    REPORT ztest LINE-SIZE 80 MESSAGE-ID zrf.
    
    TYPES: BEGIN OF grec,
             werks TYPE werks_d,
             signi TYPE signi,
             bolnr TYPE vbeln,
             exidv TYPE exidv,
             vbeln TYPE vbeln,
             wadat TYPE wadat,
           END OF grec.
    
    DATA: gt_exidv TYPE STANDARD TABLE OF grec WITH HEADER LINE.
    
    PARAMETERS: pf_wadat TYPE wadat OBLIGATORY DEFAULT sy-datum,
                pf_werks TYPE werks_d,
                pf_signi TYPE char10,
                pf_bolnr TYPE vbeln.
    SELECT-OPTIONS: st_exidv  FOR gt_exidv-exidv NO INTERVALS.
    
    *&---------------------------------------------------------------------*
    *&   Event AT SELECTION-SCREEN
    *&---------------------------------------------------------------------*
    AT SELECTION-SCREEN.
    
      IF ( NOT st_exidv[] IS INITIAL OR NOT pf_signi IS INITIAL OR
           NOT pf_werks IS INITIAL   OR NOT pf_bolnr IS INITIAL ) AND
           NOT pf_werks = '6500' AND NOT pf_werks = '8300'.
        SET CURSOR FIELD 'PF_WERKS'.
        MESSAGE e000 WITH 'Enter valid plant (6500/8300)'.
      ENDIF.
    
      IF NOT st_exidv[] IS INITIAL AND pf_signi IS INITIAL.
        SET CURSOR FIELD 'PF_SIGNI'.
        MESSAGE e000 WITH 'Enter trailer ID number'.
      ENDIF.
    
      IF NOT st_exidv[] IS INITIAL AND pf_bolnr IS INITIAL.
        SET CURSOR FIELD 'PF_BOLNR'.
        MESSAGE e000 WITH 'Enter bill of lading number'.
      ENDIF.
    
    *&---------------------------------------------------------------------*
    *&   Event START-OF-SELECTION
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.
    
      IF st_exidv IS INITIAL.
        PERFORM get_barcode.
      ELSE.
        LOOP AT st_exidv.
          gt_exidv-exidv = st_exidv-low.
          gt_exidv-werks = pf_werks.
          gt_exidv-signi = pf_signi.
          gt_exidv-bolnr = pf_bolnr.
          gt_exidv-wadat = pf_wadat.
          APPEND gt_exidv.
        ENDLOOP.
      ENDIF.
    
    *&---------------------------------------------------------------------*
    *&   Event END-OF-SELECTION
    *&---------------------------------------------------------------------*
    END-OF-SELECTION.
    
      IF gt_exidv[] IS INITIAL.
        MESSAGE i000(zrf) WITH 'No data found for given selection'.
        EXIT.
      ENDIF.
      PERFORM process_data.
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_BARCODE
    *&---------------------------------------------------------------------*
    FORM get_barcode.
    
      TYPES: BEGIN OF lrec,
               docnum TYPE edi_docnum,
               werks  TYPE werks_d,
               signi  TYPE signi,
               bolnr  TYPE vbeln,
               wadat  TYPE wadat,
             END OF lrec.
      DATA: lt_idoc TYPE STANDARD TABLE OF lrec WITH HEADER LINE,
            lf_date TYPE sydatum,
            lf_data TYPE edi_sdata.
    
    *-Get all (status 52 & 53) lt_idoc number for given date
      SELECT docnum INTO TABLE lt_idoc FROM edidc
                                       WHERE credat = pf_wadat
                                       AND   mestyp = 'ZDLPGI'
                                       AND ( status = '52'
                                       OR    status = '53' ).
    
    *-Filter the list for given plant and trailer number
      LOOP AT lt_idoc.
        SELECT SINGLE sdata INTO lf_data FROM  edid4
                                         WHERE docnum  EQ lt_idoc-docnum
                                         AND   segnam  EQ 'E1EDK31'.
    *---If CST IDOC then remove from list
        IF lf_data+228(5) NE space.
          DELETE lt_idoc.
          CONTINUE.
        ENDIF.
    *---If not given plant then remove from list
        IF NOT pf_werks IS INITIAL AND pf_werks NE lf_data+208(4).
          DELETE lt_idoc.
          CONTINUE.
        ENDIF.
    *---If not given trailer then remove from list
        TRANSLATE lf_data+168(10) TO UPPER CASE.
        IF NOT pf_signi IS INITIAL AND pf_signi NE lf_data+168(10).
          DELETE lt_idoc.
          CONTINUE.
        ENDIF.
    *---If not given BOL then remove from list
        IF NOT pf_bolnr IS INITIAL AND pf_bolnr NE lf_data+188(10).
          DELETE lt_idoc.
          CONTINUE.
        ENDIF.
        lt_idoc-werks = lf_data+208(4).
        lt_idoc-signi = lf_data+168(10).
        lt_idoc-bolnr = lf_data+188(10).
    *---Get ship date
        SELECT SINGLE sdata INTO lf_data FROM  edid4
                                         WHERE docnum  EQ lt_idoc-docnum
                                         AND   segnam  EQ 'E1EDT10'.
        IF sy-subrc = 0.
          lt_idoc-wadat = lf_data+27(10).
        ENDIF.
        MODIFY lt_idoc.
      ENDLOOP.
    
    *-Get the barcode for the selected idoc, if not processed before
      lf_date = pf_wadat - 1.
      LOOP AT lt_idoc.
        SELECT sdata INTO lf_data FROM  edid4
                                WHERE docnum  EQ lt_idoc-docnum
                                AND   segnam  EQ 'E1EDL07'.
          SELECT SINGLE COUNT(*) FROM  zremote_log
                                 WHERE ( erdat = pf_wadat
                                 OR      erdat = lf_date )
                                 AND     exidv = lf_data+10(9).
          IF sy-subrc NE 0.
            gt_exidv-werks = lt_idoc-werks.
            gt_exidv-signi = lt_idoc-signi.
            gt_exidv-bolnr = lt_idoc-bolnr.
            gt_exidv-wadat = lt_idoc-wadat.
            gt_exidv-exidv = lf_data+10(9).
            APPEND gt_exidv.
          ENDIF.
        ENDSELECT.
      ENDLOOP.
    
    *-Remove duplicate barcode if any
      SORT gt_exidv BY exidv.
      DELETE ADJACENT DUPLICATES FROM gt_exidv COMPARING exidv.
    
    ENDFORM.                    " GET_BARCODE
    *&---------------------------------------------------------------------*
    *&      Form  PROCESS_DATA
    *&---------------------------------------------------------------------*
    FORM process_data.
    
      TYPES: BEGIN OF lrec,
               werks  TYPE werks_d,
               signi  TYPE signi,
               bolnr  TYPE vbeln,
               wadat  TYPE wadat,
               vbeln  TYPE vbeln,
             END OF lrec.
      DATA: lt_trlr  TYPE STANDARD TABLE OF lrec  WITH HEADER LINE,
            lf_msg   TYPE char40.
    
    *-Group by trailer
      LOOP AT gt_exidv.
        lt_trlr-werks = gt_exidv-werks.
        lt_trlr-signi = gt_exidv-signi.
        lt_trlr-bolnr = gt_exidv-bolnr.
        lt_trlr-wadat = gt_exidv-wadat.
    *---Get the delivery number for barcodes in trailer
        SELECT SINGLE inhalt INTO lt_trlr-vbeln FROM  vekp
                             WHERE exidv  EQ gt_exidv-exidv
                             AND   status NE '0060'.
    *---If barcode not found then write log
        IF sy-subrc NE 0.
          lf_msg = 'Barcode Not Found'.
          WRITE :/ lt_trlr-werks,  (10) lt_trlr-signi, (10) lt_trlr-bolnr,
                   (10) gt_exidv-exidv, lf_msg.
        ENDIF.
        CHECK NOT lt_trlr-vbeln IS INITIAL.
        gt_exidv-vbeln = lt_trlr-vbeln.
        MODIFY gt_exidv.
        COLLECT lt_trlr.
      ENDLOOP.
    
    *-Process each delivery
      LOOP AT lt_trlr.
        SELECT SINGLE COUNT(*) FROM likp WHERE vbeln     = lt_trlr-vbeln
                                         AND   wadat_ist = '00000000'.
    *---If PGI is already done then skip the process
        IF sy-subrc NE 0.
          MESSAGE s000(zrf) WITH lt_trlr-vbeln 'Delivery already PGIed'.
          CONTINUE.
        ENDIF.
        SELECT SINGLE COUNT(*) FROM lips WHERE vbeln = lt_trlr-vbeln
                                         AND   zzconpath NE space.
    *---If consolidation delivery then skip the process
        IF sy-subrc EQ 0.
          lf_msg = 'NAPD Model - Use Transaction ZRMFGCST'.
          WRITE :/ lt_trlr-signi, lt_trlr-vbeln, lf_msg.
          CONTINUE.
        ENDIF.
    *---PGI the delivery
        PERFORM process_pgi USING lt_trlr-werks lt_trlr-signi lt_trlr-bolnr
                                  lt_trlr-wadat lt_trlr-vbeln.
    *---Check for PGI completion
        SELECT SINGLE COUNT(*) FROM likp WHERE vbeln     = lt_trlr-vbeln
                                         AND   wadat_ist = '00000000'.
        IF sy-subrc EQ 0.
          lf_msg = 'PGI Failed - Check workflow'.
          WRITE :/ lt_trlr-signi, lt_trlr-vbeln, lf_msg.
        ELSE.
          MESSAGE s000(zrf) WITH lt_trlr-vbeln 'Delivery PGIed'.
        ENDIF.
      ENDLOOP.
    
    ENDFORM.                    " PROCESS_DATA
    *&---------------------------------------------------------------------*
    *&      Form  PROCESS_PGI
    *&---------------------------------------------------------------------*
    FORM process_pgi USING pf_werks pf_signi pf_bolnr pf_wadat pf_vbeln.
    
      DATA:  lt_exidv TYPE STANDARD TABLE OF exidv WITH HEADER LINE,
             lf_msg   TYPE camsg.
    
    *-Get all HU for given delivery
      LOOP AT gt_exidv WHERE vbeln = pf_vbeln.
        APPEND gt_exidv-exidv TO lt_exidv.
      ENDLOOP.
    
    *-If no HU given then exit
      CHECK NOT lt_exidv[] IS INITIAL.
    
    *-If delivery is not picking relevant then exit
      SELECT SINGLE COUNT(*) FROM vbuk WHERE vbeln EQ pf_vbeln
                                       AND   kostk NE space.
      IF sy-subrc EQ 0.
        lf_msg = 'Delivery is picking relevant'.
        PERFORM create_workflow TABLES lt_exidv USING pf_werks pf_vbeln
                                       pf_bolnr pf_signi pf_wadat lf_msg.
        EXIT.
      ENDIF.
    
    *-Update given delivery header text
      PERFORM update_text USING pf_vbeln pf_bolnr pf_signi pf_wadat.
      IF sy-subrc NE 0.
        lf_msg = 'Delivery header text update failed'.
        PERFORM create_workflow TABLES lt_exidv USING pf_werks pf_vbeln
                                       pf_bolnr pf_signi pf_wadat lf_msg.
        EXIT.
      ENDIF.
    
    *-Split delivery
      PERFORM split_delivery TABLES lt_exidv USING pf_vbeln.
      IF sy-subrc NE 0.
        lf_msg = 'Delivery Split Failed'.
        PERFORM create_workflow TABLES lt_exidv USING pf_werks pf_vbeln
                                       pf_bolnr pf_signi pf_wadat lf_msg.
        EXIT.
      ENDIF.
    
    *-Create material document
      PERFORM create_md TABLES lt_exidv USING pf_vbeln lf_msg.
      IF NOT lf_msg IS INITIAL.
        PERFORM create_workflow TABLES lt_exidv USING pf_werks pf_vbeln
                                       pf_bolnr pf_signi pf_wadat lf_msg.
        EXIT.
      ENDIF.
    
    *-PGI the delivery
      PERFORM pgi_delivery USING pf_vbeln.
      IF sy-subrc NE 0.
        PERFORM get_error USING lf_msg.
        PERFORM create_workflow TABLES lt_exidv USING pf_werks pf_vbeln
                                       pf_bolnr pf_signi pf_wadat lf_msg.
        EXIT.
      ENDIF.
    
    *-Insert into log table for BW extract
      PERFORM insert_log TABLES lt_exidv USING pf_werks pf_vbeln pf_signi.
    
    ENDFORM.                    " PROCESS_PGI
    *&---------------------------------------------------------------------
    *&      Form  UPDATE_TEXT
    *&---------------------------------------------------------------------
    FORM update_text USING pf_vbeln pf_bolnr pf_signi pf_date.
    
      DATA: ls_header LIKE thead,
            lf_posnr  LIKE lips-posnr,
            lt_lines  TYPE STANDARD TABLE OF tline WITH HEADER LINE.
    
    *-Populate Header Text details
      ls_header-tdobject  = 'VBBK'.
      ls_header-tdname    = pf_vbeln.
      ls_header-tdid      = 'ZRM0'.
      ls_header-tdspras   = sy-langu.
    
    *-Populate details of Text
      CONCATENATE 'Shipment No   :' 'RM Ship No' INTO lt_lines-tdline
      SEPARATED BY space.
      lt_lines-tdformat = '*'.
      APPEND lt_lines.
    
      CONCATENATE 'Bill of Lading:' pf_bolnr INTO lt_lines-tdline
      SEPARATED BY space.
      APPEND lt_lines.
    
      IF pf_signi EQ space.
        pf_signi = 'RM TRAILER'.
      ENDIF.
      CONCATENATE 'Trailer       :' pf_signi INTO lt_lines-tdline
      SEPARATED BY space.
      APPEND lt_lines.
    
      IF pf_date IS INITIAL.
        pf_date = sy-datum.
      ENDIF.
      CONCATENATE 'Act Ship Date :' pf_date INTO lt_lines-tdline
      SEPARATED BY space.
      APPEND lt_lines.
    
      CONCATENATE 'Route         :' 'RM Route' INTO lt_lines-tdline
      SEPARATED BY space.
      APPEND lt_lines.
    
    *-Save Text
      CALL FUNCTION 'SAVE_TEXT'
        EXPORTING
          client          = sy-mandt
          header          = ls_header
          savemode_direct = 'X'
        TABLES
          lines           = lt_lines
        EXCEPTIONS
          OTHERS          = 1.
    
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
    
    *-Populate header and item text details
      ls_header-tdid      = 'Z052'.
      REFRESH lt_lines.
      lt_lines-tdline = pf_date.
      lt_lines-tdformat = '*'.
      APPEND lt_lines.
    
    *-Save Text for actual ship date
      CALL FUNCTION 'SAVE_TEXT'
        EXPORTING
          client          = sy-mandt
          header          = ls_header
          savemode_direct = 'X'
        TABLES
          lines           = lt_lines
        EXCEPTIONS
          OTHERS          = 1.
    
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
    
    *-Insert Texts at Item level.
      SELECT posnr INTO lf_posnr FROM lips WHERE vbeln = pf_vbeln.
        PERFORM item_text USING pf_vbeln lf_posnr 'ZLO1' pf_bolnr.
        PERFORM item_text USING pf_vbeln lf_posnr 'ZLO2' pf_date.
        PERFORM item_text USING pf_vbeln lf_posnr 'ZLO3' pf_signi.
        PERFORM item_text USING pf_vbeln lf_posnr 'ZLO4' 'Routing'.
      ENDSELECT.
    
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
    
    *-Update delivery header with bolnr and trailer Id
      UPDATE likp SET bolnr = pf_bolnr traid = pf_signi
                                 WHERE vbeln = pf_vbeln.
      COMMIT WORK AND WAIT.
    
    ENDFORM.                    " UPDATE_TEXT
    *&---------------------------------------------------------------------
    *&      Form  ITEM_TEXT
    *&---------------------------------------------------------------------
    FORM item_text USING pf_vbeln pf_posnr pf_id pf_title.
    
      DATA: ls_header LIKE thead,
            lt_lines TYPE STANDARD TABLE OF tline WITH HEADER LINE.
    
      CONCATENATE pf_vbeln pf_posnr INTO ls_header-tdname.
      ls_header-tdspras   = sy-langu.
      ls_header-tdobject  = 'VBBP'.
      ls_header-tdid      = pf_id.
      ls_header-tdtitle   = pf_title.
    
      lt_lines-tdline   = pf_title .
      lt_lines-tdformat = '*'.
      APPEND lt_lines.
    
      CALL FUNCTION 'SAVE_TEXT'
        EXPORTING
          client          = sy-mandt
          header          = ls_header
          savemode_direct = 'X'
        TABLES
          lines           = lt_lines
        EXCEPTIONS
          OTHERS          = 1.
    
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
    
    ENDFORM.                    " ITEM_TEXT
    *&---------------------------------------------------------------------
    *&      Form  SPLIT_DELIVERY
    *&---------------------------------------------------------------------
    FORM split_delivery TABLES pt_exidv USING pf_vbeln.
    
      DATA: lt_hu    TYPE STANDARD TABLE OF zhu_data  WITH HEADER LINE,
            lf_exidv TYPE exidv.
    
    *-Get number of HU for given delivery
      SELECT COUNT(*) FROM vekp WHERE inhalt  = pf_vbeln
                                AND   status <> '0060'.
    
    *-Check for split required
      DESCRIBE TABLE pt_exidv.
      CHECK sy-tfill LT sy-dbcnt.
    
    *-Get HU data for given delivery
      CALL FUNCTION 'Z_HU_GET_MULTI_DATA'
        EXPORTING
          if_vbeln = pf_vbeln
        TABLES
          et_hu    = lt_hu.
    
    *-Remove all HU that are not in IDOC
      LOOP AT lt_hu.
        READ TABLE pt_exidv INTO lf_exidv WITH KEY lt_hu-exidv.
        IF sy-subrc NE 0.
          DELETE lt_hu.
        ENDIF.
      ENDLOOP.
    
    *-Split the delivery
      CALL FUNCTION 'Z_DELIVERY_SPLIT_BY_HU'
        TABLES
          it_hu_data = lt_hu
        EXCEPTIONS
          OTHERS     = 1.
    
    ENDFORM.                    " SPLIT_DELIVERY
    *&---------------------------------------------------------------------*
    *&      Form  PGI_DELIVERY
    *&---------------------------------------------------------------------*
    FORM pgi_delivery USING pf_vbeln.
    
      DATA: lt_bdc TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE,
            lf_mode VALUE 'N'.
    
      PERFORM bdc_dynpro TABLES lt_bdc USING 'SAPMV50A' '4004'.
      PERFORM bdc_field  TABLES lt_bdc USING  'LIKP-VBELN' pf_vbeln.
      PERFORM bdc_field  TABLES lt_bdc USING 'BDC_OKCODE' 'WABU_T'.
    
      CALL TRANSACTION 'VL02N' USING  lt_bdc
                               MODE   lf_mode
                               UPDATE 'S'.
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
      COMMIT WORK AND WAIT.
    
    ENDFORM.                    " PGI_DELIVERY
    *&---------------------------------------------------------------------*
    *&      Form  INSERT_LOG
    *&---------------------------------------------------------------------*
    FORM insert_log TABLES pt_exidv USING pf_werks pf_vbeln pf_signi.
    
      DATA: ls_log   TYPE zremote_log,
            lf_lgnum TYPE lgnum.
    
      IF pf_werks = '6500'.
        lf_lgnum = 'ATL'.
      ELSEIF pf_werks = '8300'.
        lf_lgnum = 'AMX'.
      ENDIF.
      LOOP AT pt_exidv.
        ls_log-erdat = sy-datum.
        ls_log-vbeln = pf_vbeln.
        ls_log-exidv = pt_exidv.
        ls_log-lgnum = lf_lgnum.
        ls_log-tknum = pf_signi.
        INSERT zremote_log FROM ls_log.
      ENDLOOP.
    
    ENDFORM.                    " INSERT_LOG
    *&---------------------------------------------------------------------*
    *&      form  BDC_DYNPRO
    *&---------------------------------------------------------------------*
    FORM bdc_dynpro TABLES pt_bdc STRUCTURE bdcdata
                    USING  lf_program lf_dynpro.
    
      CLEAR pt_bdc.
      pt_bdc-program  = lf_program.
      pt_bdc-dynpro   = lf_dynpro.
      pt_bdc-dynbegin = 'X'.
      APPEND pt_bdc.
    
    ENDFORM.         "  BDC_DYNPRO
    *&---------------------------------------------------------------------*
    *&      form  BDC_FIELD
    *&---------------------------------------------------------------------*
    FORM bdc_field TABLES pt_bdc STRUCTURE bdcdata USING pf_nam pf_val.
    
      CLEAR pt_bdc.
      pt_bdc-fnam = pf_nam.
      pt_bdc-fval = pf_val.
      APPEND pt_bdc.
    
    ENDFORM.       "  BDC_FIELD
    *&---------------------------------------------------------------------*
    *&      Form  GET_ERROR
    *&---------------------------------------------------------------------*
    FORM get_error USING pf_msg.
    
      DATA: ls_messg LIKE message.
    
      CALL FUNCTION 'WRITE_MESSAGE'
        EXPORTING
          msgid = sy-msgid
          msgno = sy-msgno
          msgty = sy-msgty
          msgv1 = sy-msgv1
          msgv2 = sy-msgv2
          msgv3 = sy-msgv3
          msgv4 = sy-msgv4
        IMPORTING
          messg = ls_messg.
    
      pf_msg = ls_messg-msgtx.
    
    ENDFORM.                    " GET_ERROR
    *&---------------------------------------------------------------------*
    *&      Form  CREATE_MD
    *&---------------------------------------------------------------------*
    FORM create_md TABLES lt_exidv USING pf_vbeln pf_msg.
    
      DATA: ls_header LIKE bapi2017_gm_head_01,
            ls_code   LIKE bapi2017_gm_code,
            ls_vekpo  TYPE zvekpo,
            lf_exidv  TYPE exidv,
            lt_ret    TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE,
            lt_item   TYPE STANDARD TABLE OF bapi2017_gm_item_create
                      WITH HEADER LINE.
    
    *-Fill the header detail
      ls_header-pstng_date     = sy-datum.
      ls_header-doc_date       = sy-datum.
      ls_header-pr_uname       = sy-uname.
      ls_code-gm_code          = '05'.
    
    *-Fill item detail
      LOOP AT lt_exidv INTO lf_exidv.
        CLEAR ls_vekpo.
        SELECT SINGLE * FROM zvekpo INTO  ls_vekpo
                                    WHERE exidv  =  lf_exidv
                                    AND   inhalt =  pf_vbeln
                                    AND   status <> '0060'.
        SELECT SINGLE COUNT(*) FROM  mseg
                               WHERE matnr     = ls_vekpo-matnr
                               AND   werks     = ls_vekpo-werks
                               AND   lgort     = ls_vekpo-werks
                               AND   bwart     = '561'
                               AND   sobkz     = ls_vekpo-sobkz
                               AND   mat_kdauf = ls_vekpo-sonum(10)
                               AND   mat_kdpos = ls_vekpo-sonum+10(6)
                               AND   wempf     = lf_exidv.
        IF sy-subrc EQ 0.
          CONTINUE.
        ENDIF.
        lt_item-plant          = ls_vekpo-werks.
        lt_item-material       = ls_vekpo-matnr.
        lt_item-entry_qnt      = ls_vekpo-vemng.
        lt_item-entry_uom      = ls_vekpo-altme.
        lt_item-spec_stock     = ls_vekpo-sobkz.
        lt_item-sales_ord      = ls_vekpo-sonum(10).
        lt_item-s_ord_item     = ls_vekpo-sonum+10(6).
        lt_item-val_sales_ord  = ls_vekpo-sonum(10).
        lt_item-val_s_ord_item = ls_vekpo-sonum+10(6).
        lt_item-move_type      = '561'.
        lt_item-stge_loc       = ls_vekpo-werks.
        lt_item-gr_rcpt        = lf_exidv.
        APPEND lt_item.
      ENDLOOP.
    
      CHECK NOT lt_item[] IS INITIAL.
    
    *-Create material document
      CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
        EXPORTING
          goodsmvt_header = ls_header
          goodsmvt_code   = ls_code
        TABLES
          goodsmvt_item   = lt_item
          return          = lt_ret.
    
    *-If any error then send message back
      READ TABLE lt_ret INDEX 1.
      IF lt_ret-type EQ 'E'.
        pf_msg = lt_ret-message.
      ELSE.
        COMMIT WORK AND WAIT.
      ENDIF.
    
    ENDFORM.                    " CREATE_MD
    *&---------------------------------------------------------------------
    *&      Form  CREATE_WORKFLOW
    *&---------------------------------------------------------------------
    FORM create_workflow TABLES pt_exidv
             USING  pf_werks pf_vbeln pf_bolnr pf_signi pf_date  pf_msg.
    
      INCLUDE <cntn01>.
      swc_container my_container.
      DATA: lf_objkey LIKE sweinstcou-objkey.
    
      CONCATENATE 'NON SAP PGI' pf_msg INTO pf_msg SEPARATED BY space.
      swc_set_element my_container 'Plant'    pf_werks.
      swc_set_element my_container 'Delivery' pf_vbeln.
      swc_set_element my_container 'Bolnr'    pf_bolnr.
      swc_set_element my_container 'Trailer'  pf_signi.
      swc_set_element my_container 'PGIDate'  pf_date.
      swc_set_element my_container 'Message'  pf_msg.
      swc_set_table   my_container 'Barcode'  pt_exidv.
      lf_objkey = pf_vbeln.
      CALL FUNCTION 'SWE_EVENT_CREATE'
        EXPORTING
          objtype         = 'ZRMPGI'
          objkey          = lf_objkey
          event           = 'CAPTUREERROR'
        TABLES
          event_container = my_container.
      COMMIT WORK.
    
    ENDFORM.                    " CREATE_WORKFLOW

    Message was edited by: Vijay Babu Dudla

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Vijay Babu Dudla,

      I am looking for a function by which I can split the handling units of a delivery. Transaction "VLSP" can be used to do the above but I need to get this done via a program. I looked at BAPI_OUTB_DELIVERY_SPLIT_DEC but that doesn't seem to deal with Handling units.

      You seem to be using the function 'Z_DELIVERY_SPLIT_BY_HU'

      Can you detail the source code for that please.

      Your help on this will be much appreciated.

      Thanks and regards

      Mohamed