Showing posts with label SAMPLE CODES. Show all posts
Showing posts with label SAMPLE CODES. Show all posts

SAP ABAP Syntax for Parameters part Four

SAP ABAP Syntax for parameters were previously discussed in part one, two and three and the present post is in continuation with it.

Addition 13

... FOR TABLE dbtab

Effect

Assigns the database-specific parameter p to the table dbtab . This addition only makes sense in a logical database access program.

With database-specific parameters, you need this addition to ensure that the selection screen for a report contains only database-specific parameters which belong to a table from the currently active report.

Addition 14

... AS MATCHCODE STRUCTURE

Effect

Creates the database-specific parameter p as a field string according to the Dictionary structure MCPARAMS with the fields MCID (matchcode ID ) and STRING (search string ). Used for data selection through matchcode entry. On the selection screen, both sub-fields are displayed in a box with the text "Matchcode selection".

You can get a list of possible entries for the matchcode ID and the search string by pressing F4 . If you choose a matchcode ID and press F4 in the field "Search string", you see a dialog box where you can enter a search criterion for each field of the matchcode ID. The system interprets what you enter generically for each sub-field.

The addition AS MATCHCODE STRUCTURE only makes sense in a logical database access program and must therefore be used together with the addition FOR TABLE . It can also be combined with the addition MODIF ID , but not with any other additions. The matchcode object to which the matchcode ID and the search string refer is determined when you define the logical database.

Example

Input on the selection screen:

Matchcode ID: Customers Search string: Daniel

The effect of this is to select all customers whose names begin with "Daniel".

Performance

Matchcode selection can improve program performance considerably. This is because specifying a search string often describes the required set of data records more accurately than the key fields of the table. For example, it is easier to select by name ("Daniel") than by customer number ("000043010") and far fewer records are read from the database.

If a logical database (e.g. ldb ) contains a parameter p defined with AS MATCHCODE STRUCTURE , the system always creates an internal table ldb_MC which includes all the key fields of the selected records. The structure of ldb_MC is determined by the matchcode object and generated automatically. In the maintenance transaction for logical databases, the structure is displayed as a comment in the database program.

Example

Matchcode object for table T1 with key field T1-K1 . The table ldb_MC then has the following structure:

DATA: BEGIN OF ldb_MC OCCURS 100,
T1_K1 LIKE T1-K1,
END OF ldb_MC.

If the user has entered values in the matchcode parameter fields, the program reads the selected data from the matchcode table after START-OF-SELECTION and makes it available to the logical database program in the internal table ldb_MC . Then, the database program processes the records in the subroutine PUT_ldb_MATCHCODE and, with the help of PUT , triggers the appropriate GET events in the report. Subsequent processing is exactly the same as that for data selection direct from the database.


Example

FORM PUT_ldb_MATCHCODE.
SELECT * FROM T1
WHERE K1 = ldb_MC-T1_K1
FOR ALL ENTRIES IN ldb_MC.
PUT T1.
ENDSELECT.
ENDFORM.

In matchcode selection, the system flags all fields in the internal table MC_FIELDS which are filled with values by the matchcode (the field name is in MC_FIELDS-FIELDNAME and the flag is in MC_FIELDS-SUPPLIED ).

Example

A field F0 is supplied with a value by the matchcode if the following condition is satisfied:

IF MC_FIELDS-FIELDNAME EQ 'F0'
AND MC_FIELDS-SUPPLIED NE SPACE.

ABAP TOPIC WISE COMPLETE COURSE

BDC
OOPS ABAP
ALE
IDOC'S
BADI
BAPI
Syntax Check
Interview Questions
ALV Reports with sample code
ABAP complete course
ABAP Dictionary
SAP Scripts
Script Controls
Smart Forms
Work Flow
Work Flow MM
Work Flow SD
Communication Interface

OTHER PROGRAMMING COURSES:

Dot Net Complete Course Part one and two
ASP.NET part one and

SAP ABAP Syntax for Parameters part two

SAP ABAP Syntax for parameters is the previous post and this is in continuation with that.

Addition 4

... LIKE g

Effect

