ลิขิตฟ้า หรือ จะสู้มานะคน

chon_pro
Location :
สมุทรปราการ Thailand

[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed
Smember
ผู้ติดตามบล็อก : 12 คน [?]




ผมแค่อยากเขียน บันทึกเกี่ยวกับข้อมูลการทำงานของผมต่างๆ เพื่อเก็บเอาไว้ใช้ดูเวลาที่ผมหลงลืม และเพื่อเป็นประโยชน์ กับน้องๆๆๆ ทั้งหลาย
loaocat

Stat Counter :
Group Blog
 
All Blogs
 
Friends' blogs
[Add chon_pro's blog to your web]
Links
 

 

ZPP272 Transfer BOM from SAP to SFC

***********************************************************************
* ABAP Name : ZPP272
* Created by : Suchon Poomcharoen.
* Created on : 28 July 2009
* Version : 1.0
* Transport :
* Task ID :
*----------------------------------------------------------------------
* Description: This program is used for BOM SAP to SFC
*----------------------------------------------------------------------
* Modification Log:
* 1) Changed by :
* Changed on :
* Transport :
* Correction-No :
* Description : 1)
*----------------------------------------------------------------------
report zpp272.
*********************************************
* Tables
*********************************************
TABLES:
MAST,CSAP_MBOM,ZSFCBOM.
*********************************************
* select screen
*********************************************
SELECT-OPTIONS:
S_MATNR FOR CSAP_MBOM-MATNR.
PARAMETER:
P_Case(1) TYPE C DEFAULT 'A'.
*********************************************
* Data Declaration
*********************************************
data:
t_stpo like stpo_api02 occurs 0 with header line, "BOM items
t_stko like stko_api02 occurs 0 with header line, "BOM headers
t_mara like MARA_MATNR occurs 0 with header line,
T_ZSFCBOM LIKE ZSFCBOM OCCURS 0 WITH HEADER LINE,
v_MATNR like CSAP_MBOM-MATNR,
v_maktx like makt-maktx.


**********************************************
*Main Routines
**********************************************
perform get_material_mast.

loop at t_mara.
clear v_matnr.
v_matnr = t_mara-matnr.
perform get_material_bom.
endloop.

**********************************************
**********************************************

*&---------------------------------------------------------------------*
*& Form get_material_bom
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_material_bom.

perform alternative_bom_01 using '01' .
perform alternative_bom_01 using '02' .

endform. " get_material_bom
*&---------------------------------------------------------------------*
*& Form get_material_mast
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_material_mast.

*delete from ZSFCBOM where MATNR <> 1. CLEAR T_mara.
clear t_mara.
REFRESH t_mara.

CASE P_Case.
WHEN 'A'.
* เลือก Bom ทีมีการเปลี่ยนค่าระดับ Item
SELECT mast~matnr
FROM mast
INNER JOIN MARA
ON MAST~MATNR = MARA~MATNR
INNER JOIN STKO
ON STKO~STLAL = MAST~STLAL
AND STKO~STLNR = MAST~STLNR
INNER JOIN STPO
ON STPO~DATUV = STKO~DATUV
AND STPO~STLNR = STKO~STLNR
AND STPO~STLTY = STKO~STLTY
INTO t_mara-matnr
WHERE MARA~MATNR in s_matnr
and LVORM <> 'X'
and MTART in ('ZFIN','ZSFI')
and ZZPRODU eq 'PLP'
and STPO~AEDAT = SY-DATUM.
* append t_mara.
*Collect ใช้สำหรับ นำค่าที่ duplicate ออกไป
collect t_mara.
ENDSELECT.

* เลือก Bom ทีมีการเปลี่ยนค่าระดับ Header
SELECT mast~matnr
FROM mast
INNER JOIN MARA
ON MAST~MATNR = MARA~MATNR
INNER JOIN STKO
ON STKO~STLAL = MAST~STLAL
AND STKO~STLNR = MAST~STLNR
INTO t_mara-matnr
WHERE MARA~MATNR in s_matnr
and LVORM <> 'X'
and MTART in ('ZFIN','ZSFI')
and ZZPRODU eq 'PLP'
and STKO~AEDAT = SY-DATUM.
append t_mara.
ENDSELECT.

