Showing posts 1 - 5 of 11.
View more »
|
Sap Technology >
ABAP DEVELOPMENT
Add text from payment doc to FCHN
This improve version of standard report FCHN add text from payment document line item. For quick modification , I used not used yet field "Name of the payee 4 " (
alv_header-ZNME4
) to store
SGTXT
from
BSAS
. Insert Code: Select SGTXT from BSAS into alv_header-ZNME4
where BUKRS = alv_header-ZBUKR
and BELNR = alv_header-VBLNR
and GJAHR = alv_header-GJAHR.
ENDSELECT.
|
Smartform : Good Issue Note Form
This sample smartform print good issue delivery note base on Material Document. Code to call form: *----------------------------------------------------------------------- * Program Name : ZMRGISL * Description : This program is used to: * : - print document related to goods issue transaction *----------------------------------------------------------------------- * Change History Log *----------------------------------------------------------------------- * Date | Changed by | <<CR#-DEVK# * | Change Requestor | => Description *----------------------------------------------------------------------- * Date Aug 18 2011 * Change by htkhoa * Add form for HCM *----------------------------------------------------------------------- REPORT ZMRGISL MESSAGE-ID zmsg. INCLUDE ZMRGISLFORM. PERFORM show_form. form show_form.
data: OUTPUT_OPTIONS type SSFCOMPOP,
control type SSFCTRLOP. TABLES :
USR01. SELECT SINGLE * FROM USR01 WHERE BNAME = SY-UNAME. "control-device = 'PRINTER'. "control-device = 'LP01'. "OUTPUT_OPTIONS-TDNOPRINT = 'X'. "OUTPUT_OPTIONS-TDIMMED = 'X'.
OUTPUT_OPTIONS-TDDEST = USR01-SPLD.
OUTPUT_OPTIONS-TDNEWID = 'X' . "control-no_dialog = 'X'. Data : version type tdsfname. If HN = 'X' .
version = 'ZSD_DLVNOTE' . ELSEIF NA = 'X' .
version = 'ZSD_DLVNOTE_NA' .
Else.
version = 'ZSD_DLVNOTE_HCM' .
ENDIF.
data: form_name TYPE rs38l_fnam.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING
formname = version IMPORTING
fm_name = form_name EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3. CALL FUNCTION form_name EXPORTING
output_options = output_options
control_parameters = control
user_settings = ' '
p_mblnr = p_mblnr
p_mjahr = p_mjahr TABLES
it_mkpf = it_mkpf
. IF sy-subrc <> 0.
ENDIF.
ENDFORM.
|
ABAP Program to delete mass documents
[Code] BAdi/Enahcement to add custom fields to standard screens
This sample program to find BADI and enhancement for a given transaction code. Create a custom program in your system by cut and paste example below codes.
REPORT ZTEST.
TABLES: TSTC, TADIR, MODSAPT, MODACT, TRDIR, TFDIR, ENLFDIR, SXS_ATTRT , TSTCT.
DATA: JTAB LIKE TADIR OCCURS 0 WITH HEADER LINE. DATA: FIELD1(30). DATA: V_DEVCLASS LIKE TADIR-DEVCLASS.
PARAMETERS: P_TCODE LIKE TSTC-TCODE, P_PGMNA LIKE TSTC-PGMNA .
DATA: WA_TADIR TYPE TADIR.
START-OF-SELECTION.
IF NOT P_TCODE IS INITIAL. SELECT SINGLE * FROM TSTC WHERE TCODE EQ P_TCODE. ELSEIF NOT P_PGMNA IS INITIAL. TSTC-PGMNA = P_PGMNA. ENDIF.
IF SY-SUBRC EQ 0. SELECT SINGLE * FROM TADIR WHERE PGMID = 'R3TR' AND OBJECT = 'PROG' AND OBJ_NAME = TSTC-PGMNA.
MOVE : TADIR-DEVCLASS TO V_DEVCLASS.
IF SY-SUBRC NE 0. SELECT SINGLE * FROM TRDIR WHERE NAME = TSTC-PGMNA.
IF TRDIR-SUBC EQ 'F'. SELECT SINGLE * FROM TFDIR WHERE PNAME = TSTC-PGMNA.
SELECT SINGLE * FROM ENLFDIR WHERE FUNCNAME = TFDIR-FUNCNAME.
SELECT SINGLE * FROM TADIR WHERE PGMID = 'R3TR' AND OBJECT = 'FUGR' AND OBJ_NAME EQ ENLFDIR-AREA.
MOVE : TADIR-DEVCLASS TO V_DEVCLASS. ENDIF. ENDIF.
SELECT * FROM TADIR INTO TABLE JTAB WHERE PGMID = 'R3TR' AND OBJECT in ('SMOD', 'SXSD') AND DEVCLASS = V_DEVCLASS.
SELECT SINGLE * FROM TSTCT WHERE SPRSL EQ SY-LANGU AND TCODE EQ P_TCODE.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF. WRITE:/(19) 'Transaction Code - ', 20(20) P_TCODE, 45(50) TSTCT-TTEXT. SKIP. IF NOT JTAB[] IS INITIAL. WRITE:/(105) SY-ULINE. FORMAT COLOR COL_HEADING INTENSIFIED ON.
sort jtab by OBJECT. data : wf_txt(60) type c, wf_smod type i , wf_badi type i , wf_object2(30) type C. clear : wf_smod, wf_badi , wf_object2.
LOOP AT JTAB into wa_tadir. at first. FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE:/1 SY-VLINE, 2 'Enhancement/ Business Add-in', 41 SY-VLINE , 42 'Description', 105 SY-VLINE. WRITE:/(105) SY-ULINE. endat. clear wf_txt. at new object. if wa_tadir-object = 'SMOD'. wf_object2 = 'Enhancement' . elseif wa_tadir-object = 'SXSD'. wf_object2 = ' Business Add-in'.
endif. FORMAT COLOR COL_GROUP INTENSIFIED ON.
WRITE:/1 SY-VLINE,
2 wf_object2, 105 SY-VLINE. endat.
case wa_tadir-object. when 'SMOD'. wf_smod = wf_smod + 1. SELECT SINGLE MODTEXT into wf_txt FROM MODSAPT WHERE SPRSL = SY-LANGU AND NAME = wa_tadir-OBJ_NAME. FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
when 'SXSD'.
wf_badi = wf_badi + 1 . select single TEXT into wf_txt from SXS_ATTRT where sprsl = sy-langu and EXIT_NAME = wa_tadir-OBJ_NAME. FORMAT COLOR COL_NORMAL INTENSIFIED ON.
endcase.
WRITE:/1 SY-VLINE, 2 wa_tadir-OBJ_NAME hotspot on, 41 SY-VLINE , 42 wf_txt, 105 SY-VLINE. AT END OF object. write : /(105) sy-ULINE. ENDAT.
ENDLOOP.
WRITE:/(105) SY-ULINE.
SKIP. FORMAT COLOR COL_TOTAL INTENSIFIED ON. WRITE:/ 'No.of Exits:' , wf_smod. WRITE:/ 'No.of BADis:' , wf_badi.
ELSE. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(105) 'No userexits or BADis exist'. ENDIF. ELSE. FORMAT COLOR COL_NEGATIVE INTENSIFIED ON. WRITE:/(105) 'Transaction does not exist'. ENDIF.
AT LINE-SELECTION.
data : wf_object type tadir-object. clear wf_object.
GET CURSOR FIELD FIELD1. CHECK FIELD1(8) EQ 'WA_TADIR'. read table jtab with key obj_name = sy-lisel+1(20). move jtab-object to wf_object.
case wf_object. when 'SMOD'. SET PARAMETER ID 'MON' FIELD SY-LISEL+1(10).
CALL TRANSACTION 'SMOD' AND SKIP FIRST SCREEN. when 'SXSD'. SET PARAMETER ID 'EXN' FIELD SY-LISEL+1(20). CALL TRANSACTION 'SE18' AND SKIP FIRST SCREEN. ENDCASE. |
Ways to find a userexit
Application- Specific User Exits (Userexit) SAP Reference IMG -> Sales and Distribution -> System Modifications -> Userexits Customer Exits(SMOD/CMOD) ABAP Workbench -> Utilities -> Enhancements -> Definition (SMOD). Repository Info System (SE84): Enhancements -> Customer Exits -> Enhancements VOFM Routines SAP Reference IMG -> Sales and Distribution -> System Modifications -> Routines Transaction code: VOFM Business Transaction Events SAP Reference IMG -> Financial Accounting -> Financial Accounting Global Settings -> Business Transaction Events (FIBF) Business Event Repository (BERE) Classic BAdIs Repository Info System (SE84):Enhancements -> Business Add-ins -> Definitions Accelerators: Find BAdI: Find the BADI related to your transaction in minutes Enhancement Framework Enhancement Information System in the Object Navigator (transaction SE80). Repository Info System (SE84): Enhancements -> Enhancements Spots Repository Info System (SE84): Enhancements -> Composite Enhancements Spots Accelerators: Find Enhancement Points/Sections: ABAP Ninja Validations and Substitutions exits Transaction code GGB0: Validation Overview Transaction code GBB1: Substitutions Overview Application- Specific User Exits (Userexit) Modification Browser (SE95) Field Exit Report RSMODPRF Customer Exits(SMOD/CMOD) ABAP Workbench -> Utilities -> Enhancements -> Project Management (CMOD). Repository Info System (SE84): Enhancements -> Customer Exits -> Projects VOFM Routines Transaction code: VOFM Modification Browser (SE95) Business Transaction Events SAP Reference IMG -> Financial Accounting -> Financial Accounting Global Settings -> Business Transaction Events (FIBF) Business Event Repository (BERE) Classic BAdIs Repository Info System (SE84): Enhancements -> Business Add-ins -> Implementations Enhancement Framework Enhancement Information System in the Object Navigator (transaction SE80) Repository Info System (SE84): Enhancements -> Enhancements Implementations Repository Info System (SE84): Enhancements -> Composite Enh. Implementations Blogs and Articles How Many Exit Routines are active in your SAP ERP system? SAP User Exits and the People Who Love Them Finding BADI Using SQL Trace (TCODE-ST05) Accelerators ABAP X-it Ray Eye (Scans all the exit routines active in SAP ERP) To find out User Exit's and BADI's for Any Transaction code Find User-exits, BADIs, BTEs, Etc by TCode or Program Best Practices Best Practice for a SAP ECC Consolidation project: filter dependent BAdI to organize the user-exits and enhancements Dangerous Liaisons in User-Exits and How to Avoid Them Dangerous Liaisons in User-Exits - Revisited Relevant SAP Notes 381348 - Using Userexit, Customer Exit, VOFM in SD 842318 - FAQs about validations + substitutions 356737 - Customer name range for VOFM routines 327220 - VOFM function and its objects 29377 - FAQs: Field exits (CMOD) |
SAP ALV grids & lists.
SAP provides two different ways to incorporate SAP ALV into your reports or programs which need to deal with tabular data. They are mentioned below: Using REUSE_ALV_* function modules SAP offers some easy to use function modules using which different kinds of ALV grid can be displayed from your program. These function modules provide a very simplified programming approach to use SAP ALV to display and work with tabular data. All such function modules can be found under the Function group SALV & SLVC_FULLSCREEN in the package (development class) SLIS. These function modules provide an easy & simple to program way of using SAP ALV, but on the other hand compromise with some advanced functionalities and gives lesser flexibility to the programmer. Still, this is the easiest way to program SAP ALV for simple reports and applications where the main purpose of report/ program is to display a tabular result. There are four different forms of SAP ALV exposed through reuse function modules in order to cater different kinds of data display requirements. (A) Simple ALV list This form of ALV is used to display single table display. All the function modules in the above mentioned function group SALV with prefix REUSE_ALV_LIST_ belong to this form of ALV e.g. REUSE_ALV_LIST_DISPLAY, REUSE_ALV_LIST_LAYOUT_INFO_SET, REUSE_ALV_LIST_SELECTIONS_SET etc. This form of ALV outputs a single list on one complete screen. There’s a very limited possibility to control the layout of this output screen. ![]() Simple SAP ALV List (B) Hierarchical sequential ALV list This form of ALV lists is used to display 2 tables of data which form a 2-step hierarchy. The main function module to display this kind of ALV is REUSE_ALV_HIERSEQ_LIST_DISPLAY in function group SALV. There are some more function modules in function group SALV with prefix REUSE_ALV_HS_ belonging to this form of ALV. Typical to REUSE_ALV_* method of using ALV, it has a very limited possibility to control the layout of this output screen. ![]() Hierarchical Sequential ALV List (C) Block ALV List This form of ALV lists is used to display multiple independent tables. All the function modules in above mentioned function group SALV having prefix REUSE_ALV_BLOCK_ belong to this form of ALV. Block ALV list is used to display multiple ALV lists on the same output screen one after another. ![]() Block ALV List (D) ALV Grid This is the new generation of ALV replacing classical list formats mentioned above with grids. It’s used for the purpose similar to simple lists, but overtakes simple lists in terms of better usability, more in-built functionalities and look & feel. All the function modules related to this form of ALV can be found under function group SLVC_FULLSCREEN of package SLIS. ![]() ALV Grid Using ABAP Class CL_GUI_ALV_GRID This method of programming ALV grid runs on Control framework & is based on ABAP Objects. It gives 100% control of programming ALV to the developers. You can use this method to work with ALV similar to other screen elements and also freely add other screen elements on the same screen along with ALV. The main ABAP Class involved in this method is CL_GUI_ALV_GRID.
![]() Multiple ALV Grids & Tree on same screen using CL_GUI_ALV_GRID method I would be explaining important aspects of each of these methods to work with the SAP ALV in detail in my following posts. |
ABAP Sample : Changing Lines
Use the MODIFYstatement. We can use the table key to find and change a single line using its key, or find and change a set of lines that meet a certain condition. If the table has a non-unique key and there are duplicate entries, the first entry is changed. Changing a Line Using the Table KeyTo change a single line, use the following statement: MODIFY TABLE itab FROM wa [TRANSPORTING f1 f2 ...]. The work area wa, which must be compatible with the line type of the internal table, plays a double role in this statement. Not only it is used to find the line that you want to change, but it also contains the new contents. The system searches the internal table for the line whose table key corresponds to the key fields in wa. The system searches for the relevant table types as follows: · Standard tables Linear search, where the runtime is in linear relation to the number of table entries. The first entry found is changed. · Sorted tables Binary search, where the runtime is in logarithmic relation to the number of table entries. The first entry found is changed. · Hashed tables The entry is found using the hash algorithm of the internal table. The runtime is independent of the number of table entries. If a line is found, the contents of the non-key fields of the work area are copied into the corresponding fields of the line, and sy-subrc is set to 0. Otherwise, sy-subrc is set to 4. If the table has a non-unique key and the system finds duplicate entries, it changes the first entry. You can specify the non-key fields that you want to assign to the table line in the TRANSPORTING addition. You can also specify the fields f1 f2 … dynamically using (n1) (n2) … as the contents of a field n1 n2 …. If <ni> is empty when the statement is executed, it is ignored. You can also restrict all fields f1 f2 … to subfields by specifying offset and length. For tables with a complex line structure, the use of the TRANSPORTINGaddition results in better performance, provided the system does not have to transport unnecessary table-like components. Changing Several Lines Using a ConditionTo change one or more lines using a condition, use the following statement: MODIFY itab FROM wa TRANSPORTING f1 f2 ... WHERE cond. This processes all of the lines that meet the logical condition cond. The logical expression cond can consist of more than one comparison. In each comparison, the first operand must be a component of the line structure. If the table lines are not structured, the first operand can also be the expression TABLE_LINE. The comparison then applies to the entire line. If the line type of the internal table contains object reference variables as component comp or if the entire line type is a reference variable, the attributes of the attr object to which the respective line reference points can be specified as comparison values using comp->attr or table_line->attr. The work area wa, which must be compatible with the line type of the internal table, contains the new contents, which in turn will be assigned to the relevant table line using the TRANSPORTING addition. Unlike the above MODIFYstatement, the TRANSPORTING addition is not optional here. Furthermore, you can only modify the key fields of the internal table if it is a standard table. If at least one line is changed, the system sets sy-subrc to 0, otherwise to 4. REPORT demo_int_tables_modify . DATA: BEGIN OF line, DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1. DO 4 TIMES. line-col1 = 2. MODIFY TABLE itab FROM line. LOOP AT itab INTO line. The list output is:
1 1 The program fills a hashed table with a list of square numbers. The MODIFY statement changes the line of the table in which the key field col1 has the value 2. REPORT demo_int_tables_modify_transp. DATA: BEGIN OF line, DATA itab LIKE HASHED TABLE OF line WITH UNIQUE KEY col1. DO 4 TIMES. line-col2 = 100. MODIFY itab FROM line TRANSPORTING col2 LOOP AT itab INTO line. The list output is:
1 1 The program fills a hashed table with a list of square numbers. The MODIFY statement changes the lines of the table where the content of field col2 is greater than 1 and the content of field col1 is less than 4. Changing Table Lines Using the IndexYou can use the MODIFY statement to change lines in tables using their index. There is also an obsolete variant of the WRITE TOstatement that you can use to modify lines in standard tables. Changing Single Lines using MODIFYTo change a line using its index, use the following statement: MODIFY itab FROM wa [INDEX idx] [TRANSPORTING f1 f2... ]. The work area wa specified in the FROM addition replaces the addressed line in the itab table. The work area must be convertible into the line type of the internal table. If you use the INDEX option, the contents of the work area overwrite the contents of the line with the index idx. If the operation is successful, sy-subrc is set to 0. If the internal table contains fewer lines than idx, no line is changed and sy-subrc is set to 4. Without the INDEX addition, you can only use the above statement within a LOOP. In this case, you delete the current line. idx is implicitly set to sy-tabix . When you change lines in sorted tables, remember that you must not change the contents of key fields, and that a runtime error will occur if you try to replace the contents of a key field with another value. However, you can assign the same value. The TRANSPORTING addition allows you to specify the fields that you want to change explicitly in a list. If you change a sorted table, you may only specify non-key fields. REPORT demo_int_tables_modify_ind. DATA: BEGIN OF line, DATA itab LIKE TABLE OF line. DO 3 TIMES. LOOP AT itab INTO line. LOOP AT itab INTO line. This produces the following output:
1
1 1 Here, a sorted table itab is created and filled with three lines. The second line is replaced by the contents of the work area line. REPORT demo_int_tables_modify_ind_ind. DATA name(4) TYPE c VALUE 'col2'. DATA: BEGIN OF line, DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY col1. DO 4 TIMES. line-col2 = 222. line-col1 = 3. LOOP AT itab INTO line. The list output is:
1
1 1 The example fills a sorted table with four lines. In the second and third lines, the component col2 is modified. If the third line were to be changed so that the value of line-col1 was no longer 3, a runtime error would occur, since the key fields of sorted tables may not be changed. |
ABAP Sample Code : Overview of Stock Issue and Receive vs Billed Quatity by Storage Location
REPORT Z_SUM_01 LINE-SIZE 160 LINE-COUNT 44 NO STANDARD PAGE HEADING . INCLUDE Z_SUM_TOP. SET MARGIN 5 5. DATA : BEGIN OF wa_zm01, WERKS TYPE ZM01-WERKS, LGORT TYPE ZM01-LGORT, MATNR TYPE ZM01-MATNR, MBLNR TYPE ZM01-MBLNR, ZEILE TYPE ZM01-ZEILE, BUDAT TYPE ZM01-BUDAT, LGNUM TYPE ZM01-LGNUM, CHARG TYPE ZM01-CHARG, SHKZG TYPE ZM01-SHKZG, MENGE TYPE ZM01-MENGE, END OF wa_zm01. DATA itab_zm01 LIKE SORTED TABLE OF wa_zm01 WITH UNIQUE KEY TABLE LINE." WITH UNIQUE KEY LGORT MBLNR ZEILE. DATA : begin of itab1 occurs 0 , WERKS LIKE MSEG-WERKS, "Plant LGORT LIKE MSEG-LGORT, "Storage MATNR LIKE MSEG-MATNR , "Material v_input LIKE MSEG-MENGE , " Return 602 v_output LIKE MSEG-MENGE , " Issue 601 v_total LIKE MSEG-MENGE , "Net Lot end of itab1 . *DATA : tab1 LIKE STANDARD TABLE OF itab1 INITIAL SIZE 33. SELECTION-SCREEN BEGIN OF BLOCK block1. PARAMETERS: pPlant LIKE MSEG-WERKS obligatory VALUE CHECK, FROMDATE LIKE BSIS-BUDAT obligatory, TODATE LIKE BSIS-BUDAT. SELECTION-SCREEN END OF BLOCK block1. PERFORM WriteHeader. PERFORM Initialize . *Select LGORT MATNR MBLNR ZEILE MENGE From ZM01 INTO CORRESPONDING FIELDS OF TABLE itab_zm01 Select * From ZM01 INTO CORRESPONDING FIELDS OF TABLE itab_zm01 Where WERKS = pPlant AND ( BUDAT GE FROMDATE ) and ( BUDAT LE TODATE ). DATA : t_input LIKE MSEG-MENGE , " Return 602 t_output LIKE MSEG-MENGE . " Issue 601 Loop at itab_zm01 into wa_zm01. AT NEW LGORT. WRITE: / 'Plan:', wa_zm01-LGORT. ULINE. ENDAT. AT NEW MATNR. WRITE: / 'Material:', wa_zm01-MATNR. ENDAT. AT END OF MATNR. itab1-LGORT = wa_zm01-LGORT. itab1-MATNR = wa_zm01-MATNR. t_input = t_input + itab1-v_input. t_output = t_output + itab1-v_output. append itab1. clear itab1. ENDAT. AT END OF LGORT. itab1-LGORT = wa_zm01-LGORT. itab1-MATNR = '********'. itab1-v_output = t_output. itab1-v_input = t_input. append itab1. clear itab1. clear t_input. clear t_output. ENDAT. IF ( wa_zm01-SHKZG = 'H' ). itab1-v_output = itab1-v_output + wa_zm01-MENGE . ELSE. itab1-v_input = itab1-v_input + wa_zm01-MENGE . ENDIF. "WRITE : / wa_zm01-LGORT , wa_zm01-MATNR ,wa_zm01-MBLNR ,wa_zm01-ZEILE,wa_zm01-MENGE. Endloop. Loop at itab1. Write : / itab1-LGORT , itab1-MATNR , itab1-v_input ,itab1-v_output. Endloop. *SELECT * FROM MSEG INTO wa_mseg * WHERE WERKS EQ pPlant ." and ( BUDAT GE FROMDATE ) and ( BUDAT LE TODATE ). * *ENDSELECT. *PERFORM UpdateReport . *PERFORM WriteReport. PERFORM TEST. FORM INITIALIZE . Clear itab_zm01. Clear itab1. ENDFORM. " INITIALIZE *&---------------------------------------------------------------------* *& Form TEST *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM TEST . Loop at itab_zm01 into wa_zm01. Endloop. ENDFORM. " TEST *&---------------------------------------------------------------------* *& Form UPDATEREPORT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM UPDATEREPORT . "Lưu chuyển tiền thuần từ hoạt động kinh doanh ENDFORM. " UPDATEREPORT *&---------------------------------------------------------------------* *& Form WRITEHEADER *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM WRITEHEADER . "FORMAT INTENSIFIED COLOR = 2. WRITE : /5(100) 'SUMMARY OF STOCK AND MONEY' COLOR COL_HEADING INTENSIFIED OFF INVERSE. ULINE. ENDFORM. " WRITEHEADER FORM WRITEREPORT. * FORMAT INTENSIFIED COLOR = 1. WRITE : /5(85) '' ,90(10) '(70)' , 100(30) '' LEFT-JUSTIFIED , 130(30) 0 LEFT-JUSTIFIED. ENDFORM. " WRITEREPORT |
1-10 of 11