Let’s start ABAP programming!! Here is a list of popular ABAP commands including information about what it does and example code of how to use. They are also ordered in such a way that you can implement them one by one and gradually build a working ABAP report and beyond.
TYPES – Creates type value that can be used by variables within your ABAP code. i.e. can declare an internal table field structure which can be assigned using the DATA statement to create an internal table.
TYPES: BEGIN OF t_summary, lineid type i, title type string, field1 type n, filed2 type i, total type i, end of t_summary.
DATA – Declares a variable of a specific type within your ABAP code. You can reference a type declared within your program or any type available within the SAP dictionary (see t-code SE11).
DATA: it_summary type STANDARD TABLE OF t_summary, wa_summary like line of it_summary, ld_stell type pa0001-stell, ld_pernr type pa0001-pernr, it_pa0001 type STANDARD TABLE OF pa0001, wa_pa0001 like line of it_pa0001.
PARAMETERS – Declare a selection screen parameter for your report to capture user input for a specific field. The OBLIGATORY statement also makes the input by the user mandatory.
PARAMETERS: p_pernr like pa0001-pernr OBLIGATORY.
SELECT – Selects data from an SAP database table into local variables/internal table
SELECT single stell from pa0001 into ld_stell where pernr eq p_pernr and begda le sy-datum and endda ge sy-datum. SELECT single * from pa0001 into table it_pa0001 where pernr eq ld_pernr and begda le sy-datum and endda ge sy-datum.
WRITE – Display date to user on basic report screen
LOOP – loop around an internal table of data
LOOP AT it_pa0001 into wa_pa0001. WRITE:/ wa_pa0001-orgeh. “display org unit ENDLOOP.
READ – Read data within an internal table
READ TABLE it_summary into wa_summary with key lineid = ‘10’.
FORM – Declares an ABAP Subroutine which can be called from anywhere with your ABAP report or program. These can also include parameters that can be used to pass data to and from the form/subroutine.
FORM build_fieldcatalog USING p_field. wa_fieldcat-fieldname = p_field. wa_fieldcat-scrtext_s = 'Job Title (SAP)' . wa_fieldcat-scrtext_m = 'Job Title (SAP)'. wa_fieldcat-scrtext_l = 'Job Title (SAP)' . wa_fieldcat-no_out = 'X'. insert wa_fieldcat into it_fieldcat index ld_tabix. ENDFORM.
PERFORM – Used to call a subroutine within your ABAP code
PERFORM build_fieldcatalog using ‘LINEID’.
CALL FUNCTION – Used to call SAP function modules. These sections of code similar to subroutines but are created within their own function group object rather than within the ABAP report. This means they generally includes generic functionality that is relevant to many different programs such as calculating dates, reading files, updating tables, displaying popup etc.
CALL FUNCTION 'POPUP_TO_CONFIRM' EXPORTING text_question = ld_text display_cancel_button = c_no IMPORTING answer = ld_answer.
IF, ELSEIF – Adds conditional statements to your ABAP code. If condition it met then execute the following code else execute alternate code.
IF ld_pernr EQ ‘111111’. clear: ld_stell. ELSEIF ld_pernr EQ ‘222222’. refresh: it_pa0001. ENDIF.
CASE – Case conditional statement similar to if else.
CASE ld_pernr. WHEN ‘111111’. clear: ld_stell. WHEN ‘222222’. refresh: it_pa0001. ENDCASE.
More to come soon!!!!