Skip to Content

Clearly written code can help you solve your problems…

Hello everyone,

The reason I decided to write this post was the post of a user in SCN about a commonly seen batch input error ( No batch input data for screen xxx yyy ).

I tried to help the user pin point the problem and correct it but with no luck. But, I realized that If the code was written with a different and more structured way, it could be more easier for me or even for the user himself to identify and correct the error. Let me please explain what I mean :

The user has posted his code in the forum that in general was something like this :

   perform bdc_dynpro      using ‘SAPXXXX’ ‘0100’.

   perform bdc_field       using ‘BDC_CURSOR’

                                 ‘XXX-XXX’.

   perform bdc_field       using ‘BDC_OKCODE’

                                 ‘/XX’.

   perform bdc_field       using ‘XXX-XXX’

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   perform bdc_field       using XXX-XXX

                                 ‘YYY’.

   LOOP AT ZZZZ ASSIGNING <ZZZZ>.

     perform bdc_field       using XXX-XXX

                                   ‘YYY’.

     perform bdc_field       using XXX-XXX

                                   ‘YYY’.

     perform bdc_dynpro      using ‘SAPXXXX’ ‘0300’.

     perform bdc_field       using ‘BDC_CURSOR’

                                   XXX-XXX‘.

     perform bdc_field       using ‘BDC_OKCODE’

                                   ‘/XX’.

     perform bdc_field       using XXX-XXX

                                   ‘YYY’.

     perform bdc_field       using XXX-XXX

                                   ‘YYY’.

     perform bdc_dynpro      using XXX-XXX‘0102’.

     perform bdc_field       using ‘BDC_CURSOR’

                                   XXX-XXX‘.

     perform bdc_field       using ‘BDC_OKCODE’

                                   ‘=XXXX’.

     perform bdc_field       using XXX-XXX

                                  ‘YYY’.

     perform bdc_field       using XXX-XXX

                                  ‘YYY’.

     perform bdc_field       using XXX-XXX

                                  ‘YYY’.

     perform bdc_field       using XXX-XXX

                                  ‘YYY’.

As you can probably see, In the above piece of code, it’s not easy to understand when a screen ends, when a new screen starts and the whole process logic in general, so especially if you don’t have access to the system and trying to help a user identify a problem it’s not very easy to understand and try to pin point the problem by using the above mentioned snippet.

In general, The person who helped me when I was in my first steps of my career back in 1998, taught me to always write clear and structured code so that it can be easily maintainable and readable even from another person.

So, If I was assigned to write the above mentioned batch input, I would probably write something like this :

* — First Screen – Document Header data

  perform bdc_dynpro      using ‘SAPXXXX’ ‘0100’.

  perform bdc_field       using ‘BDC_CURSOR’ ‘XXX-XXX’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘BDC_OKCODE’ ‘/XX’.

* — Second Screen, Enter Line Items

   LOOP AT ZZZZ ASSIGNING <ZZZZ>.

  perform bdc_dynpro      using ‘SAPXXXX’ ‘0300’.

  perform bdc_field       using ‘BDC_CURSOR’ ‘XXX-XXX’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘BDC_OKCODE’ ‘/XX’.

* — Enter Details For Each Item

  perform bdc_dynpro      using ‘SAPXXXX’ ‘0102’.

  perform bdc_field       using ‘BDC_CURSOR’ ‘XXX-XXX’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’. 

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘XXX-XXX’ ‘YYY’.

  perform bdc_field       using ‘BDC_OKCODE’ ‘/XX’.

I prefer,when writing batch input programs to start every new screen with the form “BDC_DYNPRO” insert all the fields that I want to pass and add a “BDC_OKCODE” in the end. With this way, it will be very easy to identify and resolve any problems related to the batch input since each processing block is clearly defined and I could easily lets say combine each screen of the transaction with each block of the code when running/viewing in parallel ( mode a ) in order to find the error.

I know that everybody is used to write programs with an own unique way.The above example applies not only for batch input programs but of course in general.Writing with a clearly and structured way, not only will help you to resolve easier any kind of bugs but also can help us to identify any kind of problems and try to propose the solution in the forums.

Regards,

LF.

6 Comments
You must be Logged on to comment or reply to a post.
  • Yes, In fact I was quite surprised to see many ABAPers who don't even use pretty printer before sending the code to production.

    Not only the unstructured code makes you feel clumsy, mismatched IF-ELSE-ENDIF, CASE-WHEN statements can be nightmare to read. And as a result, I tend to avoid to review codes written by those programmers. 😛

    • In the new ABAP editor the conditional statements - IF ... ELSEIF, CASE ... WHEN - are easy to read even without a pretty print. But not to contest the fact that "Pretty print" is a must for every code 🙂

  • Hi,

    I am from the ABAP OO side.

    I would have made single methods for each section, you marked with a comment.

    Especially the code in the loop would be a single method for me, so it is clear by the name of the method, what I want to do in this loop.

  • Hello Laurent,

    Imo well-written code must be heavily "commented". In the past 6 months i've seen bad and good code. The only difference - comments.

    Good code: Comments galore 🙂 A simple COMMIT WORK was preceded with like 10 lines of comment describing why the COMMIT was required and what potential problems it might cause!

    Bad code: Sparse comments. Large programming blocks w/o any comment highlighting the rationale behind the code 🙁

    Bad, unstructured code is a maintenance nightmare!

    BR,

    Suhas

  • Hi Laurent,

    This is a great tip. I haven't coded in BDC for a long time now but yes, that is how I would do it -- screen name first, then data entry, then finally ok-code.

    If I'm not mistaken, the BDC_CURSOR is not needed. Well, in most of my BDC cases anyway.

    ~ Eric

    • Hi Eric,

      Thanks for your comment. You're right, BDC_CURSOR is not needed. I copied the code from a post in SCN that's why BDC_CURSOR is included.

      Regards.