sap - abap 'sd_salesdocument_create'

2.2k views Asked by At

I am currently working on the creation of a custom program that calls for the f.m. 'sd_salesdocument_create'.

The program aim is to massively create a seles order via se38, starting from a .csv file filled with the details.

The program seems to work properly and the orders are created but when i try to write the sales document number (held in the salesdocument_ex field), the program prints 27 blank lines and then the message string.

I already tried using set blank lines off, nothing happened. One of my collegues solved the problem using skip to line and position commands, but I'd like to know if there is another way to do it, without forcing the output in that way.

Since I already tried to look up in the official sap website and did not find any clue on how to solve this problem, I am asking to you.

thank you in advance, I am copying the code below:

FORM BAPI .

  data: COUNTER1 TYPE N VALUE 0,
        COUNTER2 TYPE N VALUE 0,
        NUM_CLI like KNA1-KUNNR.

  SORT TESTATA BY N_ORDINE.

  LOOP AT TESTATA.
    AT NEW N_ORDINE.
      READ TABLE TESTATA INDEX 1.

      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT  = TESTATA-N_CLIENTE
        IMPORTING
          OUTPUT = TESTATA-N_CLIENTE.

      SELECT single KUNNR INTO NUM_CLI FROM KNA1
    WHERE KUNNR = TESTATA-N_CLIENTE.

      IF SY-SUBRC = 0.

        COUNTER1 = COUNTER1 + 1.

        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            INPUT  = TESTATA-N_DESTINATARIO
          IMPORTING
            OUTPUT = TESTATA-N_DESTINATARIO.

        SALES_HEADER_IN-DOC_TYPE     = TESTATA-TIPO_DOC.
        SALES_HEADER_IN-SALES_ORG    = 'ZCOM'.
        SALES_HEADER_IN-DISTR_CHAN   = '01'.
        SALES_HEADER_IN-DIVISION     = '01'.
        SALES_HEADER_IN-REQ_DATE_H   = testata-data_comsegna.
        SALES_HEADER_IN-PURCH_DATE   = testata-data_or_acq_cli.

        APPEND SALES_HEADER_IN.

*      COUNTER = 0.
        SORT CORPO BY N_ORDINE.
        LOOP AT CORPO WHERE N_ORDINE  = TESTATA-N_ORDINE.

          COUNTER = COUNTER + 10.

          SELECT SINGLE MATNR INTO MAT_COD FROM MARA WHERE EAN11 =
         CORPO-EAN_MAT.

          SALES_ITEMS_IN-ITM_NUMBER = COUNTER.
          SALES_ITEMS_IN-MATERIAL = MAT_COD.
          SALES_ITEMS_IN-PLANT = 'ZDIV'.
          SALES_ITEMS_IN-STORE_LOC =  'ZMAG'.

          APPEND SALES_ITEMS_IN.

          SALES_PARTNERS-PARTN_ROLE = 'AG'.
          SALES_PARTNERS-PARTN_NUMB = TESTATA-N_CLIENTE.
          APPEND SALES_PARTNERS.

          SALES_PARTNERS-PARTN_ROLE = 'WE'.
          SALES_PARTNERS-PARTN_NUMB = TESTATA-N_DESTINATARIO.
          APPEND SALES_PARTNERS.

          SALES_SCHEDULES_IN-ITM_NUMBER = COUNTER.
          SALES_SCHEDULES_IN-REQ_QTY = CORPO-QTA.
          APPEND SALES_SCHEDULES_IN.

          REPLACE ALL OCCURRENCES OF ',' IN CORPO-PREZZO WITH '.'.
          SALES_CONDITIONS_IN-ITM_NUMBER = COUNTER.
          SALES_CONDITIONS_IN-COND_TYPE = 'PR00'.
          SALES_CONDITIONS_IN-COND_VALUE = CORPO-PREZZO.
          SALES_CONDITIONS_IN-CURRENCY = TESTATA-VALUTA.
          APPEND SALES_CONDITIONS_IN.

        ENDLOOP.

        CLEAR COUNTER.

        PERFORM CALL_FUNCTION.

        COMMIT WORK AND WAIT.

        WRITE:/ 'COUNTER TESTATA', COUNTER1.
        WRITE:/ 'DOCUMENTO', SALESDOCUMENT_EX, 'SCRITTO'.

      ENDIF.

    ENDAT.

    CLEAR SALES_HEADER_IN.

    CLEAR SALES_PARTNERS.

    CLEAR SALES_ITEMS_IN.

    CLEAR SALES_SCHEDULES_IN.

    CLEAR SALES_CONDITIONS_IN.

    CLEAR NUM_CLI.

    LOOP AT RETURN.
      WRITE:/ RETURN-MESSAGE.
    ENDLOOP.

  ENDLOOP.

  CLEAR COUNTER1.