* เลือก Bom ทีมีการสร้างใหม่
SELECT mast~matnr
FROM mast
INNER JOIN MARA
ON MAST~MATNR = MARA~MATNR
INNER JOIN STKO
ON STKO~STLAL = MAST~STLAL
AND STKO~STLNR = MAST~STLNR
INTO t_mara-matnr
WHERE MARA~MATNR in s_matnr
and LVORM <> 'X'
and MTART in ('ZFIN','ZSFI')
and ZZPRODU eq 'PLP'
and STKO~ANDAT = SY-DATUM.
append t_mara.
ENDSELECT.

WHEN 'S'.


SELECT matnr FROM mara INTO t_mara-matnr
WHERE MATNR in s_matnr
and LVORM <> 'X'
and MTART in ('ZFIN','ZSFI')
and ZZPRODU eq 'PLP'.
append t_mara.
ENDSELECT.


WHEN OTHERS.
Exit.
ENDCASE.



ENDFORM. " get_material_mast
*&---------------------------------------------------------------------*
*& Form read_mat_desc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form read_mat_desc using p_matnr.
clear: v_maktx.
select single maktx into (v_maktx)
from makt
where matnr = p_matnr
and spras = 'E'.

ENDFORM. " read_mat_desc
*&---------------------------------------------------------------------*
*& Form alternative_bom_01
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alternative_bom_01 using p_alter.
CLEAR: T_STKO,
T_STPO.
REFRESH:
T_STKO,
T_STPO.

call function 'CSAP_MAT_BOM_READ'
exporting
material = v_matnr
plant = '0006'
bom_usage = '1'
ALTERNATIVE = p_alter
* VALID_FROM =
* VALID_TO =
* CHANGE_NO =
* REVISION_LEVEL =
* FL_DOC_LINKS = ' '
* FL_DMU_TMX = ' '
* IMPORTING
* FL_WARNING =
tables
t_stpo = t_stpo
T_STKO = t_stko
* T_DEP_DATA =
* T_DEP_DESCR =
* T_DEP_ORDER =
* T_DEP_SOURCE =
* T_DEP_DOC =
* T_DOC_LINK =
* T_DMU_TMX =
exceptions
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.
IF SY-SUBRC = 0.
LOOP AT T_STPO.
clear: T_ZSFCBOM[],
T_ZSFCBOM.



call function 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = t_stpo-COMPONENT
IMPORTING
output = t_stpo-COMPONENT.

T_ZSFCBOM-MATNR = v_matnr.
t_zsfcbom-STLNR = t_stpo-bom_no.

case T_STPO-ITEM_NO.
when '0010'. "MOULD1
t_zsfcbom-mould1 = t_stpo-COMPONENT.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-mould1t = v_maktx.
when '0020'. "MOULD2
t_zsfcbom-mould2 = t_stpo-COMPONENT.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-mould2t = v_maktx.
when '0030'. "RING

t_zsfcbom-RING = t_stpo-COMPONENT.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-ringt = v_maktx.
IF t_zsfcbom-RING(1) = 'R'.
t_zsfcbom-class = '001'.
else.
t_zsfcbom-class = '022'.
ENDIF.

when '0040'. "RESIN
t_zsfcbom-Resin = t_stpo-COMPONENT.
t_zsfcbom-RESIN_WEIGHT = t_stpo-COMP_QTY.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-resint = v_maktx.
t_zsfcbom-resin_unit = t_stpo-COMP_UNIT.
when '0050'. "PACKING NO.
t_zsfcbom-PACKNO = t_stpo-COMPONENT.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-packnot = v_maktx.
when '0060'. "LABEL NO.
t_zsfcbom-labelno = t_stpo-COMPONENT.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-labelnot = v_maktx.
when '0070'. "PLASTIC INSERT.
t_zsfcbom-PINSERT = t_stpo-COMPONENT.
perform read_mat_desc using t_stpo-COMPONENT.
t_zsfcbom-pinsertt = v_maktx.
endcase.

* if t_stpo-changed_on <> ' '.

CONCATENATE t_stpo-CHANGED_ON+6(4) t_stpo-CHANGED_ON+3(2)
t_stpo-changed_on(2) into t_zsfcbom-AEDAT .
* endif.



