Friday, December 14, 2012

Important ABAP Questions Usually Missed Out!

Hi folks! Below are some of the questions that I encountered during my interviews. It is very hard to face the interviewer if you do not know how to answer those questions as they appear as basic. So, what I did, was to write down what I have remembered and add them on this list.

NOTE: Don't forget to memorize all the important FMs used in ABAP development.

1. What is needed to add a custom field to a standard table. -custom includes staring in CI or append structure button


2. What is the type needed for a table field to accept a negative and positive symbol and what are the steps.
- The data type of integers, i, has a value range of -2147483648 to +2147483647 and contains integers only. You can specify integers as numeric literals directly in the program.

3. Difference between a BAPI and FM. - bapi is stored in bor, remote enabled, pre-defined standard processes from SAP while standard FM is the opposite.
sample BAPI - BAPI_FIXEDASSET_CREATE1

4. Difference between a BAPI and RFC. -BAPI in BOR and call standard sap process while RFC is the gateway to call a remote-enabled FM like BAPI.

5. The different kind of exits.
- menu exits
- screen exits
- FM exits
- field exits

6. Steps in creating a BADI
- you need to put a break point inside class ‘CL_EXITHANDLER’

CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE’ 


of method get_instance

SE19 you will create a new copy of badi method you have detected (starting in Z) or in oop concept you will redefine(polymorphism) it. Then, in SE18, there you will see the actual coding of the method you are copying. In there you can copy paste the FM being called by the standard method and put it on your redefined badi method.

**Advantage of BADI**

The main advantage of this concept is the capacity for reuse. Once implemented, a Business Add-In
can be reimplemented by other links in the software chain**TAW10


7. Difference between a BADI and user exits.
- badi is more of OOP while user exits are the usual abap exit using FMs.

8. How to convert Smartforms/Sapscript to PDF
- get the otf file
- convert the otf file to pdf by using a certain FM
- then call an FM to download the file

9. How to format a currency using WRITE in classic list.
set country 'US' or character. If 'US' or any character the represents it is blank, then it will used what it is defined in master record or sap sytem config, otherwise it will search the one in t005x table.
set currency will override set country

10. Difference between layout and fieldcat setup in ALV.
-layout, will affect the whole alv functionality
- fieldcat for each specific field

11. How to read file and what is the FM used.

12. Difference between a GUI download and OPEN Dataset FMs.

GUI_DOWNLOAD - download file to local/presentation server, while OPEN Dataset from applicaiton server.

Running ABAP Program in batch mode is capable only of handling file from application server thus the abap statement below are the only means for you to handle data transfer running in batch mode:

OPEN DATASET
CLOSE DATASET
DELETE DATASET
READ DATASET
TRANSFER

13. What are the sample BAPIs.
- BAPI_fixedasset_create1

14. Define field-symbols.
- placeholder to a certain variable. they do not reserve space but pointing the variable value to it after referencing.

15. Logical DB advantage and disadvantage.
Advantage: Centralized authorization check, Own pre-defined selection screen, Faster retrieval of data through its hierarchal design
Event of logical DB is get. It invokes the pull event handler in LDB program (created in SE36)
Event get late - is performed after all the tables in the lower part of the hierarchy have been processed

16. How to create text fields.

17. How to create a text table - Create ID table then the Text Table by linking their keys by making it foreign.

18. What are the implications of mandt - client dependecy such that if not included in a table, data is visible across boxes/clients.
- usually not including mandt is used in SAP system tables wherein that table data will be used accross clients

19. Ways to add data to a database tabale
- modify, will update the data, if not found it will insert the data
- update - it will only update existing data otherwise error
- insert - add the new record which is not existing, otherwise error

20. Ways to add data to abap internal table
-
21. Types of SAP Dialog events
-  Process Before Output (PBO) - triggered before screen is displayed

- Process After Input (PAI) - triggered after the screen is displayed
- Process On-Help Request (POH) - F1
- Process On-Value Request (POV) - F4
----------------------ADDITIONAL QUESTIONS--------------------

22. Types of ABAP tables:
- Index tables and hashed table
- Index tables are standard table and sorted table
- Hashed table is only hashed table
- Standard table can be accessed by using an index or key
- Sort table can be accessed using an index or key and sorted in ascending order by default

23. ALE, EDI, IDOC
- ALE- Application link Enabling, enables linking between two systems
- 3 Layers of ALE are Application layer, Distribution layer, and Communication layer
   - Application layer - refers to the applicaiton data such as SD, MM, FI, HR etc
   - Distribution layer - wherein data is determined to whom it will be distributed and formatted
   - communication layer - this is where the transfer of data takes place through RFC, TCP etc

- EDI is a translator of IDOC data. Usually it is a third party component.
  - it is comprised of outbound and inbound process

IDOC - is a transporter of the data being passed to ALE. te data being hold is arranged in a structured format.

24. How SAP table handles uppercase/lowercase queries? 
 - this can be done in domain level. By default, the domain data type will convert any characters to uppercase unless the it is selected in the domain lowercase tick box.

25. SAP Memory types
 - ABAP Memory -> can be accessed by the programs within internal session using import and export parameters
 - SAP Memory -> can be accessed by different programs across external sessions using GET/SET(GPA/SPA) Parameters