Creates the field p with the same attributes as the field g which is already defined. g can be either a database field or an existing internal field.

You cannot use the addition ... LIKE g with the addition ... TYPE typ . No explicit length may be specified for the parameter (for example, a statement such as PARAMETERS p(len) LIKE g is not allowed).

Example

PARAMETERS PROGRAM LIKE SY-REPID.

If g is an ABAP/4 Dictionary field of the type CHAR , length 1 and default values 'X' and ' ' (according to the relevant domain), the parameter is always displayed as a checkbox on the selection screen (see also AS CHECKBOX ).

Field attributes on the selection screen:

The input/output field which appears on the selection screen for the parameter has the attributes of the field g specified after LIKE . These include type, length or - with ABAP/4 Dictionary fields - conversion exit .

If g is an ABAP/4 Dictionary field, the selection screen is automatically regenerated after most field attribute changes. An excception to this rule are the attributes "Check table" and "Fixed values". If these change, you must generate the program in the ABAP/4 Development Workbench. This also generates the selection screen.

The maximum permitted length of a parameter on the selection screen is 45 (scrollable up to length 132). If you have defined it longer than this (either explicitly with p(200) or implicitly with LIKE ), the parameter is truncated on the selection screen after the 132nd character. However, you can use SUBMIT to pass longer parameters to a report (particularly if these are not displayed on the selection screen at all because of the addition NO-DISPLAY ).

Addition 5

... MEMORY ID pid

Effect

On the selection screen, assigns the memory ID pid to the parameter, i.e. when you execute the report, the selection screen displays the last value which the user entered in a field with the memory ID pid .

The memory ID must be a constant, i.e. a value specified without quotation marks, and can be up to 3 characters long.

Addition 6

... MATCHCODE OBJECT mobj

Effect

On the selection screen, assigns the matchcode object mobj to the parameter.

The name of the matchcode object must be a constant, i.e. a value specified without quotation marks, and can be up to 4 characters long.

Addition 7

... MODIF ID key

Effect

The screen fields contain the specified modification group ( SCREEN-GROUP1 ) which you can use for screen modifications (e.g. set to "not ready for input") under AT SELECTION-SCREEN .

The name of the modification group must be a constant, i.e. a value specified without quotation marks, and can be up to 3 characters long.

Example

PARAMETERS CHARLY MODIF ID ABC.
...
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'ABC'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
...

Effect

The parameter is not ready for input on the selection screen.

ABAP TOPIC WISE COMPLETE COURSE

BDC
OOPS ABAP
ALE
IDOC'S
BADI
BAPI
Syntax Check
Interview Questions
ALV Reports with sample code
ABAP complete course
ABAP Dictionary
SAP Scripts
Script Controls
Smart Forms
Work Flow
Work Flow MM
Work Flow SD
Communication Interface

Sample code to send mail from SAP

A sample program to send mail from SAP to Outlook with a text on body not at attachment.











report zh_email1.
data: email type somlreci1-receiver value ''.
data: sender type soextreci1-receiver value 'SAPDEV02'.

data: imessage type standard table of solisti1 with header line,
iattach type standard table of solisti1 with header line,
ipacking_list like sopcklsti1 occurs 0 with header line,
ireceivers like somlreci1 occurs 0 with header line.

start-of-selection.

clear imessage. refresh imessage.
imessage = 'This is a mail from SAP ECC6'.
append imessage.
imessage = 'Thanks and Regards'.
append imessage.
imessage = 'xyzabax'.
append imessage.

perform send_email tables imessage
using email
'Mail from xyzbax'.

**************************************************************
*

* Form SEND_EMAIL

**************************************************************
*
form send_email tables pit_message
using email
p_mtitle.

data: xdocdata like sodocchgi1,
xcnt type i.

* Fill the document data.

xdocdata-doc_size = 1.

* Populate the subject/generic message attributes

xdocdata-obj_langu = sy-langu .
xdocdata-obj_name = 'SAPRPT' .
xdocdata-obj_descr = p_mtitle .


