ABAP – BDC ABAP Code

Home / SAP / ABAP Coding / ABAP – BDC ABAP Code

Well, we’ve created a program, and done the BDC recording.  Now, all that’s left is the BDC ABAP Code to make it all useful.  So, let’s jump right into it.

First off, you’ll need 2 FORMS and some standard data declarations:

DATA:   BEGIN OF bdcdata OCCURS 100.

INCLUDE STRUCTURE bdcdata.

DATA END OF bdcdata.

DATA: mess TYPE TABLE OF bdcmsgcoll WITH HEADER LINE.

*———————————————————————*

*       FORM BDC_DYN                                                  *

*———————————————————————*

*       start a new screen in the BDC table                           *

*———————————————————————*

*  –>  PROGRAM                                                       *

*  –>  DYNPRO                                                        *

*———————————————————————*

FORM bdc_dyn USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = ‘X’.

APPEND bdcdata.

ENDFORM.                    “bdc_dyn

*———————————————————————*

*       FORM BDC_FLD                                                  *

*———————————————————————*

*       add a field to the BDC table                                  *

*———————————————————————*

*  –>  FNAM                                                          *

*  –>  FVAL                                                          *

*———————————————————————*

FORM bdc_fld USING fnam fval.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDFORM.                    “bdc_fld

 

Now, the actual transactional stuff that will change with every transaction…

FORM load_cnf.

REFRESH: BDCDATA, MESS.

 

PERFORM bdc_dyn USING ‘SAPLCORU’ ‘3000’.

PERFORM bdc_fld USING CORUF-AUFNR ‘ ‘4000100’.

PERFORM bdc_fld USING CORUF-VORNR ‘ ‘0010’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=ENTR’.    ” ENTER

PERFORM bdc_dyn USING ‘SAPLCORU’ ‘3200’.

PERFORM bdc_fld USING AFRUD-ISMNW_2 ‘ ‘2’.

PERFORM bdc_fld USING AFRUD-LEARR ‘ ‘SRV’.

PERFORM bdc_fld USING AFRUD-AUERU ‘ ‘’.

PERFORM bdc_fld USING AFRUD-LEKNW ‘ ‘’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=MB03’.    ” ENTER

PERFORM bdc_dyn USING ‘SAPLCOWB’ ‘0130’.

PERFORM bdc_fld USING ‘BDC_OKCODE’ ‘=WEIT’.    ” ENTER

* runs transaction defined above, mode ‘A’ goes step by step, use this

* to prototype code, mode ‘N’ runs automatically, use this in

* production, mode ‘E’ generates errors only, use this for debug

COMMIT WORK AND WAIT.

CALL TRANSACTION ‘IW41’ USING bdcdata

MODE ‘A’         ” mode ‘A’,’N’,’E’

UPDATE ‘S’

MESSAGES INTO mess.

endform.                    “load_cnf

Now, the biggest piece to remember is the MODE.  In the code above, it’s set to A, which means that it will go through step by step. When you execute, it will look something like this.
blog01-12

Beyond that, it’s all about translating the recording into the steps.  You’ll notice that every screen must start with the bdc_dyn.  The bdc_fld will be all the steps within that screen.  At the end of each screen, you will add a BDC_OKCODE.  This will be like hitting enter, or pressing a button.  After ever BDC_OKCODE, you will do a bdc_dyn (even if you don’t leave the screen).

Beyond that, it’s all about entering in the data to populate the screen.  Now something to keep in mind, it won’t always be sufficient to use the same data type as the screen field.  For example, I did transaction IW41, and you have to enter in a number of time units (hours/mins/etc).  I used the same data type, but when I executed the transaction, it told me that the values didn’t fit in the field…  WTF?”.  So i changed it to a text field to enter in the number, and magically it worked.  Keep in mind, you may need to do tricks like that from time to time.

Hope you found this useful and thanks for reading,

As always, thanks for reading and don't forget to check out our SAP Service Management Products at my other company JaveLLin Solutions,
Mike

Leave a Reply

Your email address will not be published. Required fields are marked *