Misadventures of a SAP n00b

SAP is considered to be the best Enterprise Resource Planning system in the world today, and there are thousands of SAP implementations in many mega-corporations around the world.

I had the opportunity to mess around (at a very beginner level) with ABAP and some Z Programs on the SD and MM modules, and would like to document some of the things I learnt. Especially after reading an awesome SAP blog by my friend Jeewana Premarathne at http://implementsap.blogspot.com, I thought of documenting my (rather minimal) knowledge as an ABAP programmer on my blog as well.

1. Search keyword chaining

Just like with any other keyword, it is possible to chain the search keyword as well to search for multiple strings at the same time. If any of the search strings are found within the target string, sy-subrc will be set to 0.

e.g.

SEARCH target_string FOR:
  'Search string 1',
  'Search string 2'.
IF sy-subrc = 0.
  "Do something if search string is found

2.  Some useful naming conventions: http://bit.ly/yoZGGp

3.   Function to give the user a dropdown list to choose a file from the server to save to

CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
EXPORTING
  directory = 'directory on server'
  filemask = ' '
IMPORTING
  serverfile = "return variable name
EXCEPTIONS
  canceled_by_user = 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.

The above code will give the user a dropdown list to choose a file from. You can use this file as a variable within the program to write data to or read from. If the file is not available on the server or the directory path you provided is not available, this will result in a dump, so this should be handled accordingly.

4. Using OPEN DATASET to write to a file

Once you have obtained the path to the file, you can use the OPEN DATASET keyword to open this file for writing, and simply write a character string or an internal table to it.

"Open file for writing
OPEN DATASET output_file FOR OUTPUT IN TEXT MODE.

  IF sy-subrc = 0.
    * Write output string to file.
    TRANSFER t_output TO output_file.
  ELSE.
    WRITE 'The file could not be written.'.
  ENDIF.
CLOSE DATASET output_file.

5.   Concatenating char/string type variables

For this, it is possible to use the CONCATENATE keyword. If you want to separate the strings using a delimiter, this can be arranged by adding the SEPARATED BY keyword.

CONCATENATE
  lv_string1,
  lv_string2,
INTO lv_final_string SEPARATED BY 'delimiter'.

That’s about it for now from me. Since I’m such a newbie to this, there may be some mistakes. It should also be noted that SAP ABAP programming is not simply about learning the code and programming away like in other programming languages, but you have to have a thorough understanding of the business involved, as well as its processes. More on that later.