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: 

BDC

Former Member
0 Kudos
104

Hello Friends,

I have awritted a BDC.

For ex If i pass a wrong value to any of the field it errors..however I want tit to skip that record and move to the next record.

When I see the output it stoped when it errored and didnt do anything more.

I am using mode as 'N".

Any suggestions.

Ster.

5 REPLIES 5

Former Member
0 Kudos
77

Hi,

Run the BDC in Error mode 'E'.

Thanks,

Sriram Ponna.

ThomasZloch
Active Contributor
0 Kudos
77

if you call in mode "E" then enter "/n" in the command box when an error occurs, you will skip to the next transaction.

Cheers

Thomas

0 Kudos
77

Thanks, I want to run this program as a back ground as it has many records to be processed.

Whats the solution.

Ster.

0 Kudos
77

Validate the field value even before it is sent to the screen.

If you find it as an error you can skip it here.

That way you can also send the possibly correct values to the screen.

I am sure you are using BDCMSGCALL structure to capture errors.

LEt me know for any further questions.

Thanks.

0 Kudos
77

Thanks for the reply,

I am using the call transaction method.

below is the code,



*D44K900066

REPORT ZASH
       NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES : EAPL.
DATA :
T_EAPL LIKE EAPL OCCURS 0 WITH HEADER LINE,
TMP_EAPL LIKE EAPL OCCURS 0 WITH HEADER LINE,
T_PLKO LIKE PLKO OCCURS 0 WITH HEADER LINE,
T_PLAS LIKE PLAS OCCURS 0 WITH HEADER LINE,
T_PLPO LIKE PLPO OCCURS 0 WITH HEADER LINE,
T_STPO LIKE STPO OCCURS 0 WITH HEADER LINE,
T_CRHD LIKE CRHD OCCURS 0 WITH HEADER LINE,
T_PLWP LIKE PLWP OCCURS 0 WITH HEADER LINE,
T_PLMZ LIKE PLMZ OCCURS 0 WITH HEADER LINE.

DATA : MATNRSELECTION LIKE BAPIMATRAM OCCURS 0 WITH HEADER LINE.

DATA I_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

DATA I_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF I_ERROR OCCURS 0,
       EQUNR LIKE EAPL-EQUNR,
       TEXT(255) TYPE C,
       END OF I_ERROR.

DATA:
FIRST(1),
ZMSG(255) TYPE C,
PACKET_COUNT(2) TYPE N,
PRV_COUNT(2) TYPE N,
PACKET_FIELD(19) TYPE C,
MATERIAL_COUNT(2) TYPE N,
MATERIAL_FIELD(17) TYPE C,
QUANTITY_FIELD(17) TYPE C,
L_COUNT(3)  TYPE N,
OPR_FIELD(15) TYPE C,
OPR1_FIELD(17) TYPE C,
V_MENGE(16),
V_DAUNO(6) TYPE C,
V_ARBEI(8) TYPE C,
V_ANZZL(3) TYPE C.

SELECTION-SCREEN BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-B01.
SELECT-OPTIONS : S_EQUI FOR EAPL-EQUNR NO INTERVALS.
PARAMETERS     : DESTI(32) TYPE C,
                 UP_MODE(1).
SELECTION-SCREEN END OF BLOCK B01.


START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM PROCESS_DATA.

END-OF-SELECTION.
  PERFORM UPDATE_DATA.
  LOOP AT I_ERROR.
    WRITE /: I_ERROR-EQUNR, I_ERROR-TEXT.
  ENDLOOP.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_DATA .

  MATNRSELECTION[] =  S_EQUI[].

  CALL FUNCTION 'ZNPM_IA01_DATA_FOR_D44' DESTINATION DESTI
    TABLES
      MATNRSELECTION = MATNRSELECTION
      EAPL           = T_EAPL
      PLKO           = T_PLKO
      PLAS           = T_PLAS
      PLPO           = T_PLPO
      CRHD           = T_CRHD
      PLWP           = T_PLWP
      PLMZ           = T_PLMZ
      STPO           = T_STPO.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM PROCESS_DATA .
  SORT T_EAPL BY EQUNR PLNTY PLNNR PLNAL ZAEHL.
  SORT T_PLKO BY PLNTY PLNNR PLNAL ZAEHL.
  SORT T_PLAS BY PLNTY PLNNR PLNAL PLNKN.
  SORT T_PLPO BY PLNTY PLNNR PLNKN ZAEHL.
  SORT T_CRHD BY OBJID.
  SORT T_PLMZ BY PLNTY PLNNR.
  SORT T_PLWP BY PLNTY PLNNR PLNFL.
  SORT T_STPO BY STLTY STLNR STLKN.



