Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Why we are using flags for bapi_po_create1

DKanna
Explorer
0 Likes
2,418

Hi all,

In this sample code why they are using flags .i cannot understand them.

&---------------------------------------------------------------------
*& Report ZBAPI_CREATE_PO *
*& *&---------------------------------------------------------------------REPORT ZBAPI_CREATE_PO .&---------------------------------------------------------------------
*DATA DECLARATIONCONSTANTS: C_X VALUE'X'.
*Structures to hold PO header dataDATA:HEADERLIKE BAPIMEPOHEADER ,
HEADERX LIKE BAPIMEPOHEADERX .
*Internal Tables to hold PO ITEM DATADATA: ITEM LIKE BAPIMEPOITEM OCCURS0WITHHEADERLINE,
ITEMX LIKE BAPIMEPOITEMX OCCURS0WITHHEADERLINE,
**Internal table to hold messages from BAPI callRETURNLIKE BAPIRET2 OCCURS0WITHHEADERLINE.data: w_header(40)value'PO Header'.data: ws_langu likesy-langu.data: V_EXPPURCHASEORDER like BAPIMEPOHEADER-PO_NUMBER.
*text-001 = 'PO Header' - define as text elementselection-screenbeginofblock b1 withframetitletext-001.parameters: company likeheader-comp_code default'1000',
doctyp likeHEADER-DOC_TYPE default'NB',
cdate likeHEADER-CREAT_DATE defaultsy-datum ,
vendor likeHEADER-VENDOR default'RAJ',
pur_org likeHEADER-PURCH_ORG default'0001',
pur_grp likeHEADER-PUR_GROUP default'001'.selection-screenendofblock b1.selection-screenbeginofblock b2 withframetitletext-002.parameters: item_num like ITEM-PO_ITEM default'00020',
material like ITEM-MATERIAL default'M-127',
plant like ITEM-PLANT default'0001',
quantity like ITEM-QUANTITY default200.selection-screenendofblock b2.
*&---------------------------------------------------------------------
**START-OF-SELECTION.
*&---------------------------------------------------------------------
**DATA POPULATION
*&---------------------------------------------------------------------
ws_langu =sy-langu."Language variable
*POPULATE HEADER DATA FOR POHEADER-COMP_CODE = company .HEADER-DOC_TYPE = doctyp .HEADER-CREAT_DATE = cdate .HEADER-VENDOR = vendor .HEADER-LANGU = ws_langu .HEADER-PURCH_ORG = pur_org .HEADER-PUR_GROUP = pur_grp .&---------------------------------------------------------------------
*POPULATE HEADER FLAG.&---------------------------------------------------------------------
HEADERX-comp_code = c_x.
HEADERX-doc_type = c_x.
HEADERX-creat_date = c_x.
HEADERX-vendor = c_x.
HEADERX-langu = c_x.
HEADERX-purch_org = c_x.
HEADERX-pur_group = c_x.
*HEADERX-doc_date = c_x.&---------------------------------------------------------------------
*POPULATE ITEM DATA.&---------------------------------------------------------------------
ITEM-PO_ITEM = item_num.
ITEM-MATERIAL = material.
ITEM-PLANT = plant.
ITEM-QUANTITY = quantity.APPEND ITEM.&---------------------------------------------------------------------
*POPULATE ITEM FLAG TABLE&---------------------------------------------------------------------
ITEMX-PO_ITEM = item_num.
ITEMX-MATERIAL = C_X.
ITEMX-PLANT = C_X .
*ITEMX-STGE_LOC = C_X .
ITEMX-QUANTITY = C_X .
*ITEMX-TAX_CODE = C_X .
*ITEMX-ITEM_CAT = C_X .
*ITEMX-ACCTASSCAT = C_X .APPEND ITEMX.&---------------------------------------------------------------------
*BAPI CALL&---------------------------------------------------------------------CALLFUNCTION'BAPI_PO_CREATE1'EXPORTING
POHEADER =HEADER
POHEADERX = HEADERX

POADDRVENDOR = 
TESTRUN =IMPORTING
EXPPURCHASEORDER = V_EXPPURCHASEORDER

EXPHEADER = 
EXPPOEXPIMPHEADER =TABLESRETURN=RETURN
POITEM = ITEM
POITEMX = ITEMX.&---------------------------------------------------------------------
*Confirm the document creation by calling database COMMIT&---------------------------------------------------------------------CALLFUNCTION'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT='X'IMPORTINGRETURN=.end-of-selection.
****&---------------------------------------------------------------------*
****Output the messages returned from BAPI call
****&---------------------------------------------------------------------*
*LOOP AT RETURN.WRITE/ v_EXPPURCHASEORDER.
*ENDLOOP.
1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,927

For "Change" BAPIs, X flags are used to distinguish those two cases:

  • clear object field (set the X flag)
  • do not change object field (do not set the X flag)

For "Create" BAPIs, X flags are used to distinguish those two cases (that's a guess):

  • value " " for object field (set the X flag)
  • keep default value proposed by SAP (do not set the X flag)

(note: some fields may be required like key fields, not have a default value proposed by SAP, in that case it may not be needed to set the X flag explicitly ; expl: BAPI_SALESORDER_CREATEFROMDAT2, ORDER_HEADER_INX, even if DOC_TYPE, SALES_ORG... are not set, the corresponding fields in ORDER_HEADER_IN are considered)

Hi,

this bapi is well documented within SAP. Just go to se37, display and click Function Module Documentation button.

Kind regards, Rob Dielemans

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,928

For "Change" BAPIs, X flags are used to distinguish those two cases:

  • clear object field (set the X flag)
  • do not change object field (do not set the X flag)

For "Create" BAPIs, X flags are used to distinguish those two cases (that's a guess):

  • value " " for object field (set the X flag)
  • keep default value proposed by SAP (do not set the X flag)

(note: some fields may be required like key fields, not have a default value proposed by SAP, in that case it may not be needed to set the X flag explicitly ; expl: BAPI_SALESORDER_CREATEFROMDAT2, ORDER_HEADER_INX, even if DOC_TYPE, SALES_ORG... are not set, the corresponding fields in ORDER_HEADER_IN are considered)

Read only

matt
Active Contributor
1,927

...c_x = 'X'.

Not exactly the best constant definition I've seen. Could be worse I suppose, like

...c_x = 'Y'...

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,927

Did you try to read data element BAPIUPDATE documentaiton?

Read only

Nawanandana
Active Contributor
0 Likes
1,927

Hi,

If you need to change the value you should pass the X value . Ex:

If you need to update the company code

POHEADER-COMP_CODE = '1000'.

POHEADERX-COMP_CODE = 'X'.

If your not pass the parameter like 'X' , PO will not update the relevant field.

your C_X should be constant like

CONSTANTS : C_X TYPE C VALUE 'X'.
Read only

Former Member
0 Likes
1,927

Hi,

this bapi is well documented within SAP. Just go to se37, display and click Function Module Documentation button.

Kind regards, Rob Dielemans