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

Copy TOPO task loc & list between plants



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Other
View previous topic :: View next topic  
Author Message
vga
Мастер
Мастер


Age: 48
Joined: 04 Oct 2007
Posts: 1218
Location: Питер

PostPosted: Thu Mar 14, 2013 9:48 am    Post subject: Copy TOPO task loc & list between plants Reply with quote

Code:
*&---------------------------------------------------------------------*
*& Report  Z_TOPO_PLANT_COPY
*&
*&---------------------------------------------------------------------*
*  CHANGES:
*
*  Description                          : Copy TOPO task loc & list
*                                         between plants
*"----------------------------------------------------------------------

REPORT  z_topo_plant_copy.

TABLES: iflot.

TYPES: BEGIN OF ty_iflot,
          tplnr   TYPE iflot-tplnr,
          tplkz   TYPE iflot-tplkz,
          fltyp TYPE iflot-fltyp,
          iwerk TYPE iflot-iwerk,
          tplma   TYPE iflot-tplma,
          level TYPE sy-index,
       END OF ty_iflot.

TYPES: BEGIN OF ty_plwp.
        INCLUDE STRUCTURE plwp.
TYPES: END OF ty_plwp.

TYPES: BEGIN OF ty_plpo,
          plnty TYPE plpo-plnty,
          plnnr TYPE plpo-plnnr,
          plnkn TYPE plpo-plnkn,
          zaehl TYPE plpo-zaehl,
          loekz TYPE plpo-loekz,
          sumnr TYPE plpo-sumnr,
          sortn TYPE plpo-plnkn,
       END OF ty_plpo.

TYPES: BEGIN OF ty_matrix,
          plnkn TYPE plwp-plnkn,
          paket TYPE plwp-paket,
          newline TYPE as4flag,
       END OF ty_matrix.

DATA: l_level TYPE sy-index,
      g_lines TYPE sy-index,
      g_pos   TYPE sy-index,
      ls_iflot TYPE ty_iflot,
      lt_iflot TYPE TABLE OF ty_iflot,
      ls_plwp TYPE ty_plwp,
      lt_plwp TYPE TABLE OF ty_plwp,
      ls_plpo TYPE ty_plpo,
      lt_plpo TYPE TABLE OF ty_plpo,
      ls_tapl TYPE tapl,
      lt_tapl TYPE TABLE OF tapl,
      ls_plas TYPE plas,
      lt_plas TYPE TABLE OF plas,
      ls_matrix TYPE ty_matrix,
      lt_matrix TYPE TABLE OF ty_matrix.

CONSTANTS: lc_msg_pos TYPE i VALUE '90',
           g_nobinpt TYPE sy-binpt VALUE 'X'.
FIELD-SYMBOLS: <fs_up>  TYPE ty_iflot,
               <fs>     TYPE ty_iflot,
               <fs_plpo> TYPE ty_plpo.

SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME TITLE text-001.
SELECT-OPTIONS: so_tplnr FOR iflot-tplnr. "From Functional Location

PARAMETERS: p_from TYPE iflot-iwerk DEFAULT '1890', "Frpm plant
            p_to   TYPE iflot-iwerk DEFAULT '1790', "To plant
            p_gewrk TYPE itobattr-gewrk DEFAULT 'PM_WC_01',
            p_kostl TYPE itob-kostl DEFAULT '17902100',
            p_funloc AS CHECKBOX DEFAULT 'X', "Copy Function location
            p_tsklst AS CHECKBOX DEFAULT ''.  "Copy Task List
SELECTION-SCREEN END OF BLOCK main.

SELECTION-SCREEN BEGIN OF BLOCK ctu WITH FRAME TITLE text-002.
PARAMETERS: p_dismod TYPE ctu_params-dismode DEFAULT 'E', "Batch Input Display Mode
                                      "A: show all dynpros
                                      "E: show dynpro on error only
                                      "N: do not display dynpro
            p_test  AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK ctu.

START-OF-SELECTION.
  WRITE: / 'Selecting data from table IFLOT...'.

  SELECT tplnr
         tplkz
         fltyp
         iwerk
         tplma
    FROM iflot
    INTO CORRESPONDING FIELDS OF TABLE lt_iflot
    WHERE tplnr IN so_tplnr
      AND iwerk = p_from.

