piątek, 25 listopada 2011

Database: Tips & Tricks

Edycja wpisów w tabeli danych
1. Wchodzimy do transakcji se16n
2. Wpisujemy nazwę tabeli
3. Wprowadzamy &sap_edit
4. Uruchamiamy debugging mode (/h i enter)
5. Zmieniamy następujące zmienne globalne zabezpieczające bazę przed zapisem:
gd-edit = X
gd-sapedit = X
gd-tabedit = X


Program do ustalania rozmiaru tabeli: RSTABLESIZE

wtorek, 22 listopada 2011

ABAP Programming : Tips & Tricks

Appending two internal tables

APPEND LINES OF TAB_SRC TO TAB_DEST.

Three-steps: move, sort, delete dupl.

ITAB2[] = ITAB1[].
SORT ITAB2 BY K.
DELETE ADJACENT DUPLICATES FROM ITAB2 COMPARING K.

Delete a seq. of lines
DELETE ITAB FROM 450 TO 550.

wtorek, 15 marca 2011

ABAP Syntax

**********Procedure for HR ABAP******************
In ABAP editor:
Declare Logical database PNP in attributes.

TABLES: PERNR.
INFOTYPES: 0001, 0002.

Internal table declaration.

START-OF-SELECTION.
GET PERNR.

Process the data write the logic:
RP_PROVIDE_FROM_last P0032 space PN-BEGDA PN-ENDDA.

END-OF-SELECTION.
LOOP AT ITAB.
WRITE:/1 SY-TABIX CENTERED,
10 ITAB-PERNR,
50 ITAB-GBPAS.
ENDLOOP.

-----------------------------------------------------
******USING MACROS IN ABAP EDITOR****************

TABLES: PERNR.
INFOTYPES: 0032, 0002,0000.

DATA: BEGIN OF ITAB OCCURS 0,
PERNR LIKE PERNR-PERNR,
BEGDA LIKE p0032-begda,
endda like p0032-endda,
GBPAS LIKE P0002-GBPAS,
END OF ITAB.

START-OF-SELECTION.
GET PERNR.

ITAB-PERNR = PERNR-PERNR.

RP_PROVIDE_FROM_last P0032 space PN-BEGDA PN-ENDDA.
IF PNP-SW-FOUND = 1.
itab-begda = p0032-begda.
itab-endda = p0032-endda.
ENDIF.

RP_PROVIDE_FROM_LAST P0002 SPACE PN-BEGDA PN-ENDDA.
IF PNP-SW-FOUND = 1.
ITAB-GBPAS = P0002-GBPAS.
ENDIF.

APPEND ITAB.
CLEAR ITAB.

END-OF-SELECTION.
WRITE:/1 'Ser.No',
10 'Emp.No',
25 'Emp.Name',
40 'Pre.Name',
50 'DOB'.

LOOP AT ITAB.
WRITE:/1 SY-TABIX CENTERED,
10 ITAB-PERNR,
50 ITAB-GBPAS,
65 itab-begda,
85 itab-endda.
ENDLOOP.

---------------------------------------------------------
**************PROVIDE AND ENDPROVIDE****************

GET PERNR.
PROVIDE * FROM P0002
* FROM P0006 BETWEEN PN-BEGDA AND PN-ENDDA
WHERE P0006-SUBTY = '6'.

ENDPROVIDE.
---------------------------------------------------------

PROVIDE * FROM P0002
uname aedtm FROM P0006
BETWEEN PN-BEGDA AND PN-ENDDA.
ENDPROVIDE.

-----------------------------------------------------------
************REPEATATIVE STRUCTURES********************

start-of-selection.
get pernr.

clear total_bet.

rp_provide_from_last p0008 space pn-begda pn-endda.

do 12 times varying
betxx from p0008-bet01 next p0008-bet02.
total_bet = total_bet + betxx.
enddo.

--------------------------------------------------------------
*************REPETATIVE STURCTTURES***********************

rp-provide-from-last p0041 space pn-begda pn-endda.
if pnp-sw-found eq 1.

do 12 times varying v_dar from p0041-dar01 next p0041-dar02
varying v_dat from p0041-dat01 next p0041-dat02.

if v_dar = '40'.
write:/ v_dat.
endif.

enddo.

-------------------------------------------------------------
***************CONCATENATE*******************************

CONCATENATE P0002-NACHN P0002-VORNA INTO NAME
SEPARATED BY SPACE.

----------------------------------------------------------
***************ALV REPORT*****************************

start-of-selection.
GET PERNR.

ITAB-PERNR = PERNR-PERNR.
ITAB-BEGDA = PN-BEGDA.
ITAB-ENDDA = PN-ENDDA.

RP-PROVIDE-FROM-LAST P0001 SPACE PN-BEGDA PN-ENDDA.
IF PNP-SW-FOUND = 1.
ITAB-NAME = P0001-ENAME.
ENDIF.

