Application Development 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: 

BAPI_DOCUMENT_CREATE2 Longtext N lines problem

glauco
Active Contributor
0 Kudos
452

Hi.

I'm using this BAPI_DOCUMENT_CREATE2 to create a CV01N document, when the user choose a PDF file to upload and put a text to justify its necessity.

The user can fill two or more lines.

But when I execute it filling 2 or 3 lines, the longtext has just one line in the created document when I enter CV03N to see it.

Follow an attached CV03N document showing only one line on description tab. 😕

FORM upload_anexo CHANGING p_documentnumber TYPE bapi_doc_aux-docnumber.


 DATA:
  "BAPI_DOCUMENT_CREATE2
 ls_documentdata LIKE bapi_doc_draw2,
 lt_documentfiles TYPE STANDARD TABLE OF bapi_doc_files2,
 ls_documentfiles LIKE LINE OF lt_documentfiles,
 lt_longtexts TYPE STANDARD TABLE OF bapi_doc_text,
 ls_longtexts LIKE LINE OF lt_longtexts,
 lv_documentnumber TYPE bapi_doc_aux-docnumber, 
 ls_return TYPE bapiret2.


 CLEAR p_documentnumber.


*--------------------------------------------------------------------*
 " obligate user to fill text to justify the bill.
*--------------------------------------------------------------------*
 CALL SCREEN 200.


 " Read user text writen on 0200 screen (editor box)
 " back from screen 0200
 IF g_mytable[] IS NOT INITIAL.
 FREE lt_longtexts.


 LOOP AT g_mytable INTO DATA(ls_mytable).
   CLEAR ls_longtexts.
*  ls_longtexts-deletevalue
   ls_longtexts-language = 'P'."sy-langu.
   ls_longtexts-language_iso = 'PT'."sy-langu.
   ls_longtexts-textline = ls_mytable-line.
   INSERT ls_longtexts INTO TABLE lt_longtexts.
 ENDLOOP.

 ELSE.
   MESSAGE s000(zsd) WITH 'Error, user did not fill text'
                     DISPLAY LIKE 'E'.
   RETURN.
 ENDIF.


*--------------------------------------------------------------------*
 " GET FILENAME
*--------------------------------------------------------------------*
 PERFORM ler_arquivo_comprovante.


 " READ filename
 READ TABLE ti_file INTO DATA(ls_file) INDEX 1.
 IF sy-subrc = 0.
   ls_documentfiles-documenttype = 'ZAV'."Generate unic name on the system 16 characteres

  TRY.
   ls_documentfiles-documentnumber = cl_system_uuid=>create_uuid_x16_static( ).

  CATCH cx_uuid_error. "
    MESSAGE s000(zsd) WITH 'Error'
    DISPLAY LIKE 'E'.
    RETURN.
  ENDTRY.


   ls_documentfiles-documentpart = '000'.
   ls_documentfiles-documentversion = '00'.
   ls_documentfiles-storagecategory = 'DMS_C1_ST'.
   ls_documentfiles-wsapplication = 'PDF'.
   ls_documentfiles-docfile = ls_file-filename.
   ls_documentfiles-description = 'Bill example'.
   ls_documentfiles-language = 'PT'.
   INSERT ls_documentfiles INTO TABLE lt_documentfiles.
 ENDIF.


 BREAK-POINT.
*--------------------------------------------------------------------*
 " CREATE DOCUMENT CV01N
*--------------------------------------------------------------------*
 ls_documentdata-documenttype = 'ZAV'.
 ls_documentdata-documentnumber = ls_documentfiles-documentnumber. " CHAR16 unic code
 ls_documentdata-documentversion = '00'.
 ls_documentdata-documentpart = '000'.
 ls_documentdata-description = 'Bill example'.
 ls_documentdata-username = sy-uname.
 ls_documentdata-statusintern = 'LB'. "released
 

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'
 EXPORTING
    documentdata = ls_documentdata
*   HOSTNAME =
*   DOCBOMCHANGENUMBER =
*   DOCBOMVALIDFROM =
*   DOCBOMREVISIONLEVEL =
*   CAD_MODE = ' '
*   PF_FTP_DEST = ' '
*   PF_HTTP_DEST = ' '
*   DEFAULTCLASS = 'X'
 IMPORTING
*   DOCUMENTTYPE =
    documentnumber = lv_documentnumber
*   DOCUMENTPART =
*   DOCUMENTVERSION =
    return = ls_return
 TABLES
*   CHARACTERISTICVALUES =
*   CLASSALLOCATIONS =
*   DOCUMENTDESCRIPTIONS =
*   OBJECTLINKS =
*   DOCUMENTSTRUCTURE =
    documentfiles = lt_documentfiles
    longtexts = lt_longtexts
*   COMPONENTS =cv01n-text-just-1-line-error.png
 .


 IF lv_documentnumber IS NOT INITIAL.
   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
      wait = 'X'.
     p_documentnumber = lv_documentnumber.
 ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    MESSAGE s000(zsd) WITH 'Error while creating doc'
                      DISPLAY LIKE 'E'.
    RETURN.
 ENDIF.


ENDFORM. " UPLOAD_ANEXO
4 REPLIES 4

former_member602690
Active Participant
125

Ola Glauco,

1. "use empty brackets after lt_longtexts

longtexts = lt_longtexts[]

2. "can use APPEND instead of INSERT

APPEND lt_longtexts TO lt_bapi_longtexts.

*

*example: standard include program LCDESKF13 uses BAPI to populate longtext

data: lt_longtexts like bapi_doc_text_keys occurs 0 with header line,

lt_bapi_longtexts like bapi_doc_text occurs 0 with header line.

* build internal table for Long text using structure BAPI_DOC_TEXT

* where-used list for BAPI to check usage

* fill table lt_bapi_longtexts clear: lt_bapi_longtexts.

loop at lt_longtexts where tab_index = wa_plm_document-index.

APPEND lt_longtexts TO lt_bapi_longtexts. "can use APPEND instead of INSERT

endloop.

* etc.

CALL FUNCTION 'BAPI_DOCUMENT_CREATE2'

EXPORTING

documentdata = l_doc_data

IMPORTING

documenttype = l_dokar

documentnumber = l_doknr

documentpart = l_doktl

documentversion = l_dokvr

return = l_return

TABLES

characteristicvalues = lt_char_val

classallocations = lt_class_alo

documentfiles = lt_files[]

longtexts = lt_longtexts[] "use empty brackets after lt_longtexts

documentdescriptions = lt_doc_desc[].

* etc.

* Boas Festas

References

https://answers.sap.com/questions/3053259/help-on-bapidocumentcreate2.html

https://www.abapforum.com/forum/viewtopic.php?t=1414

0 Kudos
125

Oi Joanna.


I'll try the brackets. But I've debugged and the 3 lines are already recognized inside the BAPI and the BAPI itself "lost" my two other lines during its own execution.
I'm guessing if is there a bug or another parameter I need to fill up together the lt_longtext. I think I need to dig more around it or debug it more.

The standard program example fills it up from another internal table format, but in the end the fields are the same like I'm alread filling it up.

The other link shows another function which creates files to folders, but in my case the customer uses just CV01N to upload the files.

Thank you for you quick anwser.

Boas festas pra você também 🙂

Sandra_Rossi
Active Contributor
0 Kudos
125

Are you sure CV01N let you enter more than 1 line for a given language?

glauco
Active Contributor
0 Kudos
125

good question. 😕
I will talk to the functional consultant and will give this answer here.