You are on page 1of 21

Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.

htm

ABAP/4 Code - Last update Monday, November 15, 2010


Description
ABAP/4 Keywords

System Fields

275 Edit a table : run SE16N and type in the command box : &sap_edit
How to enforce an index on a table when doing a select ?
274
%_hints ORACLE 'INDEX("VBAP" "VBAP~Z06")' : this will read table VBAP with index Z06
273 How to transport variants ? -> run program RSTRANSP
If you need to read a text (READ_TEXT) but you don't know exactly the language, normally
you'll have to loop. But with the following
272
function you can read the text in several languages at one time :
SSFRT_READ_INCLUDE_TEXT
Translate a transaction code :
SE63 -> transport object
271
R3TR TRAN <transaction code>
Conversion Unit of Measure :
suppose unit of measure in NL = ST
when you logon in FR -> ST=> PC

270 call function CONVERSION_EXIT_CUNIT_OUTPUT


INPUT = ST
LANGUAGE = FR

-> OUTPUT = PC
Search for a data element ?
for example : 4 length & 2 decimals
269
se16 table DD04L -> field LEN = 4, field DECIMALS = 2 -> complete list of all data elements
(you need the field ROLLNAME)
Convert language to ISO-language:
268
CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT'
Run a program after a transport :
267
R3TR XPRA program name
266 character ß in a smartform : copy/paste from Word
265 Dynamic columns for Business Workplace (Workflow/Inbox) : SWL1
264 ABAP and Excel Transformations (XML) : transaction XSLT_TOOL
Function ALV BLOCK LIST (several layouts)
263 report BALVBT01
Transaction FBL3N for example of LIST_DISPLAY with groups

1 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

/nPFAL : HR : ALE distribution of HR Master Data

262 report :
RHALECPS : display ALE change pointers for HR Master Data
RHALESMD : Evaluate ALE change pointers for HR Master Data
261 Set the status of an IDOC
260 Do a Mass Update : transaction MASS
Translate WorkItem description :
Via transaction SE63 : R3TR PDTS 90100124 (= number of task)
259
Translate WorkItem text :
Logon in the language you want to tranlate, and change the WorkItem text
When changing requirements, pricing procedures... with transaction VOFM, always add to your
258 transport request the following entry :
R3TR XPRA RV80HGEN : this regenerates the procedures
257 update IDOC status : RC1_IDOC_SET_STATUS (as from release 6.0)
256 Mass maintenance material master - MM17
255 Reset/Refresh ALV buffer : Run program BALVBUFDEL
254 MS Word as editor for smartforms : I18N
253 view all conditions for output control => transaction NACE
translate all messages from a message class

SE63
252 choose : Transport object

fill in :
R3TR MSAG ZBM0_SD_A640
251 Program to process inbound IDOC's : RBDAPP01
Enhancements & user-exits

table MODSAP
250
Vb. user exit : EXIT_SAPLV50E_004

-> modsap-member = EXIT_SAPLV50E_004 ->name = V50EPROP (= enhancement)


249 Table with developper keys : DEVACCESS
248 Parameter-ID's : Table = TPARA
247 Scan ABAP programs : RPR_ABAP_SOURCE_SCAN
Conditions in a Sales Order
SELECT SINGLE knumv INTO l_knumv
FROM vbak
246 WHERE vbeln = g_docnum.

SELECT kposn kschl stunr zaehk INTO CORRESPONDING FIELDS OF TABLE lit_konv

2 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

FROM konv
WHERE knumv = l_knumv.
245 generate ALE interface for BAPI : transaction BDBG
244 inbound processing of IDOCs ready for transfer (status 64) : program RBDAPP01
Show icons :

DATA : ICON TYPE CHAR4.


