GOS TOOLBAR
la_obj TYPE borident.
PARAMETERS: p_kunnr TYPE kna1-kunnr.
*
*
START-OF-SELECTION.
*
* Set object Key
la_obj-objtype = 'KNA1'.
la_obj-objkey = p_kunnr.
*
* GOS toolbar
CREATE OBJECT lo_manager
EXPORTING
is_object = la_obj
ip_no_commit = space
EXCEPTIONS
OTHERS = 1.
*
* To generate output
WRITE: 'GOS test for Customer'.
Generic Object Services (GOS) Attach URL with multiple customer
TABLES : kna1.
SELECTION-SCREEN : BEGIN OF BLOCK sel WITH FRAME TITLE text-001.
SELECT-OPTIONS : p_key FOR kna1-kunnr.
SELECTION-SCREEN : END OF BLOCK sel.
DATA: BEGIN OF itab_wa,
kunnr LIKE kna1-kunnr,
END OF itab_wa.
DATA: itab LIKE itab_wa OCCURS 0 WITH HEADER LINE.
DATA :p_bo TYPE swotentry-objtype.
DATA :p_url TYPE soli .
p_url = 'www.sdn.sap.com'.
p_bo = 'KNA1'.
DATA: lv_object_a TYPE sibflporb,
lv_object_b TYPE sibflporb,
lv_reltyp TYPE mdoblrel-reltype,
lv_folder TYPE soodk,
lv_doc TYPE soodk,
lv_object TYPE sood1,
lv_file TYPE rlgrap-filename,
lv_name TYPE sood-objdes,
lv_type TYPE sood-file_ext,
lv_filename TYPE filep,
lv_fileextn TYPE dappl,
lv_length TYPE i,
lv_offset TYPE i,
lv_full_lines TYPE i,
lv_last_length TYPE i,
lv_tdname LIKE thead-tdname,
lt_tline TYPE TABLE OF tline,
wa_tline TYPE tline,
lt_links TYPE TABLE OF bapi_doc_drad_select,
wa_links TYPE bapi_doc_drad_select,
lv_dktxt TYPE dktxt,
lv_ltxin TYPE ltxin,
it_content TYPE STANDARD TABLE OF soli,
URL_content TYPE STANDARD TABLE OF soli,
wa_content TYPE soli.
DATA : lt_srgbtbrel TYPE srgbtbrel OCCURS 10.
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING
folder_id = lv_folder
EXCEPTIONS
communication_failure = 1
owner_not_exist = 2
system_failure = 3
x_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
lv_object-objla = 'EN'.
lv_object-objnam = 'MESSAGE'.
lv_object-objdes = 'test'.
break developer.
*CONCATENATE '&KEY&' p_url INTO wa_content-line.
APPEND wa_content TO it_content.
PERFORM populate_itab.
CALL FUNCTION 'SO_DOCUMENT_INSERT'
EXPORTING
parent_id = lv_folder
object_hd_change = lv_object
document_type = 'URL'
IMPORTING
document_id = lv_doc
TABLES
objcont_text = it_content
EXCEPTIONS
active_user_not_exist = 1
dl_name_exist = 2
folder_not_exist = 3
folder_no_authorization = 4
object_type_not_exist = 5
operation_no_authorization = 6
owner_not_exist = 7
parameter_error = 8
substitute_not_active = 9
substitute_not_defined = 10
x_error = 11
OTHERS = 12.
IF sy-subrc EQ 0.
LOOP AT itab.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_srgbtbrel
FROM srgbtbrel
WHERE instid_a = itab-kunnr
AND typeid_a = p_bo
AND reltype = 'URL'.
IF LINES( lt_srgbtbrel ) IS INITIAL.
MOVE: itab-kunnr TO lv_object_a-instid,
p_bo TO lv_object_a-typeid,
'BO' TO lv_object_a-catid.
CONCATENATE lv_folder-objtp lv_folder-objyr lv_folder-objno
lv_doc-objtp lv_doc-objyr lv_doc-objno
INTO lv_object_b-instid.
lv_object_b-typeid = 'MESSAGE'.
lv_object_b-catid = 'BO'.
TRY.
CALL METHOD cl_binary_relation=>create_link
EXPORTING
is_object_a = lv_object_a
is_object_b = lv_object_b
ip_reltype = 'URL'.
CATCH cx_obl_parameter_error .
CATCH cx_obl_model_error .
CATCH cx_obl_internal_error .
ENDTRY.
ELSE.
SKIP .
ENDIF.
ENDLOOP.
COMMIT WORK.
REFRESH : itab, it_content.
CLEAR : itab, it_content.
SET SCREEN 0.
ENDIF.
*&---------------------------------------------------------------------*
*& Form POPULATE_ITAB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM populate_itab .
LOOP AT p_key .
IF p_key-sign = 'I'.
IF p_key-option = 'EQ'.
itab_wa-kunnr = p_key-low.
APPEND itab_wa TO itab.
ELSEIF p_key-option = 'BT'.
DO.
itab_wa-kunnr = p_key-low.
APPEND itab_wa TO itab.
IF p_key-low EQ p_key-high.
EXIT.
ELSE.
ENDIF.
ENDDO.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " POPULATE_ITAB
BADI_How to Find it_&implement it
Badi - Bussiness Addins.
Method used for enhancement for standard SAP code. It is advisible not to change existing SAP code which is known as Modification. SAP provides and alternative to this modification which is known as Enhancement. Herein SAP provides points where the user may add his code to be reflected while a standard transaction is run.
Badi uses the concept of object oriented programming. In most of the standard transactions, SAP has provided hooks to add own code via methods of classes.
How to search a Badi ?
1. Goto and enter CL_EXITHANDLER and click on display.
2. Double click on the method _INSTANCE. Set breakpoint on CL_=>GET_CLASS_NAME_ON_INTERFACE. This works for the classic BAdI. In case you want to find the positions where methods of the new BAdI are called, just set a breakpoint on CALL BADI in the programm or class where you search for BAdI calls.
3. Run the transaction for which you want to search the Badi's.
4. Now whenever the method is called, the program goes into debugging mode. Check the value of exit_name (changing parameter),this would give the name of the Badi's.
5. Run the entire transaction and note down all the Badi's.
Some other ways to find out BADI,
→ Buffer trace (ST05) as BADI database tables are buffered. Run transaction and observe the BADI found.
→ SPRO (SAP IMG Reference)
→ SE84 (Repository Information System) → BADI definitions → Package (Development Class) → BADI definition name
Implementing the Badi.
1. Go to to check the defination of the Badi and
2. to implement the Badi.
3. Enter the name of the Badi in the create implementaion section (if you are creating a new implementation - Radiobutton Classic Badi) and click on createImplementaion.
4. Enter the name of the implementation.
5. Double click on the method name and add the code for the implementation.
Following is a Practical scenario.
Use of transaction PA40 to terminate an employee. The requirement is that when we reach the screen where the personel sub area and position have to be filled they should be auto populated with the respective values. Personel sub area should be the same as it was when the employee was first hired and the position should be defaulted to 99999999.
Upon using the above procedure to find the Badi to be used, it was found that the Badi which will be used for this purpose would be "HRPAD00INFTY". The method to be used is BEFORE_.
Upon further investigation it is found that the method is being called twice in the same transaction, so we will have to restrict the Badi to run only on the screen required else it will throw a dump.The screen numberon which we need the Badi to be executed is 2010.Upon check the parameters of the method the available structures are all importing so no value can be assigned to change the value of the screen field at runtime. This makes us to use field symbols as the alternative.
The table PA0001 is where the personel sub area for the hired employee is stored, so we will have to select the sub area from this table for the record who needs to be terminated. Issuing a select statement to find the personel sub area for and employee id (field PERNR) on table PA0001 would be
select single btrtl into sub_area where pernr = innnn-pernr.
Here btrtl is the sub area, sub_area is a user defined variable to store the value of the retrieved data and pernr is the personel number of the employee to be terminated. INNNN is a structure which has the field pernr. This structure is defined as importing in thr parameters so it can be accessed directly.
We know that the value of the subarea and position can not be assigned as they are not part of the exporting parameters in the defined Badi, so we will have t define two field symbols, which will be used to change the value at runtime. Field symbols are similar to pointers in C. They store the address of the variable it is assined to and when any change is made to the field symbol the value of the variable it is referencing is changed. Here we will have to know the program name,stucture and field name on which the changes need to be reflected. We find that the program name (via system->status) and the structure and field name via pressing F1 and clciking on technical information.We found the following for the subarea and postion.For subarea
Screen -
Structure - P0001
Field - BTRTL
For Position
Screen - MP000100
Structure - P0001
Field - PLANS
To access these fields in your program the format used is
Assign ('(screen name)structure name-fieldname') to field symbol.
So the following code would solve the purpose
data : sub_area type pa0001-btrtl.
field-.
select single btrtl from pa0001 into sub_area where pernr = innnn-pernr.
assign ('() to
endif.
TABLE DETAILS RELATED TO THE TRANSACTION CODE
*& Report ZPROG_GET_ALLTABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZPROG_GET_ALLTABLE NO STANDARD PAGE HEADING.
*&---------------------------------------------------------------------*
*& Following are the Text Elements (Selection Texts ) for this program.
* PROG Program Name
* R1 T Code
* R2 Program
* TCODE Transaction Code
* TYPE Table Type
*& Following are the Text Elements (Text Symbols) for this program.
* 001 Type
* 002 Select Any One
*& *
*
***************************** DECLARATIONS **************************
TABLES : TSTC, tstct.
TABLES : DD03l, DD02l.
DATA : Program like sy-repid.
DATA : BEGIN OF I_FINAL OCCURS 0,
tabname LIKE dd02l-tabname,
TABCLASS LIKE dd02l-tabCLASS,
TEXT LIKE DD02T-DDTEXT,
END OF I_FINAL.
DATA : BEGIN of ITAB Occurs 0,
name like dd02l-tabname,
END OF ITAB.
DATA : TCD(100) TYPE C.
DATA : var1 LIKE dd02l-tabname.
DATA : DESC LIKE TSTCT-TTEXT.
****************************** SELECTION SCREEN ************************
selection-screen skip.
SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS : r1 RADIOBUTTON GROUP r DEFAULT 'X'.
Parameters : Tcode like sy-tcode.
selection-screen skip.
PARAMETERS : r2 RADIOBUTTON GROUP r.
Parameters : Prog like sy-repid.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE text-001.
select-options : Type for dd02l-tabclass .
SELECTION-SCREEN END OF BLOCK B1 .
****************************** AT SELECTION SCREEN **********************
at selection-screen.
if r1 = 'X' and Tcode is initial.
message e001(00) with 'Enter Transaction Code' .
elseif r2 = 'X' and Prog is initial.
message e001(00) with 'Enter Program Name' .
endif.
****************************** START OF SELECTION **********************
START-OF-SELECTION.
if r1 = 'X'.
Prog = ' '.
select single * from TSTC where tcode = tcode.
if sy-subrc = 0.
program = TSTC-PGMNA.
select single TTEXT from tstct into desc where tcode = tcode and SPRSL = 'E'.
else.
Write :/ 'Invalid Transaction Code'.
exit.
endif.
elseif r2 = 'X'.
Tcode = ' '.
program = Prog.
endif.
CALL FUNCTION 'GET_TABLES'
EXPORTING
PROGNAME = Program
TABLES
TABLES_TAB = itab.
if itab is initial.
skip.
skip.
skip.
skip.
skip.
WRITE :/40 'No Data Found' color 6 INTENSIFIED OFF.
ELSE.
PERFORM : categorize.
endif.
************************** END OF SELECTION ********************************
END-OF-SELECTION.
LOOP AT I_FINAL.
WRITE :/4 I_FINAL-tabname COLOR 2 INTENSIFIED OFF NO-GAP HOTSPOT ON, 35 I_FINAL-TABCLASS COLOR 2 INTENSIFIED OFF NO-GAP,
50 I_FINAL-TEXT COLOR 2 INTENSIFIED OFF NO-GAP.
ENDLOOP.
************************** AT LINE SELECTION ********************************
AT LINE-SELECTION.
TCD = SY-LISEL.
var1 = TCD+3(30).
set parameter id 'DTB' FIELD VAR1.
call transaction 'SE11' and skip first screen.
************************** TOP OF PAGE ********************************
TOP-OF-PAGE.
WRITE :/45 'TABLE DETAILS RELATED TO THE TRANSACTION CODE' COLOR 7 .
WRITE :/2 'DATE : ' COLOR 1, SY-DATUM COLOR 1 INTENSIFIED OFF NO-GAP.
WRITE :/2 'TRANSACTION CODE : ' COLOR 1, Tcode COLOR 1 INTENSIFIED OFF NO-GAP.
WRITE :/2 'TCODE DESCRIPTION : ' COLOR 1, desc COLOR 1 INTENSIFIED OFF NO-GAP.
WRITE :/2 'PROGRAM NAME : ' COLOR 1, PROGRAM COLOR 1 INTENSIFIED OFF NO-GAP.
SKIP 1.
WRITE :/1(140) SY-ULINE.
WRITE :/4 'TABLE NAME' COLOR 5 INTENSIFIED OFF NO-GAP,35 'TABLE TYPE' COLOR 5 INTENSIFIED OFF NO-GAP,
55 'DESCRIPTION' COLOR 5 INTENSIFIED OFF NO-GAP.
WRITE :/1(140) SY-ULINE.
.
*&---------------------------------------------------------------------*
*& Form categorize
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM categorize .
SELECT dd02l~tabname dd02l~tabCLASS DD02T~DDTEXT
FROM dd02l INNER JOIN DD02T ON dd02l~tabname = dd02T~tabname
INTO TABLE I_FINAL
FOR ALL ENTRIES IN itab
WHERE DD02L~TABNAME = ITAB-NAME AND TABCLASS IN TYPE AND DDLANGUAGE = 'E'.
if sy-subrc <> 0.
skip.
skip.
skip.
skip.
skip.
WRITE :/40 'No Data Found' color 6 INTENSIFIED OFF.
endif.
ENDFORM. " categorize
Download zip file
*& Report Z_PAP_UP_ZIP_DL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_PAP_UP_ZIP_DL.
DATA: L_ZIPPER TYPE REF TO cl_abap_zip.
DATA: FILEX type XSTRING.
DATA: FILENAME type string.
DATA: PATH type string.
DATA: zip type xstring.
DATA: FILE_N_TAB type FILETABLE.
DATA: FULL_PATH type string.
DATA: FILE_LENGTH type i.
DATA: FILE_TAB type w3mimetabtype.
DATA: WA_INT type int4.
DATA: PATH_TABLE TYPE TABLE of char1024.
"-----------------------------------------------------------------------------
" Load the file
"-----------------------------------------------------------------------------
"Which file to upload
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
CHANGING
FILE_TABLE = FILE_N_TAB
RC = WA_INT
.
"load the (first) file from the frontend the user has selected.
LOOP at FILE_N_TAB into FULL_PATH.
"get the file
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
EXPORTING
FILENAME = FULL_PATH
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = FILE_LENGTH
CHANGING
DATA_TAB = file_tab.
exit.
endloop.
"create xstring from table
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
INPUT_LENGTH = FILE_LENGTH
IMPORTING
BUFFER = FILEX
TABLES
BINARY_TAB = file_tab
.
"get the name of the file. we take entry after the last '\' ...windows.
SPLIT FULL_PATH AT '\' INTO TABLE PATH_TABLE.
DESCRIBE TABLE PATH_TABLE LINES WA_INT.
READ TABLE PATH_TABLE INTO FILENAME INDEX WA_INT.
"-------------------------------------------------------------------------------
" ZIP the file
"-------------------------------------------------------------------------------
"create our zipper object
CREATE OBJECT L_ZIPPER.
"add file to zip
CALL METHOD L_ZIPPER->ADD
EXPORTING
NAME = filename
CONTENT = filex
.
"save zip
CALL METHOD L_ZIPPER->SAVE
RECEIVING
ZIP = zip
.
"-------------------------------------------------------------------------------
" Save the file
"-------------------------------------------------------------------------------
"convert to table
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = zip
IMPORTING
OUTPUT_LENGTH = file_length
TABLES
BINARY_TAB = file_tab
.
"File save dialog
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
CHANGING
FILENAME = filename
PATH = path
FULLPATH = full_path
.
"Save the file
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
EXPORTING
BIN_FILESIZE = file_length
FILENAME = full_path
FILETYPE = 'BIN'
CHANGING
DATA_TAB = file_tab
.
ALV-CHECK BOX
TYPE-POOLS: SLIS.
DATA: X_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
L_LAYOUT TYPE SLIS_LAYOUT_ALV,
X_EVENTS TYPE SLIS_ALV_EVENT,
IT_EVENTS TYPE SLIS_T_EVENT.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
CHK(1),
color(4),
END OF ITAB.
SELECT VBELN
POSNR
FROM VBAP
UP TO 20 ROWS
INTO TABLE ITAB.
X_FIELDCAT-FIELDNAME = 'CHK'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 1.
X_FIELDCAT-INPUT = 'X'.
X_FIELDCAT-EDIT = 'X'.
X_FIELDCAT-CHECKBOX = 'X'.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-SELTEXT_L = 'VBELN'.
X_FIELDCAT-HOTSPOT = 'X'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 2.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-SELTEXT_L = 'POSNR'.
X_FIELDCAT-TABNAME = 'ITAB'.
X_FIELDCAT-COL_POS = 3.
APPEND X_FIELDCAT TO IT_FIELDCAT.
CLEAR X_FIELDCAT.
L_LAYOUT-info_fieldname = 'COLOR'.
*L_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = L_LAYOUT
I_CALLBACK_PF_STATUS_SET = 'STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC = 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------
*& Form STATUS
*&---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
*-->P_EXTAB text
*----------------------------------------------------------------------
FORM STATUS USING P_EXTAB TYPE SLIS_T_EXTAB.
*Pf status
SET PF-STATUS 'STATUS'.
ENDFORM. " STATUS
*&---------------------------------------------------------------------
*& Form USER_COMMAND
*&---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
*-->R_UCOMM text
*-->RS_SELFIELD text
*----------------------------------------------------------------------
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA: GD_REPID LIKE SY-REPID, "Exists
REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
IF REF_GRID IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID.
ENDIF.
IF NOT REF_GRID IS INITIAL.
CALL METHOD REF_GRID->CHECK_CHANGED_DATA .
ENDIF.
loop at itab where chk = 'X'.
itab-color = 'C300'.
modify itab index sy-tabix transporting color.
endloop.
RS_SELFIELD-refresh = 'X'.
break-point.
ENDFORM. "USER_COMMAND
BAPI-SALESORDER GETSTATUS
TABLES: vbap. "Sales Document Item Data.
DATA: wa_bapireturn TYPE bapireturn,
wa_bapisdstat TYPE bapisdstat,
it_bapisdstat LIKE STANDARD TABLE OF wa_bapisdstat.
TYPES: BEGIN OF ty_mat_name,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF ty_mat_name.
DATA: wa_mat_name TYPE ty_mat_name,
it_mat_name LIKE TABLE OF wa_mat_name WITH KEY matnr .
PARAMETERS: p_vbeln LIKE vbap-vbeln DEFAULT 5573.
START-OF-SELECTION.
SELECT matnr maktx FROM makt INTO TABLE it_mat_name.
CALL FUNCTION 'BAPI_SALESORDER_GETSTATUS'
EXPORTING
salesdocument = p_vbeln
IMPORTING
return = wa_bapireturn
TABLES
statusinfo = it_bapisdstat.
IF wa_bapireturn IS INITIAL. " Successful Execution.
WRITE: / 'Document No: ' COLOR 1, 20 'PO Number : ', 40 'Status' , 50 'Delv.Stat',60 'Item No', 80 'Material', 90 'Material Description', 130 'Net Price' COLOR 2.
ULINE.
LOOP AT it_bapisdstat INTO wa_bapisdstat.
WRITE: / wa_bapisdstat-doc_number. " Sales Document Number.
READ TABLE it_mat_name INTO wa_mat_name WITH KEY matnr = wa_bapisdstat-material.
WRITE: /20 wa_bapisdstat-purch_no, " Customer Purchase Order Number
40 wa_bapisdstat-prc_stat_h, " Processing Status
50 wa_bapisdstat-dlv_stat_h, " Delivery Status
60 wa_bapisdstat-itm_number, " Item Number
80 wa_bapisdstat-material, " Material
90 wa_mat_name-maktx, " Material Description
130(10) wa_bapisdstat-net_price. " Net Price
CLEAR wa_bapisdstat.
ENDLOOP.
REFRESH it_bapisdstat[].
ELSE.
WRITE: wa_bapireturn-message.
ENDIF.
BAPI-SALES ORDER GETLIST
TABLES : bapi1007,
bapiorders.
DATA : salesorder_itab LIKE bapiorders OCCURS 0 WITH HEADER LINE.
DATA : cust LIKE bapi1007-customer VALUE '0000325120',
sorg LIKE bapiorders-sales_org VALUE '1020'.
CALL FUNCTION 'BAPI_SALESORDER_GETLIST'
EXPORTING
customer_number = cust
sales_organization = sorg
*MATERIAL =
*DOCUMENT_DATE =
*DOCUMENT_DATE_TO =
*PURCHASE_ORDER =
*TRANSACTION_GROUP = 0
*PURCHASE_ORDER_NUMBER =
*IMPORTING
*return = it_return
TABLES
sales_orders = salesorder_itab.
loop at salesorder_itab.
write : salesorder_itab-sd_doc.
endloop.
BAPI-CHANGE SALES ORDER
*----------------------------------------------------------------------
* Selection Screen Definitions *
*----------------------------------------------------------------------
PARAMETERS: p_vbeln TYPE vbap-vbeln OBLIGATORY, "Order Number
p_posnr TYPE vbap-posnr OBLIGATORY, "Order Item
p_etenr TYPE vbep-etenr OBLIGATORY, "Schedule Line
p_reqqty TYPE bapischdl-req_qty OBLIGATORY. " Order Qty
*----------------------------------------------------------------------
* Internal Tables/Structures/Variables for calling BAPI. *
*----------------------------------------------------------------------
DATA: i_hdr TYPE bapisdh1,
i_hdrx TYPE bapisdh1x,
i_ret TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
wa_ret TYPE bapiret2.
DATA: BEGIN OF i_sched OCCURS 10.
INCLUDE STRUCTURE bapischdl.
DATA: END OF i_sched.
DATA: BEGIN OF i_schedx OCCURS 10.
INCLUDE STRUCTURE bapischdlx.
DATA: END OF i_schedx.
*----------------------------------------------------------------------
* START-OF-SELECTION Event *
*----------------------------------------------------------------------
START-OF-SELECTION.
*"----------------------------------------------
*" Initialize internal tables.
*"----------------------------------------------
REFRESH: i_sched, i_schedx, i_ret.
CLEAR: i_sched, i_schedx, i_ret.
*"----------------------------------------------
*" Fill required ORDER_HEADER_IN data.
*"----------------------------------------------
i_hdrx-updateflag = 'U'.
*"----------------------------------------------
*" Fill required SCHEDULE_LINES data.
*"----------------------------------------------
i_sched-itm_number = p_posnr.
i_sched-sched_line = p_etenr.
i_sched-req_qty = p_reqqty.
i_schedx-updateflag = 'U'.
i_schedx-itm_number = p_posnr.
i_schedx-sched_line = p_etenr.
i_schedx-req_qty = 'X'.
APPEND i_sched.
APPEND i_schedx.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_vbeln
order_header_in = i_hdr
order_header_inx = i_hdrx
TABLES
return = i_ret
schedule_lines = i_sched
schedule_linesx = i_schedx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
LOOP AT i_ret.
WRITE / i_ret-message.
ENDLOOP.
BAPI-CREATE SALES ORDER
* Parameters
* Sales document type
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
PARAMETERS: p_auart TYPE auart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Sales organization
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Distribution channel
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Division.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
PARAMETERS: p_spart TYPE spart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SKIP 1.
* Sold-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
PARAMETERS: p_sold TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Ship-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
PARAMETERS: p_ship TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SKIP 1.
* Material
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
PARAMETERS: p_matnr TYPE matnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Quantity.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.
SELECTION-SCREEN END OF LINE.
* Plant
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
PARAMETERS: p_plant TYPE werks_d .
SELECTION-SCREEN END OF LINE.
* Complete Deliver
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text10 FOR FIELD p_autlf.
PARAMETERS: p_autlf TYPE autlf DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
* Data declarations.
DATA: v_vbeln LIKE vbak-vbeln.
DATA: header LIKE bapisdhead1.
DATA: headerx LIKE bapisdhead1x.
DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx
WITH HEADER LINE.
DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl
WITH HEADER LINE.
DATA: lt_schedules_ink TYPE STANDARD TABLE OF bapisdhead1
WITH HEADER LINE.
* Initialization.
INITIALIZATION.
v_text = 'Order type'.
v_text1 = 'Sales Org'.
v_text2 = 'Distribution channel'.
v_text3 = 'Division'.
v_text4 = 'Sold-to'.
v_text5 = 'Ship-to'.
v_text6 = 'Material'.
v_text7 = 'Quantity'.
v_text9 = 'Plant'.
v_text10 = 'Complete delivery'.
* Start-of-selection.
START-OF-SELECTION.
* Header data
* Sales document type
header-doc_type = p_auart.
headerx-doc_type = 'X'.
* Sales organization
header-sales_org = p_vkorg.
headerx-sales_org = 'X'.
* Distribution channel
header-distr_chan = p_vtweg.
headerx-distr_chan = 'X'.
* Division
header-division = p_spart.
headerx-division = 'X'.
headerx-updateflag = 'I'.
*Complete delivery
header-COMPL_DLV = p_autlf.
header-COMPL_DLV = 'X'.
* Partner data
* Sold to
partner-partn_role = 'AG'.
partner-partn_numb = p_sold.
APPEND partner.
* Ship to
partner-partn_role = 'WE'.
partner-partn_numb = p_ship.
APPEND partner.
* ITEM DATA
itemx-updateflag = 'I'.
* Line item number.
item-itm_number = '000010'.
itemx-itm_number = 'X'.
* Material
item-material = p_matnr.
itemx-material = 'X'.
* Plant
item-plant = p_plant.
itemx-plant = 'X'.
* Quantity
item-target_qty = p_menge.
itemx-target_qty = 'X'.
* item category
itemx-ITEM_CATEG = 'X'.
APPEND item.
APPEND itemx.
* ITEM DATA
itemx-updateflag = 'I'.
* Line item number.
item-itm_number = '000020'.
itemx-itm_number = 'X'.
* Material
item-material = p_matnr.
itemx-material = 'X'.
* Plant
item-plant = p_plant.
itemx-plant = 'X'.
* Quantity
item-target_qty = p_menge.
itemx-target_qty = 'X'.
APPEND item.
APPEND itemx.
* Fill schedule lines
lt_schedules_in-itm_number = '000010'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.
* Fill schedule line flags
lt_schedules_inx-itm_number = '000010'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.
* Fill schedule lines
lt_schedules_in-itm_number = '000020'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.
* Fill schedule line flags
lt_schedules_inx-itm_number = '000020'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.
* Call the BAPI to create the sales order.
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = header
sales_header_inx = headerx
IMPORTING
salesdocument_ex = v_vbeln
TABLES
return = return
sales_items_in = item
sales_items_inx = itemx
sales_schedules_in = lt_schedules_in
sales_schedules_inx = lt_schedules_inx
sales_partners = partner.
* Check the return table.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
WRITE: / 'Error in creating document'.
ELSE.
* Commit the work.
COMMIT WORK AND WAIT.
WRITE: / 'Document ', v_vbeln, ' created'.
ENDIF.
