Showing posts with label ABAP Programmes. Show all posts
Showing posts with label ABAP Programmes. Show all posts

Send email to many users

REPORT Z_SEND_EMAIL_to_Users.

TABLES: USR02.

DATA: C(15).
DATA: SENT LIKE SONV-FLAG.
DATA: EMAIL_ID LIKE SOFOLENTI1-OBJECT_ID.
DATA: BEGIN OF EMAIL_DATA.
INCLUDE STRUCTURE SODOCCHGI1.
DATA: END OF EMAIL_DATA.
DATA: BEGIN OF EMAIL_SEND OCCURS 10.
INCLUDE STRUCTURE SOMLRECI1.
DATA: END OF EMAIL_SEND.
DATA: BEGIN OF EMAIL_TEXT OCCURS 10.
INCLUDE STRUCTURE SOLISTI1.
DATA: END OF EMAIL_TEXT.


****************************************************
PARAMETERS: ALL__CLI RADIOBUTTON GROUP RADI.
PARAMETERS: THIS_CLI RADIOBUTTON GROUP RADI.
PARAMETERS: SELECT__ RADIOBUTTON GROUP RADI.
SELECT-OPTIONS SEND_TO FOR C NO INTERVALS.
SELECTION-SCREEN SKIP.

PARAMETERS: SUBJECT(30).
SELECTION-SCREEN SKIP.

