scripturi ABAP

Tuesday, October 10, 2006

Simple ALV GRID CONTROL

http://www.erpgenie.com/abap/code/abap28.htm

Monday, October 02, 2006

Hotspot in lista cu apel tranzactie

report ztest.
include .
data: p_group like apqi-groupid VALUE 'MAPA',
text(25).

at line-selection.
text = 'PANA'.
* if sy-lisel+0(20) = text+0(20).
leave to transaction 'SM35'.
* endif.
START-OF-SELECTION.
write: / 'PANA' hotspot, p_group hotspot,
icon_execute_object as icon hotspot.

Thursday, November 24, 2005

Export in fisier text cu coloane lungime fixa

DATA: begin of it_datatab occurs 0,
row(500) type c,
end of it_datatab.
......................
LOOP AT TAB.
IND = IND + 1.
SUM = SUM + TAB-NET.
WRITE TAB-NAME1 TO T_NAME1+0(19).
WRITE '"' TO T_NAME1+19(1).
CONCATENATE '"' T_NAME1 INTO it_datatab-ROW.
WRITE ' ' TO it_datatab-ROW+21(1).
WRITE '" ' TO it_datatab-ROW+22(4).
WRITE TAB-STCD1 TO it_datatab-ROW+26(13).
WRITE '" "' TO it_datatab-ROW+39(3).
WRITE TAB-IBAN TO it_datatab-ROW+42(24).
WRITE '" "' TO it_datatab-ROW+66(3).
WRITE TAB-NET TO T_NET NO-GROUPING DECIMALS 0 RIGHT-JUSTIFIED.
* WRITE TAB-NET TO it_datatab-ROW+69(8) NO-GROUPING CURRENCY TAB-WAERS DECIMALS 0 RIGHT-JUSTIFIED.
CONCATENATE it_datatab-ROW T_NET INTO it_datatab-ROW.
WRITE '"' TO it_datatab-ROW+77(1).
APPEND it_datatab.
ENDLOOP.

CALL FUNCTION 'WS_FILENAME_GET'
* EXPORTING
* DEF_FILENAME = LD_FILENAME
* DEF_PATH = PATH
* MASK = ' '
* MODE = 'S'
* TITLE = ' '
IMPORTING
FILENAME = ld_filename
* RC =
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5
.
IF SY-SUBRC <> 0.
PERFORM SHOW_EXCEPTIONS USING SY-SUBRC.
ELSE.
PERFORM SHOW_EXCEPTIONS USING SY-SUBRC.
ENDIF.


CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
FILENAME = LD_FILENAME
FILETYPE = 'DAT'
* APPEND = ' '
* WRITE_FIELD_SEPARATOR = ' '
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
CONFIRM_OVERWRITE = 'X'
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* IMPORTING
* FILELENGTH =
TABLES
DATA_TAB = it_datatab[]
* FIELDNAMES =
* EXCEPTIONS
* FILE_WRITE_ERROR = 1
* NO_BATCH = 2
* GUI_REFUSE_FILETRANSFER = 3
* INVALID_TYPE = 4
* NO_AUTHORITY = 5
* UNKNOWN_ERROR = 6
* HEADER_NOT_ALLOWED = 7
* SEPARATOR_NOT_ALLOWED = 8
* FILESIZE_NOT_ALLOWED = 9
* HEADER_TOO_LONG = 10
* DP_ERROR_CREATE = 11
* DP_ERROR_SEND = 12
* DP_ERROR_WRITE = 13
* UNKNOWN_DP_ERROR = 14
* ACCESS_DENIED = 15
* DP_OUT_OF_MEMORY = 16
* DISK_FULL = 17
* DP_TIMEOUT = 18
* FILE_NOT_FOUND = 19
* DATAPROVIDER_EXCEPTION = 20
* CONTROL_FLUSH_ERROR = 21
* OTHERS = 22
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Friday, November 18, 2005

ALV GRID CONTROLS

Pentru exemple vezi programele standard BCALV_GRID_01.......09...si mai departe

Thursday, November 17, 2005

KEEP_ALIVE

Pentru a evita erorile de tip ABAP-RUNTIME ERROR cauzate de depasirea timpului de executie a unui raport:
form get_values.
data: ls_sold_recon like gt_sold_recon.
data: ls_sold_cmspec like gt_sold_cmspec.
data: lsubrc like sy-subrc.
data: lcomp(19).
data: lins like sy-tabix.
data: lproc type i.
data: lprocprev type i.
field-symbols: .

describe table gt_rec_acc lines lins.
loop at gt_rec_acc.
lproc = sy-tabix * 100 / lins.
if lproc <> lprocprev.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting percentage = lproc
text = 'Prelucrare pozitii...'.
lprocprev = lproc.
endif.
.
.
.
endloop.

Thursday, September 29, 2005

Application Linking and Enabling

