2018年9月27日 星期四

Skip to end of metadata
Go to start of metadata
BAPIs can you find in SE37 when searching with:
BAPI
Operative Object
BAPI_BUS2172*Project
BAPI_BUS2173*Phase
BAPI_BUS2175*Task
BAPI_BUS2176*Checklist Header
BAPI_BUS2174*Checklist Item
BAPI_BUS2177*Role


BAPI
Templates
BAPI_BUS2170*Project Template
BAPI_BUS2167*Phase in Template
BAPI_BUS2169*Task in Template
BAPI_BUS2171*Checklist Template
BAPI_BUS2168*ChkLst Itm in Temp
BAPI_BUS2178*
Role in Template
New BAPIs for resource management in Detail:
BAPI name
BAPI Role/ function
BAPI_BUS2177_ROLE_DIST_GET
Determine Demand Distribution
BAPI_BUS2177_ROLE_DIST_SET
Change Demand Distribution
BAPI_BUS2177_STAFF_DIST_GET
Determine Demand Distribution
BAPI_BUS2177_STAFF_DIST_SET
Change Demand Distribution


BAPI_BUS2177_ROLE_DIST_SET SAP Function module - BAPI Role: Change Demand Distribution

 Hierarchy

☛  CPRXRPM (Software Component) SAP Portfolio and Project Management 6.0
   ⤷  PPM-PRO-EXT-API (Application Component) BAPI Interface for cProjects
     ⤷  DEVELOPMENT_PROJECTS_BAPI (Package) Project Management - BAPI

 Basic Data

Function ModuleBAPI_BUS2177_ROLE_DIST_GETBAPI Role: Determine Demand Distribution  
Function GroupDPR_BUS2177  Development Projects: Role  
Program NameSAPLDPR_BUS2177   
INCLUDE NameLDPR_BUS2177U40   

 Parameters

TypeParameter NameTypingAssociated TypeDefault valueOptionalPass ValueShort text
 ExportingES_DIST_ADMIN_DATATYPEBAPI_TS_DIST_ADMIN_DATADistribution administration data
 ExportingEV_DIST_GUIDTYPEDPR_TV_GUIDApplication Object GUID
 ExportingEV_ENTITY_GUIDTYPEDPR_TV_GUIDApplication Object GUID
 ImportingPROJECTROLE_GUIDTYPEBAPI_TS_GUID-ROLE_GUIDGUID for Project Role
 TablesET_DISTRIBUTIONTYPEBAPI_TS_DIST_DATADistribution data
 TablesRETURNTYPEBAPIRET2Return Parameters
        

 Processing Type

 Normal Function Module 
 Remote-Enabled Module BaseXML supported
 Update Module Start immediately
 Immediate Start, No Restart
 Start Delayed
 Coll.run
 JAVA Module Callable from ABAP 
 Remote-Enabled JAVA Module 
 Module Callable from JAVA 

 History

Last changed by/onSAP 20141109 
SAP Release Created in310  

讀出功能模組文件 SAP Function Module Documentation


Get SAP function module documentation



Step 1 - Execute transaction SE37 
First, execute sap transaction SE37 and enter the function module name. Then press the display button 
 

Alternatively, choose menu option Goto->Documentation->Function Module Documentation. The only problem I find with this option is that the documentation popup box appears underneath the current SAP window so you don't actually see it without moving the window 
 

Step 2 - Display documentation 
If you selected display you will be taken to the FM details, now simply choose the menu option goto->Documentation. 
 

The Function module documentation will now be displayed 
 

Step 3 - Alternate way using tcodevSE80 
You also get the same options to view Function Module documentation within SAP transaction SE80 

2018年9月26日 星期三

ABAP/4 讀取 Database table, store procedure
  1. data:
  2. PAR1(30) type C,
  3. PAR2(30) type C,
  4. OUT1 type I,
  5. OUT2(30) type C,
  6. OUT3(30) type C.
  7.  
  8. exec sql performig sp_return.
  9. select * from $PROC$sp_dummy
  10. where ( :par1, :par2 )
  11. into :out1, :out2, : out3
  12. endexec.
  13.  
  14. form sp_return.
  15. * some coding
  16. endform

General Types
Predefined data types without special semantic attributes.
Numeric Types
TypeValid Places mInitial ValueMeaningABAP Type
INT1301-byte integer, 0 to 255b
INT2502-byte integer, -32,768 to 32,767s
INT41004-byte integer, -2,147,483,648 to +2,147,483,647i
INT81908-byte integer, -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807int8
DEC1-310Packed number BCD formatp, length m DIV 2 + 1
DF16_DEC1-150Decimal floating point number stored in BCD formatdecfloat16
DF16_RAW160Decimal floating point number stored in binary formatdecfloat16
DF34_DEC1-310Decimal floating point number stored in BCD formatdecfloat34
DF34_RAW340Decimal floating point number stored in binary formatdecfloat34
FLTP160Floating point numberf

Character-Like Types
TypeValid Places mInitial ValueMeaningABAP Type
CHAR1-30000, maximum of 1333 for table fieldsm blanksCharacter stringc, length m
LCHR256-32000Nonelong character stringc, length m
SSTRING1-1333Empty stringCharacter stringstring
STRING256-...Empty stringCharacter string (CLOB)string

