Are you facing trouble with How to Create Basic SAP ABAP Program? Well, in this SAP tutorial, I will explain the basic declaration like internal tables, work area, and parameter declaration in the SAP ABAP editor.
Also, Read: How to Create Module Pool Program in SAP?
What is Basic Declaration Program in SAP ABAP Editor
The primary declaration means we have to declare some basic functionalities like internal tables, parameters, and work areas. This will be the first and foremost step in creating the report in SAP ABAP Editor.
How to Create Basic SAP ABAP Program
Whenever we want to work on the SAP ABAP editor, make sure the table has been created perfectly. If you don’t know to create a table in SAP ABAP, then you can read this complete SAP ABAP article to learn How to Create Table in SAP ABAP [With Columns].
Below are the steps to create a report in the ABAP editor in SAP to see the basic declarations.
Step-1:
- Open SAP ABAP, Type SE38 in the transaction search bar, and hit Enter (on the keyboard).
Step-2:
- Now, give the program name starting with z and click Create.
- Here I have given the program name zreport_1 (Since it is mandatory to use the report name starting with z and the underscore is for the space purpose).
Step-3:
- Once we click Create, pop-up windows open, and it will ask for the
- Title: Provide a Title as Report Program.
- Type: Give the Type as Executable Program
- Click Save at the bottom of the page.
Step-4:
- Now the SAP ABAP Editor page will open with the declaration of the report name by default.
- Double-click the table name to ensure the table has been already created.
NOTE:
If the table has not been created, it will ask for table creation first then only we can proceed with the creation of the report. Here my table name is ZCOMP_EMPLOYER and ZCOMP_EMPLOYER 2.
Report ZREPORT_1.
TABLES : zcomp_employer,
zcomp_employer2.
Step-5:
- We can also declare the table name separately like below. The reason for using commas is for continuity because we have used two tables here namely zcomp_employer and zcomp_employer2.
Report ZREPORT_1.
Tables : zcomp_employer,
Tables: zcomp_employer2.
- Check the below image in the SAP ABAP Editor to see the table declaration.
Step-6:
- The next step is to declare the internal table and work area in the SAP ABAP Editor. Internal table means fields available in the tables, whereas work area means it is used to process data in the internal table.
- For the 1st table, the internal table and work area are described below.
DATA : IT1 TYPE TABLE OF ZCOMP_EMPLOYER.
DATA: WA1 TYPE ZCOMP_EMPLOYER.
Step-7:
- For the second table, the internal table and work area are described below.
DATA : IT1 TYPE TABLE OF ZCOMP_EMPLOYER2.
DATA: WA2 TYPE ZCOMP_EMPLOYER2.
- We can declare two tables together also. Check the below code to have clarity.
DATA : IT1 TYPE TABLE OF zcomp_employer,
WA1 TYPE ZCOMP_EMPLOYER,
IT1 TYPE TABLE OF ZCOMP_EMPLOYER2,
WA2 TYPE ZCOMP_EMPLOYER2.
- The declaration of two tables in the SAP ABAP Editor is given below. But here for understanding purposes, I have taken the declaration of the internal table and work area separately.
- Now, as usual, save the check, and activate it. If it is no error it will activate immediately. Since this is a simple declaration so we won’t face many errors. Still, it throws some errors which might be because of the incorrect table name or the syntax we declared in the internal table and work area.
Note:
Since we are handling two tables, so for the declaration of the internal table, and work area name for 1st table should vary from the second table.
You may also like: How to Create Lock Object in SAP ABAP?
How to Declare Parameter in SAP ABAP Editor
Previously, we have seen the internal table and work area declarations. Here we will see how to declare a parameter in SAP ABAP SE38 Editor.
- In the ABAP editor page, declare parameters in SAP ABAP. Parameter declaration can be done in three ways.
PARAMETERS : P_EID TYPE C LENGTH 20.
OR
PARAMETERS : P_CEID TYPE ZCOMP_EMPLOYER-CEID.
OR
PARAMETERS : P_CEIN TYPE ZCEID.
Types of Parameters
We can declare 8 types of parameters based on the user requirements. Below is the list of parameters.
- Plane Declaration – Example P_EID TYPE ZCOMP_EMPLOYER CEID (Table name with field name)
- Default Type – P_EID1 TYPE ZCOMP_EMPLOYER DEFAULT ‘367’.
- Obligatory or Mandatory -f we are declaring two fields but in the output, if we are entering only one value then an error will occur.
- P_EID TYPE ZCOMP_EMPLOYER
- P_NM TYPE ZCOMP_EMPLOYER OBLIGATORY
- Declaration block for checkbox – This is used for software agreement, terms, and conditions we are accepting the agreements in the check box.
- P_EID TYPE ZCOMP_EMPLOYER-CEID OBLIGATORY
- P_AGREE AS A CHECKBOX
- Radiobutton – If we want to choose only one specific field for example in blood group or choosing gender.
- P_EID TYPE ZCOMP_EMPLOYER-CEID OBLIGATORY
- P_MALE RADIOBUTTON GROUP SEX,
- P_FEMALE RADIOBUTTON GROUP SEX.
Declaration of Parameter in SAP ABAP
Here we will see different declarations based on the user’s requirements.
Step-8:
- Here I have declared parameters without any specifications and we will see the output. Before seeing the output, save, check, and activate. Click the F8 key directly to activate the report.
PARAMETERS : P_EID TYPE ZCOMP_EMPLOYER-EMID.
Step-9:
- Next, we will see the default type parameter declaration in SAP ABAP. If we want to get the default values, then we can go for this parameter. So our output will come with this default value we have given.
PARAMETER : P_EID TYPE ZCOMP_EMPLOYER DEFAULT '235'.
Step-10:
- In this step, we are going to see obligatory parameters or mandatory parameters. If we want to make one entry of the record compulsory, then we can use the obligatory keyword. So the required field will come with a * symbol.
Parameters : P_EID TYPE ZCOMP_EMPLOYER-EMID OBLIGATORY,
P_NAME TYPE ZCOMP_EMPLOYER-EMNAME.
Step-11:
- If we forget to give a mandatory value in the output, we will see the below information.
Step-12:
- Giving the checkbox for the parameters is possible in this step. To move on to the next stage, we must check the box for the software license, terms, and conditions, for example.
PARAMETERS : P_EID TYPE ZCOMP_EMPLOYER-EMID,
P_AGREE AS A CHECKBOX
Step-13:
- To choose the particular options, we can use the radio button group parameter. For example, here I have taken a blood group selection, below is the syntax for the parameter.
PARAMTERS : P_MALE RADIOBUTTON GROUP SEX,
P_FEMALE RADIOBUTTON GROUP SEX.
In this way, we should declare parameters in SAP ABAP Editor.
What happens if we are given the wrong Field Name
While declaring the parameter we can give the variable as per our wish. For your understanding here I have given as P_EID.
But while giving the field make sure it matches with the table you created. If it is not matched, then we will get the below errors. Here I have declared a random field name but it will throw an error like No component exists also it will show the exact field name we declared in the table.
PARAMETERS : P_ID TYPE ZCOMP_EMPLOYER-EID
For more tutorials like this:
- How to Create a Foreign Key in SAP ABAP
- How to Create SAP ABAP List View Report (ALV)
- How to Create Table Maintenance Generator in SAP ABAP
- What are Reports and their Types in SAP ABAP [With Examples]
Conclusion
This tutorial explains the basic declaration of tables and parameter declaration with different keywords. Depending on your requirement you can use the particular parameter in SAP ABAP Editor. Below are the topics covered in this article.
- How to create report in SAP ABAP Editor
- How to declare a parameter in SAP ABAP Editor
- Types of parameters in SAP ABAP
- Declaration of the parameter in the ABAP editor
- What happens if we are given the wrong field name
I am Chris Waldron, working as a Senior SAP HANA Consultant at Halliburton, Houston, Texas, United States. I have been working in SAP for more than 15 years, especially in SAP IT consulting and business consulting. I worked in various industries in Sales & Distribution, Customer Relationship Management, banking, Risk Management, etc. And I am an SAP Certified Development Specialist – ABAP for SAP HANA 2.0 and SAP HANA Modeling Certified consultant. Read more