SAP Documents - ALE
1
Application Linking and Enabling (ALE)
In this document you will learn the step-by-step procedure to setup the ALE system and
go through a transaction between to clients
For our purpose we have two clients namely Client 100 and Client 200.
System name is cysap03
1) SETUP LOGICAL SYSTEM: To do this follow the following steps
Tools à Business Engg à Customizing.
Click Enterprise IMG button.
Cross Applications à Distribution (ALE) à Basic
Configuration.
Set up ‘Logical System à Maintain Logical System.
Click New Entries Button (E.g. WalMart100 receiving
system)
(Walmart200 sending system)
Enter two logical system names and their description.
Save
Comeback to IMG setting screen.
2) Now you have to allocate the created logical systems to respective clients.
WalMart100 assign to client 100
WalMart200 assign to client 200
To do this, do the following.
Click Allocate logical system to the client.
Ignore the message that comes up on the screen.
Select client 100
SAP Documents - ALE
2
Click details button on the toolbar icon or press F2.
In the logical system box, enter WalMart100.
Click on the save Icon
Click the back button.
Now select client 200.
Click details icon or press f2.
In logical Systems box, enter WalMart200.
Save
Back.
Come back to the IMG settings screen.
Now define the RFC Destination. Do the following.
Click Cross Application Ü Distribution (ALE).
Click on communication.
Execute RFC Destination.
Click R/3 connections. (Expand it).
Put cursor on R/3 connection.
Click the create button.
Enter WalMart100 in RFC destination box.
Connection type 3
Give a description for the RFC destination.
Language E.
User: User11 (This is the logon for dist.)
Client : 100
Password: Enter the client logon password.
SAP Documents - ALE
3
Save.
In target machine box enter cysap03 (This is the system
name)
Save.
Click on test connection and remote logon to verify.
Click on Back button.
Position your cursor on R/3 connection.
Click on create to do the above process for WalMart200
logical system for client 200.
Click on the back button.
Click on the distribution customer model.
Execute Maintain customer distribution model directly for
creating the customer model.
Put your cursor in Maintain customer distribution model
directly box.
Click Choose.
Specify the source logical system (WalMart200) and give a
customer model name. (ModelMar10)
Click on create icon.
Select the target logical system (WalMart100) from the list.
Click on create message type.
In the resulting screen, in log message type enter MATMAS.
Click on transfer.
Save.
SAP Documents - ALE
4
Back to IMG setting screen.
Click distribute customer model.
Select generate partner profiles and click choose.
In customer model box enter the model name that you
created (Modelmar10)
Click execute button.
You should get a screen mentioning successful creation of
customer model in green color.
Click back button
Select distribute customer model and click choose.
In the resulting screen enter customer model (Modelmar10)
Receiving logical system (WalMart200)
Click execute.
You get messages :
copy with RFC destination WalMart100
model data sent successfully.
Click back.
Now execute R/3 and login to client 100.
Execute transaction SPRO.
Click Cross applications à Distribution ALE
Communications à generate partner profiles.
Enter the customer Model (Modelmar10)
Execute
You should get all the resulting messages in green color.
SAP Documents - ALE
5
Switch back to client 200 Session.
Logistics à MM à Material master
Material à Create(General) à Immediately.
Enter the material name (mat1000)
Industry sector as M
Material Type as Fert.
Click Select views.
In the select views box for materials check basic data or any
other view(s)
Click enter icon.
In the next screen that you get
Give the text of the material
Base unit of measure as PC
In the description area language (E) and material
description.
Click Save.
Come back to the first screen of the session
Logistics à Central Functions à distribution
Master Data à Material à Send.
Enter the material name. (Mat1000)
Message type (Matmas)
Logical System (WalMart100- target logical system)
Click Execute.
SAP Documents - ALE
6
Switch to Client 100 session to verify.
Logistics à Material Management à Material Master.
Material à Display à Display Current.
Give the name of the material (Mat1000)
Click select views button.
You should get select views screen for the given
material.

Wednesday, July 27, 2005

Incercare reusita :) de lucru cu BAPI

BAPI sunt folosite pentru a putea accesa, prin intermediul unei aplicatii externe, de ex VB, prin RFC, obiecte din SAP, sau mai degraba prin BAPI se pot apela metodele definite pentru obiectul respectiv din SAP.
Tutorialul l-am gasit postat pe http://www.sapgenie.com/abap/bapi/example.htm
Mai intai, cu tranzactia SWO1 se creaza un obiect ZBAPITEST. La object type am pus ZBAPITEST, object name ZTextBapi.Programul este ZBAPITEST.La application se pune Z.
Prin acest BAPI se va incerca accesarea tabelei ZTEST, pe care am creat-o cu campul CHEIE (primary key, CHAR 3), si campurile FIELD1 si FIELD2, amandoua CHAR(15). Am pus trei inregistrari in tabela.
Pentru obiectul BAPI, care de fapt este un FUNCTION MODULE, am creat mai intai o structura pentru transmiterea parametrilor de import, la mine structura aceasta se numeste ZBAPISTRCT, care are doar campul CHEIE. Urmeaza crearea function module Z_BAPI_GET_FIELD, la care e foarte important ca la atribute sa se selecteze Remote-enabled module, altfel BAPI-ul nu va putea fi apelat prin RFC. La import am pus BAPIMPORT type ZBAPISTRCT, cu bifa PASS VALUE. La export se pune RETURN type BAPIRETURN, tot cu pass value.La tables ZBAPITABLE type ZTEST, evident cu pass value :)
Mai jos este source code-ul:

function z_bapi_get_field.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(BAPIMPORT) TYPE ZBAPISTRCT
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRETURN
*" TABLES
*" ZBAPITABLE STRUCTURE ZTEST
*"----------------------------------------------------------------------
data: l_field1 like ztest-field1,
l_field2 like ztest-field2,
l_cheie like ztest-cheie.

select * from ztest into table zbapitable
where cheie = bapimport-cheie.
if sy-subrc ne 0.
clear message.
message-msgty = 'E'.
message-msgid = 'Z3'.
message-msgno = '000'.
message-msgv1 = bapimport-cheie.
perform set_return_message using message
changing return.
if 1 = 2.
* The only reason to include this statement, that will obviously
* never execute, is that it will create a referecence so that you
* can find out where a particular message is being used. This
* functionality is used by the BAPIs programmed by SAP
message e000(z3).
endif.
endif.
check return is initial.

endfunction.


Function module SAPLZBAPITESTGR trebuie sa contina:

*******************************************************************
* System-defined Include-files. *
*******************************************************************
* REPORT SAPLZBAPITESTGR.
include lzbapitestgrtop. " Global Data
include lzbapitestgruxx. " Function Modules
*******************************************************************
* User-defined Include-files (if necessary). *
*******************************************************************
* INCLUDE LZBAPITESTGRF... " Subprograms
* INCLUDE LZBAPITESTGRO... " PBO-Modules
* INCLUDE LZBAPITESTGRI... " PAI-Modules
include lzbapitestgrf01.



Include-ul lzbapitestgrtop:

function-pool zbapitestgr. "MESSAGE-ID ..
types:
begin of type_tj02t,
istat like tj02t-istat,
txt04 like tj02t-txt04,
txt30 like tj02t-txt30,
end of type_tj02t.
data:
* Declarations for TABLE parameter
t_bapitable like ztest occurs 0,
g_bapitable like ztest,
* Table for object texts
t_tj02t type type_tj02t occurs 0,
g_tj02t type type_tj02t.
* Structure for return messages
data:
begin of message,
msgty like sy-msgty,
msgid like sy-msgid,
msgno like sy-msgno,
msgv1 like sy-msgv1,
msgv2 like sy-msgv2,
msgv3 like sy-msgv3,
msgv4 like sy-msgv4,
end of message.


Include-ul lzbapitestgruxx:

*****************************************************************
* THIS FILE IS GENERATED BY THE FUNCTION LIBRARY. *
* NEVER CHANGE IT MANUALLY, PLEASE! *
*****************************************************************
include lzbapitestgru01. "asta duce la function Z_BAPI_GET_FIELD (codul)
"Z_BAPI_GET_FIELD




*----------------------------------------------------------------------*
***INCLUDE LZBAPITESTGRF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form set_return_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_MESSAGE text
* <--P_RETURN text
*----------------------------------------------------------------------*
form set_return_message using value(p_message) like message
changing p_return like bapireturn.
check not message is initial.
call function 'BALW_BAPIRETURN_GET'
exporting
type = p_message-msgty
cl = p_message-msgid
number = p_message-msgno
par1 = p_message-msgv1
par2 = p_message-msgv2
par3 = p_message-msgv3
par4 = p_message-msgv4
* LOG_NO = ' '
* LOG_MSG_NO = ' '
importing
bapireturn = p_return
exceptions
others = 1.
endform. " SET_RETURN_MESSAGE


Dupa ce se activeaza toate astea, se revine la ZBAPITEST in SWO1,pe change, in meniul Utilities -> API methods ->Add method, aici se pune Z_BAPI_GET_FIELD (o sa dea o avertizare cum ca ar trebui alesi parametri care incep cu BAPI, dar se poate trece de ea), la method se completeaza automat cu ZGetField, la name cu ce vreau, la fel si la descriere.Dupa ce se termina cu wizard-ul, metoda apare in nodul methods, pentru obiectul ZBAPITEST.In continuare se merge in Edit->Change releases status->Object type->To implemented.

Pasii urmatori sunt cei referitori la modificarea status-ului Release:
1. Release pentru BAPI function module (in Function Builder)
2.Release in BOR pentru business object type, adica din meniu ObjectType->Change release status to->Implemented
3. Release pentru metoda din BAPI in BOR, pune cursorul pe metoda, si apoi din Edit->Change release status->Object Type componen->To released.
Dupa toate astea, cu tranzactia BAPI, la filtrare alfabetica, trebuie sa apara cam in coada listei.