ENDFORM.                    " PROCESS_DATA

*&---------------------------------------------------------------------*
*&      Form  UPDATE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM UPDATE_DATA .

  TMP_EAPL[] = T_EAPL[].

  DELETE ADJACENT DUPLICATES FROM T_EAPL COMPARING EQUNR.

  LOOP AT T_EAPL. ""BDC for the first screen can be done.
    FIRST = 'X'.
    PERFORM BDC_SAPLCPDI_3010.
    LOOP AT T_PLKO
      WHERE PLNTY = T_EAPL-PLNTY
        AND PLNNR = T_EAPL-PLNNR
        AND PLNAL = T_EAPL-PLNAL
        AND ZAEHL = T_EAPL-ZAEHL.

      CLEAR: T_CRHD.

      READ TABLE T_CRHD
      WITH KEY OBJID = T_PLKO-ARBID.

      PERFORM BDC_SAPLCPDA_3010.

      LOOP AT T_PLAS
        WHERE PLNTY = T_PLKO-PLNTY
          AND PLNNR = T_PLKO-PLNNR
          AND PLNAL = T_PLKO-PLNAL.

        CLEAR : T_PLPO, T_CRHD, T_PLWP.

        READ TABLE T_PLPO
           WITH KEY PLNTY = T_PLAS-PLNTY
                    PLNNR = T_PLAS-PLNNR
                    PLNKN = T_PLAS-PLNKN
                    ZAEHL = T_PLAS-ZAEHL.
        READ TABLE T_CRHD
           WITH KEY OBJID = T_PLPO-ARBID.

        READ TABLE T_PLWP
           WITH KEY PLNTY = T_PLPO-PLNTY
                    PLNNR = T_PLPO-PLNNR
                    PLNKN = T_PLPO-PLNKN.

        PERFORM BDC_SAPLCPDI_3400.

        PERFORM ASSING_COMPONENT.

        CLEAR : MATERIAL_COUNT.
      ENDLOOP.
      CLEAR : PACKET_COUNT.
    ENDLOOP.
    PERFORM TRANSACTION_SAVE.
    CALL TRANSACTION 'IA01' USING I_BDCDATA
                  MODE UP_MODE
*                     optIONS  FROM l_opt
                  MESSAGES INTO I_BDCMSGCOLL.

    PERFORM FORMAT_OUTPUT.

    CLEAR : FIRST.
  ENDLOOP.
ENDFORM.                    " UPDATE_DATA
*&---------------------------------------------------------------------*
*&      Form  BDC_SAPLCPDI_3010
*&---------------------------------------------------------------------*
*       Always Triggered
*----------------------------------------------------------------------*
FORM BDC_SAPLCPDI_3010 .

  WRITE SY-DATUM TO SY-DATUM.

  PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3010'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'RC27E-EQUNR'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '/00'.
  PERFORM BDC_FIELD       USING 'RC27E-EQUNR'
                                 T_EAPL-EQUNR.
  PERFORM BDC_FIELD       USING 'RC271-STTAG'
                                SY-DATUM.
*write a querry for already existing
*Select * from
  IF FIRST <> 'X'.

    PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3200'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'RC270-HEAD2'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=ANLG'.
  ENDIF.
ENDFORM.                    " BDC_SAPLCPDI_3010

