Skip to Content
Author's profile photo Fahad Javed

How to convert a front end BDC recording code(generated via SHDB) into a modular Code to be run in the background using ‘Call Transaction’ with error Log

In this article,we are going to convert a bdc recording macro code into a portable code that can be utilized and embedded in any posting based program in the background with a log as well using ‘CALL TRANSACTION‘ mechanism.

We can import this recording for T-code ABAVN through the file attached in this article named ‘‘ via Tcode shdb. Just extract it and then import it using the instructions provided in the link below for the importing part in your system:[01]-HowtoexportaBDCrecordingfromoneclienttoanother:

For creating a batch upload program we will be using a  BDC recording in SAP carried out via transaction code ‘SHDB‘. We can ask a Functional Consultant of the specific module to create a BDC recording for a given transaction along with the fields that are required for batch upload. Once a recording is created we can generate a macro by clicking the [] Program button to generate the macro code for the given recording in SHDB. We can also run the macro recording in different modes as it was created originally by clicking the Process[] button in SHDB. We will follow steps from when the BDC recording macro has been created and saved as a program,with an option of ‘Transfer from Recording‘ radio button selected in the Field Contents


from the pop-up menu.

In our case,it will be a BDC recording for Tcode = ABAVN, which is used for directly retiring an Asset by Scrapping it,which is used in SAP FI module.

To have a look at the BDC recording macro code generated,refer to the code below:


    [BDC Macro Code for Transaction ABAVN ]

no standard page heading line-size 255.

include bdcrecx1.


perform open_group.

perform bdc_dynpro      using ‘SAPLAMDP’ ‘0100’.
perform bdc_field      using ‘BDC_OKCODE’
perform bdc_field      using ‘RAIFP2-ANLN1’
perform bdc_field      using ‘RAIFP2-ANLN2’
perform bdc_field      using ‘RAIFP1-BLDAT’   
perform bdc_field      using ‘RAIFP1-BUDAT’
perform bdc_field      using ‘RAIFP1-BZDAT’
perform bdc_field      using ‘BDC_CURSOR’   
perform bdc_field      using ‘RAIFP2-SGTXT’
‘Asset Scrap’.
perform bdc_dynpro      using ‘SAPLAMDP’ ‘0100’.
perform bdc_field      using ‘BDC_OKCODE’
perform bdc_field      using ‘RAIFP2-ANLN1’   
perform bdc_field      using ‘RAIFP2-ANLN2’
perform bdc_field      using ‘RAIFP2-MONAT’
perform bdc_field      using ‘RAIFP1-BLART’
perform bdc_field      using ‘BDC_CURSOR’
perform bdc_field      using ‘RAIFP1-XBLNR’   
perform bdc_dynpro      using ‘SAPMSSY0’ ‘0120’.
perform bdc_field      using ‘BDC_OKCODE’
perform bdc_transaction using ABAVN.

perform close_group.


Here is a brief description of the elements in the BDC recording Macro Code used in the code above:

> All the fields called in the BDC recording start with the the following fields e.g:  ‘perform bdc_field using ‘RAIFP1-BLART’‘ followed by a value which could either be a constant or a data object etc. as could be seen from the code above.

> The ones with the text ‘BDC_CURSOR‘ follow up with the name of the field where the cursor is to be placed on the screen.


perform bdc_field using ‘BDC_CURSOR’

> When a specific screen or tab is called on a screen,it is usually followed with a  Module Pool Name and Screen No. e.g:

perform bdc_dynpro      using SAPLAMDP‘ ‘0100.
perform bdc_field      using ‘BDC_OKCODE’

Here BDC_OKCODE is the ok code or an identifier for identifying which UI element  in Dynpro screen was clicked followed by the identifier id. For those of you who have done dynpro programming know the system constant sy-ucomm holds this value at runtime.

> Finally the transaction code for which this macro was generated is called using ‘BDC_TRANSACTION‘. e.g:

perform bdc_transaction using ABAVN.


With the BDC recording out of the way,we can now concentrate on how  to convert it for Call Transaction Mechanism. The  best way to map fields is to create a single structure in ABAP for holding all values that are to be passed for all fields in the Macro recording discussed before.