243
icon = '@0A@'. "icon red light.
icon = '@09@'. "icon yellow light
icon = '@08@'. "icon green light
242 Show for all fields -> fieldgroups -> screens,... : transaction OMSR
241 How to transport sapscripts ? Program : RSTXR3TR
240 Program to find all user exits for a transaction code.
239 IDOC user exits
238 ALV popup to select
237 Work with Classes
236 Defining a BADI (Business Add-In)
Work with BADI's :
235 SE18 = SMOD
SE19 = CMOD
234 Convert an XML message to an internal table
How to use push buttons in a subscreen ?
233 You don't have the OK-code, and it is a user-exit.
Add the program, code to tables T185 and T185V
Change Move-in date for a contract ? (SAP-ISU)
232
Transaction EC51E
table : DFKKLOCKS
FI-CA: Bedrijfseconomische blokkeringen
231
call function ' FKK_S_LOCK_CREATE_RFC'
-> om locks te zetten op de tabel FKKVKP
Get Workitem from the Business Workplace (Workflow)

call function 'RH_INBOX_VIEW_CREATE'


exporting
search_date = sy-datum
inbox_user = sy-uname
tables
230 wi_head = wi_head
exceptions
no_active_plvar = 1
no_tasks_found = 2
user_not_defined = 3
no_workitem_found = 4
others = 5.

3 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

Get the root from a Workitem (Workflow)


call function 'SWI_GET_ROOT_WORKITEM'
exporting
wi_id = gs_wi-wi_id
229 importing
root_item = root_item
exceptions
workitem_does_not_exist = 1
others = 2.
228 Drildown ALV
227 ALV with Hotspots
How to Archive customers & vendors ?
SAPF056 & SAPF058
226
Mark for deletion : XK02 & XK06
Archive via SARA (for vendors object = FI_ACCPAYB)
225 Delete a Workflow Logically

224 How to change the priority of a WorkItem ? (Workflow)


SAP_WAPI_CHANGE_WORKITEM_PRIO

223 If you have a program, how can you find the jobs for it ?
TBTCP veld PROGNAME -> JOBNAME
222 Table for version management : VRSD
221 Start a WorkItem from within ABAP (Workflow)
220 Generate an instance of an object : (Workflow)
Set a status to a Switchdocument (Workflow) :
object :
219 ISUIDESWD
methode :
SETSTATUS
Set an activity in a Switchdocument (Workflow) :
object
218 ISUSWITCHD
method
SETSTATUSACTIVITY
217 Send and Receive an IDOC in the same system
216 User decision in a Workflow
215 Application Logging (via SLG0 and SLG1)
214 Show fields on a screen or not
213 Add an IDOC status (WE47)

212 Read complete IDOC structure :


call function IDOCTYPE_READ
Re-start a specific workflow item :
vanaf 4.7
211
Put this in the TOP of the function-group :

4 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

include rswwincl.
include lswwaf01.
data: return_code like syst-subrc.

211 Search in an IDOC for segments/fields/values : transaction-code WE09


210 Do a Call Transaction, but continue after the COMMIT
Get a filename (input) :
parameters: p_file like rlgrap-filename.
at selection-screen on value-request for p_file.
perform get_file changing p_file.
form get_file changing filename.
209 call function 'KD_GET_FILENAME_ON_F4'
changing
file_name = filename
exceptions
mask_too_long = 1
others = 2.
endform. " get_file

208 Delete some Workitems out of the Business Place : transaction-code SWWL
207 How to stop a Workflow for a Switchdocument (SAP-ISU) ?
Stop a Workflow : Transaction-code : SWW_WI_ADMIN_CANCEL
Read all objects of a container : Function SWW_WI_CONTAINER_READ_OBJECTS
206
Read all attributes : Function SWW_WI_CONTAINER_READ
Example program...
205 Update an IDOC-status
204 Download ABAP-program code, TABLE-definition
Show an IDOC :

PARAMETERS : p_idocnr TYPE edidc-docnum.

RANGES range_credat FOR edidc-credat.

CLEAR range_credat.
203
REFRESH range_credat.

SUBMIT rseidoc2 WITH docnum = p_idocnr

WITH credat IN range_credat

AND RETURN.
Get the value of an attribute of a copied object :
* Get the property of the Requisitioneruser.
SWC_CREATE_OBJECT REF_BUS2121 'BUS2121' object-key-REQUIREMENTREQUEST.
SWC_GET_PROPERTY REF_BUS2121
202 'REQUISITIONERUSER'
w_requisitioneruser.
* it_users is filled with all the users for the org units
* check if requisitioner is in user table
read table it_users into wa_users