clear ipacking_list. refresh ipacking_list.
ipacking_list-transf_bin = space.
ipacking_list-head_start = 1.
ipacking_list-head_num = 0.
ipacking_list-body_start = 1.
describe table imessage lines ipacking_list-body_num.
ipacking_list-doc_type = 'RAW'.
append ipacking_list.


clear ireceivers.
refresh ireceivers.
ireceivers-receiver = email.
ireceivers-rec_type = 'U'.

append ireceivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = xdocdata
put_in_outbox = 'X'
sender_address = sender
commit_work = 'X'
tables
packing_list = ipacking_list
contents_txt = imessage
receivers = ireceivers
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.


*** These two statemnets are used to force the
mail to send it to the
*receipeint otherwise we need to go to SOST
tcode where we need to press
* F8 to send the mail to the other user.
To avoid this we need to use
*these two statemnets. Here the mail is not in queue.

submit rsconn01 using selection-set 'INT' and return.
call function 'SO_DEQUEUE_UPDATE_LOCKS'.
* SUBMIT rsconn01 WITH mode = 'INT'
* WITH output = 'X'
* AND RETURN.

endform.

Sample code for CS_BOM_EXPL_MAT_V2

TABLES: mard,stpo,stko,tc04,t024d,marc,ekbe,mara,ekko,makt.

DATA : capid LIKE tc04-capid,
datuv LIKE stko-datuv,
emeng LIKE stko-bmeng,
mehrs LIKE csdata-xfeld,
mtnrv LIKE mara-matnr,
stlal LIKE stko-stlal,
stpst LIKE stpox-stufe,
werks LIKE marc-werks.
DATA : istb LIKE stpox OCCURS 0 WITH HEADER LINE.

DATA : BEGIN OF ibod OCCURS 0,
stufe LIKE stpox-stufe,
idnrk LIKE stpox-idnrk,
bismt LIKE mara-bismt,
ojtxp LIKE stpox-ojtxp,
menge LIKE stpox-menge,
meins LIKE stpox-meins,
mnglg LIKE stpox-mnglg,
meins1 LIKE stpox-meins,
*lgort LIKE mard-lgort,
*labst LIKE mard-labst,
*insme LIKE mard-insme,
*umlme LIKE mard-umlme,
wesbs LIKE ekbe-wesbs,
dispo LIKE marc-dispo,
dsnam LIKE t024d-dsnam,
END OF ibod.

DATA : BEGIN OF imara OCCURS 0,
matnr LIKE mara-matnr,
bismt LIKE mara-bismt,
meins LIKE mara-meins,
END OF imara.

DATA: BEGIN OF idis OCCURS 0,
matnr LIKE marc-matnr,
dispo LIKE marc-dispo,
dsnam LIKE t024d-dsnam,
END OF idis.

DATA: BEGIN OF xtab2 OCCURS 10,
werks LIKE ekpo-werks,
matnr LIKE ekpo-matnr,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
wesbs LIKE ekbe-wesbs,
wesb2 LIKE ekbe-wesbs,
meinh LIKE ekpo-meins,
END OF xtab2.
DATA : total LIKE ekbe-wesbs.
*data: begin of i_werks occurs 0,

  • werks like marc-werks,
  • end of i_werks.

RANGES : i_werks FOR marc-werks.

DATA : BEGIN OF imard OCCURS 0,
matnr LIKE mard-matnr,
werks LIKE mard-werks,
lgort LIKE mard-lgort,
labst LIKE mard-labst,
insme LIKE mard-insme,
umlme LIKE mard-umlme,
END OF imard.

DATA : labst LIKE mard-labst,
insme LIKE mard-insme,
umlme LIKE mard-umlme.


SELECTION-SCREEN BEGIN OF BLOCK v1 WITH FRAME TITLE text-001.
PARAMETERS : p_werks LIKE marc-werks OBLIGATORY ,
p_mtnrv LIKE mara-matnr OBLIGATORY ,
p_stlal LIKE stko-stlal OBLIGATORY,
p_emeng LIKE stko-bmeng OBLIGATORY,
p_stpst LIKE stpox-stufe.
SELECTION-SCREEN END OF BLOCK v1.

