Product view data function
One of the great things in APO is to have the product planning information data in LiveCache for very fast access.
You can see the planning data for a material with the /SAPAPO/RRP3 transaction, but, as far as I know, there is no single function to get that information. The closest I could find was /SAPAPO/RRP_PT_IOLIST_READ, but it missed some data. The following code adds some more fields to the output of that function and makes it easier to use.
One use for this function is to have a transaction in R3 to display the APO material plan information, like the scenario described in a previous post. One other idea that I might try in the future is to have a web application/service with materials planning data ( for instance vendors having detailed information on their VMI stock ).
Instructions: First the definition of a new structure that adds some fields to the standard /SAPAPO/RRP_IO_STR (in the code this structure was named ZSPP_PRODVIEW).
The following goes to the function module top include.
And the following function returns most of the product view data shown in the /SAPAPO/RRP3 transaction.
You can see the planning data for a material with the /SAPAPO/RRP3 transaction, but, as far as I know, there is no single function to get that information. The closest I could find was /SAPAPO/RRP_PT_IOLIST_READ, but it missed some data. The following code adds some more fields to the output of that function and makes it easier to use.
One use for this function is to have a transaction in R3 to display the APO material plan information, like the scenario described in a previous post. One other idea that I might try in the future is to have a web application/service with materials planning data ( for instance vendors having detailed information on their VMI stock ).
Instructions: First the definition of a new structure that adds some fields to the standard /SAPAPO/RRP_IO_STR (in the code this structure was named ZSPP_PRODVIEW).
.INCLUDE /SAPAPO/RRP_IO_STR
RQDAT /SAPAPO/RQDAT
RQTIM /SAPAPO/RQTIM
CONTI_DAT /SAPAPO/CONTI_DAT
CONTI_TIM /SAPAPO/CONTI_TIM
CHAR_VAL1 ATWRT
CHAR_VAL2 ATWRT
CHAR_VAL3 ATWRT
CHAR_VAL4 ATWRT
CHAR_VAL5 ATWRT
CHAR_VAL6 ATWRT
CHAR_VAL7 ATWRT
CHAR_VAL8 ATWRT
CHAR_VAL9 ATWRT
CHAR_VAL10 ATWRT
DESQTY /SAPAPO/DESQTY
SOBKZ /SAPAPO/SOBKZ
The following goes to the function module top include.
INCLUDE /sapapo/rrp_constants.
INCLUDE /sapapo/seq_constants.
And the following function returns most of the product view data shown in the /SAPAPO/RRP3 transaction.
FUNCTION z_simple_prodview.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(P_MATNR) TYPE /SAPAPO/MATNR
*" VALUE(P_PLANT) TYPE WERKS_D
*" VALUE(P_SIMID) TYPE /SAPAPO/VRSIOID DEFAULT '000'
*" VALUE(P_CPROF) TYPE /SAPAPO/SEQ_CVPROFIL_ID DEFAULT ''
*" TABLES
*" P_PVDATA STRUCTURE ZSPP_PRODVIEW
*" EXCEPTIONS
*" PLANT_NOT_FOUND
*" MATERIAL_NOT_FOUND
*"----------------------------------------------------------------------
CONSTANTS:
gc_true TYPE c VALUE 'X',
gc_false TYPE c VALUE space,
gc_seq_pse_0001 TYPE /sapapo/seq_cvapplication VALUE 'PSE_0001',
gc_mintime TYPE /sapapo/startti VALUE '19700102000000'.
DATA: l_matid TYPE /sapapo/matid,
l_locid TYPE /sapapo/locid,
l_fcode TYPE syucomm,
l_loc TYPE /sapapo/locno,
lt_pegid TYPE /sapapo/pegid_tab,
ls_pegkey TYPE /sapapo/pegkey,
lt_pegkey TYPE /sapapo/pegkey_tab.
DATA: ls_io TYPE /sapapo/om_io_pp,
ls_iopt TYPE /sapapo/rrp_io_str,
ls_pvdata TYPE zspp_prodview,
lv_io_time TYPE timestamp,
lt_iopt TYPE /sapapo/rrp_io_tab.
DATA: lv_char_count LIKE sy-tabix,
ls_cpocv TYPE /sapapo/pt_cpocv_str,
lt_cpord TYPE /sapapo/pt_cpord_tht WITH HEADER LINE,
lt_cviews TYPE /sapapo/seq_cviews_tab WITH HEADER LINE,
lt_schedule TYPE /sapapo/dm_po_sched_tab WITH HEADER LINE.
l_loc = p_plant.
CALL FUNCTION '/SAPAPO/DM_LOCNO_GET_LOCID'
EXPORTING
iv_locno = l_loc
IMPORTING
ev_locid = l_locid
EXCEPTIONS
location_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE plant_not_found.
ENDIF.
CALL FUNCTION '/SAPAPO/DM_MATERIAL_GET_MATID'
EXPORTING
iv_matnr = p_matnr
IMPORTING
ev_matid = l_matid
EXCEPTIONS
matid_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
RAISE material_not_found.
ENDIF.
CALL FUNCTION '/SAPAPO/DM_MATERIAL_FIND_PEGID'
EXPORTING
iv_matid = l_matid
iv_locid = l_locid
iv_simid = p_simid
iv_accid = ''
IMPORTING
et_pegid = lt_pegid
EXCEPTIONS
selection_insufficient = 1
no_pegids_found = 2
OTHERS = 3.
CALL FUNCTION '/SAPAPO/DM_PEGID_GET_PEGKEY'
EXPORTING
it_pegid = lt_pegid
IMPORTING
et_pegkey = lt_pegkey.
CALL FUNCTION '/SAPAPO/RRP_PT_IOLIST_READ'
EXPORTING
iv_simid = p_simid
it_pegarea = lt_pegid
IMPORTING
et_iopt = lt_iopt.
CALL FUNCTION '/SAPAPO/PT_GET_CHAR_VALUES'
EXPORTING
iv_simid = p_simid
iv_cappl = gc_seq_pse_0001
iv_cprof = p_cprof
it_pegid = lt_pegid
IMPORTING
et_cpord = lt_cpord[]
et_cviews = lt_cviews[]
EXCEPTIONS
error = 1
OTHERS = 2.
LOOP AT lt_iopt INTO ls_iopt.
CLEAR ls_pvdata.
* For now I will just split the data in MTS and MTO segments. If later
* the MTO needs to be split into individual segments the function
* module /SAPAPO/DM_ACCID_GET_ACCOUNT with lt_pegkey-accid can be used
* to get the MTO segment name
READ TABLE lt_pegkey INTO ls_pegkey WITH KEY pegid = ls_iopt-pegid.
IF NOT ls_pegkey-accid IS INITIAL.
ls_pvdata-sobkz = 'E'.
ENDIF.
MOVE-CORRESPONDING ls_iopt TO ls_pvdata.
IF ls_iopt-io_time < gc_mintime.
GET TIME STAMP FIELD lv_io_time.
ELSE.
lv_io_time = ls_iopt-io_time.
ENDIF.
IF NOT lv_io_time IS INITIAL.
CALL FUNCTION '/SAPAPO/TIMESTAMP_CONVERT_DATE'
EXPORTING
iv_timestamp = lv_io_time
iv_pegid = ls_iopt-pegid
IMPORTING
ev_date = ls_pvdata-rqdat
ev_time = ls_pvdata-rqtim.
ENDIF.
IF NOT ls_iopt-io_end_time IS INITIAL.
CALL FUNCTION '/SAPAPO/TIMESTAMP_CONVERT_DATE'
EXPORTING
iv_timestamp = ls_iopt-io_end_time
iv_pegid = ls_iopt-pegid
IMPORTING
ev_date = ls_pvdata-conti_dat
ev_time = ls_pvdata-conti_tim.
ENDIF.
IF ls_iopt-order_type = gc_om_sales_order_consumption OR
ls_iopt-order_type = gc_om_sales_order_no_cons OR
ls_iopt-order_type = gc_om_temp_demand OR
( ls_iopt-order_type = gc_om_transfer_order AND
( ls_iopt-r3obj = gc_customer_order OR
ls_iopt-r3obj = gc_delivery_sd ) ).
ls_pvdata-desqty = ls_iopt-quantity.
ENDIF.
* Build order/item/subitem desc if initial
IF ls_pvdata-extra IS INITIAL.
CLEAR ls_io.
MOVE-CORRESPONDING ls_iopt TO ls_io.
CALL FUNCTION '/SAPAPO/DM_NODE_GET_DATA'
EXPORTING
is_node = ls_io
IMPORTING
ev_extract = ls_pvdata-extra
EXCEPTIONS
error_message = 1.
ENDIF.
* Get characteristics
READ TABLE lt_cpord
WITH TABLE KEY ordid = ls_iopt-orderid
posno = ls_iopt-position_no
linno = ls_iopt-line_no
cprof = p_cprof.
IF sy-subrc = 0.
LOOP AT lt_cviews.
lv_char_count = sy-tabix.
READ TABLE lt_cpord-t_cpocv INTO ls_cpocv
WITH KEY chaid = lt_cviews-atinn.
CHECK sy-subrc = 0.
CASE lv_char_count.
WHEN 1.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val1.
WHEN 2.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val2.
WHEN 3.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val3.
WHEN 4.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val4.
WHEN 5.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val5.
WHEN 6.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val6.
WHEN 7.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val7.
WHEN 8.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val8.
WHEN 9.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val9.
WHEN 10.
PERFORM get_char_value USING ls_cpocv
CHANGING ls_pvdata-char_val10.
ENDCASE.
ENDLOOP.
ENDIF.
APPEND ls_pvdata TO p_pvdata.
ENDLOOP.
ENDFUNCTION.
*---------------------------------------------------------------------*
* FORM get_char_value
*---------------------------------------------------------------------*
FORM get_char_value USING is_cpovc TYPE /sapapo/pt_cpocv_str
CHANGING cv_value TYPE atwrt.
CLEAR cv_value.
IF NOT is_cpovc-valch IS INITIAL.
cv_value = is_cpovc-valch.
ELSEIF NOT is_cpovc-valqu IS INITIAL.
WRITE is_cpovc-valqu TO cv_value.
ELSEIF NOT is_cpovc-valfl IS INITIAL.
WRITE is_cpovc-valfl TO cv_value.
ENDIF.
CONDENSE cv_value.
ENDFORM.
0 Comments:
Post a Comment
<< Home