Byte-like types
TypeValid Places mInitial ValueMeaningABAP Type
RAW1-32000 maximum of 255 for table fieldsNoneByte stringx, length m
LRAW256-32000NoneLong byte stringx, length m
RAWSTRING256-...Empty stringByte string (BLOB)xstring

Special Types
Predefined data types with special semantic attributes.
Date Types/Time Types
TypeValid Places mInitial ValueMeaningABAP Type
DATS800000000Date in the format YYYYMMDDd
TIMS6000000Time in the format HHMMSSt
ACCP66 blanksPosting period in the format YYYYMMn, length 6

Character-Like Types with Special Semantics
TypeValid Places mInitial ValueMeaningABAP Type
NUMC1-255m zeroesNumeric textn, length m
CLNT3000Clientc, length 3
LANG1BlankLanguage keyc, length 1

Currency Fields and Quantity Fields
TypeValid Places mInitial ValueMeaningABAP Type
CURR1-310Currency field in BCD formatp, length m DIV 2 + 1
CUKY55 blanksCurrency key for currency fieldsc, length 5
QUAN1-310Quantity field in BCD formatp, length m DIV 2 + 1
UNIT2-32 or 3 blanksUnit key of a quantity fieldc, length m

Obsolete Types
TypeValid Places mInitial ValueMeaningABAP Type
DF16_SCL160Decimal floating point number stored in binary format with scaling specified (obsolete)decfloat16
DF34_SCL340Decimal floating point number stored in binary format with scaling specified (obsolete)decfloat34
PREC20Obsolete data types
VARC1-...NoneObsolete data typec, length m



Character-Like Types and Byte-Like Types
Character Strings
The following predefined data types in ABAP Dictionary are available for general character strings:
  • CHAR for text fields
The predefined type CHAR, mapped to the ABAP type c, is used to describe general text fields with a maximum length of 30000 characters (only 1333 characters for table fields).
  • LCHR for long text fields
The predefined type LCHR, also mapped to the ABAP type c, is used to describe general text fields with lengths between 256 and 32000 characters. In database tables, the maximum length must be specified as the value of a preceding INT2 or INT4 field. Table fields of this type cannot be used as key fields of database tables or in any positions in Open SQL statements.
The predefined type SSTRING is mapped to the ABAP type string, but handled like the type CHAR or VARCHAR in ABAP Dictionary and by database tables. The length is restricted to a maximum of 1333, but table fields of this type can also be used as key fields by database tables and used by Open SQL statements in almost all positions where text fields are possible.
The predefined type STRING is mapped to the ABAP type string and also handled like a text string (CLOB) in ABAP Dictionary and by database tables. Table fields of this type cannot be used as key fields or index fields in database tables or in any positions in Open SQL statements.
Notes
  • In general structures, the length of a component of type CHAR is not restricted to 1333.
  • In database tables, there can be only one table field of the type LCHR and it must be the last table field. This means that the type LRAW cannot be used simultaneously in the same database table. If the statement SELECT is used to read an LCHR field, the preceding length field must also be read. In writes using Open SQL, the length field must be given the correct value or data may be lost.
  • LCHR is no longer recommended for new developments. The type STRING is recommended instead, however it is also not suitable for key fields of database tables or for unrestricted use in Open SQL. Where possible, SSTRING can be used here instead.
  • Switching existing dictionary objects from LCHR to STRING or SSTRING, on the other hand, can be critical, since all ABAP types and ABAP objects that reference dictionary objects like this are then given a deep data type. A switch from a flat data type to a deep data type usually constitutes an incompatible change and can produce syntax errors in ABAP programs.

Example
Like the example for literals; the row to be read is here also specified using host variables. The addition STRUCTURE is specified after INTO. However, this is not necessary since wa can be identified statically as a structure. The structure wa is handled in the INTO clause as if all substrings were specified separately: INTO :wa-cityfrom, :wa-cityto.
PARAMETERS: p_carrid TYPE spfli-carrid,
            p_connid TYPE spfli-connid.

DATA: BEGIN OF wa,
        cityfrom TYPE spfli-cityfrom,
        cityto   TYPE spfli-cityto,
      END OF wa.

EXEC SQL.
  SELECT cityfrom, cityto
         INTO STRUCTURE :wa
         FROM spfli
         WHERE mandt  = :sy-mandt AND
               carrid = :p_carrid AND connid = :p_connid
ENDEXEC. 



Example
Reads multiple rows from the database table SPFLI using cursor handling and host variables in static Native SQL. If rows are found, sy-subrc is set to 0 and sy-dbcnt is increased by one for each row read.
PARAMETERS p_carrid TYPE spfli-carrid.

DATA:  connid   TYPE spfli-connid,
       cityfrom TYPE spfli-cityfrom,
       cityto   TYPE spfli-cityto.

EXEC SQL.
  OPEN dbcur FOR
    SELECT connid, cityfrom, cityto
           FROM spfli
           WHERE mandt  = :sy-mandt AND
                 carrid = :p_carrid
