0% found this document useful (0 votes)
111 views9 pages

Z PP PRD Ord

This program module handles the processing and display of production order documents. It retrieves production order data from the database, converts it to PDF format, loads it into an HTML viewer control for display, and provides functionality to download attachments. User input is handled to navigate between screens and transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views9 pages

Z PP PRD Ord

This program module handles the processing and display of production order documents. It retrieves production order data from the database, converts it to PDF format, loads it into an HTML viewer control for display, and provides functionality to download attachments. User input is handled to navigate between screens and transactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

*&---------------------------------------------------------------------*

*& Module Pool Z_PP_PRD_ORD


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

PROGRAM z_pp_prd_ord.
TABLES:aufk.
FIELD-SYMBOLS <fs_x> TYPE x.
DATA : l_job_output_info TYPE ssfcrescl.
DATA : ls_control_param TYPE ssfctrlop.
DATA : g_html_container TYPE REF TO cl_gui_custom_container,
g_html_control TYPE REF TO cl_gui_html_viewer,
v_fm_name TYPE rs38l_fnam,
pdf_fsize TYPE i.
DATA: lt_pdf TYPE TABLE OF tline,
ls_pdf LIKE LINE OF lt_pdf,
lv_content TYPE xstring,
lt_data TYPE STANDARD TABLE OF x255,
lv_url TYPE char255.
CONSTANTS : c_formname TYPE tdsfname VALUE 'Z_PP_PRD_ORDER'.

DATA lv_prueflos TYPE qals-prueflos.


*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
IF sy-ucomm NE 'BACK'.
SET PF-STATUS 'MAIN'.
* SET TITLEBAR 'xxx'.
CLEAR:aufk-aufnr ,l_job_output_info.
ELSE.
SET SCREEN 0.
LEAVE SCREEN.
ENDIF.
ENDMODULE. " STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
SET SCREEN 0.
LEAVE SCREEN ."0.
* exit.
WHEN 'CANCEL'.
* LEAVE PROGRAM.
EXIT.
WHEN 'EXIT'.
* LEAVE PROGRAM.
EXIT.
WHEN 'PRNT'.
PERFORM dwn_atta.
PERFORM fetch_data.
CALL SCREEN '9002'.
WHEN OTHERS.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fetch_data .
ls_control_param-getotf = 'X'.
ls_control_param-no_dialog = 'X'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = c_formname
IMPORTING
fm_name = v_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc EQ 0.
CALL FUNCTION v_fm_name
EXPORTING
control_parameters = ls_control_param
number = aufk-aufnr
IMPORTING
job_output_info = l_job_output_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc EQ 0.
CLEAR:lt_pdf[],pdf_fsize,ls_pdf,lv_content.
CALL METHOD cl_gui_cfw=>flush.
UNASSIGN <fs_x>.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
IMPORTING
bin_filesize = pdf_fsize
TABLES
otf = l_job_output_info-otfdata
lines = lt_pdf
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
* convert pdf to xstring string
LOOP AT lt_pdf INTO ls_pdf.
ASSIGN ls_pdf TO <fs_x> CASTING.
CONCATENATE lv_content <fs_x> INTO lv_content IN BYTE MODE.
ENDLOOP.

ENDIF.
ENDIF.
ENDFORM. " FETCH_DATA
*&---------------------------------------------------------------------*
*& Module STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9002 OUTPUT.
IF sy-ucomm NE 'BACK'.
DATA:g_dock TYPE REF TO cl_gui_docking_container.
CLEAR:lt_data[],lv_url,g_html_container.
SET PF-STATUS 'SECOND'.
CALL METHOD cl_gui_cfw=>flush.
* SET TITLEBAR 'xxx'.
IF g_html_container IS NOT INITIAL.
CALL METHOD g_html_container->free
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2.
ENDIF.
CREATE OBJECT g_html_container
EXPORTING
container_name = 'PDF'.
CREATE OBJECT g_html_control
EXPORTING
parent = g_html_container.
* Convert xstring to binary table to pass to the LOAD_DATA method
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
TABLES
binary_tab = lt_data.

* Load the HTML