5 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

with key uname = w_requisitioneruser.


Call an external command :
SM69 contains the list (or create new ones)
call function 'SXPG_CALL_SYSTEM'
exporting
commandname = 'ZBATCHCREATION'
additional_parameters = ls_param
importing
status = ls_execstatus
exitcode = ls_exitcode
tables
exec_protocol = it_btcxpm
exceptions
201
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
others = 12.
Check in an ALV-grid if a field has changed :
200
cl_gui_alv_grid->check_changed_data
Get characteristics of a material :
First select in table INOB with key :

klart = 'Class type' (example ZZ1)


OBTAB = 'MARA'
OBJEK = material number
199 then select in table AUSP withkey :
objek = inob-cuobj
atinn = number for characteristic name (atnam -> tablle CABN with key atnam =
characteristic name)
klart = 'Class type' (example ZZ1)

field ATWRT from table AUS¨P contains the value.


Show own logical system :
data : p_sndprn like edidc-sndprn.

call function 'PARTNER_LOGICAL_SYSTEM_GET'


198 importing
p_logsys = p_sndprn
exceptions
own_logical_system_not_defined = 1
others = 2.

6 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

197 Number Range for WorkItems : SWW_WIID


Send a DOS command via ABAP

parameters: p_text(60) type c default 'Coucou SAP' lower case,

196 data: doscmd(90) value 'h:\data\alex.bat'.


concatenate doscmd p_text into doscmd separated by space.
call function 'GUI_EXEC'
exporting
command = doscmd.
If an IDOC has errors, this workflow is started automatically :

195 object = IDOCAPPL


methode = ERRORPROCESS
Default workflow = WS30000483
Check serialnumber via user-exit :
194
EXIT_SAPLIPW1_008
SAP Component = IQSM0008 voor de CMOD
How to send a mail to the general map with submaps (Business Workplace) :
193
Do not forget to add user WF-BATCH to table TSOUX = add user as a system user for the
authorization of the mailboxes !!!
Add a 'green light' to a listing :
--> INCLUDE <ICON>.
move ICON_GREEN_LIGHT to i_print-icon.
append i_print.
192 clear i_print.

i_print --> data: begin of i_print occurs 0,


icon(4).
data: end of i_print.
191 Synchronise buffers : SWU_OBUF
Get all fields from a table :
DATA : li_dfies_tab TYPE STANDARD TABLE OF dfies
WITH HEADER LINE.

CALL FUNCTION 'DDIF_NAMETAB_GET'


EXPORTING
190 tabname = 'the tablename'
TABLES
dfies_tab = li_dfies_tab
EXCEPTIONS
not_found =1
OTHERS =2
189 Sync the buffers in SAP : transactioncode = /$sync

7 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

Put icon's on screen :

v_icon = '@08\QAnnulering OK@'.


188 v_icon = '@0A\QAnnulering niet mogelijk@'.
v_icon(132) type c.

187 Change a workitem in error (Workflow)


186 Number ranges for an object : transactioncode = /nSNRO
Read an IDOC :

DOCUMENTNUMBER TYPE EDIDC-DOCNUM


w_idoccontrol TYPE edidc
EDIDD STRUCTURE EDIDD

******** LEES DE IDOC ********

CALL FUNCTION 'IDOC_READ_COMPLETELY'


EXPORTING
185 document_number = documentnumber
IMPORTING
idoc_control = w_idoccontrol
TABLES
int_edidd = edidd
EXCEPTIONS
document_not_exist = 01
document_number_invalid = 02
OTHERS = 03

Search an internal POD (SAP-ISU) :

SELECT * FROM euitrans


WHERE
184 ( dateto >= sy-datum AND datefrom <= sy-datum )
AND ext_ui = w_place_id.
ENDSELECT

Search an installation for a POD (SAP-ISU) :

183 select * from euiinstln


