As many of you already know, BAPIs often use dual structure.
Data is collected in the first structure, and verified in the second structure. This verification is done by crossing out. This means that the field will be updated / created.
Example;
1 2 3 4 5 6 | mystrucute-myfield = 0.005. mystrucutex-myfield = 'X'. mystrucute-yourfield = 'Ali'. mystrucutex-yourfield = 'X'. mystrucute-ourfield = '0085066996'. mystrucutex-ourfield = ''. //Won't update. |
Receiving and verifying data can take hundreds of line. The data, from the database, is manually matched one by one BAPI structure, and xStructure is crossed out one by one.
Example BAPI (Just a part) |
Mapping functions provided by SAP can be used to fill BAPI structures similar to database tables.
These functions work with external-> internal or internal-> external logic.
For example; bapi_marc -> marc or marc-> bapi_marc. In this way you can easily fill a whole structure.
For example;
1 2 3 4 5 6 7 8 9 10 11 12 13 | Select Single * From mard Into ls_mard Where matnr = lv_matnr And lgort = lv_lgort. Check sy-subrc Is Initial. Call Function 'MAP2E_MARD_TO_BAPI_MARD' Exporting mard = ls_mard Changing bapi_mard = ls_bapi_mard. |
These functions may not always be pre-generated in the system, but can be generated using the BDBS transaction code.
However, SAP doesnt provides a function for dynamic crossing out. We can do this ourselves. My solution is as follows;
Local Interface:
Importing: iv_stname Type ddobjname
Changing: cv_structure ve cv_structurex
However, SAP doesnt provides a function for dynamic crossing out. We can do this ourselves. My solution is as follows;
Local Interface:
Importing: iv_stname Type ddobjname
Changing: cv_structure ve cv_structurex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | DATA lt_fields TYPE STANDARD TABLE OF x031l WITH HEADER LINE. FIELD-SYMBOLS: <st> TYPE ANY. FIELD-SYMBOLS: <stx> TYPE ANY. FIELD-SYMBOLS: <line> TYPE x031l. CALL FUNCTION 'DDIF_NAMETAB_GET' EXPORTING tabname = iv_stname TABLES x031l_tab = lt_fields EXCEPTIONS not_found = 1 OTHERS = 2. CHECK sy-subrc = 0. LOOP AT lt_fields ASSIGNING <line>. ASSIGN COMPONENT <line>-fieldname OF STRUCTURE cv_structurex TO <stx>. CHECK <stx> IS ASSIGNED. ASSIGN COMPONENT <line>-fieldname OF STRUCTURE cv_structure TO <st>. CHECK <st> IS ASSIGNED. IF <st> IS INITIAL. CLEAR <stx>. ELSE. <stx> = 'X'. ENDIF. ENDLOOP. ENDFUNCTION. |
An example for function call;
1 2 3 4 5 6 | CALL FUNCTION 'Z_XXXXXXXXXXXX' EXPORTING iv_stname = 'BAPI_MARD' CHANGING cv_structure = ls_bapi_mard cv_structurex = ls_bapi_mardx. |
If xStructure has a key field, which means its type is not char1, remember to fill it. I have not added this feature, dont know why :)
With these two functions, you can fill and validate hundreds of lines much faster!