ENDFORM.                    " BAPI

 this is the bapi form in which is nested the call function:



 FORM CALL_FUNCTION .



CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'



     EXPORTING
*   SALESDOCUMENT                 = SALESDOCUMENT_EX
              SALES_HEADER_IN               = SALES_HEADER_IN
*
**   SALES_HEADER_INX              =
**   SENDER                        =
**   BINARY_RELATIONSHIPTYPE       = ' '
           INT_NUMBER_ASSIGNMENT         = 'X'
**   BEHAVE_WHEN_ERROR             = ' '
**   LOGIC_SWITCH                  = ' '
       BUSINESS_OBJECT               = 'BUS2032'
       TESTRUN                       = ' '

*   CONVERT_PARVW_AUART           = ' '
*   STATUS_BUFFER_REFRESH         = 'X'

           IMPORTING
             SALESDOCUMENT_EX       = SALESDOCUMENT_EX


*   SALES_HEADER_OUT              =
*   SALES_HEADER_STATUS           =

           TABLES
             RETURN                        = RETURN
             SALES_ITEMS_IN                = SALES_ITEMS_IN
*   SALES_ITEMS_INX               =
       SALES_PARTNERS                = SALES_PARTNERS
      SALES_SCHEDULES_IN            = SALES_SCHEDULES_IN
*   SALES_SCHEDULES_INX         =
      SALES_CONDITIONS_IN           =  SALES_CONDITIONS_IN
*   SALES_CONDITIONS_INX          =
*   SALES_CFGS_REF                =
*   SALES_CFGS_INST               =
*   SALES_CFGS_PART_OF            =
*   SALES_CFGS_VALUE              =
*   SALES_CFGS_BLOB               =
*   SALES_CFGS_VK                 =
*   SALES_CFGS_REFINST            =
*   SALES_CCARD                   =
*   SALES_TEXT                    = testi e liìni
*   SALES_KEYS                    =
*   SALES_CONTRACT_IN             =
*   SALES_CONTRACT_INX            =
*   EXTENSIONIN                   =
*   PARTNERADDRESSES              =
*   SALES_SCHED_CONF_IN           =
*   ITEMS_EX                      =
*   SCHEDULE_EX                   =
*   BUSINESS_EX                   =
*   INCOMPLETE_LOG                =
*   EXTENSIONEX                   =
*   CONDITIONS_EX                 =
*   PARTNERS_EX                   =
*   TEXTHEADERS_EX                =
*   TEXTLINES_EX                  =
*   BATCH_CHARC                   =
*   CAMPAIGN_ASGN                 =
*   CONDITIONS_KONV_EX            =
    .

ENDFORM.                    " CALL_FUNCTION
1

There are 1 answers

0
user1498318 On

I'm not sure what you mean by "skip to line and position commands". SALESDOCUMENT_EX is a field of type vbeln, and would contain the document number if the salsorder was created.

But are you sure an order is created? In the code you have posted the SALES_HEADER_INX and _inx structures for item/schedule line are not used. Even if this resultet in an order being created (which I don't think it would), it would not be according to your input values.