where int_ui = euitrans-int_ui
and ( dateto >= sy-datum and datefrom <= sy-datum ).
182 Send an e-mail via Outlook...
181 Open an application on the PC (Word, Excel,...)

8 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

Show a directory on the PC :

data: dir type string.


dir = 'W:\09BE001\13_Project Soclev\03_Ice soclev\'.

call method cl_gui_frontend_services=>execute


exporting
application = dir
exceptions
cntl_error =1
180 error_no_gui =2
bad_parameter =3
file_not_found =4
path_not_found =5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
others = 10

Status of an equipment (SAP-ISU) :


DATA : w_objnr TYPE itob-objnr,
w_equnr TYPE v_eger-equnr. "equipment number

CONCATENATE 'IE' w_equnr


INTO w_objnr.

CALL FUNCTION 'STATUS_TEXT_EDIT'


EXPORTING
objnr = w_objnr
179 flg_user_stat = 'X'
spras = sy-langu
IMPORTING
line = w_sttxt
user_line = w_sttxu
EXCEPTIONS
object_not_found = 1
OTHERS = 2.

-> status in w_sttxt


178 A general form for error handling...
Number ranges for IDOC's :
177 /nSNUM
object = EDIDOC
176 Use SAP Standard Texts : transactioncode SO10
IDOC's between 2 SAP systems
175 1) create RFC-destination type R3
2) use WE14 on existing idoc in system A to send to system B, and use RFC-destination created in

9 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

1)
Matchcode table for Business Partners :
174 M_BUPAA
SAP-ISU
173 Play a WAV-file
SAP ISU : Business Partner change :

1) CALL FUNCTION 'BAPI_ISUPARTNER_CHANGE'


2) CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
3)
172 DATA: BUSINESSPARTNER TYPE BUT000-PARTNER.
SWC_GET_ELEMENT CONTAINER 'BusinessPartner' BUSINESSPARTNER.
call function 'ISU_S_PARTNER_DISPLAY'
exporting
x_partner = BUSINESSPARTNER
171 Convert SAPscript spool to PDF file : RSTXPDF4
Get the shortdumps (ST22)
170
CALL FUNCTION '/SDF/EWA_GET_ABAP_DUMPS'
How to download a listing automatically (with popup for filepath)

CALL FUNCTION 'LIST_DOWNLOAD'


EXPORTING
169
list_index = sy-lsind
method = 'RTF' -> Rich Text Format
'DAT' -> Spreadsheet
'NOCO' -> Unconverted
168 View SAP parameters, settings,... -> report RSPARAM
167 Table TKA01 -> controlling area, contains the dummy profit center (for example SAPF181)
166 View table changes -> report RSTBPROT
165 Link between COBK and COEP -> View COVP
BDC INSERT, internal data area for screen && too small...
164
-> See OSS Note 11842
163 The variant name of a program is stored in : sy-slset
Change the SAP logon screen :
162
SAPMSYST 0020
Read IDOC's
1) EDI_DOCUMENT_OPEN_FOR_READ
EXPORTING
document_number = w_docnum (w_docnum LIKE edidc-docnum)
161
2) EDI_SEGMENT_GET
EXPORTING

10 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

document_number = w_docnum
segment_name = c_segnam_e1knvvm ( LIKE edidd-segnam value 'E1KNVVM')
IMPORTING
idoc_container = w_edidd (INCLUDE STRUCTURE edidd)

if OK
w_e1knvvm = w_edidd-sdata (w_e1knvvm LIKE e1knvvm)

3) EDI_DOCUMENT_CLOSE_READ

4) EDI_DOCUMENT_TREE_DISPLAY
BOM explosion

CS_BOM_EXPL_MAT_V2
capid = PP01
datuv = 07.09.2004
ehndl = 1
mtnrv = 121641
mehrs = X
werks = 0t00

returns 2 tables :

1) MATCAT
160 contains the main material and the 'sub' BOMS

2) STB
contains all the materials from the BOM

-> you can delete all the records where STB-IDNRK = MATCAT-MATNR

-> take field MNGKO for the quantity, and MMEIN for the Unit of Measure

