Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

I want to convert following BDC code Into BAPI,What i have to do for it?

$
0
0

*&---------------------------------------------------------------------*
*& Report  ZMAP_UPDATE_SALESSET
*&
*&---------------------------------------------------------------------*
*& Report Name : ZMAP_UPDATE_SALESSET                                 *
*& Program Type : Executable Program                                   *
*& Program Description : Update MAP for Sales Sets                     *
*& Functional Area : MM                                                *
*& Functional    : Kirit Mehta                                         *
*& Package :  ZSCM                                                     *
*& T-Code  :  ZMAPUPDATE                                                         *
*& Created by : Ritesh Parikh                                          *
*& Created on :  12.10.2011                                            *
*& Request No. : SRDK908813                                            *
*&*&-------------------------------------------------------------------*

REPORT  zmap_update_salesset.

*---------- Data Declaration---------------*

TYPE-POOLS : sscr.

TABLES: mbew,t001w,t100,mara,marc.


TYPES : BEGIN OF ty_mara,
         matnr TYPE mara-matnr,
         ersda TYPE mara-ersda,
         ernam TYPE mara-ernam,
         matkl TYPE mara-matkl,
         attyp TYPE mara-attyp,
         END OF ty_mara.

DATA : it_mara TYPE TABLE OF ty_mara.
DATA : wa_mara LIKE LINE OF it_mara.


TYPES : BEGIN OF ty_marc,
         matnr TYPE mara-matnr,
         werks TYPE marc-werks,
         END OF ty_marc.

DATA : it_marc TYPE TABLE OF ty_marc.
DATA : wa_marc LIKE LINE OF it_marc.

DATA : it_mara_final TYPE TABLE OF ty_marc.
DATA : wa_mara_final LIKE LINE OF it_mara_final.

TYPES : BEGIN OF ty_mast,
         matnr TYPE mast-matnr,
         stlnr TYPE mast-stlnr,
         END OF ty_mast.

DATA : it_mast TYPE TABLE OF ty_mast.
DATA : wa_mast LIKE LINE OF it_mast.

TYPES : BEGIN OF ty_stpo,
         stlnr TYPE stpo-stlnr,
         idnrk TYPE stpo-idnrk,
         menge TYPE stpo-menge,
         END OF ty_stpo.

DATA : it_stpo TYPE TABLE OF ty_stpo.
DATA : wa_stpo LIKE LINE OF it_stpo.


TYPES : BEGIN OF ty_mbew,
         matnr TYPE mbew-matnr,
         verpr TYPE mbew-verpr,
         END OF ty_mbew.

DATA : it_mbew TYPE TABLE OF ty_mbew.
DATA : wa_mbew LIKE LINE OF it_mbew.

TYPES : BEGIN OF ty_mbew_p,
         matnr TYPE mbew-matnr,
         lbkum TYPE mbew-lbkum,
         END OF ty_mbew_p.

DATA : it_mbew_p TYPE TABLE OF ty_mbew_p.
DATA : wa_mbew_p LIKE LINE OF it_mbew_p.



TYPES : BEGIN OF ty_final,
         smatnr  TYPE mast-matnr,
         verpr   TYPE mbew-verpr,
         menge   TYPE stpo-menge,
         valpr  TYPE valpr,
         END OF ty_final.

DATA : it_final TYPE HASHED TABLE OF ty_final
                WITH UNIQUE KEY smatnr.
DATA : wa_final LIKE LINE OF it_final.


DATA:   bdcdata LIKE bdcdata    OCCURS 0 WITH HEADER LINE.
DATA:   messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

DATA: tamount TYPE mbew-verpr.
DATA: v_cnt(2) TYPE n.
DATA: msg_str  TYPE string.


DATA : gs_restriction TYPE sscr_restrict.  "Select Option Restrict
DATA : gs_opt_list TYPE sscr_opt_list.
DATA : gs_*** TYPE sscr_***.

RANGES :  r_stlty          FOR stpo-stlty,
           r_stlkn          FOR stpo-stlkn,
           r_stpoz          FOR stpo-stpoz.

DATA : st_ctu_params LIKE ctu_params .

*-----------------------------------------------------------------------
*                       Selection Screen                               *
*-----------------------------------------------------------------------

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_matnr FOR mara-matnr.

PARAMETERS :    p_werks TYPE marc-werks OBLIGATORY.

SELECT-OPTIONS: s_matkl FOR mara-matkl OBLIGATORY,
                 s_ersda FOR mara-ersda,
                 s_ernam FOR mara-ernam.
SELECTION-SCREEN : END OF BLOCK b1.
*---------------------------------------------------------------------*

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

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: p_mode TYPE   ctu_params-dismode DEFAULT 'N'.
SELECTION-SCREEN : END OF BLOCK b2.

*---------------------------------------------------------------------*
*                End of Selection Screen                              *
*---------------------------------------------------------------------*