SELECTION-SCREEN COMMENT /1(20) TEXT-999.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L1(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L2(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L3(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L4(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L5(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L6(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L7(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L8(84).
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: L9(84).
SELECTION-SCREEN END OF LINE.
***********************************************

EMAIL_TEXT-LINE = L1.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L2.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L3.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L4.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L5.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L6.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L7.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L8.
APPEND EMAIL_TEXT.
EMAIL_TEXT-LINE = L9.
APPEND EMAIL_TEXT.

EMAIL_DATA-OBJ_NAME = ‘MESSAGE’.
EMAIL_DATA-OBJ_DESCR = SUBJECT.
EMAIL_DATA-OBJ_LANGU = ‘E’.
EMAIL_DATA-SENSITIVTY = ‘P’.
EMAIL_DATA-OBJ_PRIO = ’1′.
EMAIL_DATA-NO_CHANGE = ‘X’.
EMAIL_DATA-PRIORITY = ’1′.

IF SELECT__ = ‘X’.
LOOP AT SEND_TO.
EMAIL_SEND-RECEIVER = SEND_TO-LOW.
EMAIL_SEND-REC_TYPE = ‘U’.
EMAIL_SEND-EXPRESS = ‘X’.
APPEND EMAIL_SEND.
ENDLOOP.
ELSEIF THIS_CLI = ‘X’.
SELECT * FROM USR02.
IF USR02-USTYP = ‘A’ AND USR02-BNAME NE ‘SAP*’
AND USR02-BNAME NE ‘DDIC’.
EMAIL_SEND-RECEIVER = USR02-BNAME.
EMAIL_SEND-REC_TYPE = ‘U’.
EMAIL_SEND-EXPRESS = ‘X’.
APPEND EMAIL_SEND.
ENDIF.
ENDSELECT.
ELSEIF ALL__CLI = ‘X’.
SELECT * FROM USR02 CLIENT SPECIFIED.
IF USR02-USTYP = ‘A’ AND USR02-BNAME NE ‘SAP*’
AND USR02-BNAME NE ‘DDIC’.
EMAIL_SEND-RECEIVER = USR02-BNAME.
EMAIL_SEND-REC_TYPE = ‘U’.
EMAIL_SEND-EXPRESS = ‘X’.
APPEND EMAIL_SEND.
ENDIF.
ENDSELECT.
ENDIF.

WRITE:/ ‘End of program’.

*****************************************************
CALL FUNCTION ‘SO_NEW_DOCUMENT_SEND_API1
EXPORTING
DOCUMENT_DATA = EMAIL_DATA
DOCUMENT_TYPE = ‘RAW’
PUT_IN_OUTBOX = ‘X’
IMPORTING
SENT_TO_ALL = SENT
NEW_OBJECT_ID = EMAIL_ID
TABLES
OBJECT_CONTENT = EMAIL_TEXT
RECEIVERS = EMAIL_SEND
EXCEPTIONS
TOO_MANY_RECEIVERS = 1
DOCUMENT_NOT_SENT = 2
DOCUMENT_TYPE_NOT_EXIST = 3
OPERATION_NO_AUTHORIZATION = 4
PARAMETER_ERROR = 5
X_ERROR = 6
ENQUEUE_ERROR = 7
OTHERS = 8.

Write output to a window

REPORT Z_write_to_WINDOW NO STANDARD PAGE HEADING.

TABLES: LFA1, LFBK.

START-OF-SELECTION.

GET LFA1.
WRITE: / LFA1-NAME1, LFA1-PSTLZ.
HIDE LFA1-LIFNR.

AT LINE-SELECTION.
SELECT * FROM LFA1 WHERE LIFNR = LFA1-LIFNR.
WINDOW STARTING AT 05 10
ENDING AT 50 20.
WRITE: LFA1-ORT01.
ENDSELECT.

SAP Gui Progress Indicator

REPORT Z_SAPGUI_INDICATOR.

DATA: A LIKE SY-UCOMM.

DO 100 TIMES.
DO 300 TIMES.
GET TIME.
ENDDO.
A(3) = SY-INDEX.A+3 = ‘%’.
CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR’
EXPORTING
PERCENTAGE = SY-INDEX
TEXT = A.
ENDDO.

Use of Commit and Rollback

REPORT Z_IMPORT_EXPORT_to_cluster NO STANDARD PAGE HEADING.
TABLES : ZGLGRP , SKB1.
PARAMETERS : IFILE(30) DEFAULT ‘/tmp/cdslink.dat’ LOWER CASE,
PBUKRS LIKE BKPF-BUKRS ,
PKTOPL LIKE ZGLGRP-KTOPL.
DATA : BEGIN OF TAB1 OCCURS 100 ,
NEWGL(6) ,
OLDGL(4) ,
LINK(2) ,
END OF TAB1.
DATA : BEGIN OF TAB2 OCCURS 100.
INCLUDE STRUCTURE ZGLGRP.
DATA : END OF TAB2.
DATA : LIN(4) TYPE N ,
GLOK(1) VALUE ‘N’ ,
GL10(10) ,

START-OF-SELECTION.
OPEN DATASET IFILE FOR INPUT IN TEXT MODE.

DO.
CLEAR TAB1.
READ DATASET IFILE INTO TAB1.
IF SY-SUBRC NE 0.
EXIT.
ENDIF.
PERFORM GET_GLOK.
IF GLOK = ‘Y’.
CLEAR TAB2.
MOVE : SY-MANDT TO TAB2-MANDT , PKTOPL TO TAB2-KTOPL ,
PBUKRS TO TAB2-BUKRS , GL10 TO TAB2-HKONT ,
TAB1-LINK TO TAB2-ZCDSGRP.
APPEND TAB2.
ELSE.
APPEND TAB1.
ENDIF.
ENDDO.
END-OF-SELECTION.
*
MODIFY ZGLGRP FROM TABLE TAB2.
DESCRIBE TABLE TAB2 LINES LIN.
IF LIN NE SY-DBCNT.
LIN = LIN – SY-DBCNT.
ROLLBACK WORK.
WRITE :/2 ‘Update Failed For ‘ , LIN ,
‘ Records. Table ROLLED BACK Entirely’.
ELSE.
COMMIT WORK.
ENDIF.
*
CLEAR LIN.
DESCRIBE TABLE TAB1 LINES LIN.
IF LIN > 0.
WRITE :/2 ‘Reocrds Not Updated ‘. ULINE /2(25).
LOOP AT TAB1.
WRITE :/4 TAB1-NEWGL , TAB1-LINK .
ENDLOOP.
ENDIF.

FORM GET_GLOK.
MOVE ‘N’ TO GLOK.
CLEAR GL10. MOVE : ’0000′ TO GL10 , TAB1-NEWGL TO GL10+4(6).
SELECT SINGLE * FROM SKB1 WHERE BUKRS = PBUKRS
AND SAKNR = GL10.
IF SY-SUBRC EQ 0.
MOVE ‘Y’ TO GLOK.
ENDIF.
ENDFORM.

Source Code: Few simple examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
REPORT CHAP0102.

* Copying the content of one data object to another
DATA: SOURCE(10) TYPE C,
TARGET LIKE SOURCE.
MOVE SOURCE TO TARGET.

* Displaying the contents of fields
WRITE 'ABAP/4 is easy.'.
NEW-LINE.
WRITE 'This text is displayed on a new line.'.
WRITE / 'After the symbol /, text also appears on a new line.'.

* Standard control structures (conditions and loops)
IF SOURCE = TARGET.
WRITE / 'Fields source and target have the same content'.
ELSE.
WRITE / 'Fields source and target do not have the same content'.
ENDIF.

DO 3 TIMES.
WRITE / SY-INDEX.
ENDDO.

* Local subroutine of a single program
DATA: A1 TYPE I,
A2 TYPE I.
PERFORM CALC USING A1
CHANGING A2.
WRITE / A2.
FORM CALC USING F1 LIKE A1
CHANGING F2 LIKE A2.
F2 = F1 + ( F2 * 17 ).
ENDFORM.

* Event for drill-down facilities (reacts when a user selects a line)
AT LINE-SELECTION.
WRITE 'This is displayed after double-clicking a line'.

Source Code: Working with database tables and internal tables

REPORT ZSOURCE0103.

* Declaration of a work area for a Dictionary table
TABLES CUSTOMERS.

* Internal table used as snapshot of the database table
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
WITH HEADER LINE.

* Reading the entries of the database table into an internal table
SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS.

* Displaying each line of an internal table
LOOP AT ALL_CUSTOMERS.
WRITE: / ALL_CUSTOMERS-NAME.
ENDLOOP.

Source Code: Designing a report

REPORT ZSOURCE0104.

* Declaration of a work area for a Dictionary table
TABLES CUSTOMERS.

* Internal table used as snapshot of the database table
DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100
WITH HEADER LINE.

* Definition of input fields on the report’s selection screen
SELECT-OPTIONS SNAME FOR CUSTOMERS-NAME.

* Reading the entries of the database table into an internal table
SELECT * FROM CUSTOMERS INTO TABLE ALL_CUSTOMERS
WHERE NAME IN SNAME.

* Displaying each line of an internal table
LOOP AT ALL_CUSTOMERS.
WRITE: / ALL_CUSTOMERS-NAME.
ENDLOOP.
———————

ABAP Source Code: Syntax of ABAP/4 Programs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
* Declaration of the program name
REPORT ZSOURCE0301.

* Displaying the words 'Customer list' on the screen
WRITE / 'Customer list'.

* Using an addition of the write command
WRITE AT /10 'Customer list'.

* Using single quotation marks within the text of a literal
WRITE / 'Customer''s Name'.

* Here is a comment with an asterisk in the first column
WRITE / 'Ms O''Connor'. "This is a comment at the end of the line

* A field of type character and length 40
DATA TARGET_STRING(40) TYPE C.

* Statements may extend over several lines
* (e.g., copying fields using the move command):
MOVE 'Source string'
TO
TARGET_STRING.
WRITE / TARGET_STRING.

* Combining Statements
WRITE: / 'Customer list',
'Bookings'.

ABAP Source Code: Three approaches to define data objects

REPORT ZSOURCE0401.

* 1. Elementary types

DATA: CUSTOMER_NAME_1(25) TYPE C,
VENDOR_NAME_1(25) TYPE C.

* 2. Reference to an existing field
DATA: CUSTOMER_NAME_2(25) TYPE C,
VENDOR_NAME_2 LIKE CUSTOMER_NAME_2.

* 3. Reference to a non-elementary type
TYPES T_NAME(25) TYPE C.
DATA: CUSTOMER_NAME_3 TYPE T_NAME,
VENDOR_NAME_3 TYPE T_NAME.

ABAP Source Code: Types, data, constants

REPORT ZSOURCE0402.

* Type flag defines an abstract type

TYPES FLAG TYPE C.

* Field address_flag will allocate space in main memory at runtime
DATA ADDRESS_FLAG TYPE FLAG VALUE ‘X’.

* Constants are defined like fields and cannot be changed

CONSTANTS: COMPANY_NAME(3) TYPE C VALUE ‘SAP’,
MAX_COUNTER TYPE I VALUE 9999.

* Using constants to define initial values

DATA COUNTER TYPE I VALUE MAX_COUNTER.

ABAP Source Code: Character types

REPORT ZSOURCE0403.

* Type c is the default type when no type is specified.
* Initial value is space, if it is not specified explicitly.

DATA: NAME(25) TYPE C,
CITY(25),
FLAG,
SINGLE_CHARACTER VALUE ‘A’.

* If the field and the initial value have different lengths, the
* initial value is either truncated or padded with blanks on the right:

DATA LANGUAGE(2) VALUE ‘ABAP/4′.
WRITE / LANGUAGE.


* Maximum length 64KB

DATA MAX_CHARACTER_FIELD(65535).

* Variables of type n (numeric texts) contain strings of digits

DATA CUSTOMER_ID(8) TYPE N VALUE ’87654321′.

* The default length for a field of type n is 1,
* and the default initial value is a string of zeros

DATA ZIP_CODE(5) TYPE N.
WRITE / ZIP_CODE.

* Type n fields pad the left side with zeroes
CUSTOMER_ID = ’1234′.
WRITE / CUSTOMER_ID.

ABAP Programs: Date and Time

REPORT ZSOURCE0405.

* Date fields are type d with the fixed length 8 and the internal
* representation YYYYMMDD (year, month, and day).
* The initial value of a date field is 00000000.

DATA TODAY TYPE D.

* The write command formats dates according to personal settings of
* the end user.

TODAY = SY-DATUM.
WRITE (10) TODAY.

* Using date fields to perform computations
DATA ULTIMO TYPE D.
* Set variable to first day of current month.
ULTIMO = SY-DATUM.
ULTIMO+6(2) = ’01′.
* Set variable to last day of previous month.
SUBTRACT 1 FROM ULTIMO.
WRITE / ULTIMO.

* Time fields are type t with the fixed length 6
* and the format HHMMSS (hours, minutes, and seconds)

DATA MY_TIME TYPE T.
WRITE /(8) MY_TIME.

ABAP Programs: Hexadecimal (or binary) data

REPORT CHAP0406.

* Hexadecimal (or binary) data is stored in fields of type x.
* A type x field of length n contains 2n digits
* and its output length is also equal to 2n.
* For example, the bit stream 1111000010001001 can be defined as
* follows (remind that 1111 = F, 0000 = 0, 1000 = 8, 1001 = 9):

DATA XSTRING(2) TYPE X VALUE ‘F089′.

———————

ABAP Programs: Records and internal tables

REPORT ZSOURCE0407.

* Records (or structures) consist of a fixed number of components
DATA: BEGIN OF CUSTOMER,
ID(8) TYPE N,
NAME(25),
TELEPHONE(12),
END OF CUSTOMER.

* Working with the different components and the structure itself
DATA VENDOR LIKE CUSTOMER.
CUSTOMER-ID = ’87654321′.
CUSTOMER-NAME = ‘Edison’.
CUSTOMER-TELEPHONE = ’111-111-1111′.
MOVE CUSTOMER TO VENDOR.
WRITE / VENDOR-NAME.

* Defining an internal table each entry having the structure of
* the record customer
DATA ALL_CUSTOMERS LIKE CUSTOMER OCCURS 100.

* Using a reference to a non-elementary type.
TYPES: BEGIN OF PERSONAL_DATA,
NAME(25),
CITY(25),
STREET(30),
END OF PERSONAL_DATA.
DATA PEOPLE TYPE PERSONAL_DATA OCCURS 300.

* Internal table with a header line, which is used as a default record
* to hold the record currently being added to the table
DATA NEW_CUSTOMERS LIKE CUSTOMER OCCURS 100
WITH HEADER LINE.

ABAP Programs: Complex Non-Elementary Types and Data Objects

REPORT ZSOURCE0408.

* Nested records
TYPES: BEGIN OF ADDRESS,
CITY(25),
STREET(30),
END OF ADDRESS,
BEGIN OF PERSON,
NAME(25),
ADDRESS TYPE ADDRESS,
END OF PERSON.
DATA RECEIVER TYPE PERSON.
RECEIVER-NAME = ‘Smith’.
RECEIVER-ADDRESS-CITY = ‘Big City’.
RECEIVER-ADDRESS-STREET = ‘Main street’.

* Nested internal tables
TYPES: BEGIN OF PHONE_FAX_NUMBERS,
COUNTRY_CODE(3) TYPE N,
AREA_CODE(3) TYPE N,
NUMBER(10) TYPE N,
END OF PHONE_FAX_NUMBERS,
BEGIN OF EMPLOYEE,
NAME(25),
PHONE TYPE PHONE_FAX_NUMBERS OCCURS 10,
FAX TYPE PHONE_FAX_NUMBERS OCCURS 5,
END OF EMPLOYEE.
DATA EMPLOYEES TYPE EMPLOYEE OCCURS 100.

ABAP Programs: Working with tables from the Dictionary

REPORT ZSOURCE0501.

* Declaration of a work area for a Dictionary table
TABLES CUSTOMERS.
* Reading all entries of the database table and displaying each entry
SELECT * FROM CUSTOMERS.
WRITE: / CUSTOMERS-NAME.
ENDSELECT.

ABAP Programs: Using system fields

REPORT ZSOURCE0409.

WRITE: / ‘Current date’, SY-DATUM,
/ ‘Current table index’, SY-TABIX,
/ ‘Loop counter’, SY-INDEX,
/ ‘System return code’, SY-SUBRC.

ABAP Programs: Copying fields

REPORT ZSOURCE0701.

* move fields
DATA: NAME(25),
COUNTER TYPE I.
DATA: SOURCE LIKE NAME,
TARGET LIKE SOURCE.
MOVE: ‘Edison’ TO NAME,
17 TO COUNTER.
MOVE SOURCE TO TARGET.

* Using the compute command (keyword can be omitted)
COMPUTE TARGET = SOURCE.
TARGET = SOURCE.

* Concatenating compute commands
DATA: PHONE_1 LIKE SOURCE,
PHONE_2 LIKE PHONE_1,
PHONE_3 LIKE PHONE_2,
PHONE_4 LIKE PHONE_3.
PHONE_4 = PHONE_3 = PHONE_2 = PHONE_1 = SOURCE.

ABAP Programs: Simple examples of field conversion

REPORT ZSOURCE0702.

* Converting to numbers during computations
DATA: NUMBER_1(4) VALUE ’1771′,
NUMBER_2(3),
RESULT TYPE I.

NUMBER_2 = ’005′.
RESULT = NUMBER_1 + NUMBER_2.
WRITE / RESULT.

NUMBER_2 = ‘ 5′.
RESULT = NUMBER_1 + NUMBER_2.
WRITE / RESULT.

* Padding character fields with blanks
DATA: OLD_CUSTOMER_NAME(10) VALUE ‘Edison’,
NEW_CUSTOMER_NAME(25).
MOVE OLD_CUSTOMER_NAME TO NEW_CUSTOMER_NAME.
WRITE / NEW_CUSTOMER_NAME.

* Calculating dates
DATA: ANY_DATE TYPE D,
SAME_DAY_OF_NEXT_WEEK TYPE D.

ANY_DATE = ’19991231′.
SAME_DAY_OF_NEXT_WEEK = ANY_DATE + 7.
WRITE / SAME_DAY_OF_NEXT_WEEK.

ANY_DATE = ’20000228′.
SAME_DAY_OF_NEXT_WEEK = ANY_DATE + 7.
WRITE / SAME_DAY_OF_NEXT_WEEK.

ABAP Programs: Converting character fields

REPORT ZSOURCE0703.

* Truncating fields or padding with blanks
DATA: SHORT_NAME(8),
LONG_NAME(16).
MOVE ‘Washington’ TO: SHORT_NAME, LONG_NAME.
WRITE: / SHORT_NAME, LONG_NAME.

* Take care of intermediate steps
LONG_NAME = SHORT_NAME = ‘Washington’.
WRITE: / SHORT_NAME, LONG_NAME.