END-OF-SELECTION.
  IF lt_iflot IS INITIAL.
    WRITE: / 'There is no data to copy...'.
    EXIT.
  ENDIF.

  DESCRIBE TABLE lt_iflot LINES g_lines.

  SORT lt_iflot BY tplnr.
  LOOP AT lt_iflot ASSIGNING <fs_up>.
    l_level = 1.
    ls_iflot-tplma = <fs_up>-tplma.
    DO.
      READ TABLE lt_iflot ASSIGNING <fs> WITH KEY tplnr = ls_iflot-tplma
                                                          BINARY SEARCH.
      IF NOT sy-subrc IS INITIAL.
        <fs_up>-level = l_level.
        EXIT.
      ELSE.
        ls_iflot-tplma = <fs>-tplma.
        l_level = l_level + 1.
      ENDIF.
    ENDDO.
  ENDLOOP.
  SORT lt_iflot BY level.

  DATA: l_strno TYPE iflos-strno,
        l_subrc TYPE sy-subrc.

  IF NOT p_funloc IS INITIAL.
    WRITE: / 'Start processing Functional Location...'.

    CLEAR g_pos.
    LOOP AT lt_iflot ASSIGNING <fs_up> WHERE iwerk = p_from.

      g_pos = g_pos + 1.
      PERFORM show_process USING 'Task location:' g_pos g_lines.

      l_strno = <fs_up>-tplnr.
      l_strno(4) = p_to.
      IF sy-uname EQ 'VAFANASY'.
        l_strno(4) = 'TEST'.
      ENDIF.

      WRITE: / <fs_up>-tplnr, '-> '.

      SELECT SINGLE tplnr INTO l_strno
        FROM iflot
        WHERE tplnr = l_strno.

      IF sy-subrc IS INITIAL.
        WRITE: AT lc_msg_pos 'already exists'.
        CONTINUE.
      ENDIF.
      WRITE: l_strno.

      PERFORM open_group.

      PERFORM bdc_dynpro      USING 'SAPMILO0' '1110'.
      PERFORM bdc_field       USING 'BDC_CURSOR' 'RILO0-TPLCP'.
      PERFORM bdc_field       USING 'BDC_OKCODE' '/00'.
      PERFORM bdc_field       USING 'IFLOS-STRNO' l_strno.
      PERFORM bdc_field       USING 'RILO0-TPLKZ' <fs_up>-tplkz.
      PERFORM bdc_field       USING 'IFLO-FLTYP'  <fs_up>-fltyp.
      PERFORM bdc_field       USING 'RILO0-TPLCP' <fs_up>-tplnr.

      PERFORM bdc_dynpro      USING 'SAPMILO0' '6190'.
      PERFORM bdc_field       USING 'BDC_CURSOR' 'IFLO_CP-TPLNR'.
      PERFORM bdc_field       USING 'BDC_OKCODE' '=NEXT'.
      PERFORM bdc_field       USING 'RILOCP-CPTXT' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPTXA' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPCLS' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPDOC' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPPRT' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPPRM' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPADR' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPMPT' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPMPX' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPMPC' 'X'.
      PERFORM bdc_field       USING 'RILOCP-CPMPD' 'X'.

      IF NOT g_nobinpt IS INITIAL.
        PERFORM bdc_dynpro      USING 'SAPMILO0' '2100'.
        PERFORM bdc_field       USING 'BDC_CURSOR' 'IFLO-PLTXT'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=CHP'.
*      PERFORM bdc_field       USING 'ITOB-SWERK' p_to.
        PERFORM bdc_field       USING 'ITOB-IWERK' p_to.
        PERFORM bdc_field       USING 'ITOBATTR-GEWRK' p_gewrk. "'PM_WC_01'. " change

        PERFORM bdc_dynpro      USING 'SAPMILO0' '6180'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=NEXT'.
        PERFORM bdc_field       USING 'BDC_CURSOR' 'ITOB-SWERK'.
        PERFORM bdc_field       USING 'ITOB-SWERK' p_to.

        PERFORM bdc_dynpro      USING 'SAPMILO0' '2100'.
        PERFORM bdc_field       USING 'BDC_CURSOR' 'IFLO-PLTXT'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=T\02'.