ENDLOOP.
t_zsfcbom-status = 'X'.
* t_zsfcbom-status = 'E'.
* t_zsfcbom-AEDAT = t_stpo-CHANGED_ON.
t_zsfcbom-STLAL = p_alter.
APPEND T_ZSFCBOM.
MODIFY ZSFCBOM FROM TABLE T_ZSFCBOM.
* Commit work สั่งให้ DataBase ทำการ Save data ทันที
COMMIT WORK.
endif.




 

Create Date : 28 สิงหาคม 2552    
Last Update : 28 สิงหาคม 2552 13:55:35 น.
Counter : 713 Pageviews.  

Simple ALV Report

Simple example to use ALV and to define the ALV data in an internal table.

Also see ALV Grid Control

REPORT Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB .
************************************************************************
*Simple example to use ALV and to define the ALV data in an internal
*table
************************************************************************
* Martin Schlegel, BearingPoint, December 2004
*
* Thanks to Madhusudhan Sonee and Rama Krishna Kommineni for testing
* and feedback
*
************************************************************************
************************************************************************
*For a very long time, people gave me the feeling that ALV is a
*complicated tool that is difficult to understand and to use.
*Lately I had to use it and I discovered that ALV is easy to use and
*saves a lot of work:
*ALV will generate the column headings on its own, so one does not need
*to work on headlines and transalation.
*ALV allows the user to select the columns he wants to see, so the user
*does not need to contact a developer for every change he likes to have.
*ALV allows the user to create his own sums, so …
*ALV has a simple way to work with internal tables.
*If you really want to save time, use ALV instead of write!
************************************************************************
*
*Please take 30 minutes to explore the following example and see how
*easy it is to use ALV!
*
************************************************************************

*data definition

tables:
marav. "Table MARA and table MAKT

*---------------------------------------------------------------------*
* Data to be displayed in ALV
* Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
* matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
" intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
"make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.

*---------------------------------------------------------------------*
* Other data needed
* field to store report name
data i_repid like sy-repid.
* field to check table length
data i_lines like sy-tabix.

*---------------------------------------------------------------------*
* Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.

*---------------------------------------------------------------------*
select-options:
s_matnr for marav-matnr matchcode object MAT1.

*---------------------------------------------------------------------*
start-of-selection.

* read data into table imat
select * from marav
into corresponding fields of table imat
where
matnr in s_matnr.

* Check if material was found
clear i_lines.
describe table imat lines i_lines.
if i_lines lt 1.
* Using hardcoded write here for easy upload
write: /
'No materials found.'.
exit.
endif.

end-of-selection.
*---------------------------------------------------------------------*
*
* Now, we start with ALV
*
*---------------------------------------------------------------------*
*
*
* To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.
* The fieldcatalouge can be generated by FUNCTION
* 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
* report source, including this report.
* The only problem one might have is that the report and table names
* need to be in capital letters. (I had it :-( )
*
*
*---------------------------------------------------------------------*

* Store report name
i_repid = sy-repid.

* Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = i_repid
I_INTERNAL_TABNAME = 'IMAT' "capital letters!
I_INCLNAME = i_repid
CHANGING
CT_FIELDCAT = int_fcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
*explanations:
* I_PROGRAM_NAME is the program which calls this function
*
* I_INTERNAL_TABNAME is the name of the internal table which you want
* to display in ALV
*
* I_INCLNAME is the ABAP-source where the internal table is defined
* (DATA....)
* CT_FIELDCAT contains the Fieldcatalouge that we need later for
* ALV display


IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.

*This was the fieldcatlogue
*---------------------------------------------------------------------*
*
* And now, we are ready to display our list

* Call for ALV list display
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat
I_SAVE = 'A'
TABLES
T_OUTTAB = imat
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*
*explanations:
* I_CALLBACK_PROGRAM is the program which calls this function
*
* IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
* now the data definition needed for display
*
* I_SAVE allows the user to save his own layouts
*
* T_OUTTAB contains the data to be displayed in ALV


IF SY-SUBRC <> 0.
write: /
'Returncode',
sy-subrc,
'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
ENDIF.
*
*---------------------------------------------------------------------*
*
* yes, it is that simple. Go ahead and try yourself!
*
*---------------------------------------------------------------------*




 

Create Date : 07 มีนาคม 2551    
Last Update : 7 มีนาคม 2551 9:18:27 น.
Counter : 480 Pageviews.  

1  2  
 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.