InterviewSolution
| 1. |
Write an ABAP sample program for ALV display. |
|
Answer» TABLES: pa002. *Type DeclarartionTYPES : BEGIN OF ty_employee, "Structure declaration pernr TYPE pa0002-pernr, subty TYPE pa0002-subty, nachn TYPE pa0002-nachn, vorna TYPE pa0002-vorna, gesch TYPE pa0002-gesch, END OF ty_employee. *--Data DeclarationDATA : lt_employee TYPE STANDARD TABLE OF ty_employee, "Internal table ls_employee TYPE ty_employee, "Work area lt_fieldcat TYPE slis_t_fieldcat_alv, "Internal table for ALV display ls_fieldcat TYPE slis_fieldcat_alv, lv_repid LIKE sy_repid. "Local variable for the PROGRAM name *Selection ScreenSELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. "Please enter employee number SELECTION-OPTIONS: so_pernr FOR pa002-pernr. "Selection screen field to enter employee numberSELECTION-SCREEN END OF BLOCK b1.START-OF-SELECTION.*Data Fetching "To get the employee details from database SELECT pernr subty nachn vorna gesch FROM pa0002 INTO TABLE lt_employee WHERE pernr IN so_pernr. IF sy-subrc=0. SORT lt_employee BY pernr. ENDIF. END-OF-SELECTION.*Field Catalog "Inserting records for ALV display CLEAR ls_fieldcat. ls_fieldcat-col_pos = 1. "Column position in output ls_fieldcat-fieldname = 'PERNR'. "Field name in the output ls_fieldcat-tabname = 'LT_EMPLOYEE'. ls_fieldcat-seltext_m = 'Employee number'. "Field description APPEND ls_fieldcat TO lt_fieldcat. CLEAR ls_fieldcat. ls_fieldcat-col_pos = 2. ls_fieldcat-fieldname = 'SUBTY'. ls_fieldcat-tabname = 'LT_EMPLOYEE'. ls_fieldcat-seltext_m = 'Sub type'. APPEND ls_fieldcat TO lt_fieldcat. CLEAR ls_fieldcat. ls_fieldcat-col_pos = 3. ls_fieldcat-fieldname = 'NACHN'. ls_fieldcat-tabname = 'LT_EMPLOYEE'. ls_fieldcat-seltext_m = 'Last name'. APPEND ls_fieldcat TO lt_fieldcat. CLEAR ls_fieldcat. ls_fieldcat-col_pos = 4. ls_fieldcat-fieldname = 'VORNA'. ls_fieldcat-tabname = 'LT_EMPLOYEE'. ls_fieldcat-seltext_m = 'First name'. APPEND ls_fieldcat TO lt_fieldcat. CLEAR ls_fieldcat. ls_fieldcat-col_pos = 5. ls_fieldcat-fieldname = 'GESCH'. ls_fieldcat-tabname = 'LT_EMPLOYEE'. ls_fieldcat-seltext_m = 'Gender'. APPEND ls_fieldcat TO lt_fieldcat. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' "Function module to display data in ALV format EXPORTING it_fieldcat = lt_fieldcat TABLES t_outtab = lt_employee EXCEPTIONS program_error = 1 OTHERS = 2 The below snapshot represents the selection screen. Output in an ALV grid: ConclusionTo obtain any technical position, theory and basic concepts are necessary for any fresher who is applying for the SAP ABAP job role, but for an experienced CANDIDATE both practical and applied concepts are mandatory. Usually, for an experienced candidate, a lot of SAP ABAP interview questions will be related to your previous project and roles. This article essentially covered a list of frequently asked SAP ABAP related questions that fits the interview requirements. A candidate who wants to get a job in an SAP ABAP role should glance through these questions once before heading towards the SAP ABAP Interview round. You can prepare well and give your best in the next interview. References
|
|