*&---------------------------------------------------------------------*
*&      Form  BDC_SAPLCPDA_3010
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BDC_SAPLCPDA_3010 .

  PERFORM BDC_DYNPRO      USING 'SAPLCPDA' '3010'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'PLKOD-STRAT'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=VOUE'.
  PERFORM BDC_FIELD       USING 'PLKOD-PLNAL'
                                T_PLKO-PLNAL.
  PERFORM BDC_FIELD       USING 'PLKOD-KTEXT'
                                T_PLKO-KTEXT.
  PERFORM BDC_FIELD       USING 'RCR01-ARBPL'
                                T_CRHD-ARBPL.
  PERFORM BDC_FIELD       USING 'RCR01-WERKS'
                                T_PLKO-WERKS.
  PERFORM BDC_FIELD       USING 'PLKOD-VERWE'
                                T_PLKO-VERWE.
  PERFORM BDC_FIELD       USING 'PLKOD-VAGRP'
                                T_PLKO-VAGRP.
  PERFORM BDC_FIELD       USING 'PLKOD-STATU'
                                T_PLKO-STATU.
  PERFORM BDC_FIELD       USING 'PLKOD-ANLZU'
                                T_PLKO-ANLZU.
  PERFORM BDC_FIELD       USING 'PLKOD-STRAT'
                                T_PLKO-STRAT.
ENDFORM.                    " BDC_SAPLCPDA_3010

*&---------------------------------------------------------------------*
*&      Form  BDC_SAPLCPDI_3400
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM BDC_SAPLCPDI_3400 .

  PACKET_COUNT = PACKET_COUNT + 1.
  L_COUNT = L_COUNT + 1.

  IF L_COUNT = 015.
    L_COUNT = 1.
    PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3400'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=P+'.
    L_COUNT = L_COUNT + 1.

  ENDIF.

  PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3400'.

  CONCATENATE 'PLPOD-VORNR' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                OPR_FIELD.

  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=WPLT'.

  CONCATENATE 'RC27X-FLG_SEL' '(' L_COUNT ')' INTO OPR1_FIELD.
  PERFORM BDC_FIELD       USING OPR1_FIELD
                                'X'.

  PRV_COUNT = L_COUNT - 1.
  CONCATENATE 'RC27X-FLG_SEL' '(' PRV_COUNT ')' INTO OPR1_FIELD.
  PERFORM BDC_FIELD       USING OPR1_FIELD
                                ''.

  CONCATENATE 'PLPOD-ARBPL' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                T_CRHD-ARBPL.

  CONCATENATE 'PLPOD-LTXA1' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                T_PLPO-LTXA1.

  CONCATENATE 'PLPOD-ARBEI' '(' L_COUNT ')' INTO OPR_FIELD.
  WRITE T_PLPO-ARBEI TO V_ARBEI.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                V_ARBEI.

  CONCATENATE 'PLPOD-ARBEH' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                T_PLPO-ARBEH.

  CONCATENATE 'PLPOD-ANZZL' '(' L_COUNT ')' INTO OPR_FIELD.
  WRITE T_PLPO-ANZZL TO V_ANZZL.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                V_ANZZL.

  CONCATENATE 'PLPOD-DAUNO' '(' L_COUNT ')' INTO OPR_FIELD.
  WRITE T_PLPO-DAUNO TO V_DAUNO.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                V_DAUNO.

  CONCATENATE 'PLPOD-DAUNE' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                T_PLPO-DAUNE.

  CONCATENATE 'PLPOD-INDET' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                T_PLPO-INDET.

  CONCATENATE 'PLPOD-STEUS' '(' L_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING OPR_FIELD
                                T_PLPO-STEUS.

  IF T_PLWP-PAKET <> ''.
    CONCATENATE 'RIHSTRAT-MARK' T_PLWP-PAKET '(' L_COUNT ')'
      INTO PACKET_FIELD.

    PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3600'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  PACKET_FIELD.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                  '=BACK'.
    PERFORM BDC_FIELD       USING PACKET_FIELD
                                  'X'.
  ENDIF.

ENDFORM.                    " BDC_SAPLCPDI_3400
*&---------------------------------------------------------------------*
*&      Form  ASSING_COMPONENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM ASSING_COMPONENT .