-> take field OJTXP for the description

report = RCS13001
159 Report RATSTDEL = Delete Data From a Company Code in Asset Accounting
STORAGE_PARAMETERS_WRONG_SET
158 -> SELECT is too big for the internal table
-> already too much data in the system with 'maloc'...
Print to your Local Printer :
157 in SAP set the printer to 'LOCL'.
this sends the output to your default printer...
CO tables like GLT0 :
156 COSP CO Object: Cost Totals - External Postings
COSS CO Object: Cost Totals - Internal Postings
155 RSQL error 23 = output area too small -> check your internal table

11 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

154 Wait for a BDC Job


Service Entry Sheets : (SES)
ESSR (=Service Entry Sheet Header Data) + ESLL (=Lines of Service Package)
153 ESKN = Account Assignment in Service Package
Links :
ESKN -> ESLH -> ESKL -> ESLL
Tables for Goods Receipt : (GR)
152
EKBE + EKKO
convert to year 4 digits
151
CONVERSION_EXIT_GJAHR_INPUT
CONVERSION_EXIT_GJAHR_OUTPUT
Convert language from 2 digit ISO to 1 digit SAP
150
CONVERSION_EXIT_ISOLA_INPUT
CONVERSION_EXIT_ISOLA_OUTPUT
149 How to update a record in a table when SE16 is disabled ?
V1 update = synchronous update
148
V2 update = asynchronous update
Randomizer :
Number between 0 and 10 :

DATA: number LIKE datatype-integer2.

147 CALL FUNCTION 'RANDOM_I2'


EXPORTING
rnd_min = 0
rnd_max = 10
IMPORTING
rnd_value = number.
TSV_TNEW_PAGE_ALLOC_FAILED
146
-> too many records in an internal table (or too much data)
145 How to use Sets ?
Define an Internal Table :
TYPES : BEGIN OF tt_<type name>,
<fields>.
144 TYPES : END OF tt_<type name>.

DATA : t_<internal table name> TYPE STANDARD TABLE OF tt_<type name>


INITIAL SIZE 0 WITH HEADER LINE.
Get printer information :
143 Transaction : SPAD
table : TSP03D
142 Program authorizations table : TPGPT

12 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

How much lines in an internal table ?


DESCRIBE TABLE <internal table> LINES SY-TFILL.
IF SY-TFILL = 0.
141
give message.
STOP.
ENDIF.
Display a table via SM30
DATA: t_dba_sellist LIKE vimsellist OCCURS 0.

CALL FUNCTION 'VIEW_MAINTENANCE_CALL'


140 EXPORTING
action = 'S'
view_name = 'here the table name'
TABLES
dba_sellist = t_dba_sellist
Allowed posting periods
Table T001B.

139 fields FRYE2/FRPE2 = beginning of allowed fiscal year and fiscal period
fields TOYE2/TOPE2 = end of allowed fiscal year and fiscal period

for G/L accounts use field MKOAR = S


In table CATSDB/PRPS the field RPROJ/PSPNR shows on the screen a projectnumber, but
internally it holds a number.
138
Use routine 'CONVERSION_EXIT_KONPR_OUTPUT' to show the projectnumber...
137 Example of 2D graphics and 3D graphics
136 ALV example with refresh and input field
Read field GDATU in table TCURR
135
use function CONVERSION_EXIT_INVDT_OUTPUT
Get the first day of a fiscal year :

1) read table T001 with the company code, and get the field PERIV (fiscal
year variant)
134 2) CALL FUNCTION 'G_POSTING_DATE_OF_YEAR_GET'
with VARIANT = t001-periv
YEAR = the fiscal year

-> returns ; FROM_DATE = first day of fiscal year


Internal dates in table TCURR

CONVERSION_EXIT_INVDT_OUTPUT
133 vb. 79968869 = 30.11.2003

CONVERSION_EXIT_INVDT_INPUT

13 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

vb. 30.11.2003 = 79968869


132 If checked on in the dictionary all changes are logged in table DBTABLOG
Create a macro in ABAP

DATA : w_countm TYPE i.