capid = 'PP01'.
datuv = sy-datum.
emeng = p_emeng.
mehrs = 'X'.
mtnrv = p_mtnrv.
stlal = p_stlal.
stpst = p_stpst.
werks = p_werks.
i_werks-low = werks.
i_werks-sign = 'I'.
i_werks-option = 'EQ'.
APPEND i_werks.
CLEAR i_werks.
*skip.
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING

  • FTREL = ' '
  • ALEKZ = ' '
  • ALTVO = ' '
  • AUFSW = ' '
  • AUMGB = ' '
  • AUMNG = 0
  • AUSKZ = ' '
  • AMIND = ' '
  • BAGRP = ' '
  • BEIKZ = ' '
  • BESSL = ' '
  • BGIXO = ' '
  • BREMS = ' '
capid = capid
  • CHLST = ' '
  • COSPR = ' '
  • CUOBJ = 000000000000000
  • CUOVS = 0
  • CUOLS = ' '
datuv = datuv
  • DELNL = ' '
  • DRLDT = ' '
  • EHNDL = ' '
emeng = emeng
  • ERSKZ = ' '
  • ERSSL = ' '
  • FBSTP = ' '
  • KNFBA = ' '
  • KSBVO = ' '
  • MBWLS = ' '
  • MKTLS = 'X'
  • MDMPS = ' '
mehrs = mehrs
  • MKMAT = ' '
  • MMAPS = ' '
  • SALWW = ' '
  • SPLWW = ' '
  • MMORY = ' '
mtnrv = mtnrv
  • NLINK = ' '
  • POSTP = ' '
  • RNDKZ = ' '
  • RVREL = ' '
  • SANFR = ' '
  • SANIN = ' '
  • SANKA = ' '
  • SANKO = ' '
  • SANVS = ' '
  • SCHGT = ' '
  • STKKZ = ' '
stlal = stlal
  • STLAN = ' '
stpst = stpst
  • SVWVO = 'X'
werks = werks
  • NORVL = ' '
  • MDNOT = ' '
  • PANOT = ' '
  • QVERW = ' '
  • VERID = ' '
  • VRSVO = 'X'
  • IMPORTING
  • TOPMAT =
  • DSTST =
TABLES
stb = istb
  • MATCAT =
  • EXCEPTIONS
  • ALT_NOT_FOUND = 1
  • CALL_INVALID = 2
  • MATERIAL_NOT_FOUND = 3
  • MISSING_AUTHORIZATION = 4
  • NO_BOM_FOUND = 5
  • NO_PLANT_DATA = 6
  • NO_SUITABLE_BOM_FOUND = 7
  • CONVERSION_ERROR = 8
  • OTHERS = 9
.
IF sy-subrc 0.
  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT istb.
IF istb-postp = 'L'.
ibod-stufe = istb-stufe.
ibod-idnrk = istb-idnrk.
ibod-ojtxp = istb-ojtxp.
ibod-menge = istb-menge.
ibod-meins = istb-meins.
ibod-mnglg = istb-mnglg.
APPEND ibod.
CLEAR ibod.
ENDIF.
ENDLOOP.

SELECT matnr bismt meins INTO TABLE imara FROM mara FOR ALL ENTRIES IN ibod
WHERE matnr = ibod-idnrk.
SELECT a~matnr a~dispo b~dsnam INTO TABLE idis FROM marc AS a INNER JOIN t024d AS b
ON a~dispo = b~dispo FOR ALL ENTRIES IN ibod WHERE matnr = ibod-idnrk.

SELECT matnr werks lgort labst insme umlme INTO TABLE imard FROM mard
FOR ALL ENTRIES IN ibod WHERE matnr = ibod-idnrk AND werks EQ p_werks
.
LOOP AT ibod.
READ TABLE imara WITH KEY matnr = ibod-idnrk.
IF sy-subrc EQ 0.
ibod-bismt = imara-bismt.
ibod-meins1 = imara-meins.
ENDIF.
READ TABLE idis WITH KEY matnr = ibod-idnrk.
IF sy-subrc EQ 0.
ibod-dispo = idis-dispo.
ibod-dsnam = idis-dsnam.
ENDIF.
CALL FUNCTION 'MB_SELECT_GR_BLOCKED_STOCK'
EXPORTING
  • X_KZVBR = ' '