*  LOOP AT T_PLMZ
*     WHERE PLNTY = T_PLPO-PLNTY
*       AND PLNNR = T_PLPO-PLNNR
*       AND PLNKN = T_PLPO-PLNKN.
*
*    CLEAR : T_STPO.
*
*    READ TABLE T_STPO
*    WITH KEY STLTY = T_PLMZ-STLTY
*             STLNR = T_PLMZ-STLNR
*             STLKN = T_PLMZ-STLKN BINARY SEARCH.
*    IF T_STPO-IDNRK <> ''.
  PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3400'.

  CONCATENATE 'PLPOD-VORNR' '(' PACKET_COUNT ')' INTO OPR_FIELD.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                OPR_FIELD.

  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=MAPM'.
  LOOP AT T_PLMZ
     WHERE PLNTY = T_PLPO-PLNTY
       AND PLNNR = T_PLPO-PLNNR
       AND PLNKN = T_PLPO-PLNKN.

    CLEAR : T_STPO.

    READ TABLE T_STPO
    WITH KEY STLTY = T_PLMZ-STLTY
             STLNR = T_PLMZ-STLNR
             STLKN = T_PLMZ-STLKN BINARY SEARCH.
    IF T_STPO-IDNRK <> ''.
      MATERIAL_COUNT = MATERIAL_COUNT + 1.

      PERFORM BDC_DYNPRO      USING 'SAPLCMDI' '3500'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                    'RIHSTPX-MENGE(01)'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '/00'.

      CONCATENATE 'RIHSTPX-IDNRK' '(' MATERIAL_COUNT ')'
      INTO MATERIAL_FIELD.

      CONCATENATE 'RIHSTPX-MENGE' '(' MATERIAL_COUNT ')'
      INTO QUANTITY_FIELD.

      PERFORM BDC_FIELD       USING MATERIAL_FIELD
                                    T_STPO-IDNRK.

      WRITE  T_STPO-MENGE TO V_MENGE.
      PERFORM BDC_FIELD       USING QUANTITY_FIELD
                                    V_MENGE.

*      PERFORM BDC_DYNPRO      USING 'SAPLCMDI' '3500'.
*      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
*                                    'RIHSTPX-IDNRK(01)'.
*      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
*                                    '=BACK'.

    ENDIF.
  ENDLOOP.
  PERFORM BDC_DYNPRO      USING 'SAPLCMDI' '3500'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'RIHSTPX-IDNRK(01)'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=BACK'.

  PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3400'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'PLPOD-VORNR(03)'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                 '/00'.
ENDFORM.                    " ASSING_COMPONENT
*&---------------------------------------------------------------------*
*&      Form  TRANSACTION_SAVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM TRANSACTION_SAVE .
  PERFORM BDC_DYNPRO      USING 'SAPLCPDI' '3400'.
  PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                'PLPOD-VORNR(03)'.
  PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                '=BU'.
ENDFORM.                    "TRANSACTION_SAVE
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR I_BDCDATA.
  I_BDCDATA-PROGRAM  = PROGRAM.
  I_BDCDATA-DYNPRO   = DYNPRO.
  I_BDCDATA-DYNBEGIN = 'X'.
  APPEND I_BDCDATA.
ENDFORM.                    "BDC_DYNPRO

*----------------------------------------------------------------------*
*        Insert field                                                  *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.

  CLEAR I_BDCDATA.
  I_BDCDATA-FNAM = FNAM.
  I_BDCDATA-FVAL = FVAL.
  APPEND I_BDCDATA.

ENDFORM.                    "BDC_FIELD
" TRANSACTION_SAVE
*&---------------------------------------------------------------------*
*&      Form  FORMAT_OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FORMAT_OUTPUT .

  REFRESH I_BDCDATA.

  CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
      ID        = SY-MSGID
      LANG      = '-E'
      NO        = SY-MSGNO
      V1        = SY-MSGV1
      V2        = SY-MSGV2
      V3        = SY-MSGV3
      V4        = SY-MSGV4
    IMPORTING
      MSG       = ZMSG
    EXCEPTIONS
      NOT_FOUND = 1
      OTHERS    = 2.
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  I_ERROR-EQUNR = T_EAPL-EQUNR.
  I_ERROR-TEXT = ZMSG.
  APPEND I_ERROR.
  CLEAR I_ERROR.

ENDFORM.                    " FORMAT_OUTPUT