*---------------------------------------------------------------------*
*                Start-of-Selection                                   *
*---------------------------------------------------------------------*

START-OF-SELECTION.

   IF sy-batch = 'X'.
     v_cnt = '09'.
   ELSE.
     v_cnt = '09'.
   ENDIF.

   PERFORM get_data.

   IF NOT it_final[] IS INITIAL.

     PERFORM update_map.

   ENDIF.

END-OF-SELECTION.


*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .

*--------- Article details from MARA Table----------*


   IF NOT s_matnr[] IS INITIAL.
     SELECT matnr ersda ernam matkl attyp FROM mara
       INTO TABLE it_mara
            WHERE matnr IN s_matnr.
   ELSE.
     SELECT matnr ersda ernam matkl attyp FROM mara
        INTO TABLE it_mara
             WHERE matkl IN s_matkl AND
                   attyp EQ '10'.
   ENDIF.

   DELETE it_mara WHERE ersda NOT IN s_ersda.
   DELETE it_mara WHERE ernam NOT IN s_ernam.

   SORT : it_mara BY matnr.
   IF NOT it_mara[] IS INITIAL.

*---------Listed Article base on Site Code------------*

     SELECT matnr werks FROM marc
       INTO TABLE it_marc
         FOR ALL ENTRIES IN it_mara
          WHERE matnr = it_mara-matnr AND
                werks = p_werks.

     FREE : it_mara.
     SORT : it_marc BY matnr.
     it_mara_final[] = it_marc[].

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

     SORT : it_mara_final BY matnr.
     IF NOT it_mara_final[] IS INITIAL.

*---- Fetching BOM Number Details from MAST Table------*

       SELECT matnr stlnr FROM mast
           INTO TABLE it_mast
             FOR ALL ENTRIES IN it_mara_final
               WHERE matnr = it_mara_final-matnr   AND
                     werks = ''                    AND
                     stlan = '5'.

       SORT : it_mast BY stlnr.
       IF NOT it_mast[] IS INITIAL .

*-------- Component code and quantity-------------------*

         SELECT stlnr idnrk menge FROM stpo
           INTO TABLE it_stpo
             FOR ALL ENTRIES IN it_mast
               WHERE stlty IN r_stlty AND
                     stlnr = it_mast-stlnr AND
                     stlkn IN r_stlkn AND
                     stpoz IN r_stpoz.

       ENDIF.

       SORT : it_stpo BY idnrk.
       IF NOT it_stpo[] IS  INITIAL.

*-------Moving Avg Price of Component Article-------------*

         SELECT matnr verpr FROM mbew
           INTO TABLE it_mbew
            FOR ALL ENTRIES IN it_stpo
             WHERE matnr = it_stpo-idnrk
                   AND bwkey = p_werks.

*-- Validation for  Stock check for sales set article & MAP check for component article--*

         SELECT matnr lbkum FROM mbew
           INTO TABLE it_mbew_p
            FOR ALL ENTRIES IN it_mara_final
             WHERE matnr = it_mara_final-matnr
                   AND bwkey = p_werks.

         DELETE it_mbew_p WHERE lbkum NE '0'.

         SORT : it_mara_final BY matnr.
         LOOP AT  it_mara_final INTO wa_mara_final.
           READ TABLE it_mbew_p INTO wa_mbew_p WITH KEY matnr = wa_mara_final-matnr BINARY SEARCH.
           IF sy-subrc <> 0.
             CONCATENATE  wa_mara_final-matnr
                         'Sales set article is not updated due to stock is available in sales set article for site' p_werks
                          INTO msg_str SEPARATED BY space.
             WRITE : / msg_str.
             CLEAR : msg_str.
             CONTINUE.
           ENDIF.
           CLEAR : wa_mara_final,wa_mbew_p.
         ENDLOOP.

       ENDIF.

     ENDIF.