DEFINE fill_string.
w_countm = 0.
do &2 times.
131 &1+w_countm(1) = &3.
w_countm = w_countm + 1.
enddo.
END-OF-DEFINITION.

-> the variable w_countm must be declared globally

fill_string <string> <number of characters> <fill character>.


130 BAPI example
129 Refresh a report : for example you click on a button, and the same list must be shown sorted...
Run Notepad
CONCATENATE 'C:\WINDOWS\NOTEPAD.EXE C:\WINDOWS\DESKTOP\NAIMESH.TXT'
INTO
FILE.

CALL FUNCTION 'WS_EXECUTE'


EXPORTING
128
PROGRAM = FILE
EXCEPTIONS
FRONTEND_ERROR = 1
NO_BATCH = 2
PROG_NOT_FOUND = 3
ILLEGAL_OPTION = 4
OTHERS = 5.
127 ABAP certification questions + answers
126 How to use coding block/field status groups ?
View the external path of a logical file name :
ex. Y_0000_SOM_DATA
table PATH
125 -> PATHEXTERN = \\<V=Y_SERVER>\<SYSID>\<SYSID>\SOM\<FILENAME>

Table FILENAMECI contains the filename in field FILEEXTERN :


SomCNTLlist.txt, the format in field FILEFORMAT : ASC
Get a list of fixed values for a domain (the value table).
Read table DD01L with the domain name.
124
If the field VALEXI has an X -> there is a value table

14 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

Read table DD07L with the domain name.


The field DOMVALUE_L holds the value.
Get user profiles :
123
CALL FUNCTION 'SUSR_USER_PROFS_PROFILES_GET'
122 Get partner information (Table VBPA)
121 Search a string in programs
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
120 signum = '-' or '+'
-> you can add/subtract days, months and years.
119 Total numerics and characters in a string
To have all the names of the months in a certain language :
118
CALL FUNCTION 'MONTH_NAMES_GET'
117 Create a button on the selection screen of a report
program : RSABTPGP
116
table : TPGP (ABAP/4 Authorization Groups)
In data dictionary for tables :
flag => Table Maintenance Allowed
115 If yes -> you can create data via SE16 !!!!
Is not needed to set on, to do 'Table Maintenance Generator'. The table
maintenance is linked via SM30
114 Get the user list (program help-request)
Get the user name :
113
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
READ_TEXT -> read texts
112
INIT_TEXT before the SAVE_TEXT
To be able to allow an '*' as input for a field :
111
attributes of the field = click on '* entry'
110 Fill all fields of a structure with the same value
>From 4.6 you can display an internal table, do a find, download,...
109
In the debugger :
menu goto -> display data object -> Structure editor
If you delete a record in 1 table via SM30 -> check if an entry exists in another table. If yes, you
108
may NOT delete !
SELECT SINGLE....

with not all the key fields does NOT work


107
-> SELECT * FROM ...
UP TO 1 ROWS
WHERE...
Table COBK has a field TIMESTMP :
106 = Time created (Greenwich Meantime)

15 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

How to convert ?

RKE_TIMESTAMP_CONVERT_OUTPUT -> show date and time


RKE_TIMESTAMP_CONVERT_INPUT -> give timestmp

You need :
- SY-DAYST
- SY-TZONE
105 Example of a tree program
104 How to scan an ABAP/4 program for statements,...
103 Lock a table
Get fieldname of a variable when you select a line.
DATA : w_field(30) TYPE c.
102
AT LINE-SELECTION.
GET CURSOR FIELD w_field.
Examples of SET/GET PARAMETER ID + CALL TRANSACTION xxx AND SKIP FIRST
101
SCREEN
Standard SAP program for creating a BDC for characteristics
RCCTBI01
100
Display and change the data created by that program
RCCTBISC
Show the variants of a program in a popup-screen (like the default SAP)
99 Call function RS_VARIANT_CATALOG
Uses tables VARIS and VARID
98 Fill in an Excel spreadsheet (several sheets !)
97 Insert a button on the selection-screen
Read balance of an GL-account
Table GLT0 read with