Thursday, June 07, 2012

Authorization Check (FM)

After our QA checked our program, she found out that we are not checking auhtorization before calling a tcode. Upon checking the program, other "CALL TRANSACTION" statement is using function module " AUTHORITY_CHECK_TCODE" to check the authority before calling a tcode. This is very simple to use by just passing the tcode you want to call and make sure to declare the exception parameters for you to be able to handle the appropriate returned error code.

      CALL FUNCTION 'AUTHORITY_CHECK_TCODE'
        EXPORTING
          tcode  = [tcode]
        EXCEPTIONS
          ok     = 1
          not_ok = 2
          OTHERS = 3.
      IF sy-subrc NE 1.
        wa_errmsg-type = c_error.
        wa_errmsg-message = 'No authorization for Transaction'(031).
        APPEND wa_errmsg TO p_tb_errmsg.
      ELSE.
 

Happy coding everyone!!

Tuesday, April 10, 2012

SAP SpecialTables

I came across this topic "SAP Special Tables" upon reading my SAP ABAP Certification ebook. SAP Special Tables are very common table types of SAP that we as ABAPERs encounter from our day to day ABAP development. SAP Special Tables are very common in ABAP and very important as far as SAP technology is concerned. They are simply tables that contain the business data needed by everyone using SAP technology. 

These special tables are called Transparent, Cluster, and Pooled tables. You may find various definitions and comparisons in the internet if you like but, I noticed that those definitions are described commonly based on textbook type of explanations which for me I found it difficult to understand quickly esp. by the newbies. So, I decided to write this down immediately after compiling my own understanding and figuring out how I am going to plot and describe it here through my blog.

First, I will explain one by one the definition and how these tables are used and how to create one of them in SAP. Let's start with Transparent table:

Transparent table - is a type of table in SAP with a direct relation to the database itself. meaning every time you create a transparent table, there should always a corresponding instance as one to one physical relationship in a database table. The below picture shows how ABAP tables relate to the database tables from dictionary logical view relationship.

 
Creating transparent table can be done in SE11. Changing the type can be done by clicking extras and Change Table Category.

Cluster table - is a special table contains many cluster tables and grouped them into one table by combining each of their keys whichever is identical otherwise create a new key field. As you can see on the above picture, cluster table is composed of various cluster tables in dictionary logical view but it is made of only one physical database table.

Pooled table - simply a combination of various tables regardless of the key combination. Meaning keys are not combined but rather treated them independently for each table being pooled.

The below picture how pooled and cluster table differentiate to each other by means of UNION.



The letter shows the keys, if you noticed, in cluster same keys are combined to produced only one key in the database table while in pooled keys are treated independently.



Thursday, March 08, 2012

Alv events for real time scenario

It has been so long that I have not been able to update my blog. I was quite busy with left to right projects to one of our clients.

Today, I want to share with you on how to handle oop alv using events specifically if front-end data has been changed. I.e sorted, deleted or filtered. On the following scenario below, I am going to present to you my own approach on how to deal with issues regarding alv front-end changes.

Steps:

1. Create a wrapper class for " set_table_for_first_display " method of cl_gui_alv_grid to handle "changing" internal table - meaning every time there are changes on the alv front-end, we will be able to capture and to read the appropriate record or data being clicked (hotpost_click event), changed (user_command event), etc.

2. Create a constructor (class' method called during creation of an object - typically for initialization of attributes) for your wrapper class for us to be able to send the cl_gui_alv_grid object coming from our main program. Our main program should act as a caller for the wrapper class by passing the appropriate parameters for "set_table_for_first_display_ method as shown below:

  variant-report = sy-repid. "to save the alv layout
  variant-username = sy-uname. "to save the alv layout
  variant-variant = alv_var. "layout name

  CREATE OBJECT obj_alv_pir01
    EXPORTING
      i_object = grid1
      .

  CALL METHOD obj_alv_pir01->set_table_for_first_display
    EXPORTING
      is_layout       = wa_alv_layout
      is_variant      = variant "to show the alv layout button
      i_save          = 'A' "to show the alv layout button
    CHANGING
      it_outtab       =   tb_final
      it_fieldcatalog = tb_fieldcat


 3. In our wrapper class, declare a static attribute for our internal table that will handle the it_outtab of "set_table_for_first_display" method. Note: parameter "changing" means that changes of an it_table inside the called method will reflect also to the it_table of the calling program.

4. Inside our event, let us take event USER_COMMAND, we should do the below code in ordfer for us to capture the appropriate line of records being selected from the ALV front-end. "NO matter what happens to the front-end data will also reflect to our static table as shown below":

  DATA lt_selected_rows TYPE lvc_t_roid .
  DATA ls_selected_row TYPE lvc_s_roid .

  CALL METHOD grid_object->get_selected_rows
  IMPORTING
  et_row_no = lt_selected_rows .
  READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1 .

  IF sy-subrc ne 0 .
    MESSAGE s000(su) WITH 'Select a row!'(203) .
    EXIT.
  ENDIF .

  READ TABLE ZCL_ALV_PIR01=>tb_final INDEX ls_selected_row-row_id INTO l_wa_final.

That's it! If you have any clarification, please don't hesitate to post a comment.

Have a nice day!