*        PERFORM bdc_field       USING 'ITOB-SWERK' p_to.
        PERFORM bdc_field       USING 'ITOB-IWERK' p_to.
        PERFORM bdc_field       USING 'ITOBATTR-GEWRK' p_gewrk. "'PM_WC_01'. " change

      ELSE.
        PERFORM bdc_dynpro      USING 'SAPMILO0' '2100'.
        PERFORM bdc_field       USING 'BDC_CURSOR' 'IFLO-PLTXT'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=T\02'.
        PERFORM bdc_field       USING 'ITOB-SWERK' p_to.
        PERFORM bdc_field       USING 'ITOB-IWERK' p_to.
        PERFORM bdc_field       USING 'ITOBATTR-GEWRK' p_gewrk. "'PM_WC_01'. " change
      ENDIF.
      PERFORM bdc_dynpro      USING 'SAPMILO0' '2100'.
      PERFORM bdc_field       USING 'BDC_CURSOR' 'ITOB-KOSTL'.
      PERFORM bdc_field       USING 'BDC_OKCODE' '=T\01'.
      PERFORM bdc_field       USING 'ITOB-KOSTL' p_kostl. "'17902100'. " change

      PERFORM bdc_dynpro      USING 'SAPMILO0' '2100'.
      PERFORM bdc_field       USING 'BDC_CURSOR' 'IFLO-PLTXT'.
      IF p_test IS INITIAL.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=BU'.
      ELSE.
        PERFORM bdc_field       USING 'BDC_OKCODE' '/EEN'.

        PERFORM bdc_dynpro      USING 'SAPLSPO1' '0100'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=NO'.
      ENDIF.
      PERFORM bdc_transaction USING 'IL01' CHANGING l_subrc.
      IF NOT l_subrc IS INITIAL.
        WRITE: AT lc_msg_pos 'COPY ERROR!'.
      ENDIF.
      PERFORM close_group.

      IF sy-batch IS INITIAL.
        CALL FUNCTION 'TH_REDISPATCH'.
      ENDIF.

    ENDLOOP.
    WRITE: / 'Finish processing Functional Location'.
  ENDIF.

  CONSTANTS: lc_defsize TYPE i VALUE '11', "default size of screen table of ia11,
             lc_defsize_15 TYPE i VALUE '15'. "default size of Pack TOPO screen

  DATA: l_from_tasklist_count TYPE sy-tabix,
        l_to_tasklist_count TYPE sy-tabix,
        l_plnkn TYPE plwp-plnkn,
        l_row   TYPE plwp-paket,
        l_pos(2) TYPE n,
        l_mod TYPE i,
        l_pick_count TYPE i,
        l_first TYPE i,
        l_end TYPE i,
        l_fval TYPE bdcdata-fval,
        l_fnam TYPE bdcdata-fnam.

  IF NOT p_tsklst IS INITIAL.

    WRITE: / 'Start processing Task List...'.

    IF NOT lt_iflot[] IS INITIAL.
      SELECT * FROM tapl INTO TABLE lt_tapl
        FOR ALL ENTRIES IN lt_iflot
        WHERE tplnr = lt_iflot-tplnr
          AND datuv LE sy-datum
          AND loekz = ''.
    ENDIF.

    IF NOT lt_tapl[] IS INITIAL.
      SELECT *
        INTO TABLE lt_plas
        FROM plas
        FOR ALL ENTRIES IN lt_tapl
        WHERE plnty = lt_tapl-plnty
          AND plnnr = lt_tapl-plnnr
          AND plnal = lt_tapl-plnal
          AND plnty = 'T'
          AND loekz = ''.

    ENDIF.

    SORT lt_plas BY plnty plnnr plnal.

    IF NOT lt_plas[] IS INITIAL.
      SELECT *
        INTO TABLE lt_plwp
        FROM plwp
        FOR ALL ENTRIES IN lt_plas
        WHERE plnty = lt_plas-plnty
          AND plnnr = lt_plas-plnnr
          AND plnal = lt_plas-plnal
          AND loekz = ''.

      SELECT
          plnty
          plnnr
          plnkn
          zaehl
          loekz
          sumnr
        INTO CORRESPONDING FIELDS OF TABLE lt_plpo
        FROM plpo
        FOR ALL ENTRIES IN lt_plas
        WHERE plnty = lt_plas-plnty
          AND plnnr = lt_plas-plnnr
          AND loekz = ''.

      LOOP AT lt_plpo ASSIGNING <fs_plpo>.
        IF <fs_plpo>-sumnr IS INITIAL.
          <fs_plpo>-sortn = <fs_plpo>-plnkn.
        ELSE.
          <fs_plpo>-sortn = <fs_plpo>-sumnr.
        ENDIF.
      ENDLOOP.
      SORT lt_plpo BY plnty plnnr sortn sumnr.
    ENDIF.

    CLEAR g_pos.
    LOOP AT lt_iflot ASSIGNING <fs_up> WHERE iwerk = p_from.

      g_pos = g_pos + 1.
      PERFORM show_process USING 'Task list:' g_pos g_lines.

      l_strno = <fs_up>-tplnr.
      l_strno(4) = p_to.
      IF sy-uname EQ 'VAFANASY'.
        l_strno(4) = 'TEST'.
      ENDIF.
      WRITE: / <fs_up>-tplnr, '->', l_strno.

      SELECT SINGLE tplnr FROM iflot
        INTO l_strno
        WHERE tplnr = l_strno.

      IF NOT sy-subrc IS INITIAL.
        WRITE: AT lc_msg_pos 'does not exist'.
        CONTINUE.
      ENDIF.

      CLEAR l_from_tasklist_count.
      LOOP AT lt_tapl INTO ls_tapl WHERE tplnr = <fs_up>-tplnr.
        ADD 1 TO l_from_tasklist_count.
      ENDLOOP.

      IF l_from_tasklist_count IS INITIAL.
        WRITE: AT lc_msg_pos 'No valid task list exists. Not copied.'.
        CONTINUE.
      ENDIF.