RLDNR = 00
RRCTY = 0
RVERS = 001
96 BUKRS = the company code
RYEAR = the year
RACCT = the account (with leading zeros)

in group currency columns KSLxx


in local currency (EUR) columns HSLxx
95 Calculate date conversions : add days, months, last day of month,...
Authority check for company code
AUTHORITY-CHECK OBJECT 'F_SKA1_BUK'
94
ID 'BUKRS' FIELD s_bukrs-low
ID 'ACTVT' FIELD '03'.

16 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

-> check to see if you may display the company code

Check table TACTZ for the field ACTVT

03 = display
93 Example program for downloading characteristics in general
92 Run a transaction and skip first screen
91 Get a user parameter
Show a grid in a screen
90
flow logic
89 Function to invert a string of characters (max. 256 length)
88 Get characteristics of a class for batches
87 Show an internal table in a window to make a choise
86 Example of INNER JOIN
Put in upper case
85
Translate <variable> to upper case.
Texts types for SD (via IMG - Text determination - text types) of VOTX
84 Then you get for example billing text = 9902
This is the ID needed for 'READ_TEXT'.
83 Check change pointers after a data upload
82 FI Document ranges -> FBN1 and function RF_GET_DOCUMENT_NUMBER
81 Write system log messages -> SE92 and function RSLG_WRITE_SYSLOG_ENTRY
80 Loop at screen -> Make a parameter output only
79 Check wether a unit of measure can be used for a material ?
Change documents for FI
BKPF-TCODE
78
= FBD1 -> objectclass = BELEGD
= FB01 -> objectclass = BELEG
Read change documents
CDHDR and CDPOS
77
CHANGEDOCUMENT_READ_HEADERS
CHANGEDOCUMENT_READ_POSITIONS
76 How to run in LSMW a Direct Input ?
75 Convert date in user format
74 List of all LSMW Tables

17 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

Get the correct Unit Of Measurement


Main table = T006
73 But display on screen and internal UoM (MSEHI) can be different....
-> read table T006 with SPRAS = SY-LANGU and MSEH3 = displayed UoM to find
the internal UoM
Call FB03 - Display FI document
suppose t_data contains the data needed, and displayed with HIDE...

AT LINE-SELECTION.
CHECK t_data-belnr NE space.
72 SET PARAMETER ID 'BLN' FIELD t_data-belnr.
SET PARAMETER ID 'BUK' FIELD t_data-bukrs.
SET PARAMETER ID 'GJR' FIELD t_data-gjahr.

CALL TRANSACTION 'FB03'


AND SKIP FIRST SCREEN.
Need to have all letters and numbers in constants ?
71
include INCLF124
70 How to play solitaire in ABAP ?
Send a general message in SAP : message e398(00)
69
-> contains & & & &
Change a select-option to a range (to have all the values of the select-option)

RANGES : r_bukrs for t001-bukrs.

SELECT bukrs
from t001
INTO TABLE t_t001
WHERE bukrs IN s_bukrs.
68
CLEAR r_bukrs. REFRESH r_bukrs.
LOOP AT t_t001.
MOVE 'IEQ' TO r_bukrs.
MOVE t_t001-bukrs TO r_bukrs-low.
MOVE space TO r_bukrs-high.
APPEND r_bukrs.
CLEAR r_bukrs.
ENDLOOP.
Get a list of all the company codes in a select-option
SELECT bukrs FROM t001
INTO TABLE t_t001
WHERE bukrs IN s_send.
67 IF sy-subrc NE 0.
MESSAGE e306.
ENDIF.

-> t_t001

18 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

DATA : BEGIN OF t_t001 OCCURS 20,


