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

Problem in creating ZBAPI

Former Member
0 Likes
621

Hi all,

I am creating a ZBAPI for Sales order creation. In which i am calling BAPI_SALESORDER_CREATEFROMDAT2 bapi.

In this BAPI i want to give only madatory fields of Sales order creation in IMPORT Parameters.

Thats why i created my own structure with same variables and data elements of structure which is an import parameter in Standard BAPI.

But its giving Run time Error for incompatible type and length of structure.

CODE

Here is Structure:


TYPES: BEGIN OF ty_x_struct1,
           DOC_TYPE   TYPE  AUART,
           SALES_ORG  TYPE  VKORG,
           DISTR_CHAN TYPE  VTWEG,
           DIVISION   TYPE  SPART,
           REQ_DATE_H TYPE  EDATU_VBAK,
           PMNTTRMS   TYPE  DZTERM ,
        END OF ty_x_struct1.

Here is Data Declaration:


DATA: x_struct1x    type ty_x_struct1x,
      x_struct1     TYPE ty_x_struct1.

Here is BAPI CALLING:


CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
      order_header_in     = x_struct1
      order_header_inx    = x_struct1x
    IMPORTING
      salesdocument       = vbeln
    TABLES
      return              = it_ret
      order_items_in      = it_item_in
      order_items_inx     = it_item_inx
      order_schedules_in  = it_schlines
      order_schedules_inx = it_schlinesx
      order_partners      = it_parnr.

Please Help. I will appriciate it.

Regards,

Sachin Bhatnagar.

Edited by: Alvaro Tejada Galindo on Jan 11, 2008 5:28 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
586

Hi Sachin,

When you are passing the import and export parameters to the BAPI BAPI_SALESORDER_CREATEFROMDAT2 ,you have to check if the variables you are passing are compatible with the structures of the BAPI.The structures of the of the import and export parameters will be present in the source code of the BAPI.Use the same structure for your variables also instaead of your own structure.

For IMPORTING,the structures in the BAPI_SALESORDER_CREATEFROMDAT2 can be found here,

Just go throught this once and you will understand it better.


*"     VALUE(SALESDOCUMENTIN) LIKE  BAPIVBELN-VBELN OPTIONAL
*"     VALUE(ORDER_HEADER_IN) LIKE  BAPISDHD1 STRUCTURE  BAPISDHD1
*"     VALUE(ORDER_HEADER_INX) LIKE  BAPISDHD1X STRUCTURE  BAPISDHD1X
*"       OPTIONAL
*"     VALUE(SENDER) LIKE  BAPI_SENDER STRUCTURE  BAPI_SENDER OPTIONAL
*"     VALUE(BINARY_RELATIONSHIPTYPE) LIKE  BAPIRELTYPE-RELTYPE
*"       OPTIONAL
*"     VALUE(INT_NUMBER_ASSIGNMENT) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(BEHAVE_WHEN_ERROR) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(LOGIC_SWITCH) LIKE  BAPISDLS STRUCTURE  BAPISDLS OPTIONAL
*"     VALUE(TESTRUN) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(CONVERT) LIKE  BAPIFLAG-BAPIFLAG DEFAULT SPACE
*"  EXPORTING
*"     VALUE(SALESDOCUMENT) LIKE  BAPIVBELN-VBELN
*"  TABLES
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      ORDER_ITEMS_IN STRUCTURE  BAPISDITM OPTIONAL
*"      ORDER_ITEMS_INX STRUCTURE  BAPISDITMX OPTIONAL
*"      ORDER_PARTNERS STRUCTURE  BAPIPARNR
*"      ORDER_SCHEDULES_IN STRUCTURE  BAPISCHDL OPTIONAL
*"      ORDER_SCHEDULES_INX STRUCTURE  BAPISCHDLX OPTIONAL
*"      ORDER_CONDITIONS_IN STRUCTURE  BAPICOND OPTIONAL
*"      ORDER_CONDITIONS_INX STRUCTURE  BAPICONDX OPTIONAL
*"      ORDER_CFGS_REF STRUCTURE  BAPICUCFG OPTIONAL
*"      ORDER_CFGS_INST STRUCTURE  BAPICUINS OPTIONAL
*"      ORDER_CFGS_PART_OF STRUCTURE  BAPICUPRT OPTIONAL
*"      ORDER_CFGS_VALUE STRUCTURE  BAPICUVAL OPTIONAL
*"      ORDER_CFGS_BLOB STRUCTURE  BAPICUBLB OPTIONAL
*"      ORDER_CFGS_VK STRUCTURE  BAPICUVK OPTIONAL
*"      ORDER_CFGS_REFINST STRUCTURE  BAPICUREF OPTIONAL
*"      ORDER_CCARD STRUCTURE  BAPICCARD OPTIONAL
*"      ORDER_TEXT STRUCTURE  BAPISDTEXT OPTIONAL
*"      ORDER_KEYS STRUCTURE  BAPISDKEY OPTIONAL
*"      EXTENSIONIN STRUCTURE  BAPIPAREX OPTIONAL
*"      PARTNERADDRESSES STRUCTURE  BAPIADDR1 OPTIONAL

In that way,you can avoid the run time error.

<REMOVED BY MODERATOR>

Regards,

Kashyap

Edited by: Alvaro Tejada Galindo on Jan 11, 2008 5:34 PM