* Delete exists Task List
      CLEAR l_to_tasklist_count.
      SELECT COUNT(*) FROM tapl INTO l_to_tasklist_count
        WHERE tplnr = l_strno
          AND datuv LE sy-datum
          AND loekz = ''.

*      IF sy-uname EQ 'VAFANASY'.
*        l_to_tasklist_count = 0.
*      ENDIF.

      IF NOT l_to_tasklist_count IS INITIAL.
        PERFORM open_group.

        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3005'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'RC271-PLNAL'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=ALUE'.
        PERFORM bdc_field       USING 'RC27E-TPLNR'
                                      l_strno.
        PERFORM bdc_field       USING 'RC271-PLNAL'
                                      ''.
        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3200'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'RC27X-ENTRY_ACT'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=MAAL'.
        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3200'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'PLKOD-KTEXT(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=LOE'.
        PERFORM bdc_dynpro      USING 'SAPLSPO1' '0100'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=YES'.
        DO l_to_tasklist_count TIMES.

          PERFORM bdc_dynpro      USING 'SAPLSPO2' '0100'.
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=OPT1'.
        ENDDO.

        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3200'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'RC27X-ENTRY_ACT'.
        IF p_test IS INITIAL.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=BU'.
        ELSE.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=END'.

          PERFORM bdc_dynpro      USING 'SAPLSPO1' '0100'.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=NO'.
        ENDIF.

        PERFORM bdc_transaction USING 'IA12' CHANGING l_subrc.

        PERFORM close_group.
      ENDIF.

* Insert Task List
      DATA: l_tapl_count TYPE i.

      PERFORM open_group.
      CLEAR l_pos.
      LOOP AT lt_tapl INTO ls_tapl WHERE tplnr = <fs_up>-tplnr.
        l_pos =  l_pos + 1.

        l_tapl_count = 0.
        LOOP AT lt_tapl TRANSPORTING NO FIELDS
            WHERE tplnr = <fs_up>-tplnr.
          l_tapl_count = l_tapl_count + 1.
        ENDLOOP.

        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3005'.
        PERFORM bdc_field       USING 'BDC_CURSOR' 'RC27E-TPLNR'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=COPY'.
        PERFORM bdc_field       USING 'RC27E-TPLNR' l_strno.

        PERFORM bdc_dynpro      USING 'SAPLCPCO' '0101'.
        PERFORM bdc_field       USING 'BDC_CURSOR' 'TYP(03)'.
        PERFORM bdc_field       USING 'BDC_OKCODE' '=CONT'.
        PERFORM bdc_field       USING 'TYP(01)' ''.
        PERFORM bdc_field       USING 'TYP(02)' ''.
        PERFORM bdc_field       USING 'TYP(03)' 'X'.

        PERFORM bdc_dynpro      USING 'SAPLCPCO' '3005'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'RC27E-TPLNR'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=CONT'.
        PERFORM bdc_field       USING 'RC27E-TPLNR' <fs_up>-tplnr.

        IF l_tapl_count > 1.

          IF l_pos >= lc_defsize.   "default size of screen table of ia11
*         BREAK VAFANASY.
            IF sy-uname EQ 'VAFANASY'.
*            p_dismod = 'A'.
            ENDIF.
          ENDIF.

          l_pick_count = l_pos DIV lc_defsize.
          l_mod = l_pos MOD lc_defsize.
          IF NOT l_pick_count IS INITIAL AND l_mod IS INITIAL.
            l_pick_count = l_pick_count - 1.
          ENDIF.

          DO l_pick_count TIMES.

            PERFORM bdc_dynpro      USING 'SAPLCPSL' '3120'.
            PERFORM bdc_field       USING 'BDC_CURSOR' 'PLKO-KTEXT(01)'.
            PERFORM bdc_field       USING 'BDC_OKCODE' '=P+'.

          ENDDO.

*        l_first = l_pick_count * lc_defsize + 1.
*        l_end = l_first + lc_defsize - 1.
*        IF l_end > l_from_tasklist_count.
*          l_end = l_from_tasklist_count.
*          l_first = l_end - lc_defsize + 1.
*        ENDIF.
*
*        l_pos = l_pos - l_first + 1.

          l_first = l_pick_count * lc_defsize.
          l_end = l_first + lc_defsize.
          IF l_end > l_from_tasklist_count.
            l_end = l_from_tasklist_count.
            l_first = l_end - lc_defsize.
          ENDIF.
          IF l_first < 0.
            l_first = 0.
          ENDIF.

          l_pos = l_pos - l_first.

          PERFORM bdc_dynpro      USING 'SAPLCPSL' '3120'.

          CONCATENATE 'PLKO-KTEXT(' l_pos ')' INTO l_fval.
          PERFORM bdc_field       USING 'BDC_CURSOR' l_fval.
          .
          PERFORM bdc_field       USING 'BDC_OKCODE'
                                        '=PICK'.

        ENDIF.

        PERFORM bdc_dynpro      USING 'SAPLCPDA' '3010'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'RCR01-WERKS'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=NEXT'.

        PERFORM bdc_field       USING 'RCR01-WERKS' p_to.
        PERFORM bdc_field       USING 'PLKOD-STATU' '4'.


        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3400'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'PLPOD-VORNR(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=WPLT'.

        REFRESH lt_matrix.

        LOOP AT lt_plas INTO ls_plas WHERE plnty = ls_tapl-plnty
                                       AND plnnr = ls_tapl-plnnr
                                       AND plnal = ls_tapl-plnal.
          CLEAR ls_matrix.
          ls_matrix-plnkn = ls_plas-plnkn.

          LOOP AT lt_plwp INTO ls_plwp WHERE plnty = ls_plas-plnty
                                         AND plnnr = ls_plas-plnnr
                                         AND plnkn = ls_plas-plnkn
                                         AND plnal = ls_plas-plnal.
            ls_matrix-paket = ls_plwp-paket.
            APPEND ls_matrix TO lt_matrix.
          ENDLOOP.
          IF ls_matrix-paket IS INITIAL.
            APPEND ls_matrix TO lt_matrix.
          ENDIF.

          CLEAR ls_matrix-paket.
          LOOP AT lt_plpo INTO ls_plpo WHERE plnty = ls_plas-plnty
                                         AND plnnr = ls_plas-plnnr
                                         AND sortn = ls_plas-plnkn
                                         AND sumnr <> ''.
            ls_matrix-newline = 'X'.
            APPEND ls_matrix TO lt_matrix.
          ENDLOOP.

        ENDLOOP.

        SORT lt_matrix BY plnkn paket DESCENDING.

        CLEAR: l_plnkn, l_row.

        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3600'.
        IF NOT lt_matrix[] IS INITIAL.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'RIHSTRAT-MARK01(01)'.
        ELSE.
          PERFORM bdc_field       USING 'BDC_CURSOR'
                                        'RC27X-ENTRY_ACT'.
        ENDIF.

        LOOP AT lt_matrix INTO ls_matrix.

          IF ls_matrix-plnkn NE l_plnkn.
            l_plnkn = ls_matrix-plnkn.
            l_row = l_row + 1.
          ELSEIF NOT ls_matrix-newline IS INITIAL.
            l_row = l_row + 1.
          ENDIF.

          l_pick_count = l_row DIV lc_defsize_15.
          l_mod =        l_row MOD lc_defsize_15.
          IF NOT l_pick_count IS INITIAL AND l_mod = 1.
            PERFORM bdc_field       USING 'BDC_OKCODE' '=P+'.
            PERFORM bdc_dynpro      USING 'SAPLCPDI' '3600'.
            PERFORM bdc_field       USING 'BDC_CURSOR'
                                          'RIHSTRAT-MARK01(01)'.
            l_row = 1.
          ENDIF.

          IF NOT ls_matrix-paket IS INITIAL.
            CONCATENATE 'RIHSTRAT-MARK' ls_matrix-paket '(' l_row ')' INTO l_fnam.
            PERFORM bdc_field       USING l_fnam 'X'.
          ENDIF.

        ENDLOOP.

        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BACK'.

        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3400'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'PLPOD-VORNR(01)'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BACK'.

        PERFORM bdc_dynpro      USING 'SAPLCPDA' '3010'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'PLKOD-KTEXT'.
        PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=BACK'.
        PERFORM bdc_field       USING 'RCR01-ARBPL' p_gewrk.

        PERFORM bdc_field       USING 'RCR01-WERKS' p_to.
        PERFORM bdc_field       USING 'PLKOD-STATU' '4'.

        PERFORM bdc_dynpro      USING 'SAPLCPDI' '3200'.
        PERFORM bdc_field       USING 'BDC_CURSOR'
                                      'PLKOD-WERKS(01)'.
        IF p_test IS INITIAL.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=BU'.
        ELSE.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=END'.

          PERFORM bdc_dynpro      USING 'SAPLSPO1' '0100'.
          PERFORM bdc_field       USING 'BDC_OKCODE' '=NO'.
        ENDIF.

        PERFORM bdc_transaction USING 'IA11' CHANGING l_subrc.
        IF NOT l_subrc IS INITIAL.
          WRITE: AT lc_msg_pos 'ERROR!'.
        ENDIF.
        PERFORM close_group.
      ENDLOOP.

      sy-msgv1 = l_from_tasklist_count.
      SHIFT sy-msgv1 LEFT DELETING LEADING space.
      CONCATENATE sy-msgv1 'task list copied.'
        INTO sy-msgv1 SEPARATED BY space.

      WRITE: AT lc_msg_pos sy-msgv1.

      IF sy-batch IS INITIAL.
        CALL FUNCTION 'TH_REDISPATCH'.
      ENDIF.

    ENDLOOP.
    WRITE: / 'Finish processing Task List'.
  ENDIF.

  CONSTANTS: nodata TYPE c VALUE '/'.          "nodata
  DATA:   bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
  DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

*----------------------------------------------------------------------*
*        show_process                                                  *
*----------------------------------------------------------------------*
FORM show_process USING p_text p_pos p_total.

  DATA: l_str TYPE char100,
        l_mod TYPE i,
        l_pos(8) TYPE c,
        l_total(8) TYPE c.

  l_mod = p_pos MOD 1.
  IF NOT l_mod IS INITIAL.
    RETURN.
  ENDIF.
  l_pos = p_pos.
  l_total = p_total.
  CONCATENATE p_text 'Item' l_pos 'of' l_total 'is processing...'
    INTO l_str SEPARATED BY space.
  SHIFT l_str LEFT DELETING LEADING space.
  CONDENSE l_str.

  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = l_str.

ENDFORM.                    "show_process

*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
FORM bdc_transaction USING tcode CHANGING p_subrc TYPE sy-subrc.

  DATA: ls_params TYPE ctu_params.

* batch input session
  REFRESH messtab.

  ls_params-defsize = 'X'.
  ls_params-updmode = 'S'.
  ls_params-nobinpt = g_nobinpt. "='X'. "do not set batch input mode
  ls_params-nobiend = 'X'.
  IF NOT p_test IS INITIAL.
    ls_params-dismode = 'A'.
  ELSE.
    ls_params-dismode = p_dismod.
  ENDIF.

  CALL TRANSACTION tcode USING bdcdata
                          OPTIONS FROM ls_params
                          MESSAGES INTO messtab.


  CLEAR p_subrc.
  LOOP AT messtab WHERE msgtyp = 'E' OR msgtyp = 'A'.
    p_subrc = 4.
  ENDLOOP.

  REFRESH bdcdata.
ENDFORM.                    "BDC_TRANSACTION

*----------------------------------------------------------------------*
*   create batchinput session                                          *
*----------------------------------------------------------------------*
FORM open_group.
ENDFORM.                    "OPEN_GROUP

*----------------------------------------------------------------------*
*   end batchinput session                                             *
*----------------------------------------------------------------------*
FORM close_group.
ENDFORM.                    "CLOSE_GROUP

*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
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.
  IF fval <> nodata.
    CLEAR bdcdata.
    bdcdata-fnam = fnam.
    bdcdata-fval = fval.
    APPEND bdcdata.
  ENDIF.
ENDFORM.                    "BDC_FIELD

_________________
Молитва - это запрос разработчику на изменение кода программы.
Back to top
View user's profile Send private message Blog
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SAP Other 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 cannot 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.