bukrs LIKE bkpf-bukrs. "Company code
DATA : END OF t_t001.
Reset the password for all users in a client to initpass
DATA: CODE(8) VALUE 'initpass'.
data: retruncode.
TABLES: USR02.
66 SELECT * FROM USR02.
PERFORM SET_NEW_PASS IN PROGRAM SAPMS01J USING USR02-BNAME CODE
CODE
CHANGING RETRUNCODE.
ENDSELECT.
Reset the users password history, so he/she can use the same password
TABLES: USR02.
PARAMETERS: USER LIKE USR02-BNAME.
SELECT * FROM USR02 WHERE BNAME = USER. ENDSELECT.
IF SY-SUBRC = 0.
65 USR02-OCOD1 = USR02-OCOD2 = USR02-OCOD3 =
USR02-OCOD4 = USR02-OCOD5 = USR02-BCODE.
MODIFY USR02.
ELSE.
WRITE: / 'User does not exist'.
ENDIF.
How to use MODIFY...TRANSPORTING ?

FORM 0000_init.

DATA: BEGIN OF t_reqtype_werks OCCURS 0,


zzreqtype(4) TYPE c,
END OF t_reqtype_werks.
64
SELECT werks FROM t001w INTO TABLE t_reqtype_werks.

t_reqtype_werks-zzreqtype+0(1) = 'O'.

MODIFY t_reqtype_werks TRANSPORTING zzreqtype+0(1)


WHERE NOT ( zzreqtype IS INITIAL ).

ENDFORM. " 0000_INIT


63 Read IDOC and download
62 How to call a BAPI with Visual Basic (example in Excel)
61 ALV example with header and line items...
60 Simple ALV example
59 Show all variants for a program
Common routines for printing a report
58
top

19 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

57 Read from archive


56 Direct input programs
View the ABAP/4 statements ?
55
Report RSABAPIV
54 How to check/print/... dynamic selections (not the parameters, select-options) ?
53 Copy Favorites to another client/system
52 How to set the first letter of each word in capitals
51 Professional uploading input file
Need to write a batch input ???
50
First have a look at transaction SXDB : Data Transfer Workbench for a standard program
49 Show table dictionary (fields, description, length,...) in HTML format
48 Show all variants for a report : parameters, select-options, description,...
47 How to check if a field is numeric or character ?
46 Function to let the computer wait for n seconds
45 Check if a country is an EMU country ? -> is there an EURO conversion ?
44 How to update an IDOC status ?
43 How to find an FI document for an Billing document ? (or the document flow)
42 Download an ABAP/4 program with all text elements, selections,...
To check for any numeric data in a string
If field-name ca '1234567890'
41
write / 'Field is numeric'.
Endif.
40 Show user selections for a report
39 Up and download a transport request
38 Show help for a field (eg. PF4 on a PARAMETER) ; simple way
37 How to add months to the date
36 How to de-select buttons on a screen ?
35 How to print out page 1 of 8, page 2 of 8,... on a listing
34 How to suppress a parameter/select-option
33 Send a report/listing as an attachment
32 Send a listing to a file in HTML format
31 Read the password for an RFC destination with a CPIC-user !
30 Reset user password history
29 Swith off the editor lock for an ABAP/4 program (eg. when user is on holiday)
28 Send e-mail (very very simple)
27 Create a 3D-graph from data
26 An empty skeleton for ABAP/4 Code

20 of 21 21/12/2012 5:26 PM
Usefull ABAP/4 code http://users.skynet.be/am261047/SAP/abap.htm

25 Send a message to all on-line users


24 Upload an Excel file into an internal table
23 Read all text-elements, parameters & select-option names + descriptions
22 Start a batch input via a job
21 Send e-mail
20 Create own PF4 for a field/parameter
19 Open/Read file
18 Get logical filename
17 Get user defaults
16 Show help to input file-name (PF4)
15 Show help for field (PF4) -> see also 38
14 Make a download (file)
13 Convert date to user defaults
12 Create a backup file
11 User defaults : point or comma
10 Batch Input skeleton
9 How to create a progressbar
8 Read the date in table TCURR (Julian date)
7 How to round up/down an amount
6 How to get leading zeros
5 How to work with currencies in an ABAP program
4 How to split up a tab-delimited file into fields
3 Start a UNIX command or Shell script
2 Fill a field in a segment that is now not filled
1 Create an IDOC segment + fill the segment via a user-exit

21 of 21 21/12/2012 5:26 PM

You might also like