CALL METHOD g_html_control->load_data(
EXPORTING
type = 'application'
subtype = 'pdf'
IMPORTING
assigned_url = lv_url
CHANGING
data_table = lt_data
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_general = 2
cntl_error = 3
OTHERS = 4 ).
CALL METHOD cl_gui_cfw=>flush.
* Show it
CALL METHOD g_html_control->show_url( url = lv_url
in_place = 'X' ).
ELSE.
SET SCREEN 0.
LEAVE SCREEN.
ENDIF.
ENDMODULE. " STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9002 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9002 INPUT.
CASE sy-ucomm.
WHEN 'BACK'.
* CALL METHOD G_HTML_CONTROL->free.
* CLEAR:AUFK-AUFNR ,L_JOB_OUTPUT_INFO,lv_url,lt_data[],lv_content.
* IF NOT g_dock IS INITIAL.
* CALL METHOD g_dock->free.
* CLEAR g_dock.
* ENDIF.
CALL TRANSACTION 'ZPORD'.

* CALL SCREEN 9001.


WHEN 'CANCEL'.
CLEAR:aufk-aufnr ,l_job_output_info.
* LEAVE PROGRAM.
CALL SCREEN 9001.
WHEN 'EXIT'.
CLEAR:aufk-aufnr ,l_job_output_info.
* LEAVE PROGRAM.
CALL SCREEN 9001.
ENDCASE.
ENDMODULE. " USER_COMMAND_9002 INPUT
*&---------------------------------------------------------------------*
*& Module VALUE_REF_AUFNR INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE value_ref_aufnr INPUT.
DATA:lt_aufk TYPE aufk OCCURS 0,
wa_aufk TYPE aufk.
DATA:BEGIN OF lt_aufnr OCCURS 0,
aufnr TYPE aufk-aufnr,
END OF lt_aufnr.
DATA: it_return TYPE STANDARD TABLE OF ddshretval,
wa_return LIKE LINE OF it_return.
SELECT * FROM aufk INTO TABLE lt_aufk.
LOOP AT lt_aufk INTO wa_aufk.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_aufk-aufnr
IMPORTING
output = lt_aufnr-aufnr.
APPEND lt_aufnr.
ENDLOOP.
SORT lt_aufnr ASCENDING BY aufnr.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'AUFK-AUFNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
* DYNPROFIELD = 'REF_AUFNR'
value_org = 'S'
TABLES
value_tab = lt_aufnr
return_tab = it_return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc EQ 0.
READ TABLE it_return INTO wa_return INDEX 1.
aufk-aufnr = wa_return-fieldval.
ENDIF.
ENDMODULE. " VALUE_REF_AUFNR INPUT
*&---------------------------------------------------------------------*
*& Form DWN_ATTA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM dwn_atta .

DATA:lt_header TYPE bapi_order_header1 OCCURS 0.


*data:LS_operation type BAPI_ORDER_OPERATION1.
DATA:lt_component TYPE bapi_order_component OCCURS 0.
DATA:objects TYPE bapi_pp_order_objects.
DATA lt_prt TYPE TABLE OF bapi_order_prod_rel_tools .
DATA lt_operation TYPE TABLE OF bapi_order_operation1 .
DATA ls_header TYPE bapi_order_header1 .

DATA: wa_resb TYPE resb.

DATA: it_qals TYPE TABLE OF qals.


CLEAR lv_prueflos.

SELECT SINGLE * FROM resb INTO wa_resb WHERE aufnr EQ aufk-aufnr.

SELECT SINGLE prueflos FROM qals INTO lv_prueflos


WHERE matnr EQ wa_resb-matnr
AND charg EQ wa_resb-charg
AND stat35 EQ 'X'.

PERFORM print_download.
*
* ENDIF.
* ENDIF.
ENDFORM. " DWN_ATTA
*&---------------------------------------------------------------------*
*& Form PRINT_DOWNLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM print_download .
TYPES : BEGIN OF lty_tsp01,
rqident TYPE rspoid,
rqcretime TYPE rspocrtime,
rqfinal TYPE rspofinal,
END OF lty_tsp01.

DATA : li_tsp01 TYPE STANDARD TABLE OF lty_tsp01,


ls_tsp01 TYPE lty_tsp01.

SELECT rqident
rqcretime
rqfinal
FROM tsp01
INTO TABLE li_tsp01
WHERE rqowner = sy-uname.

IF sy-subrc = 0.
SORT li_tsp01 BY rqcretime DESCENDING.
CLEAR: ls_tsp01.

READ TABLE li_tsp01 INTO ls_tsp01 INDEX 1.


IF sy-subrc = 0.
UPDATE tsp01
SET rqprio = '1'
WHERE rqident = ls_tsp01-rqident.

