ABAP Programming - Day 2
ABAP Programming - Day 2
Day 2
ABAP Programming
Execute one "Hello SAP Yard" Program
Internal Tables (Indexed & Hashed), Two Types of Indexed Tables (Standard & Sorted)
SY-SUBRC Checks
ABAP Programming
Execute one "Hello SAPYard" Program
Standard Data Type (Complete(D,T,I,F,STRING and XSTRING) and Incomplete(C,N,X,P)); Local Data
Type(Created Locally in a Program>> Can’t be accessed in other programs and created using Syntax TYPES;
Global Data Type(Created globally in DATA Dictionary and accessible throughout the SAP system>> Show
via SE11).
Selection Screens in ABAP Programming (SELECT OPTIONS & PARAMETERS) & Radio
Buttons & Check Boxes in ABAP Programming
Refer to program Z_ABAP_TRAINING
"The load of Program Event loads the program into Memory for Execution and it
s always the first event in Execution Sequence,
*LOAD-OF-PROGRAM.
"This event is used for initializing the Variables, Screen Values and Other
Default Actions
INITIALIZATION .
PERFORM init_variables.
AT SELECTION-SCREEN OUTPUT.
PERFORM screen_modification.
"To validate the Screen Input Parameters and it validates a Single Input Fi
eld.
"If we want to Validate Multiple Input Fields we need to use AT SELECTION-
SCREEN.
AT SELECTION-SCREEN ON p_land1.
PERFORM validate_land1 .
"Default Event
START-OF-SELECTION .
PERFORM get_data.
END-OF-SELECTION .
IF p_dload = 'X' AND p_fname IS NOT INITIAL.
PERFORM download_data .
ELSE.
PERFORM display_data .
ENDIF.
TOP-OF-PAGE .
PERFORM display_heading . "SubRoutine
*----------------------------------------------------------------------*
FORM screen_modification.
IF p_dload IS INITIAL.
LOOP AT SCREEN.
CHECK screen-group1 = 'DLD'.
screen-input = '0'.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form VALIDATE_LAND1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text * <-- p2 text
*----------------------------------------------------------------------*
FORM validate_land1 .
SELECT land1 FROM kna1 INTO v_land1 UP TO 1 ROWS WHERE land1 = p_land1.
ENDSELECT .
IF sy-subrc <> 0 .
MESSAGE 'INVALID COUNTRY CODE' TYPE 'E' .
ENDIF .
ENDFORM. " VALIDATE_LAND1
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_data .
SELECT kunnr land1 name1 ort01 FROM kna1 INTO TABLE it_kna1 WHERE land1 = p
_land1 .
IF sy-subrc <> 0 .
MESSAGE 'NO DATA FOUND' TYPE 'I' .
ENDIF .
ENDFORM. "GET_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_HEADING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_heading .
WRITE : / sy-uline .
WRITE : /45 v_title COLOR 6 .
WRITE : / sy-uline .
ENDFORM. "DISPLAY_HEADING
*&---------------------------------------------------------------------*
*& Form DISPLAY_FOOTER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_footer.
WRITE : / sy-uline .
WRITE : /55 'SAPYARD' COLOR 6 .
WRITE : / sy-uline .
ENDFORM. "DISPLAY_FOOTER
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display_data .
LOOP AT it_kna1 INTO wa_kna1.
WRITE : / wa_kna1-kunnr ,
wa_kna1-land1 ,
wa_kna1-name1 ,
wa_kna1-ort01 .
ENDLOOP .
ENDFORM. "DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM download_data .
v_fname = p_fname .
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = v_fname "'C:\KNA1.TXT'
filetype = 'ASC' "ASC MEANS NOTEPAD FILE/DAT MEASN EXCEL F
ILE
write_field_separator = 'X'
TABLES
data_tab = it_kna1.
IF sy-subrc = 0.
MESSAGE 'DATA IS SUCCESSFULLY DOWNLOADED' TYPE 'I'.
ENDIF.
ENDFORM. "DOWNLOAD_DATA
*&---------------------------------------------------------------------*
*& Form GET_FILE_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_file_name .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = syst-repid
dynpro_number = syst-dynnr
field_name = 'P_FNAME'
CHANGING
file_name = p_fname.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. "GET_FILE_NAME
*&---------------------------------------------------------------------*
*& Form GET_HELP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_help .
MESSAGE 'PLEASE CLCIIK ON F4 FOR FILE NAME' TYPE 'I'.
ENDFORM. "GET_HELP
*******************************************
Internal tables are the core of ABAP. They are like soul of a body. For any
program we use internal tables extensively. We can use Internal tables like
normal data base tables only, but the basic difference is the memory allocated
for internal tables is temporary. Once the program is closed the memory
allocated for internal tables will also be out of memory.
But while using the internal tables, there are many performance issues to be
considered. i.e. which type of internal table to be used for the program like
standard internal table, hashed internal table or sorted internal table etc..
ALL PRACTICAL AND THEORATICAL CONCEPTS RELATED TO BELOW TOPICS Refer to PROGRAM: -
Z_ABAP_TRAINING
• Internal Tables (Indexed & Hashed), Two Types of Indexed Tables (Standard & Sorted)
• How to define Internal Table Data Types and Work Area?
• Alpha Conversions (external/internal) display
• Strings & Text Elements, Concatenate Statement
• All Operations in Internal Tables
• SELECT Statements, JOINS, For All Entries
• SY-SUBRC Checks
• Conditional Statements (IF/ENDIF, CASE), LOOPs, READs, Termination Statements
• Modularization - Subroutines (Performs), Function Modules, Includes
• Field Symbols Declaration, Usage and Assign Statement
"Select EndSelect
*DATA : it_mara TYPE TABLE OF mara. " Declare internal table
*DATA : wa_mara TYPE mara. " Declare work area
*
*SELECT * FROM mara INTO wa_mara UP TO 50 ROWS WHERE mtart = 'FERT'. " Read 5
"For all entries is the best alternative for SELECT WITH JOINS, this stateme
nt is very helpful for reading data from more than 2 tables.
*Parent internal table must not be empty ( If it is empty, where condition fa
ils and it will get all records from database).
*Remove all duplicate entries in parent internal table
*DATA: it_mara TYPE TABLE OF mara,
* wa_mara TYPE mara.
*DATA: it_makt TYPE TABLE OF makt,
* wa_makt TYPE makt.
*SELECT *
* FROM mara
* INTO TABLE it_mara
* WHERE mtart = 'FERT'.
*IF it_mara IS NOT INITIAL.
* SELECT *
* FROM makt
* INTO TABLE it_makt
* FOR ALL ENTRIES IN it_mara
• STRING
• C
• D
• I
In SAP ABAP there are 3 types of data Type. What are those 3 types??
• DATA
• TYPES
• VALUE
• DEFAULT
Which of the following codes are true to assign a value to data object VAR.
• DATA VAR TYPE string. VAR <> ‘AA’.
• DATA VAR TYPE string VALUE ‘AA’.
• DATA VAR TYPE string. VAR == ‘AA’.
• DATA VAR TYPE string. VAR > ‘AA’.
While designing a Selection-Screen what can be the max length of a Parameter Variable name?
• 7
• 5
• 8
• 9
When should we use Select Single and when should we use Select upto 1 rows?
While using FOR ALL ENTRIES in a SELECT query if the parent Internal Table is initial what will happen??
While creating an Include Program what is the Type to be chosen under Program Attributes?
• Executable
• Include
• Module Pool
• Function Group
Exercise: -
• Write a events-based program to display data on screen or if the Radio Button Download is
selected then the data should be downloaded to your local machine by giving the desired file
path?
• Write a small program to display all radio-buttons horizontally rather than vertically along with
the Radio Button Text.