3 REPLIES 3
Read only

Former Member
0 Likes
586

Hi,

Try this,

BAPISDHD1

BAPISDHD1X

Here is Structure:


TYPES: BEGIN OF ty_x_struct1,
DOC_TYPE TYPE AUART,
SALES_ORG TYPE VKORG,
DISTR_CHAN TYPE VTWEG,
DIVISION TYPE SPART,
REQ_DATE_H TYPE EDATU_VBAK,
PMNTTRMS TYPE DZTERM ,
END OF ty_x_struct1.

Here is Data Declaration:


DATA: x_struct1x type ty_x_struct1x,
x_struct1 TYPE ty_x_struct1.

data:x_struct2x type BAPISDHD1X,
       x_struct2 type BAPISDHD1.

Here is BAPI CALLING:


move-corresponding x_struct1x to x_struct2x.
move-corresponding x_struct1 to x_struct2. 
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = x_struct2
order_header_inx = x_struct2x
IMPORTING
salesdocument = vbeln
TABLES
return = it_ret
order_items_in = it_item_in
order_items_inx = it_item_inx
order_schedules_in = it_schlines
order_schedules_inx = it_schlinesx
order_partners = it_parnr.

Edited by: Alvaro Tejada Galindo on Jan 11, 2008 5:29 PM

Read only

Former Member
0 Likes
587

Hi Sachin,

When you are passing the import and export parameters to the BAPI BAPI_SALESORDER_CREATEFROMDAT2 ,you have to check if the variables you are passing are compatible with the structures of the BAPI.The structures of the of the import and export parameters will be present in the source code of the BAPI.Use the same structure for your variables also instaead of your own structure.

For IMPORTING,the structures in the BAPI_SALESORDER_CREATEFROMDAT2 can be found here,

Just go throught this once and you will understand it better.


*"     VALUE(SALESDOCUMENTIN) LIKE  BAPIVBELN-VBELN OPTIONAL
*"     VALUE(ORDER_HEADER_IN) LIKE  BAPISDHD1 STRUCTURE  BAPISDHD1
*"     VALUE(ORDER_HEADER_INX) LIKE  BAPISDHD1X STRUCTURE  BAPISDHD1X
*"       OPTIONAL
*"     VALUE(SENDER) LIKE  BAPI_SENDER STRUCTURE  BAPI_SENDER OPTIONAL
*"     VALUE(BINARY_RELATIONSHIPTYPE) LIKE  BAPIRELTYPE-RELTYPE
*"       OPTIONAL
*"     VALUE(INT_NUMBER_ASSIGNMENT) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(BEHAVE_WHEN_ERROR) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(LOGIC_SWITCH) LIKE  BAPISDLS STRUCTURE  BAPISDLS OPTIONAL
*"     VALUE(TESTRUN) LIKE  BAPIFLAG-BAPIFLAG OPTIONAL
*"     VALUE(CONVERT) LIKE  BAPIFLAG-BAPIFLAG DEFAULT SPACE
*"  EXPORTING
*"     VALUE(SALESDOCUMENT) LIKE  BAPIVBELN-VBELN
*"  TABLES
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      ORDER_ITEMS_IN STRUCTURE  BAPISDITM OPTIONAL
*"      ORDER_ITEMS_INX STRUCTURE  BAPISDITMX OPTIONAL
*"      ORDER_PARTNERS STRUCTURE  BAPIPARNR
*"      ORDER_SCHEDULES_IN STRUCTURE  BAPISCHDL OPTIONAL
*"      ORDER_SCHEDULES_INX STRUCTURE  BAPISCHDLX OPTIONAL
*"      ORDER_CONDITIONS_IN STRUCTURE  BAPICOND OPTIONAL
*"      ORDER_CONDITIONS_INX STRUCTURE  BAPICONDX OPTIONAL
*"      ORDER_CFGS_REF STRUCTURE  BAPICUCFG OPTIONAL
*"      ORDER_CFGS_INST STRUCTURE  BAPICUINS OPTIONAL
*"      ORDER_CFGS_PART_OF STRUCTURE  BAPICUPRT OPTIONAL
*"      ORDER_CFGS_VALUE STRUCTURE  BAPICUVAL OPTIONAL
*"      ORDER_CFGS_BLOB STRUCTURE  BAPICUBLB OPTIONAL
*"      ORDER_CFGS_VK STRUCTURE  BAPICUVK OPTIONAL
*"      ORDER_CFGS_REFINST STRUCTURE  BAPICUREF OPTIONAL
*"      ORDER_CCARD STRUCTURE  BAPICCARD OPTIONAL
*"      ORDER_TEXT STRUCTURE  BAPISDTEXT OPTIONAL
*"      ORDER_KEYS STRUCTURE  BAPISDKEY OPTIONAL
*"      EXTENSIONIN STRUCTURE  BAPIPAREX OPTIONAL
*"      PARTNERADDRESSES STRUCTURE  BAPIADDR1 OPTIONAL

In that way,you can avoid the run time error.

<REMOVED BY MODERATOR>

Regards,

Kashyap

Edited by: Alvaro Tejada Galindo on Jan 11, 2008 5:34 PM

Read only

Former Member
0 Likes
586

Hi all,

Thanks for your Inputs. My problem is solved.

Regards,

Sachin