ENDEXEC.

DO.
  EXEC SQL.
    FETCH NEXT dbcur INTO :connid, :cityfrom, :cityto
  ENDEXEC.
  IF sy-subrc <> 0.
    EXIT.
  ELSE.
    ...
  ENDIF.
ENDDO.

EXEC SQL.
  CLOSE dbcur
ENDEXEC. 

Bad Example
Reads multiple rows from the database table SCARR and calls the subroutine evaluate for each row read.
DATA wa TYPE spfli-carrid.

EXEC SQL PERFORMING evaluate.
  SELECT carrid FROM spfli INTO :wa WHERE mandt = :sy-mandt
ENDEXEC.
cl_demo_output=>display( ).

FORM evaluate.
  cl_demo_output=>write( |{ wa } | ).
ENDFORM.
Good Example
Explicit cursor processing.
DATA wa TYPE spfli-carrid.

EXEC SQL.
  OPEN CUR FOR
  SELECT carrid FROM spfli WHERE mandt = :sy-mandt
ENDEXEC.

DO.
  EXEC SQL.
    FETCH NEXT CUR INTO :wa
  ENDEXEC.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  cl_demo_output=>write( |{ wa } | ).
ENDDO.
cl_demo_output=>display( ).

2018年8月20日 星期一

現場SFC交易檔自動轉入ERP
假如有生產入庫退回時
不能用負數拋入
會造成一正一負

要先找出原先拋入的生產入庫
找出已存在的入庫資料
TRX_ID,TRANSACTION_DATE
8607,2018/7/25 下午 04:05:12
18504,2018/7/25 下午 04:15:08
TRX_ID,ORGANIZATION_CODE,BATCH_NO,ITEM_NO,LOT_NUMBER,TRANSACTION_QUANTITY,TRANSACTION_UOM,
SUBINVENTORY_CODE,TRANSACTION_DATE,
ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,
ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,
STATUS,STATUS_MESSAGE,CREATION_DATE,CREATION_BY_NAME,
ERP_UPDATE_DATE,REQUEST_ID,ORGANIZATION_ID,INVENTORY_ITEM_ID,BATCH_ID,OPRN_NO
-----------------------
8607,TH1,5212018012202,4B1-7A0353-A51002,171215312-T17112001,-7,PCS,
1308,2018/7/25 下午 04:05:12,
D322018012216Q,,1,3,2,,0,-80,kg,P0821A,,E,,
2018/1/22,,2018/7/25 下午 04:51:22,1553024,121,8248,2231,5502

18504,TH1,5162018020803,4B1-D00302-T51004,180207513-A18020411,-300,PCS,
1208,2018/7/25 下午 04:15:08,
D322018021012Q,D001,1,5,3,,0,230.15,kg,,,S,,2018/2/10,,

2018/7/25 下午 06:04:53,1553167,121,9146,4640,5501


                       SELECT ROW_NUMBER() OVER(PARTITION BY
                                      MMT.TRANSACTION_SOURCE_ID, 

                                      MMT.INVENTORY_ITEM_ID, 
                                      MTL.LOT_NUMBER 
                                      ORDER BY 
                                      MTL.TRANSACTION_QUANTITY DESC) ROW_NUM,
 -- 以上先將同一 Source + Item + Lot 並列 並依據數量排序                                

                                      MMT.TRANSACTION_SOURCE_ID, 
                                      MMT.INVENTORY_ITEM_ID,
                                      MTL.LOT_NUMBER,
                                      MMT.TRANSACTION_ID,
                                      MMT.ORGANIZATION_ID,
                                      MMT.TRANSACTION_DATE,
                                      
                                   --ABS(IN_TRANSACTION_QUANTITY) START_QUANTITY,
                                      MTL.TRANSACTION_QUANTITY QUANTITY_ISSUED,
                                      MT.TRANSACTION_TYPE_NAME
                           FROM APPS.MTL_MATERIAL_TRANSACTIONS        MMT,
                                       APPS.MTL_TRANSACTION_LOT_NUMBERS MTL,
                                       APPS.MTL_TRANSACTION_TYPES                MT
                        WHERE 1 = 1
                              AND MMT.TRANSACTION_TYPE_ID     = MT.TRANSACTION_TYPE_ID
                              AND MT.TRANSACTION_TYPE_NAME LIKE 'WIP%Completion'
                              AND MTL.TRANSACTION_ID                 = MMT.TRANSACTION_ID
                                
                              AND MMT.TRANSACTION_SOURCE_ID =  IN_BATCH_ID
                              AND MMT.INVENTORY_ITEM_ID             =  IN_ITEM_ID
                              AND MTL.LOT_NUMBER                          =  IN_LOT_NUMBER
                              AND MMT.SUBINVENTORY_CODE         =  IN_SUBINV_CODE








不分料號的前一個日期

SELECT product_id, order_date,
LAG (order_date,1) OVER (ORDER BY order_date) AS prev_order_date
FROM orders;
要分的前一個日期

SELECT product_id, order_date,
LAG (order_date,1) OVER (PARTITION BY product_id ORDER BY order_date) AS prev_order_date
FROM orders;