DATA: BEGIN OF s_assetscrap,
        bukrs type ANLABUKRS,“Company Code
        ANLN1 type anlaanln1,“Asset No
        ANLN2 type ANLAANLN2,“Sub Asset No
        BLDAT type RAIFP1BLDAT,“Document Date
        budat type RAIFP1BUDAT,“Posting Date
        BZDAT type RAIFP1BZDAT,“Asset Value Date
        SGTXT type RAIFP2SGTXT,“Text

        monat type RAIFP2MONAT,“Posting Period
        BLART type RAIFP1BLART,“Document Type
        XBLNR type RAIFP1XBLNR,“Reference
      END OF s_assetscrap.

We now need to add in each of the BDC recording code lines to an internal table that will eventually be passed as a parameter when using the ‘Call Transaction‘ construct. It will be based on 5 parameters as is required when calling a bdc code in Call Transaction construct based on the standard structure named ‘BDCDATA‘. Here are the fields in the structure:

  1. PROGRAM(Module Pool Name)
  2. DYNPRO(Screen No for the Dynpro)
  3. DYNBEGIN(BDC screen start)
  4. FNAM(Field name on the Screen)
  5. FVAL(Field value to be used)

Based on these fields,this is how we are going to convert it.


“Original Code as provided in BDC recording macro

perform bdc_dynpro      using SAPLAMDP‘ ‘0100.

Code Converted for BDC recording called in Call Transaction construct

wa_bdcdata-program = ‘SAPLAMDP’.

wa_bdcdata-dynpro = ‘0100’.

wa_bdcdata-dynbegin = ‘X’.

wa_bdcdata-fnam = ”.

wa_bdcdata-fval = ”.

Compare the fields with the code above to get a better idea about value passed here.

Here is the complete code converted to the format as required for Call Transaction construct line by line.

_________[Each of the 19 Lines converted to Call Transaction Format based on BDCDATA structure]

> Add multiple records for this bdc recording in one go as well.


     it_bdcdata type standard table of BDCDATA,

     wa_bdcdata like line of it_bdcdata.


wa_bdcdata-program = ‘SAPLAMDP’.

wa_bdcdata-dynpro = ‘0100’.

wa_bdcdata-dynbegin = ‘X’.

wa_bdcdata-fnam = ”.

wa_bdcdata-fval = ”.

append wa_bdcdata it_bdcdata.

clear wa_bdcdata.

“…and so on. Only shortened code is shown here for illustrative purposes.

[Refer to the complete code in the attached text file named ‘‘].


The final element of transaction code  will be passed when using the final Call Transaction construct for uploading or posting .

dyn_begin = ‘X’ indicates that a screen is called at this point,therefore the module pool name and screen no is called here and for the rest field name and value pairs are passed in.

Here is how the final Call Transaction code will be called for posting this Asset Retirement via scrap:


     it_msg type standard table of bdcmsgcoll.”This will hold all Messages


    MODE ‘N


    MESSAGES INTO it_msg.

Here it_bdcdata is the BDC recording format converted for compatibility with BDC Recording.

     Mode   = N[For Running in the Background]

               [All Modes in BDC recording are supported like

                ‘E‘(Errors),’A‘(All Screens)]

     Update = S[Synchronous]

     it_msg = Holds all error messages and successful messages

For Logging,Internal table it_msg can be looped through for finding successful postings(msgtyp = ‘S‘) and failed postings(msgtyp = ‘F‘) of uploads via call transaction construct. e.g for successful messages:

LOOP AT it_msg INTO wa_msg WHERE msgtyp EQ ‘S‘.
msgid = wa_msg-msgid
msgnr = wa_msg-msgnr
msgv1 = wa_msg-msgv1
msgv2 = wa_msg-msgv2
msgv3 = wa_msg-msgv3
msgv4 = wa_msg-msgv4
message_text_output = wa_msg_all.


Here the data object ‘wa_msg_all‘ complete error message in one line, where as individual components are also store in one of the structures like wa_msg-msgid(Message Id number),wa_msg-msgnr(Message No),wa_msg-msgv1 to wa_msg-msgv4(contains error or successful messages with description).

Using this code mechanism through Call Transaction we can convert BDC recordings into portable executable code which can be embedded especially if you are working on a selective posting program using an interactive ALV report for selecting records and posting them.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.