*------------------CONSOLIDATED DATA -----------------------*

     SORT : it_mbew BY matnr.
     SORT : it_mast BY stlnr.
     SORT : it_mbew_p BY matnr.
     LOOP AT it_stpo INTO wa_stpo.

       CLEAR : wa_final,wa_mbew,wa_mast.

       READ TABLE it_mast INTO wa_mast WITH KEY stlnr = wa_stpo-stlnr BINARY SEARCH.
       IF sy-subrc = 0.
         wa_final-smatnr = wa_mast-matnr.
       ENDIF.
       READ TABLE it_mbew_p INTO wa_mbew_p WITH KEY matnr = wa_mast-matnr BINARY SEARCH.
       IF sy-subrc <> 0.
         CONTINUE.
       ENDIF.

       READ TABLE it_mbew INTO wa_mbew WITH KEY matnr = wa_stpo-idnrk BINARY SEARCH.
       IF sy-subrc = 0.
         IF wa_mbew-verpr = '0'.
           CONCATENATE  wa_mast-matnr 'Sales set article is not updated due to component' wa_mbew-matnr
                        'MAP is zero for site' p_werks
                        INTO msg_str SEPARATED BY space.
           WRITE : / msg_str.
           CLEAR : msg_str.
           CONTINUE.
         ENDIF.

         wa_final-verpr   = wa_mbew-verpr.
         wa_final-menge   = wa_stpo-menge.
         wa_final-valpr  = wa_mbew-verpr * wa_stpo-menge.
         COLLECT wa_final INTO it_final.
       ENDIF.

     ENDLOOP.

     SORT : it_final BY smatnr.

   ELSE.

     WRITE :/ 'No Data Found'(006) COLOR 6.

   ENDIF.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  UPDATE_MAP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM update_map .

   DATA: l_date(10) TYPE c.
   DATA: p_date TYPE sy-datum.
   DATA: cnt(2) TYPE n.
   DATA: l_str TYPE string.
   DATA: l_valpr(12) TYPE c.

   p_date = sy-datum.
   CONCATENATE p_date+6(2) '.' p_date+4(2) '.' p_date+0(4) INTO l_date.




   PERFORM bdc_dynpro      USING 'SAPRCKM_MR21' '0201'.
   PERFORM bdc_field       USING 'MR21HEAD-BUDAT'
                                  l_date.
   PERFORM bdc_field       USING 'MR21HEAD-BUKRS'
                                     ' '.
   PERFORM bdc_field       USING 'MR21HEAD-WERKS'
                                  p_werks.
   PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=ENTR'.

   PERFORM bdc_dynpro      USING 'SAPRCKM_MR21' '0201'.
   PERFORM bdc_field       USING 'MR21HEAD-SCREEN_VARIANT'
                                  'MR21_LAGERMATERIAL_0250'.





   LOOP AT it_final INTO wa_final.

     cnt = cnt + 1.

     CONCATENATE 'CKI_MR21_0250-MATNR(' cnt ')' INTO l_str.
     PERFORM bdc_field       USING l_str
                                   wa_final-smatnr.

     CLEAR : l_str.

     CONCATENATE 'CKI_MR21_0250-NEWVALPR(' cnt ')' INTO l_str.
     l_valpr = wa_final-valpr.
     PERFORM bdc_field       USING l_str
                                   l_valpr.

     CLEAR : l_str.


     IF cnt = v_cnt.
       PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=ENTR'.

       PERFORM bdc_dynpro      USING 'SAPRCKM_MR21' '0201'.
       PERFORM bdc_field       USING 'BDC_OKCODE'
                                      '=DOWN'.

       PERFORM bdc_dynpro      USING 'SAPRCKM_MR21' '0201'.
       cnt = '01'.
     ENDIF.

     CLEAR : wa_final.
   ENDLOOP.

   PERFORM bdc_field       USING 'BDC_OKCODE'
                                   '=ENTR'.

   PERFORM bdc_dynpro      USING 'SAPRCKM_MR21' '0201'.
   PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=SAVE'.

   PERFORM bdc_transaction USING 'MR21'.


ENDFORM.                    " UPDATE_MAP
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0778   text
*      -->P_0779   text
*----------------------------------------------------------------------*
FORM bdc_dynpro  USING    program dynpro  .
   CLEAR bdcdata.
   bdcdata-program  = program.
   bdcdata-dynpro   = dynpro.
   bdcdata-dynbegin = 'X'.
   APPEND bdcdata.
   CLEAR bdcdata.
ENDFORM.                    " bdc_dynpro


*&---------------------------------------------------------------------*
*&      Form  bdc_field
*&---------------------------------------------------------------------*
FORM bdc_field  USING    fnam fval.
   CLEAR bdcdata.
   bdcdata-fnam = fnam.
   bdcdata-fval = fval.
   APPEND bdcdata.
   CLEAR bdcdata.
ENDFORM.                    " bdc_field
*&---------------------------------------------------------------------*
*&      Form  BDC_TRANSACTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0860   text
*----------------------------------------------------------------------*
FORM bdc_transaction  USING tcode.

   DATA: l_mstring(480).
   DATA: l_subrc LIKE sy-subrc.
   st_ctu_params-nobinpt = 'X' .
   st_ctu_params-dismode = p_mode.
   st_ctu_params-defsize = 'X'.

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

   LOOP AT messtab WHERE ( msgtyp = 'S' OR msgtyp = 'E' ).
     SELECT SINGLE * FROM t100 WHERE sprsl = 'EN'
                               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: /  l_mstring(250).
     ELSE.
       WRITE: / messtab.
     ENDIF.
   ENDLOOP.

   REFRESH: bdcdata,messtab.
   CLEAR bdcdata.

ENDFORM.                    " BDC_TRANSACTION


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>