Posted: Wed Sep 19, 2007 6:22 pm Post subject: Create and include a Program in a Transport request
Code:
REPORT zbctrans LINE-SIZE 128 NO STANDARD PAGE HEADING.
* Data definition
TABLES: trdir, t002, e070, e071, e07t.
DATA: BEGIN OF itab OCCURS 0,
prog LIKE rs38m-programm,
text LIKE rs38m-repti,
END OF itab.
DATA: BEGIN OF iout OCCURS 0,
prog LIKE rs38m-programm,
END OF iout.
DATA: BEGIN OF itext OCCURS 200.
INCLUDE STRUCTURE textpool.
DATA: END OF itext.
* Table for the tasks created.
DATA: BEGIN OF tasks OCCURS 1.
INCLUDE STRUCTURE e070.
DATA: END OF tasks.
* Table for the objects to insert in the order.
DATA: BEGIN OF t_e071 OCCURS 0.
INCLUDE STRUCTURE e071.
DATA: END OF t_e071.
DATA: BEGIN OF t_e071k OCCURS 0.
INCLUDE STRUCTURE e071k.
DATA: END OF t_e071k.
* Variables
DATA: answer,
l_checkbox,
l_prog LIKE rs38m-programm,
ew_order LIKE e070,
ev_order LIKE e070-trkorr,
ev_task LIKE e070-trkorr,
v_subrc LIKE sy-subrc,
color,
checkbox.
* Selection screen.
SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.
SELECT-OPTIONS: reps FOR trdir-name,
lang FOR t002-spras NO-EXTENSION NO INTERVALS
OBLIGATORY.
SELECTION-SCREEN END OF BLOCK 001.
* User input.
AT USER-COMMAND.
CASE sy-ucomm.
* Create request.
WHEN 'REQ'.
PERFORM confirm USING text-005 text-006.
IF answer = 'J'.
PERFORM choice.
PERFORM request.
IF sy-subrc = 0.
PERFORM ok.
ELSE.
v_subrc = sy-subrc.
PERFORM error.
ENDIF.
ENDIF.
* Select all.
WHEN 'SEL'.
PERFORM select.
* Unselect all.
WHEN 'UNS'.
PERFORM unselect.
ENDCASE.
* Process.
START-OF-SELECTION.
* Warning if the user tries to select standard programs.
READ TABLE reps INDEX 1.
IF reps-low(1) NE 'Z'.
PERFORM confirm USING text-003 text-004.
ENDIF.
IF answer = 'J' OR reps-low(1) = 'Z'.
* We place the list of programs in the internal table.
SELECT * FROM trdir WHERE name IN reps.
MOVE trdir-name TO itab-prog.
APPEND itab. CLEAR itab.
ENDSELECT.
READ TABLE lang INDEX 1.
LOOP AT itab.
READ TEXTPOOL itab-prog LANGUAGE lang-low INTO itext.
LOOP AT itext WHERE id = 'R'.
itab-text = itext-entry.
MODIFY itab. CLEAR itab.
EXIT.
ENDLOOP.
REFRESH itext. CLEAR itext.
ENDLOOP.
* List output.
SET PF-STATUS 'LIST'.
ULINE.
FORMAT COLOR 1 INTENSIFIED ON.
WRITE: / sy-vline,
4 text-010,
15 text-011,
128 sy-vline.
ULINE.
LOOP AT itab WHERE NOT text IS INITIAL.
IF color = 'X'.
CLEAR color.
FORMAT COLOR 2 INTENSIFIED OFF.
ELSE.
color = 'X'.
FORMAT COLOR 2 INTENSIFIED ON.
ENDIF.
WRITE: / sy-vline,
2 checkbox AS CHECKBOX,
4 itab-prog,
15 itab-text,
128 sy-vline.
ENDLOOP.
IF sy-subrc NE 0.
FORMAT COLOR 6 INTENSIFIED OFF.
WRITE: / sy-vline, 4 text-012, 128 sy-vline.
ENDIF.
ULINE.
ENDIF.
*---------------------------------------------------------------------*
* FORM SELECT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM select.
DO.
READ LINE sy-index FIELD VALUE checkbox.
IF sy-subrc NE 0.
EXIT.
ENDIF.
MODIFY CURRENT LINE FIELD VALUE checkbox FROM 'X'.
ENDDO.
ENDFORM. "SELECT
*---------------------------------------------------------------------*
* FORM UNSELECT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM unselect.
DO.
READ LINE sy-index FIELD VALUE checkbox.
IF sy-subrc NE 0.
EXIT.
ENDIF.
MODIFY CURRENT LINE FIELD VALUE checkbox FROM ' '.
ENDDO.
ENDFORM. "UNSELECT
*---------------------------------------------------------------------*
* FORM CHOICE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM choice.
REFRESH iout. CLEAR iout.
DO.
CLEAR: l_checkbox, l_prog.
READ LINE sy-index FIELD VALUE checkbox INTO l_checkbox
itab-prog INTO l_prog.
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF l_checkbox = 'X'.
MOVE l_prog TO iout-prog.
APPEND iout. CLEAR iout.
ENDIF.
ENDDO.
ENDFORM. "CHOICE
*---------------------------------------------------------------------*
* FORM REQUEST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM request.
* First we create the order.
CALL FUNCTION 'TR_ORDER_CREATE'
EXPORTING
iv_start_column = 1
iv_start_row = 8
iv_client = sy-mandt
iv_new_order_type = 'A'
iv_new_task_type = 'X'
iv_category = 'SYST'
IMPORTING
ew_order = ew_order
ev_order = ev_order
ev_task = ev_task
TABLES
tt_tasks = tasks
EXCEPTIONS
no_authorization = 1
OTHERS = 2.
* Set the order as transportable...
ew_order-trfunction = 'K'.
CALL FUNCTION 'TRINT_CHANGE_OF_ATTRIBUTES'
EXPORTING
is_e070 = ew_order
EXCEPTIONS
change_error = 1
e070_update_error = 2
e070_not_filled = 3
OTHERS = 4.
* ...and the task.
READ TABLE tasks INDEX 1.
tasks-trfunction = 'S'.
CALL FUNCTION 'TRINT_CHANGE_OF_ATTRIBUTES'
EXPORTING
is_e070 = tasks
EXCEPTIONS
change_error = 1
e070_update_error = 2
e070_not_filled = 3
OTHERS = 4.
* Include the programs in the transference table.
LOOP AT iout.
MOVE: tasks-trkorr TO t_e071-trkorr,
'999999' TO t_e071-as4pos,
'LIMU' TO t_e071-pgmid,
'REPT' TO t_e071-object,
iout-prog TO t_e071-obj_name.
APPEND t_e071. CLEAR t_e071.
ENDLOOP.
* Insert the objects.
SELECT SINGLE * FROM e070 WHERE trkorr = tasks-trkorr.
SELECT SINGLE * FROM e07t WHERE trkorr = tasks-trkorr.
CALL FUNCTION 'TRINT_MODIFY_COMM'
EXPORTING
wi_called_by_editor = ' '
wi_e070 = e070
wi_e07t = e07t
wi_lock_sort_flag = 'X'
wi_save_user = ' '
wi_sel_e071 = 'X'
wi_sel_e071k = ' '
wi_sel_e07t = ' '
TABLES
wt_e071 = t_e071
wt_e071k = t_e071k
EXCEPTIONS
chosen_project_closed = 1
e070_insert_error = 2
e070_update_error = 3
e071k_insert_error = 4
e071k_update_error = 5
e071_insert_error = 6
e071_update_error = 7
e07t_insert_error = 8
e07t_update_error = 9
locked_entries = 10
locked_object_not_deleted = 11
ordername_forbidden = 12
order_change_but_locked_object = 13
order_released = 14
order_user_locked = 15
tr_check_keysyntax_error = 16
no_authorization = 17
e070c_insert_error = 18
e070c_update_error = 19
wrong_client = 20
unallowed_source_client = 21
unallowed_user = 22
OTHERS = 23.
ENDFORM. "REQUEST
*---------------------------------------------------------------------*
* FORM ok *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM ok.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-007
txt1 = text-008
txt2 = ' '.
ENDFORM. "ok
*---------------------------------------------------------------------*
* FORM error *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM error.
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = text-007
txt1 = text-009
txt2 = v_subrc.
ENDFORM. "error
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.