HR ABAP Programming
HR ABAP Programming
What is ABAP/4?
Advanced Business Application Programming.ABAP is SAP's fourth generation language. All of
R/3's applications and even parts of its basic system are developed in ABAP. ABAP is used for
customization and modification of SAP applications.
HR ABAP
HR ABAP
1) Logical database
To use logical database PNP in your program, specify in your program attributes.
Standard Selection Screen
Date selection
Date selection delimits the time period for which data is evaluated. GET
PERNR retrieves all records of the relevant infotypes from the database.
When you enter a date selection period, the PROVIDE loop retrieves the
infotype records whose validity period overlaps with at least one day of this
period.
Person selection
Person selection is the 'true' selection of choosing a group of employees for
whom the report is to run.
Sorting Data
The standard sort sequence lists personnel numbers in ascending order.
SORT function allows you to sort the report data otherwise. All the sorting
fields are from infotype 0001.
Report Class
You can suppress input fields which are not used on the selection screen by
assigning a report class to your program.
If SAP standard delivered report classes do not satisfy your requirements,
you can create your own report class through the IMG.
Infotype structures (after GET PERNR) are internal tables loaded with data.
The infotype records (selected within the period) are processed sequentially
by the PROVIDE - ENDPROVIDE loop.
GET PERNR.
PROVIDE * FROM Pnnnn BETWEEN PN/BEGDA AND PN/ENDDA
If Pnnnn-XXXX = ' '. write:/ Pnnnn-XXXX. endif.
ENDPROVIDE.
Period-Related Data
All infotype records are time stamped.
IT0006 (Address infotype)
01/01/1990 12/31/9999 present
Which record to be read depends on the date selection period specified on the
selection screen. PN/BEGDA PN/ENDDA.
Current Data
IT0006 Address - 01/01/1990 12/31/9999
present
2) Process Infotypes
The RP-UPDATE macro updates the database. The parameters of this macro are the
OLD internal table containing the unchanged records and the NEW internal table
containing the changed records. You cannot create or delete data. Only modification
is possible.
INFOTYPES: Pnnnn NAME OLD,
Pnnnn NAME NEW.
GET PERNR.
PROVIDE * FROM OLD
WHERE .... = ... "Change old record
*Save old record in alternate table
NEW = OLD.
ENDPROVIDE.
RP-UPDATE OLD NEW. "Update changed record
Infotype with repeat structures
How to identify repeat structures.
4) Database Tables in HR
Personnel Administration (PA) - master and time data infotype tables (transparent
tables).
PAnnnn: e.g. PA0001 for infotype 0001
Personnel Development (PD) - Org Unit, Job, Position, etc. (transparent tables).
HRPnnnn: e.g. HRP1000 for infotype 1000
Time/Travel expense/Payroll/Applicant Tracking data/HR work areas/Documents
(cluster
PCLn: e.g. PCL2 for time/payroll results.
Cluster Table
Cluster tables combine the data from several tables with identical (or almost
identical) keys
into one physical record on the database.
. Data is written to a database in compressed form.
Retrieval of data is very fast if the primary key is known.
Cluster tables are defined in the data dictionary as transparent tables.
External programs can NOT interpret the data in a cluster table.
Special language elements EXPORT TO DATABASE, IMPORT TO DATABASE and
DELETE
FROM DATABASE are used to process data in the cluster tables.
PCL1
PCL2
PCL3
PCL4
INCLUDE RPPPXD10.
DATA: END OF COMMON PART 'BUFFER'.
...
RP-EXP-Cn-xy.
IF SY-SUBRC EQ 0.
PERFORM PREPARE_UPDATE USING 'V'..
ENDIF.
Importing Data (I)
The IMPORT command causes data objects with the specified key values to be read
from
PCLn.
If the import is successful, SY-SUBRC is 0; if not, it is 4.
REPORT RPIMPORT.
TABLES: PCLn.
INCLUDE RPCnxxy0. "Cluster definition
* Fill cluster Key
* Import record
IMPORT TABLE1 FROM DATABASE PCLn(xy) ID xy-KEY.
IF SY-SUBRC EQ 0.
* Display data object
ENDIF.
Importing data (II)
Import data using macro RP-IMP-Cn-xy.
Check return code SY-SUBRC. If 0, it is successful. If 4, error.
Need include buffer management routines RPPPXM00
REPORT RPIMPORT.
*Buffer definition
INCLUDE RPPPXD00.
DATA: BEGIN OF COMMON PART 'BUFFER'.
INCLUDE RPPPXD10.
DATA: END OF COMMON PART 'BUFFER'.
*import data to buffer
RP-IMP-Cn-xy.
....
*Buffer management routines
INCLUDE RPPPXM00.
Cluster Authorization
Simple EXPORT/IMPORT statement does not check for cluster authorization.
Use EXPORT/IMPORT via buffer, the buffer management routines check for cluster
authorization.
Payroll Results (I)
Payroll results are stored in cluster Rn of PCL2 as field string and internal tables.
n - country identifier.
Standard reports read the results from cluster Rn. Report RPCLSTRn lists all payroll
results;
report RPCEDTn0 lists the results on a payroll form.
Payroll Results (II)
The cluster definition of payroll results is stored in two INLCUDE reports:
include: rpc2rx09. "Definition Cluster Ru (I)
include: rpc2ruu0. "Definition Cluster Ru (II)
The first INCLUDE defines the country-independent part; The second INCLUDE
defines the country-specific part (US).
The cluster key is stored in the field string RX-KEY.
Payroll Results (III)
All the field string and internal tables stored in PCL2 are defined in the ABAP/4
dictionary. This
allows you to use the same structures in different definitions and nonetheless
maintain data
consistency.
The structures for cluster definition comply with the name convention PCnnn.
Unfortunately,
'nnn' can be any set of alphanumeric characters.
*Key definition
DATA: BEGIN OF RX-KEY.
INCLUDE STRUCTURE PC200.
DATA: END OF RX-KEY.
*Payroll directory
DATA: BEGIN OF RGDIR OCCURS 100.
INCLUDE STRUCTURE PC261.
DATA: END OF RGDIR.
Payroll Cluster Directory
To read payroll results, you need two keys: pernr and seqno
. You can get SEQNO by importing the cluster directory (CD) first.
REPORT ZHRIMPRT.
TABLES: PERNR, PCL1, PCL2.
INLCUDE: rpc2cd09. "definition cluster CD
PARAMETERS: PERSON LIKE PERNR-PERNR.
...
RP-INIT-BUFFER.
*Import cluster Directory
CD-KEY-PERNR = PERNR-PERNR.
RP-IMP-C2-CU.
CHECK SY-SUBRC = 0.
LOOP AT RGDIR.
RX-KEY-PERNR = PERSON.
UNPACK RGDIR-SEQNR TO RX-KEY-SEQNO.
*Import data from PCL2
RP-IMP-C2-RU.
KEYWORDS:
Keywords
, [, ], {, }
*, "
**
+, -, *, /
->, =>, ->>, ~, ?=
ABS
ACOS
ADD
ADD-CORRESPONDING
ADJACENT DUPLICATES
AND
ANY TABLE
APPEND
ASIN
ASSIGN
AT
ATAN
AUTHORITY-CHECK
AVG
BACK
BETWEEN
BINARY SEARCH
BIT-NOT
BIT-AND
BIT-OR
BIT-XOR
SET BIT
GET BIT
BLANK LINES
BREAK-POINT
C
CA
CALL
CASE
Description
Syntax conventions, Syntax notation
Comments
Arithm. Operator: Exponentiation (COMPUTE)
Arithmetical operators (COMPUTE)
Operators in ABAP Objects
Mathematical function: Absolute amount
COMPUTE)
Mathematical function: Cosine arc (COMPUTE)
Add
Field string addition
Delete duplicates from internal table (DELETE)
Comparison operator: and
Generic table type for internal tables
Append line to internaltable
Mathematical function: Sine arc (COMPUTE)
Assign field symbol
Event, control break, field group determination
Mathematical function: Tangent arc
Check authorization
Aggregate expression: Average (SELECT)
Positioning in list
Relational operator: Between
Binary read of internaltable (READ TABLE)
Bit calculation operator: NOT (COMPUTE)
Bit calculation operator: AND (COMPUTE)
Bit calculation operator: OR (COMPUTE)
Bit calculation operator: AND/OR (COMPUTE)
Set bit of an X field
Read bit of an X field
Switch on blank lines in list
Stop processing in debug mode
Data type for fixed-length character string
Contains any characters -Relational operator
forstring comparison
Call external component
Begin case distinction
CATCH
Exception handling (catch runtime errors)
CEIL
Mathematical function: Smallest whole value
CENTERED
Output format: Centered(WRITE)
CHECK
Check condition
CHECKBOX
Display as checkbox
PARAMETERS ... AS CHECKBOX
on the selection screen
WRITE ... AS CHECKBOX
in a list
CLASS
Definition of a class
CLASS-DATA
Static attributes in classes
CLASS-METHODS
Static methods in classes
CLASS-EVENTS
Static events in classes
CLASS-POOL
Introduction for type Kprograms
CLEAR
Initialize data object
CLIENT
Client handling when
DELETE ... CLIENT SPECIFIED
deleting from a database
EXPORT ... TO DATABASE ...
Storing a data cluster
CLIENT
IMPORT ... FROM DATABASE ...
Reading a data cluster
CLIENT
EXPORT ... TO SHARED BUFFER ...
Storing a data cluster
CLIENT
IMPORT ... FROM SHARED
Reading a data cluster
BUFFER ... CLIENT
INSERT ... CLIENT SPECIFIED
inserting into a database
MODIFY ... CLIENT SPECIFIED
Insert/Modify in database(s)
SELECT ... CLIENT SPECIFIED
reading from a database
UPDATE ... CLIENT SPECIFIED
updating a database
CLOSE
Close file/cursor
Contains Not Only - Relational operator for
CN
character comparison:
CNT
Field groups: Number ofdifferent values
Contains Only - Relational operator for character
CO
comparison:
CODE PAGE
Character set
TRANSLATE ... FROM/TOCODE
Translate character codes
PAGE
COLLECT
Internal table: Add entries
COLOR
Output format: Color (FORMAT)
COMMENT
Comment on selection screen
SELECTION-SCREEN COMMENT
Generate comment
COMMIT
Close processing unit
COMMUNICATION
Data exchange
COMPUTE
Perform calculations
CONCATENATE
Concatenate character fields
CONDENSE
Condense character fields
CONSTANTS
Defing constants
CONTEXTS
Communicate contexts
CONTINUE
Exit current loop pass
CONTROLS
Define controls for visualization
CONVERT
Convert fields
COS
Mathematical function: Cosine (COMPUTE)
COSH
COUNT
COUNTRY
CP
DATABASE
CREATE
CS
CURRENCY
CURSOR
CLOSE
FETCH NEXT CURSOR
GET CURSOR FIELD
OPEN CURSOR
SET CURSOR
CUSTOMER-FUNCTION
DATA
DATABASE
DELETE FROM DATABASE
EXPORT ... TO DATABASE
IMPORT ... FROM DATABASE
DATASET
CLOSE DATASET
DELETE DATASET
EXPORT ... TO DATASET
IMPORT ... FROM DATASET
OPEN DATASET Open file
READ DATASET
TRANSFER
DECIMALS
DEFINE
DELETE
DEMAND
DESCRIBE
DIALOG
DISTINCT
SELECT DISTINCT
AVG( DISTINCT ... )
COUNT( DISTINCT ... )
MAX( DISTINCT ... )
MIN( DISTINCT ... )
SUM( DISTINCT ... )
DIV
DIVIDE
DIVIDE-CORRESPONDINGField
string division
DO
DYNPRO
Screen
Delete
Export
Generate
Import
Check
Call editor
Query
Query
End of a macro definition
Event: End of page handling in lists
Event: After processingof all records in a LDB
End of an event introduced by AT
End of case distinction
End of exception handling
End of a DO loop
End of a Native SQL statement
End of a subroutine
End of a function module
End of a query
End of an interface definition
End of a LOOP
End of a module definition
End of a conditional statement
End of a PROVIDE loop
End of a SELECT loop
End of a WHILE loop
Relational operator: Equals
Native SQL statement
Exit loop or terminate processing
Mathematical function: Exponential function
Output format: Exponentdisplay (WRITE)
Export data
Switch extended syntax check on/off (SET)
Generate extract dataset
Read line from a database table
Define field groups
Define field symbols
Mathematical function:Largest whole value
Define subroutine
Output format for lists
Read database table with lock (SELECT)
Mathematical function: Fraction (COMPUTE)
Release resources no longer needed
Define function module
Call function module
Introduction for type Fprograms
Relational operator: Greater than or equal
Generate a program or screen
Event, read settings
GT
HASHED TABLE
HEADER LINE
HELP-ID
DESCRIBE FIELD ... HELP-ID
HELP-REQUEST
PARAMETERS ... HELP-REQUEST
SELECT-OPTIONS ... HELPREQUEST
HIDE
HOTSPOT
ICON
IF
IMPORT
IN
INCLUDE
INDEX
INDEX TABLE
DELETE ... INDEX
INSERT ... INDEX
MODIFY ... INDEX
READ TABLE ... INDEX
INFOTYPES
INITIAL
INITIAL SIZE
INITIALIZATION
INPUT
INSERT
INTENSIFIED
INTERFACE
INTERFACES
INTERFACE-POOL
INVERSE
IS
IS ASSIGNED
IS INITIAL
IS REQUESTED
parameter
JOIN
LANGUAGE
LE
LEAVE
LEFT-JUSTIFIED
LIKE
TYPES ... LIKE
DATA ... LIKE
LINE
MODIFY LINE
READ LINE
LINE-COUNT
LINE-SIZE
LIST-PROCESSING
LOAD
LOAD-OF-PROGRAM
LOCAL
LOCAL COPY
LOCALE
SET LOCALE
GET LOCALE
LOG
Logical condition
SELECT ... WHERE
UPDATE ... WHERE
DELETE ... WHERE
SELECT ... FROM ... ON
NO-HEADING
NO-SCROLLING
NO-SIGN
NO-TITLE
NO-ZERO
NON-UNIQUE
TYPES
DATA
NP
NS
O
OBJECT
CREATE OBJECT
FREE OBJECT
OCCURS
TYPES
DATA
ON CHANGE
OPEN
OR
ORDER BY
OVERLAY
PACK
PARAMETER
GET
SET
PARAMETERS
PERFORM
PF-STATUS
POSITION
PRINT
PRINT-CONTROL
PRIVATE
PROGRAM
LEAVE PROGRAM
PROPERTY
GET PROPERTY
SET PROPERTY
PROVIDE
PUT
RADIOBUTTON
RAISE
RAISING
RANGES
READ
RECEIVE
REFRESH
REFRESH CONTROL
REJECT
REPLACE
REPORT
DELETE REPORT
EDITOR-CALL FOR REPORT
INSERT REPORT
READ REPORT
RESERVE
RESET
RIGHT-JUSTIFIED
ROLLBACK
ROUND
RTTI
RUN TIME ANALYZER
SCAN
SCREEN
CALL SCREEN
SET SCREEN
LEAVE SCREEN
LEAVE TO SCREEN
LOOP AT SCREEN
MODIFY SCREEN
SCROLL
SCROLL-BOUNDARY
SEARCH
SELECT
SELECT-OPTIONS
SELECTION-SCREEN
AT SELECTION-SCREENEvent:
SHARED BUFFER
DELETE FROM SHARED BUFFER
EXPORT ... TO SHARED BUFFER
IMPORT ... FROM SHARED BUFFER
SELECTION-TABLE
SET
SHIFT
SIGN
SIN
SINGLE
SINH
SKIP
SORT
SORTED TABLE
SPLIT
SQRT
STANDARD TABLE
START-OF-SELECTION
STATICS
Initialize control
Do not process current database line further
Replace characters
Introduction for type 1programs
Delete program
Call ABAP program editor
Insert program in library
Read program
List processing: Conditional new page
Output format: Reset all formats (FORMAT)
Output format: Right justified (WRITE)
Roll back database changes
Output format: Scaled (WRITE)
Runtime type identification
Activate/Deactivate runtime analysis (SET)
Analyze ABAP/4 source code
Screen
Call screen
Set next screen
Leave screen
Branch to a screen
Loop through screen fields
Modify screen fields
List processing: Scroll
List processing: Fix lead columns (SET)
Find character
Read database table
Define selection criterion
Design selection screen
After editing ofselection screen
Cross-transaction application buffer
delete from application buffer
Store data in application buffer
Read data from application buffer
Selection table (SUBMIT)
Set different processing parameters
Move character
Mathematical function: Sign (COMPUTE)
Mathematical function: Sine (COMPUTE)
Select single record (SELECT)
Mathematical function: Hyperbola sine
(COMPUTE)
List processing: Outputblank line
Sort internal table or extract dataset
Table type for internaltables that are always kept
Split character fields
Mathematical function: Square root (COMPUTE)
Table type for standardinternal tables
Event: Before first access to LDB
Define static data
STOP
STRING
STRLEN
STRUCTURE
INCLUDE STRUCTURE
SUBMIT
SUBTRACT
SUBTRACT-CORRESPONDING
SUM
SELECT ... SUM
SUPPLY
SUPPRESS DIALOG
SYMBOL
SYNTAX-CHECK
SYNTAX-TRACE
SYSTEM-CALL
SYSTEM-EXCEPTIONS
TABLE LINE
TABLE_LINE
TABLES
TABLE
DELETE ... FROM TABLE
INSERT ... FROM TABLE
MODIFY ... FROM TABLE
UPDATE ... FROM TABLE
SELECT ... INTO TABLE
TAN
TANH
TEXT
CONVERT TEXT
SORT itab AS TEXT
SORT AS TEXT
TEXTPOOL
DELETE TEXTPOOL
INSERT TEXTPOOL
READ TEXTPOOL
TIME
GET RUN TIME
GET TIME
SET RUN TIME ANALYZER
TIME STAMP
GET TIME STAMP
CONVERT TIME STAMP
WRITE f TIME ZONE
TITLEBAR
TOP-OF-PAGE
TRANSACTION
CALL TRANSACTION
LEAVE TO TRANSACTION
TRANSFER
TRANSLATE
TRANSPORTING
MODIFY ... TRANSPORTING
READ ... TRANSPORTING
LOOP ... TRANSPORTING
TRUNC
TYPE
TYPES ... TYPE
DATA ... TYPE
TYPE-POOL
TYPE-POOLS
TYPES
ULINE
UNDER
UNIQUE
TYPES
DATA
UNIT
UNPACK
UPDATE
USER-COMMAND
USING
USING
USING EDIT MASK
VALUE-REQUEST
PARAMETERS ... VALUE-REQUEST
SELECT-OPTIONS ... VALUEREQUEST
WHEN
SELECT ... WHERE
UPDATE ... WHERE
DELETE ... WHERE
LOOP AT ... WHERE
DELETE ... WHERE
WHILE
WINDOW
WITH-TITLE
WORK
COMMIT WORK
ROLLBACK WORK
WRITE
WRITE TO
X
XSTRING
Z
Output to file
Character conversion incharacter fields
Selective field transport
Modify lines of an internal table
Read lines of an internal table
Loop through an internal table
Mathematical function: Whole number part
(COMPUTE)
Define a type
Define a type
Define a field
Introduction for type Tprograms
Include type group
Define types
List processing: Underscore
Output format: One under the other (WRITE)
Define an
internal table type
internal table object
Output format: Unit (WRITE)
Conversion
Update database table
List processing: Execute command immediately
(SET)
Use parameter or format
Parameter of a subroutine
Output format: Use template (WRITE)
Self-programmed value help(F4)
for parameters
for selection options
Case distinction
when reading from databasetables
when changing database tables
when deleting database tables
when looping at internal tables
when deleting from internal tables
Loop
List processing: Outputin window
Output standard page header (NEW-PAGE)
Processing unit
Close unit
Close unit, but undo changes
List processing: Output
Correct type output in a variable
Data type for fixed-length byte sequence
Data type for variable-length byte sequence
Relational bit operator: Bit positions occupiedby
INDEX
LANGU
LDBPG
LILLI
LINCT
LINNO
LINSZ
LISEL
LISTI
LOCDB
LOCOP
LOOPC
LSIND
LSTAT
MACDB
MACOL
MANDT
MARKY
MAROW
MODNO
MSGID
MSGLI
MSGNO
MSGTY
MSGV1
MSGV2
MSGV3
MSGV4
OPSYS
PAART
PAGCT
PAGNO
PDEST
PEXPI
PFKEY
PLIST
PRABT
PRBIG
PRCOP
PRDSN
PREFX
PRIMM
PRNEW
PRREC
PRREL
PRTXT
REPID
RTITL
SAPRL
SCOLS
SLSET
SPONO
SPONR
SROWS
STACO
STARO
STEPL
SUBRC
SUBTY
SYSID
TABIX
TCODE
TFDSN
TFILL
TIMLO
TIMUT
TITLE
TLENG
TMAXL
TNAME
TOCCU
TPAGI
TSTLO
TSTUT
TTABC
TTABI
TVAR0
TVAR1
EXAMPLES:
System fields I
Program code
REPORT ZBCTCB93 NO STANDARD PAGE HEADING.
DETAIL.
WRITE: /5 'Logon name of the user:
WRITE: /5 'Logon client:
WRITE: /5 'Logon language:
System fields II
Program code
REPORT ZBCTCB92.
TABLES: T000.
DATA: BEGIN OF T OCCURS 0,
FIELD(10),
END OF T.
DATA: NUM TYPE N.
DETAIL.
* sy-linct and sy-linsz describes a page of the list
WRITE: / 'Example of sy-linct and sy-linsz'.
SKIP.
WRITE: / SY-LINCT, 'line and', (3) SY-LINSZ, 'column is a page'.
* sy-index works in do-enddo and while-endwhile loops.
* it contains the number of loop passes.
WRITE: /'Example of sy-index'.
SKIP.
DO 5 TIMES.
WRITE: SY-INDEX.
ENDDO.
* sy-tabix is the index number of the currently processed row
Program code
REPORT ZBCTCB90 NO STANDARD PAGE HEADING
LINE-COUNT 20 LINE-SIZE 255.
TABLES: T000.
DETAIL.
DO 5 TIMES.
SELECT * FROM T000.
WRITE: / T000-MANDT, T000-MTEXT.
ENDSELECT.
NEW-PAGE.
ENDDO.
TOP-OF-PAGE.
WRITE: / 'Page', SY-PAGNO.
AT LINE-SELECTION.
DETAIL.
* SY-LSIND is the index of the current list
WRITE: / 'SY-LSIND:', SY-LSIND LEFT-JUSTIFIED.
* SY-LISTI is the index of the previous list
WRITE: / 'SY-LISTI:', SY-LISTI LEFT-JUSTIFIED.
* SY-LILLI is the number of the selected line in the absolute list
WRITE: / 'SY-LILLI:', SY-LILLI LEFT-JUSTIFIED.
* SY-CUROW is the position of the selected line on the screen
WRITE: / 'SY-CUROW:', SY-CUROW LEFT-JUSTIFIED.
* SY-CUCOL is the position of the cursor in the window
WRITE: / 'SY-CUCOL:', SY-CUCOL LEFT-JUSTIFIED.
SKIP.
WRITE: / 'SY-CPAGE and SY-STAR0 do not depend on the cursor
position'.
SKIP.
* SY-CPAGE is the currently displayed page of the list
WRITE: / 'SY-CPAGE:', SY-CPAGE LEFT-JUSTIFIED.
* SY-STARO is the number of the topmost actual list line displayed
* on the current page.
WRITE: / 'SY-STARO:', SY-STARO LEFT-JUSTIFIED.
SKIP.
* SY-STACO is the number of the first displayed column on the
* screen. Scroll the list right with the scrollbar to test it
WRITE: / 'SY-STACO:', SY-STACO LEFT-JUSTIFIED.
SKIP.
* contents of the selected line
WRITE: / 'SY-LISEL:', SY-LISEL.
System fields V
Program code
System fields IV
Program code
REPORT ZBCTCB99 NO STANDARD PAGE HEADING.
PARAMETERS: TEST.
DETAIL.
IF SY-BATCH EQ SPACE.
WRITE: / 'Report was started on-line'.
WRITE: / 'Using variant:', SY-SLSET.
ELSE.
WRITE: / 'Report was started in background'.
ENDIF.
System fields VI
SY-DATAR
In transaction programming this field indicates the change of data on the
screen. In the PBO part you may set default values of the input fields of
the dynpro. In the PAI part you can check if they were changed. If SYDATAR is set, then the user has modified or entered new data on the
screen.
SY-BINPT
This field indicates if the transaction was called in a Batch Input session or
by an online user.To test it, a batch input session must be created. From
Release 3.1g the next procedure can be used.
Create a report which displays this system field
Create a Transaction code for this report
Use transaction SHDB to record a the previous transaction
Press the Overview button and choose the 'generate
program' function.
Running the previously generated program it will create a
Batch Input session
Now call transaction SM35 and process the created Batch
Input in foreground. It should display an 'X' for system
field SY-BINPT.
SY-CALLD
This field indicates if the transaction was called from another transaction.
Create a report which displays this system field
Create a Transaction code for this report
Create a new report containing the next ABAP command:
CALL TRANSACTION tcode. Where tcode is the
Transaction code you created. When you run this report, it
should display an 'X' for system field SY-CALLD.
SY-MSGV1
CLEAR G_BDCDATA.
G_BDCDATA-PROGRAM = P_PROGRAM.
G_BDCDATA-DYNPRO = P_DYNPRO.
G_BDCDATA-DYNBEGIN = 'X'.
APPEND G_BDCDATA.
ENDFORM.
" BDC_DYNPRO
*---------------------------------------------------------------------*
*
FORM BDC_FIELD
*
*---------------------------------------------------------------------*
*
Batchinput: Feld hinzufugen
*
*---------------------------------------------------------------------*
FORM BDC_FIELD USING P_FNAM P_FVAL.
CLEAR G_BDCDATA.
G_BDCDATA-FNAM = P_FNAM.
G_BDCDATA-FVAL = P_FVAL.
APPEND G_BDCDATA.
ENDFORM.
" BDC_FIELD
*---------------------------------------------------------------------*
*
FORM REPLACE_PARAMETERS
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> P_PAR_1
*
* --> P_PAR_2
*
* --> P_PAR_3
*
* --> P_PAR_4
*
* --> P_MESSAGE
*
*---------------------------------------------------------------------*
FORM REPLACE_PARAMETERS USING P_PAR_1
P_PAR_2
P_PAR_3
P_PAR_4
CHANGING P_MESSAGE.
* erst mal pruefen, ob numerierte Parameter verwendet wurden
DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
* falls keine numerierten Parameter vorh., ersetzen wie gehabt
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
"replace_parameters
SAMPLE REPORTS:
Interactive Reporting
SQL Syntax
SQL programming
ABAP
2) Q.Write a program that lists the Vendors and their Accounting documents.
Create extract dataset from KDF logical database. Loop through the dataset to create
the required report. Don't list those vendors which has no documents.
Creating Extract Dataset
Your code should be like this.
report zfwr0001 no standard page heading.
tables: lfa1, bsik.
field-groups: header, item1, item2.
insert lfa1-lifnr bsik-belnr into header.
insert lfa1-land1 lfa1-name1 into item1.
do.
read dataset test into unix_intab.
if sy-subrc ne 0.
exit.
else.
append unix_intab.
endif.
enddo.
close dataset test.
***to process the data. load the database table
loop at unix_intab.
z_mver-mandt = sy-mandt.
z_mver-matnr = unix_intab-field(10).
translate z_mver-matnr to upper case.
z_mver-werks = unix_intab-field+10(4).
translate z_mver-werks to upper case.
z_mver-gjahr = sy-datum(4).
z_mver-perkz = 'M'.
z_mver-mgv01 = unix_intab-field+14(13).
z_mver-mgv02 = unix_intab-field+27(13).
z_mver-mgv03 = unix_intab-field+40(13).
* to check the data on the screen (this is just for checking
purpose)
write: / z_mver-mandt, z_mver-matnr, z_mver-werks, z_mvergjahr,
z_mver-perkz, z_mver-mgv01,
z_mver-mgv02, z_mver-mgv03.
insert z_mver client specified.
*if the data already had been in table z_mver then sy-subrc
will not be
*equal with zero. (this can be *interesting for you - (this list is
*not necessary but it maybe useful for you)
if sy-subrc ne 0.
write:/ z_mver-matnr, z_mver-werks.
endif.
endloop.
NOTES:
1. This solution is recommended only if the database table is
NOT a standard SAP database table .
2. In the above mentioned unix file record's size is 53 bytes.
Every record in the unix file as the same size:
10 bytes for material
04 bytes for plant
13 bytes for corrected consumption for January
13 bytes for corrected consumption for February
13 bytes for corrected consumption for March
3. Table Z_MVER
This table was created to store the consumption values for first quarter of the
year.
Fields
Data Element
mandt
mandt
matnr
matnr
werks
werks
gjahr
gjahr
perkz
perkz
mgv01
mgvbr
mgv02
mgvbr
mgv03
mgvbr
4) Q. List the first 100 purchase requsitions at the plant 'PL01' (table EBAN). Then
make it possible to change the purchase requisition itself from the list by clicking
twice on the row or by using a push-button.
Interactive Reporting
In the purchasing (MM modul) you can process the purchase requisitions. The
purchase requisitions define primarily the need for a material/service. List the first
100 purchase requsitions at the plant 'PL01' (table EBAN). Then make it possible to
change the purchase requisition itself from the list by clicking twice on the row or by
using a push-button.
ADDITIONAL REQUIREMENTS TO THE LIST:
1. CONTENT: PURCHASE REQUISITION NUMBER, ITEM NUMBER, DOCUMENT TYPE,
MATERIAL, QUANTITY, UNIT OF MEASURE
pur_req-banfn = eban-banfn.
pur_req-matnr = eban-matnr.
pur_req-werks = eban-werks.
pur_req-ekgrp = eban-ekgrp.
pur_req-bnfpo = eban-bnfpo.
pur_req-bsart = eban-bsart.
pur_req-menge = eban-menge.
pur_req-meins = eban-meins.
pur_req-estkz = eban-estkz.
append pur_req.
pur_req-numb = pur_req-numb + 1.
endselect.
* CHECK WHETHER THE TABLE EBAN CONTAINS ANY PURCHASE
REQUISITIONS
if sy-subrc ne 0.
write: / 'No Purchase Requisition found.'.
endif.
* PROCESS THE INTERNAL TABLE; WRITE OUT THE
REQUIRED FIELDS AND HIDE THE
*FIELDS YOU ARE GOING TO USE LATER
loop at pur_req.
write: /1 pur_req-numb, 9 pur_req-banfn, 21 pur_reqbnfpo, 31 pur_req-bsart, 41 pur_req-matnr,
61 pur_req-menge unit pur_req-meins, 82 pur_reqmeins.
hide: pur_req-matnr, pur_req-werks, pur_req-banfn.
endloop.
clear pur_req-banfn. clear pur_req-matnr. clear pur_reqwerks.
* IN THE MENU PAINTER (SE41) CREATE A STATUS TO
YOUR PROGRAM. HERE YOU CAN
*DEFINE THE PUSH-BUTTON
set pf-status 'basic'.
* CHOOSE A REQUISITION (WITH DOUBLE CLICKING
OR PUSH-BUTTON) IN THE LIST! THE
*PURCHASE REQUISITION IS GOING TO COME UP
at line-selection.
if pur_req-banfn <> space.
set parameter id 'BAN' field pur_req-banfn. "
parameter id for pruchase req. number
call transaction 'ME52' and skip first screen. "trans.
code 'ME52': Change Purchase Requis.
clear pur_req-banfn. clear pur_req-matnr.
clear pur_req-werks.
endif.
* FORM THE HEADER
form header_write.
write: / prog_nam, 32 'FUN-FACTORY',
/ 'Purch.Gr.:', pur_req-ekgrp, 26 'Purchase
Requisition List',
61 'As Of Date:', 75 sy-datum,
/ 'Plant:', pur_req-werks, 61 'Page:', 75 sypagno.
uline.
write: / text-001,
/ text-002.
uline.
endform.
NOTES:
1. PUSH-BUTTON DEFINITION (SE11)
In the Menu Painter a status must be created where you can maintain
the function keys
001
Numb.__Requisition__Item___Document_____Material_________________Q
uantity_Unit_of
002 _________Number_____Num______Type____________Measure
THE FIRST 15 LINE ITEMS OF THE RESULT AND THE HEADERS:
ZMJUD001
FUN-FACTORY
Purch. Gr.: 001 Purchase Requisition List
As Of Date: 05/09/1997
Plant: D031
Page: 1
------------------------------------------------------------------------Numb. Requisition Item Document Material
Quantity Unit of
Number
Num
Type
Measure
------------------------------------------------------------------------1
10049227
00010 NB
11141-030
23.000 CS
2
10049223
00010 NB
11141-030
23.000 CS
3
10049225
00010 NB
11141-030
13.000 CS
4
10049226
00010 NB
11141-030
9.000 CS
5
10049224
00010 NB
11141-030
23.000 CS
6
10049222
00010 NB
11141-030
23.000 CS
7
10049221
00010 NB
11141-030
38.000 CS
8
10049228
00010 NB
11141-030
23.000 CS
9
10049229
00010 NB
11141-030
23.000 CS
10
10049230
00010 NB
11141-030
22.000 CS
11
10049231
00010 NB
11141-030
24.000 CS
12
10049232
00010 NB
11141-030
24.000 CS
13
10049233
00010 NB
11141-030
24.000 CS
14
10049234
00010 NB
11141-030
23.000 CS
15
10049235
00010 NB
11141-030
5.000 CS
Basic form:
SELECT result FROM source [INTO target] [WHERE condition] [GROUP BY fields]
[ORDER BY order].
SELECT clause
Variants:
1. SELECT [SINGLE [FOR UPDATE] DISTINCT] *
2. SELECT [SINGLE [FOR UPDATE] DISTINCT] s1 ... sn
3. SELECT [SINGLE [FOR UPDATE] DISTINCT] (itab)
FROM clause
Variants:
1. ... FROM dbtab
Additions:
1. ... CLIENT SPECIFIED
2. ... BYPASSING BUFFER
3. ... UP TO n ROWS
2. ... FROM (dbtabname)
Additions:
1. ... CLIENT SPECIFIED
2. ... BYPASSING BUFFER
3. ... UP TO n ROWS
INTO target
(This form of the FROM clause works only in conjunction with the INTO
clause.)
INTO clause
Variants:
1. ... INTO wa
2. ... INTO CORRESPONDING FIELDS OF wa
3. ... INTO (f1, ..., fn)
4. ... INTO TABLE itab
5. ... INTO CORRESPONDING FIELDS OF TABLE itab
6. ... APPENDING TABLE itab
7. ... APPENDING CORRESPONDING FIELDS OF TABLE itab
WHERE clause
Variants:
1. ... WHERE f op g
2. ... WHERE f [NOT] BETWEEN g1 AND g2
3. ... WHERE f [NOT] LIKE g
4. ... WHERE f [NOT] IN (g1, ..., gn)
5. ... WHERE f [NOT] IN itab
6. ... WHERE f IS [NOT] NULL
7. ... WHERE NOT cond
8. ... WHERE cond1 AND cond2
9. ... WHERE cond1 OR cond2
10. ... WHERE (itab)
11. ... WHERE cond AND (itab)
12. ... FOR ALL ENTRIES IN itab WHERE cond
Operator
EQ or =
NE or < >
LT or <
LE or < =
GT or >
GE or >=
Meaning
equal to
not
equal to
less than
less than
or equal
to
greater
than
greater
than or
equal to
GROUP-BY clause
Variants:
1. ... GROUP BY f1 ... fn
2. ... GROUP BY (itab)
ORDER-BY clause
Variants:
1. ... ORDER BY PRIMARY KEY
2. ... ORDER BY f1 ... fn
3. ... ORDER BY (itab)
6) Q. Select those MM tables which are language dependant (For example you
want to translate the customizing in two languages)
Language dependent MM tables
report zbctcb96.
tables: dd03l, tadir.
data: counter type i value 1.
select * from tadir where pgmid eq 'R3TR' and
o
o
( fieldname like 'SPRA%' or fieldname like 'LANG%' ).
write: / counter, dd03l-tabname, dd03l-fieldname.
add 1 to counter.
exit.
endselect.
endselect.
The TADIR contains the development objects.
All the 'table' objects are selected which are in an MM development class
(MM development classes begin with 'M').
The DD03L table contains the fields of the database tables.
Just those tables are selected, which has a field beginning with either 'SPRA'
or 'LANG'.
( 'language' is 'Sprache' in german).
Performance considerations in this example:
How frequently runs the report?
This report was used only once . I have tried to run it in dialog and
finished without 'time out error'.
Performance optimization is not necessary.
Is DD03L and TADIR buffered and how many records are in the tables?
Table
Buffering
DDL03L
No Buffering
TADIR
Buffering Single
92,000 - 370,000
Records
The primary key fields are always indexed. Other fields are indexed
through additional index files.
From the Table Display, /Goto/Indexes.
7) Q. Choose a transaction and write a Batch Input program with 'Call Transaction'.
Do not use the Messagetab feature of 'Call Transaction'. In this case the last error
message will be at the SY-MSG* system fields. Recreate the complete error message
from table T100!
BDC program using Call Trasaction
SY-MSGV1
/ 'System variables:'.
/
/
/
/
/
/
/
'
'
'
'
'
'
'
Sy-msgty:', SY-MSGTY.
Sy-msgid:', SY-MSGID.
Sy-msgno:', SY-MSGNO.
Sy-msgv1:', SY-MSGV1.
Sy-msgv2:', SY-MSGV2.
Sy-msgv3:', SY-MSGV3.
Sy-msgv4:', SY-MSGV4.
*---------------------------------------------------------------------*
*
Build up the BDC-table
*
*---------------------------------------------------------------------*
FORM FILL_BDCDATA.
REFRESH G_BDCDATA.
PERFORM BDC_DYNPRO USING 'SAPMF02B' '0100'.
PERFORM BDC_FIELD USING 'BNKA-BANKS' 'ZZZ'.
PERFORM BDC_FIELD USING 'BDC_OKCODE' 'QQQQQ'.
ENDFORM.
*---------------------------------------------------------------------*
*
FORM BDC_DYNPRO
*
*---------------------------------------------------------------------*
*
Batchinput: Start new Dynpro
*
*---------------------------------------------------------------------*
FORM BDC_DYNPRO USING P_PROGRAM P_DYNPRO.
CLEAR G_BDCDATA.
G_BDCDATA-PROGRAM = P_PROGRAM.
G_BDCDATA-DYNPRO = P_DYNPRO.
G_BDCDATA-DYNBEGIN = 'X'.
APPEND G_BDCDATA.
ENDFORM.
" BDC_DYNPRO
*---------------------------------------------------------------------*
*
FORM BDC_FIELD
*
*---------------------------------------------------------------------*
*
Batchinput: Feld hinzufugen
*
*---------------------------------------------------------------------*
FORM BDC_FIELD USING P_FNAM P_FVAL.
CLEAR G_BDCDATA.
G_BDCDATA-FNAM = P_FNAM.
G_BDCDATA-FVAL = P_FVAL.
APPEND G_BDCDATA.
ENDFORM.
" BDC_FIELD
*---------------------------------------------------------------------*
*
FORM REPLACE_PARAMETERS
*
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> P_PAR_1
*
* --> P_PAR_2
*
* --> P_PAR_3
*
* --> P_PAR_4
*
* --> P_MESSAGE
*
*---------------------------------------------------------------------*
FORM REPLACE_PARAMETERS USING P_PAR_1
P_PAR_2
P_PAR_3
P_PAR_4
CHANGING P_MESSAGE.
* erst mal pruefen, ob numerierte Parameter verwendet wurden
DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
* falls keine numerierten Parameter vorh., ersetzen wie gehabt
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
"replace_parameters