x_matnr = ibod-idnrk
x_meins = ibod-meins
  • X_KZWSO = ' '
  • X_NOVBR = ' '
TABLES
xtab2 = xtab2
xwerks = i_werks
.

LOOP AT xtab2.

total = total + xtab2-wesbs.

ENDLOOP.
ibod-wesbs = total.
CLEAR xtab2[].
MODIFY ibod.
CLEAR : ibod,imara,idis,total,xtab2.
ENDLOOP.
CLEAR imard.
LOOP AT ibod.
WRITE :/03 sy-tabix LEFT-JUSTIFIED,12 ibod-stufe LEFT-JUSTIFIED,
18 ibod-idnrk LEFT-JUSTIFIED,37 ibod-bismt LEFT-JUSTIFIED ,57 ibod-ojtxp ,
99 ibod-menge LEFT-JUSTIFIED ,118 ibod-meins, 123 ibod-mnglg LEFT-JUSTIFIED,
142 ibod-meins1, 149 ibod-dispo, 157 ibod-dsnam.
WRITE :/10 sy-uline(90) .
WRITE :/10 '|',11 'Stg Loc',18 '|', 19 'Unres Use Stk',37 '|',39 'QAI Stk ',58 '|', 59 'Trans Loc Stk',
78 '|',79 'GR Blck Stk' , 99 '|'.
WRITE :/10 sy-uline(90) .
LOOP AT imard WHERE matnr EQ ibod-idnrk.
IF imard-labst GT 0 OR imard-insme GT 0 OR imard-umlme GT 0.
WRITE :/10 '|', 11 imard-lgort,18 '|', 19 imard-labst LEFT-JUSTIFIED ,37 '|',
39 imard-insme LEFT-JUSTIFIED,58 '|', 59 imard-umlme LEFT-JUSTIFIED,78 '|', 99 '|'.
ENDIF.
labst = labst + imard-labst.
insme = insme + imard-insme.
umlme = umlme + imard-umlme.
ENDLOOP.
WRITE :/10 sy-uline(90) .
WRITE :/10 '|', 11 'Total',18 '|', 19 labst LEFT-JUSTIFIED ,37 '|',39 insme LEFT-JUSTIFIED,
58 '|', 59 umlme LEFT-JUSTIFIED,78 '|',79 ibod-wesbs LEFT-JUSTIFIED, 99 '|'.
CLEAR: labst,insme,umlme,ibod-wesbs.
WRITE :/10 sy-uline(90) .
ENDLOOP.
ULINE.

TOP-OF-PAGE.
Select single maktx from makt into makt-maktx where matnr eq p_mtnrv.
WRITE :/40 'Bill Of Material - Stock Position'.
WRITE :/40 '*********************************'.
WRITE:/.
WRITE:/01 'Product Code : ', mtnrv,30 '(',makt-maktx,')', 'Plant : ',werks, 100 'Alternative BOM : ',stlal,125 'Req Qty : ',
emeng,160 'Level : ' , stpst.
ULINE.
WRITE:/ '|', 'Sl.No',9 '|',11 'Level','|', 23 'Item Code',36 '|',41 'Old Code',56 '|' ,
70 'Description',98 '|',104 'BOM Qty ',117 '|', 118 'UOM', 122 '|', 127 'Need Qty', 140 '|',
141 'UOM' ,146 '|',147 'MRP Code' ,156 '|', 160 'MRP Con Name',175 '|'.
*write:/ '|', 'No',6 '|'.

RELATED POST

ELIMINATION OF DUPLICATE ENTRIES IN INTERNAL TABLE SAMPLE CODE
EVENTS IN LISTs syntax for sap abap

EVENTS IN LISTS PART TWO syntax for sap abap

EVENTS ON SELECTION SCREEN PART ONE syntax for sap abap

EVENTS ON SELECTION SCREEN PART TWO syntax for sap abap

AUTHORITY CHECK syntax for sap abap