REFRESH li_tsp01[].
ENDIF.
ENDIF.

DATA : file_table TYPE STANDARD TABLE OF file_table,


count TYPE i,
lv_path TYPE string VALUE 'C:\Dwn_Attachment'.

"GET THE LIST OF FILES


CALL METHOD cl_gui_frontend_services=>directory_list_files
EXPORTING
directory = lv_path
CHANGING
file_table = file_table
count = count
EXCEPTIONS
cntl_error = 1
directory_list_files_failed = 2
wrong_parameter = 3
error_no_gui = 4
not_supported_by_gui = 5
OTHERS = 6.

DATA : lv_filename TYPE string,


rc TYPE i,
wa_list LIKE LINE OF file_table.

IF file_table[] IS NOT INITIAL.


LOOP AT file_table INTO wa_list.

CONCATENATE lv_path wa_list-filename INTO lv_filename SEPARATED BY '\'.


"DELETE THE EARLIER DOWNLOADED FILES
CALL METHOD cl_gui_frontend_services=>file_delete
EXPORTING
filename = lv_filename
CHANGING
rc = rc
EXCEPTIONS
file_delete_failed = 1
cntl_error = 2
error_no_gui = 3
file_not_found = 4
access_denied = 5
unknown_error = 6
not_supported_by_gui = 7
wrong_parameter = 8
OTHERS = 9.
CLEAR: lv_filename, rc.
ENDLOOP.
ENDIF.

DATA : i_connections TYPE STANDARD TABLE OF bdn_con INITIAL SIZE 0,


l_objkey TYPE swotobjid-objkey.

DATA: i_connections_rec TYPE bdn_con .

l_objkey = lv_prueflos.

CALL FUNCTION 'BDS_GOS_CONNECTIONS_GET'


EXPORTING
classname = 'BUS2045'
objkey = l_objkey
client = sy-mandt
TABLES
gos_connections = i_connections
EXCEPTIONS
no_objects_found = 1
internal_error = 2
internal_gos_error = 3
OTHERS = 4.
IF sy-subrc NE 0.
"DO NOTHING
ENDIF.

DATA : objcont TYPE STANDARD TABLE OF soli INITIAL SIZE 0,


fol_id TYPE soodk,
doc_id TYPE soodk,

path TYPE char255,


comp_id TYPE char255,

lv_min TYPE string,


lv_operation TYPE string,
i_preview TYPE tdpreview.
* IF cb_prvw EQ 'X'.
i_preview = 'X'.
* ELSE.
* i_preview = space.
* ENDIF.

LOOP AT i_connections INTO i_connections_rec .

MOVE i_connections_rec-loio_id TO fol_id .


MOVE i_connections_rec-loio_id+17(25) TO doc_id .

CALL FUNCTION 'SO_OBJECT_READ'


EXPORTING
folder_id = fol_id
object_id = doc_id
TABLES
objcont = objcont
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
object_not_exist = 6
object_no_authorization = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
OTHERS = 15.
IF sy-subrc NE 0.
"DO NOTHING
ENDIF.

CONCATENATE lv_path '\' i_connections_rec-descript


'.' i_connections_rec-docuclass
INTO path ."SEPARATED BY '\'.

CONCATENATE i_connections_rec-descript
'.' i_connections_rec-docuclass
INTO comp_id .

CALL FUNCTION 'SO_OBJECT_DOWNLOAD'


EXPORTING
default_filename = comp_id
filetype = 'BIN'
path_and_file = path
extct = 'K'
no_dialog = 'X'
TABLES
objcont = objcont
EXCEPTIONS
file_write_error = 1
invalid_type = 2
x_error = 3
kpro_error = 4
OTHERS = 5.
IF sy-subrc NE 0.
"DO NOTHING
ENDIF.

lv_filename = path.
IF i_preview = 'X'.
CLEAR: lv_min.
lv_operation = 'OPEN'.
ELSE.
lv_operation = 'PRINT'.
lv_min = 'X'.
ENDIF.
*
*
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document = lv_filename
minimized = lv_min
operation = lv_operation
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
bad_parameter = 3
file_not_found = 4
path_not_found = 5
file_extension_unknown = 6
error_execute_failed = 7
synchronous_failed = 8
not_supported_by_gui = 9
OTHERS = 10.
ENDLOOP.

ENDFORM. " PRINT_DOWNLOAD

You might also like