APPEND ITAB.
CLEAR ITAB.

end-of-selection.

DATA: T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
S_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

S_FIELDCAT-FIELDNAME = 'PERNR'.
S_FIELDCAT-TABNAME = 'ITAB'.
S_FIELDCAT-REF_FIELDNAME = 'PERNR'.
S_FIELDCAT-REF_TABNAME = 'PERNR'.
APPEND S_FIELDCAT TO T_FIELDCAT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

-------------------------------------------------------
*******************HR_READ_INFOTYPE****************

DATA: V_INFTY LIKE PRELP-INFTY,
S_SUBRC LIKE SY-SUBRC.
V_INFTY = '0001'.

CALL FUNCTION 'HR_READ_INFOTYPE'

-------------------------------------------------------
***********REJECT**********************************

CHECK SY-LANGU NE T513S-SPRSL OR
P0001-STELL NE T513S-STELL OR
P0001-BEGDA LT T513S-BEGDA OR
P0001-BEGDA GT T513S-ENDDA.

SELECT * FROM T513S
WHERE SPRSL EQ SY-LANGU
AND STELL EQ P0001-STELL
AND ENDDA GE P0001-BEGDA
AND BEGDA LE P0001-BEGDA.
ENDSELECT.

IF SY-SUBRC NE 0.
CLEAR T513S.
WRITE:/ PERNR-PERNR,
'NO ENTRY IN T513S FOR JOB KEY',
P0001-STELL.
* REJECT.
ENDIF.
------------------------------------------------------------
*************************************************************
DATA: BEGIN OF ITAB OCCURS 0,
I_NAME(25), "type p0001-ename,
I_BEGDA LIKE PN-BEGDA,
I_ENDDA LIKE PN-ENDDA,
I_GBDAT TYPE P0002-GBDAT,
I_STELL TYPE PERNR-STELL,
I_STLTX TYPE T513S-STLTX,
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 0,
I_STELL TYPE T513S-STELL,
I_STLTX TYPE T513S-STLTX,
END OF ITAB1.

IF NOT ITAB[] IS INITIAL.
SELECT STELL STLTX FROM T513S INTO TABLE ITAB1
FOR ALL ENTRIES IN ITAB WHERE STELL EQ ITAB-I_STELL " HERE STELL IS T513S-STELL
AND SPRSL EQ SY-LANGU.
ENDIF.

SORT ITAB.
SORT ITAB1 BY I_STELL.

LOOP AT ITAB.
READ TABLE ITAB1 WITH KEY I_STELL = ITAB-I_STELL.
IF SY-SUBRC = 0.
ITAB-I_STLTX = ITAB1-I_STLTX.
MODIFY ITAB TRANSPORTING I_STLTX.
ENDIF.

ENDLOOP.

----------------------------------------------------------
TABLES: PERNR.
INFOTYPES: 0002, 0001, 0006.

SELECT-OPTIONS: LANGUAGE FOR P0002-SPRSL.

GET PERNR.
RP_PROVIDE_FROM_LAST P0002 SPACE PN-BEGDA PN-ENDDA.
IF PNP-SW-FOUND = 1.
WRITE: / P0002-PERNR,

ENDIF.

-------------------------------------------------
ZRAM_APPLICATION_SERVER.
OPEN DATASET BGLR FOR OUTPUT IN TEXT MODE. " encoding default.

LOOP AT RAM_TAB.

TRANSFER RAM_TAB TO BGLR.
ENDLOOP.

CLOSE DATASET BGLR.

----------------------------------------------------
CHECK V_VAR1 = V_VAR2.

-----------------------------------------------------
FORMAT COLOR 5.
WRITE:/1 'Sales Docu No.', 18 'Item No.', 35 'Net Value'.
FORMAT INVERSE.
-----------------------------------------------------
DELETE IT_VBAK FROM 2 TO 5.
DELETE ITAB2 INDEX SY-TABIX.
--------------------------
SORT ITAB.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MATNR SPRAS.
------------------------------------------
REPORT ZRAM_INNER_JOINS .

data: begin of itab occurs 0,
ebeln like ekko-ebeln,
ebelp like ekpo-ebelp,
end of itab.

SELECT B~EBELN B~EBELP INTO TABLE ITAB
FROM EKKO AS A INNER JOIN EKPO AS B
ON A~EBELN = B~EBELN
WHERE A~EBELN EQ B~EBELN.

LOOP AT ITAB.
WRITE:/ ITAB-EBELN, ITAB-EBELP.
ENDLOOP.

-----------------------------------------------
WRITE:/ IT_MARA-MATNR UNDER 'X',
IT_MARA-ERSDA UNDER 'Material no.',
ENDLOOP.
------------------------------------------------